Skip to content

Commit 6e38695

Browse files
konardclaude
andcommitted
Remove LoadOperationsFrom config setting and implement automatic calculation
The LoadOperationsFrom setting has been removed from configuration files and is now calculated automatically. The system uses the maximum of either the account open date or 30 days ago as the starting point for loading operations, preventing the need for manual updates that could cause errors. Changes: - Made LoadOperationsFrom nullable in TradingSettings - Removed LoadOperationsFrom from both appsettings files - Implemented automatic calculation logic in TradingService constructor - Updated README.md to remove documentation for the removed setting - Added informative logging for both configured and calculated values 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 8750f66 commit 6e38695

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed

csharp/TraderBot/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ Configuration is located in `appsettings.json` file.
7878
| `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. |
7979
| `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`). |
8080
| `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`). |
81-
| `TradingSettings`/`LoadOperationsFrom` | Minimum data and time to load operations from. |
8281

8382
## Current default trading time-frame
8483

csharp/TraderBot/TradingService.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ public TradingService(ILogger<TradingService> logger, InvestApiClient investApi,
6262
Logger.LogInformation($"MaximumTimeToBuy: {MaximumTimeToBuy}");
6363
Logger.LogInformation($"EarlySellOwnedLotsDelta: {settings.EarlySellOwnedLotsDelta}");
6464
Logger.LogInformation($"EarlySellOwnedLotsMultiplier: {settings.EarlySellOwnedLotsMultiplier}");
65-
Logger.LogInformation($"LoadOperationsFrom: {settings.LoadOperationsFrom}");
66-
6765
var currentTime = DateTime.UtcNow.TimeOfDay;
6866
Logger.LogInformation($"Current time: {currentTime}");
6967

@@ -111,7 +109,23 @@ public TradingService(ILogger<TradingService> logger, InvestApiClient investApi,
111109
ActiveSellOrders = new ConcurrentDictionary<string, OrderState>();
112110
LotsSets = new ConcurrentDictionary<decimal, long>();
113111
ActiveSellOrderSourcePrice = new ConcurrentDictionary<string, decimal>();
114-
LastOperationsCheckpoint = settings.LoadOperationsFrom;
112+
113+
// Calculate LoadOperationsFrom automatically if not provided
114+
DateTime calculatedLoadOperationsFrom;
115+
if (settings.LoadOperationsFrom.HasValue)
116+
{
117+
calculatedLoadOperationsFrom = settings.LoadOperationsFrom.Value;
118+
Logger.LogInformation($"LoadOperationsFrom (from config): {calculatedLoadOperationsFrom}");
119+
}
120+
else
121+
{
122+
// Use account open date or 30 days ago, whichever is more recent
123+
DateTime accountOpenDate = DateTime.SpecifyKind(CurrentAccount.OpenedDate.ToDateTime(), DateTimeKind.Utc);
124+
DateTime thirtyDaysAgo = DateTime.UtcNow.AddDays(-30);
125+
calculatedLoadOperationsFrom = new[] { accountOpenDate, thirtyDaysAgo }.Max();
126+
Logger.LogInformation($"LoadOperationsFrom (calculated automatically): {calculatedLoadOperationsFrom}");
127+
}
128+
LastOperationsCheckpoint = calculatedLoadOperationsFrom;
115129
}
116130

117131
protected async Task ReceiveTrades(CancellationToken cancellationToken)

csharp/TraderBot/TradingSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ public class TradingSettings
1616
public string? MaximumTimeToBuy { get; set; }
1717
public long EarlySellOwnedLotsDelta { get; set; }
1818
public decimal EarlySellOwnedLotsMultiplier { get; set; }
19-
public DateTime LoadOperationsFrom { get; set; }
19+
public DateTime? LoadOperationsFrom { get; set; }
2020
}

csharp/TraderBot/appsettings.TMON.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"MinimumTimeToBuy": "00:00:01",
2424
"MaximumTimeToBuy": "23:59:59",
2525
"EarlySellOwnedLotsDelta": 300000,
26-
"EarlySellOwnedLotsMultiplier": 0,
27-
"LoadOperationsFrom": "2025-03-01T00:00:01.3389860Z"
26+
"EarlySellOwnedLotsMultiplier": 0
2827
}
2928
}

csharp/TraderBot/appsettings.TRUR.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"MinimumTimeToBuy": "09:00:00",
2424
"MaximumTimeToBuy": "14:45:00",
2525
"EarlySellOwnedLotsDelta": 300000,
26-
"EarlySellOwnedLotsMultiplier": 0,
27-
"LoadOperationsFrom": "2025-03-01T00:00:01.3389860Z"
26+
"EarlySellOwnedLotsMultiplier": 0
2827
}
2928
}

0 commit comments

Comments
 (0)