diff --git a/csharp/TraderBot/README.md b/csharp/TraderBot/README.md index 352b8b97..138fea35 100644 --- a/csharp/TraderBot/README.md +++ b/csharp/TraderBot/README.md @@ -78,7 +78,6 @@ Configuration is located in `appsettings.json` file. | `TradingSettings`/`MinimumMarketOrderSizeToSell` | Minimum size of the market order to sell. The price will be not acceptable unless there is that much lots on the market at this price. | | `TradingSettings`/`EarlySellOwnedLotsDelta` | A constant component of the minimum number of lots that the market order placed at the buy price should have in order to trigger the immediate sell order. Complete formula: (`TradingSettings`/`EarlySellOwnedLotsDelta` + `TradingSettings`/`EarlySellOwnedLotsMultiplier` * `Lots requested to sell`). | | `TradingSettings`/`EarlySellOwnedLotsMultiplier` | A multiplier of lots requested to sell. A component of the minimum number of lots that the market order placed at the buy price should have in order to trigger the immediate sell order. Complete formula: (`TradingSettings`/`EarlySellOwnedLotsDelta` + `TradingSettings`/`EarlySellOwnedLotsMultiplier` * `Lots requested to sell`). | -| `TradingSettings`/`LoadOperationsFrom` | Minimum data and time to load operations from. | ## Current default trading time-frame diff --git a/csharp/TraderBot/TradingService.cs b/csharp/TraderBot/TradingService.cs index 0302809b..1dad0292 100644 --- a/csharp/TraderBot/TradingService.cs +++ b/csharp/TraderBot/TradingService.cs @@ -62,8 +62,6 @@ public TradingService(ILogger logger, InvestApiClient investApi, Logger.LogInformation($"MaximumTimeToBuy: {MaximumTimeToBuy}"); Logger.LogInformation($"EarlySellOwnedLotsDelta: {settings.EarlySellOwnedLotsDelta}"); Logger.LogInformation($"EarlySellOwnedLotsMultiplier: {settings.EarlySellOwnedLotsMultiplier}"); - Logger.LogInformation($"LoadOperationsFrom: {settings.LoadOperationsFrom}"); - var currentTime = DateTime.UtcNow.TimeOfDay; Logger.LogInformation($"Current time: {currentTime}"); @@ -111,7 +109,23 @@ public TradingService(ILogger logger, InvestApiClient investApi, ActiveSellOrders = new ConcurrentDictionary(); LotsSets = new ConcurrentDictionary(); ActiveSellOrderSourcePrice = new ConcurrentDictionary(); - LastOperationsCheckpoint = settings.LoadOperationsFrom; + + // Calculate LoadOperationsFrom automatically if not provided + DateTime calculatedLoadOperationsFrom; + if (settings.LoadOperationsFrom.HasValue) + { + calculatedLoadOperationsFrom = settings.LoadOperationsFrom.Value; + Logger.LogInformation($"LoadOperationsFrom (from config): {calculatedLoadOperationsFrom}"); + } + else + { + // Use account open date or 30 days ago, whichever is more recent + DateTime accountOpenDate = DateTime.SpecifyKind(CurrentAccount.OpenedDate.ToDateTime(), DateTimeKind.Utc); + DateTime thirtyDaysAgo = DateTime.UtcNow.AddDays(-30); + calculatedLoadOperationsFrom = new[] { accountOpenDate, thirtyDaysAgo }.Max(); + Logger.LogInformation($"LoadOperationsFrom (calculated automatically): {calculatedLoadOperationsFrom}"); + } + LastOperationsCheckpoint = calculatedLoadOperationsFrom; } protected async Task ReceiveTrades(CancellationToken cancellationToken) diff --git a/csharp/TraderBot/TradingSettings.cs b/csharp/TraderBot/TradingSettings.cs index 884a25df..624cdda0 100644 --- a/csharp/TraderBot/TradingSettings.cs +++ b/csharp/TraderBot/TradingSettings.cs @@ -16,5 +16,5 @@ public class TradingSettings public string? MaximumTimeToBuy { get; set; } public long EarlySellOwnedLotsDelta { get; set; } public decimal EarlySellOwnedLotsMultiplier { get; set; } - public DateTime LoadOperationsFrom { get; set; } + public DateTime? LoadOperationsFrom { get; set; } } \ No newline at end of file diff --git a/csharp/TraderBot/appsettings.TMON.json b/csharp/TraderBot/appsettings.TMON.json index c7b66d7a..5ada1dae 100644 --- a/csharp/TraderBot/appsettings.TMON.json +++ b/csharp/TraderBot/appsettings.TMON.json @@ -23,7 +23,6 @@ "MinimumTimeToBuy": "00:00:01", "MaximumTimeToBuy": "23:59:59", "EarlySellOwnedLotsDelta": 300000, - "EarlySellOwnedLotsMultiplier": 0, - "LoadOperationsFrom": "2025-03-01T00:00:01.3389860Z" + "EarlySellOwnedLotsMultiplier": 0 } } diff --git a/csharp/TraderBot/appsettings.TRUR.json b/csharp/TraderBot/appsettings.TRUR.json index 1dc848e6..e71c06c9 100644 --- a/csharp/TraderBot/appsettings.TRUR.json +++ b/csharp/TraderBot/appsettings.TRUR.json @@ -23,7 +23,6 @@ "MinimumTimeToBuy": "09:00:00", "MaximumTimeToBuy": "14:45:00", "EarlySellOwnedLotsDelta": 300000, - "EarlySellOwnedLotsMultiplier": 0, - "LoadOperationsFrom": "2025-03-01T00:00:01.3389860Z" + "EarlySellOwnedLotsMultiplier": 0 } }