Refactoring TradingBotBase.cs + clean architecture (#38)

* Refactoring TradingBotBase.cs + clean architecture

* Fix basic tests

* Fix tests

* Fix workers

* Fix open positions

* Fix closing position stucking the grain

* Fix comments

* Refactor candle handling to use IReadOnlyList for chronological order preservation across various components
This commit is contained in:
Oda
2025-12-01 19:32:06 +07:00
committed by GitHub
parent ab26260f6d
commit 9d536ea49e
74 changed files with 4525 additions and 2350 deletions

View File

@@ -121,26 +121,14 @@ namespace Managing.Infrastructure.Exchanges
reduceOnly: true);
}
public async Task<Trade> ClosePosition(Account account, Position position, decimal lastPrice,
bool isForPaperTrading = false)
public async Task<Trade> ClosePosition(Account account, Position position, decimal lastPrice)
{
var direction = position.OriginDirection == TradeDirection.Long
? TradeDirection.Short
: TradeDirection.Long;
if (isForPaperTrading)
{
var fake = BuildEmptyTrade(position.Open.Ticker,
lastPrice,
position.Open.Quantity,
direction,
position.Open.Leverage,
TradeType.Market,
position.Open.Date,
TradeStatus.Filled);
return fake;
}
// Paper trading logic has been moved to CloseBacktestFuturesPositionCommandHandler
// This method now only handles live trading
var processor = GetProcessor(account);
var closedTrade = await processor.OpenTrade(
account,