diff --git a/.gitignore b/.gitignore index 2bcb9a8..c4c704b 100644 --- a/.gitignore +++ b/.gitignore @@ -132,14 +132,3 @@ $RECYCLE.BIN/ .DS_Store _NCrunch* -/Bots/AleixBot/.vs -/Bots/ExampleTraderBot/.vs/ExampleTraderBot -/Source/.vs -/Build/NasdaqTrader.Bot.Core.dll -/Build/NasdaqTrader.CLI.dll -/Build/NasdaqTrader.CLI.exe -/Build/NasdaqTraderSystem.Core.dll -/Build/NasdaqTraderSystem.Html.dll -/Bots/AleixBot.Tests/AleixBot.Tests.csproj -/Bots/AleixBot.Tests/ListingPickerTests.cs -/Bots/AleixBot/Properties/launchSettings.json diff --git a/Bots/YurritBot/BuyCalculator.cs b/Bots/YurritBot/BuyCalculator.cs index c53f129..4b45945 100644 --- a/Bots/YurritBot/BuyCalculator.cs +++ b/Bots/YurritBot/BuyCalculator.cs @@ -2,7 +2,7 @@ public class BuyCalculator(int maximumBuyAmountPerStock) { - public int MaximumBuyAmountPerStock { get; private set; } = maximumBuyAmountPerStock; + private int maximumBuyAmountPerStock = maximumBuyAmountPerStock; public int CalculateMaximuumBuyAmount(decimal currentCash, decimal listingPrice) { diff --git a/Bots/YurritBot/Buyer.cs b/Bots/YurritBot/Buyer.cs deleted file mode 100644 index 1847e13..0000000 --- a/Bots/YurritBot/Buyer.cs +++ /dev/null @@ -1,54 +0,0 @@ -using NasdaqTrader.Bot.Core; -using System.Reflection; -using YurritBot.Logging; - -namespace YurritBot; - -class Buyer(ITraderBot traderBot, ITraderSystemContext systemContext, int indexToday, int indexReferenceDay, ILogger logger) : ITrader -{ - public ITraderBot TraderBot { get; private set; } = traderBot; - public ITraderSystemContext SystemContext { get; private set; } = systemContext; - public int IndexToday { get; private set; } = indexToday; - public int IndexReferenceDay { get; private set; } = indexReferenceDay; - public ILogger Logger { get; private set; } = logger; - - private const decimal cashlowerLimit = 100; - private const int maxBuyAmountPerStock = 1000; - - public void ExecuteStrategy() - { - var currentCash = SystemContext.GetCurrentCash(TraderBot); - var listingsByExpectedIncrease = SystemContext.GetListings() - .Where(listing => listing.PricePoints[IndexToday].Price <= currentCash) - .Where(listing => listing.PricePoints[IndexReferenceDay].Price / listing.PricePoints[IndexToday].Price > 1) - .OrderByDescending(listing => (listing.PricePoints[IndexReferenceDay].Price / listing.PricePoints[IndexToday].Price)); - - var buyCalculator = new BuyCalculator(maxBuyAmountPerStock); - - foreach (var listing in listingsByExpectedIncrease) - { - currentCash = SystemContext.GetCurrentCash(TraderBot); - if (SystemContext.GetTradesLeftForToday(TraderBot) <= 0 - || currentCash < cashlowerLimit) - { - return; - } - - var maxBuyAmount = buyCalculator.CalculateMaximuumBuyAmount(currentCash, listing.PricePoints[IndexToday].Price); - - if (maxBuyAmount < 1) - { - continue; - } - - var success = SystemContext.BuyStock(TraderBot, listing, maxBuyAmount); - - Logger.LogTransaction( - category: success ? "" : "ERR", - ticker: listing.Ticker, - currentCash: SystemContext.GetCurrentCash(TraderBot), - pricePoint: listing.PricePoints[IndexToday].Price, - amount: maxBuyAmount); - } - } -} diff --git a/Bots/YurritBot/ITrader.cs b/Bots/YurritBot/ITrader.cs deleted file mode 100644 index b90d4e4..0000000 --- a/Bots/YurritBot/ITrader.cs +++ /dev/null @@ -1,16 +0,0 @@ -using NasdaqTrader.Bot.Core; -using YurritBot.Logging; - -namespace YurritBot -{ - internal interface ITrader - { - int IndexToday { get; } - int IndexReferenceDay { get; } - ILogger Logger { get; } - ITraderBot TraderBot { get; } - ITraderSystemContext SystemContext { get; } - - void ExecuteStrategy(); - } -} \ No newline at end of file diff --git a/Bots/YurritBot/Logging/FileLogger.cs b/Bots/YurritBot/Logging/FileLogger.cs deleted file mode 100644 index 934f99c..0000000 --- a/Bots/YurritBot/Logging/FileLogger.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace YurritBot.Logging; - -public class FileLogger : ILogger -{ - public void Log(string text) - { - var logFilePath = Path.Combine(AppContext.BaseDirectory, "yurritbot_errors.log"); - File.AppendAllText(logFilePath, $"{text}{Environment.NewLine}"); - } - - public void LogTransaction(string category, string ticker, decimal currentCash, decimal pricePoint, int amount) - { - Log($"- {category} {currentCash:F2} | {ticker} {amount} @ {pricePoint:F2}"); - } -} diff --git a/Bots/YurritBot/Logging/HtmlLogger.cs b/Bots/YurritBot/Logging/HtmlLogger.cs new file mode 100644 index 0000000..e8adea9 --- /dev/null +++ b/Bots/YurritBot/Logging/HtmlLogger.cs @@ -0,0 +1,41 @@ +using static System.Net.Mime.MediaTypeNames; + +namespace YurritBot.Logging; + +public class HtmlLogger(string logFilePath) : ILogger +{ + private readonly string logFilePath = logFilePath; + + public void Log(string text) + { + File.AppendAllText(logFilePath, $"
{text}
{Environment.NewLine}"); + } + + public void LogTransaction(string category, string ticker, decimal currentCash, decimal pricePoint, int amount) + { + Log($"{category} | €{currentCash:F2} | {ticker} {amount} @ {pricePoint:F2}
"); + } + + public void LogHeader1(string text) + { + Log($"