Trading bot grain (#33)

* Trading bot Grain

* Fix a bit more of the trading bot

* Advance on the tradingbot grain

* Fix build

* Fix db script

* Fix user login

* Fix a bit backtest

* Fix cooldown and backtest

* start fixing bot start

* Fix startup

* Setup local db

* Fix build and update candles and scenario

* Add bot registry

* Add reminder

* Updateing the grains

* fix bootstraping

* Save stats on tick

* Save bot data every tick

* Fix serialization

* fix save bot stats

* Fix get candles

* use dict instead of list for position

* Switch hashset to dict

* Fix a bit

* Fix bot launch and bot view

* add migrations

* Remove the tolist

* Add agent grain

* Save agent summary

* clean

* Add save bot

* Update get bots

* Add get bots

* Fix stop/restart

* fix Update config

* Update scanner table on new backtest saved

* Fix backtestRowDetails.tsx

* Fix agentIndex

* Update agentIndex

* Fix more things

* Update user cache

* Fix

* Fix account load/start/restart/run
This commit is contained in:
Oda
2025-08-04 23:07:06 +02:00
committed by GitHub
parent cd378587aa
commit 082ae8714b
215 changed files with 9562 additions and 14028 deletions

View File

@@ -33,7 +33,7 @@ public interface IExchangeProcessor
Task<List<Trade>> GetTrades(Account account, Ticker ticker);
Task<bool> CancelOrder(Account account, Ticker ticker);
decimal GetFee(Account account, bool isForPaperTrading = false);
Candle GetCandle(Account account, Ticker ticker, DateTime date);
Task<Candle> GetCandle(Account account, Ticker ticker, DateTime date);
Task<decimal> GetQuantityInPosition(Account account, Ticker ticker);
Orderbook GetOrderbook(Account account, Ticker ticker);
Task<List<Trade>> GetOrders(Account account, Ticker ticker);

View File

@@ -200,7 +200,8 @@ namespace Managing.Infrastructure.Exchanges
return await processor.GetTrades(account, ticker);
}
public async Task<List<Candle>> GetCandles(Account account, Ticker ticker, DateTime startDate, Timeframe timeframe, bool isFirstCall)
public async Task<List<Candle>> GetCandles(Account account, Ticker ticker, DateTime startDate,
Timeframe timeframe, bool isFirstCall)
{
var processor = GetProcessor(account);
// Only EvmProcessor supports isFirstCall
@@ -208,22 +209,26 @@ namespace Managing.Infrastructure.Exchanges
{
return await evmProcessor.GetCandles(account, ticker, startDate, timeframe, isFirstCall);
}
// Fallback to default behavior for other processors
return await processor.GetCandles(account, ticker, startDate, timeframe);
}
public async Task<List<Candle>> GetCandlesInflux(TradingExchanges exchange, Ticker ticker, DateTime startDate,
Timeframe timeframe)
public async Task<HashSet<Candle>> GetCandlesInflux(TradingExchanges exchange, Ticker ticker,
DateTime startDate,
Timeframe timeframe, int? limit = null)
{
var candlesFromRepo = await _candleRepository.GetCandles(exchange, ticker, timeframe, startDate);
return candlesFromRepo.ToList();
var candlesFromRepo = await _candleRepository.GetCandles(exchange, ticker, timeframe, startDate, limit);
return candlesFromRepo;
}
public async Task<List<Candle>> GetCandlesInflux(TradingExchanges exchange, Ticker ticker, DateTime startDate,
Timeframe timeframe, DateTime endDate)
public async Task<HashSet<Candle>> GetCandlesInflux(TradingExchanges exchange, Ticker ticker,
DateTime startDate,
Timeframe timeframe, DateTime endDate, int? limit = null)
{
var candlesFromRepo = await _candleRepository.GetCandles(exchange, ticker, timeframe, startDate, endDate);
return candlesFromRepo.ToList();
var candlesFromRepo =
await _candleRepository.GetCandles(exchange, ticker, timeframe, startDate, endDate, limit);
return candlesFromRepo;
}
public async Task<decimal> GetBalance(Account account, bool isForPaperTrading = false)
@@ -249,10 +254,10 @@ namespace Managing.Infrastructure.Exchanges
return await processor.GetPrice(account, ticker, date);
}
public Candle GetCandle(Account account, Ticker ticker, DateTime date)
public async Task<Candle> GetCandle(Account account, Ticker ticker, DateTime date)
{
var processor = GetProcessor(account);
return processor.GetCandle(account, ticker, date);
return await processor.GetCandle(account, ticker, date);
}
public async Task<decimal> GetQuantityInPosition(Account account, Ticker ticker)

View File

@@ -13,7 +13,7 @@ namespace Managing.Infrastructure.Exchanges.Exchanges
public abstract Task<bool> CancelOrder(Account account, Ticker ticker);
public abstract TradingExchanges Exchange();
public abstract Task<decimal> GetBalance(Account account, bool isForPaperTrading = false);
public abstract Candle GetCandle(Account account, Ticker ticker, DateTime date);
public abstract Task<Candle> GetCandle(Account account, Ticker ticker, DateTime date);
public abstract Task<List<Candle>> GetCandles(Account account, Ticker ticker, DateTime startDate, Timeframe interval);
public abstract decimal GetFee(Account account, bool isForPaperTrading = false);
public abstract Task<decimal> GetPrice(Account account, Ticker ticker, DateTime date);

View File

@@ -62,9 +62,9 @@ public class EvmProcessor : BaseProcessor
});
}
public override Candle GetCandle(Account account, Ticker ticker, DateTime date)
public override async Task<Candle> GetCandle(Account account, Ticker ticker, DateTime date)
{
return _evmManager.GetCandle(ticker).Result;
return await _evmManager.GetCandle(ticker);
}
public override async Task<List<Candle>> GetCandles(Account account, Ticker ticker, DateTime startDate,