Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion csharp/TraderBot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 17 additions & 3 deletions csharp/TraderBot/TradingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public TradingService(ILogger<TradingService> 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}");

Expand Down Expand Up @@ -111,7 +109,23 @@ public TradingService(ILogger<TradingService> logger, InvestApiClient investApi,
ActiveSellOrders = new ConcurrentDictionary<string, OrderState>();
LotsSets = new ConcurrentDictionary<decimal, long>();
ActiveSellOrderSourcePrice = new ConcurrentDictionary<string, decimal>();
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)
Expand Down
2 changes: 1 addition & 1 deletion csharp/TraderBot/TradingSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
3 changes: 1 addition & 2 deletions csharp/TraderBot/appsettings.TMON.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
3 changes: 1 addition & 2 deletions csharp/TraderBot/appsettings.TRUR.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Loading