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:
@@ -1,9 +1,9 @@
|
||||
using Managing.Application.Abstractions.Repositories;
|
||||
using Managing.Application.Abstractions.Services;
|
||||
using Managing.Core.FixedSizedQueue;
|
||||
using Managing.Domain.Accounts;
|
||||
using Managing.Domain.Bots;
|
||||
using Managing.Domain.Candles;
|
||||
using Managing.Domain.Indicators;
|
||||
using Managing.Domain.Scenarios;
|
||||
using Managing.Domain.Shared.Helpers;
|
||||
using Managing.Domain.Statistics;
|
||||
@@ -11,6 +11,7 @@ using Managing.Domain.Strategies;
|
||||
using Managing.Domain.Strategies.Base;
|
||||
using Managing.Domain.Synth.Models;
|
||||
using Managing.Domain.Trades;
|
||||
using Managing.Domain.Users;
|
||||
using Managing.Infrastructure.Evm.Models.Privy;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using static Managing.Common.Enums;
|
||||
@@ -56,12 +57,12 @@ public class TradingService : ITradingService
|
||||
await _tradingRepository.DeleteScenarioAsync(name);
|
||||
}
|
||||
|
||||
public async Task DeleteStrategyAsync(string name)
|
||||
public async Task DeleteIndicatorAsync(string name)
|
||||
{
|
||||
await _tradingRepository.DeleteIndicatorAsync(name);
|
||||
}
|
||||
|
||||
public async Task<Position> GetPositionByIdentifierAsync(string identifier)
|
||||
public async Task<Position> GetPositionByIdentifierAsync(Guid identifier)
|
||||
{
|
||||
return await _tradingRepository.GetPositionByIdentifierAsync(identifier);
|
||||
}
|
||||
@@ -87,12 +88,12 @@ public class TradingService : ITradingService
|
||||
return await _tradingRepository.GetScenariosAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Indicator>> GetStrategiesAsync()
|
||||
public async Task<IEnumerable<IndicatorBase>> GetIndicatorsAsync()
|
||||
{
|
||||
return await _tradingRepository.GetStrategiesAsync();
|
||||
}
|
||||
|
||||
public async Task<Indicator> GetStrategyByNameAsync(string strategy)
|
||||
public async Task<IndicatorBase> GetIndicatorByNameAsync(string strategy)
|
||||
{
|
||||
return await _tradingRepository.GetStrategyByNameAsync(strategy);
|
||||
}
|
||||
@@ -107,9 +108,9 @@ public class TradingService : ITradingService
|
||||
await _tradingRepository.InsertScenarioAsync(scenario);
|
||||
}
|
||||
|
||||
public async Task InsertStrategyAsync(Indicator indicator)
|
||||
public async Task InsertIndicatorAsync(IndicatorBase indicatorBase)
|
||||
{
|
||||
await _tradingRepository.InsertStrategyAsync(indicator);
|
||||
await _tradingRepository.InsertIndicatorAsync(indicatorBase);
|
||||
}
|
||||
|
||||
public async Task<Position> ManagePosition(Account account, Position position)
|
||||
@@ -170,7 +171,6 @@ public class TradingService : ITradingService
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task UpdatePositionAsync(Position position)
|
||||
{
|
||||
await _tradingRepository.UpdatePositionAsync(position);
|
||||
@@ -235,9 +235,9 @@ public class TradingService : ITradingService
|
||||
await _tradingRepository.UpdateScenarioAsync(scenario);
|
||||
}
|
||||
|
||||
public async Task UpdateStrategyAsync(Indicator indicator)
|
||||
public async Task UpdateIndicatorAsync(IndicatorBase indicatorBase)
|
||||
{
|
||||
await _tradingRepository.UpdateStrategyAsync(indicator);
|
||||
await _tradingRepository.UpdateStrategyAsync(indicatorBase);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Position>> GetBrokerPositions(Account account)
|
||||
@@ -372,7 +372,7 @@ public class TradingService : ITradingService
|
||||
}
|
||||
|
||||
public async Task<SynthRiskResult> MonitorSynthPositionRiskAsync(Ticker ticker, TradeDirection direction,
|
||||
decimal currentPrice, decimal liquidationPrice, string positionIdentifier, TradingBotConfig botConfig)
|
||||
decimal currentPrice, decimal liquidationPrice, Guid positionIdentifier, TradingBotConfig botConfig)
|
||||
{
|
||||
return await _synthPredictionService.MonitorPositionRiskAsync(ticker, direction, currentPrice, liquidationPrice,
|
||||
positionIdentifier, botConfig);
|
||||
@@ -386,7 +386,7 @@ public class TradingService : ITradingService
|
||||
/// <returns>A dictionary of indicator types to their calculated values.</returns>
|
||||
public Dictionary<IndicatorType, IndicatorsResultBase> CalculateIndicatorsValuesAsync(
|
||||
Scenario scenario,
|
||||
List<Candle> candles)
|
||||
HashSet<Candle> candles)
|
||||
{
|
||||
var indicatorsValues = new Dictionary<IndicatorType, IndicatorsResultBase>();
|
||||
|
||||
@@ -395,27 +395,15 @@ public class TradingService : ITradingService
|
||||
return indicatorsValues;
|
||||
}
|
||||
|
||||
// Convert candles to FixedSizeQueue for indicators
|
||||
var fixedCandles = new FixedSizeQueue<Candle>(10000);
|
||||
foreach (var candle in candles)
|
||||
{
|
||||
fixedCandles.Enqueue(candle);
|
||||
}
|
||||
|
||||
// Build indicators from scenario
|
||||
foreach (var indicator in scenario.Indicators)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Build the indicator using ScenarioHelpers
|
||||
var builtIndicator = ScenarioHelpers.BuildIndicator(indicator, 10000);
|
||||
builtIndicator.Candles = fixedCandles;
|
||||
|
||||
indicatorsValues[indicator.Type] = builtIndicator.GetIndicatorValues();
|
||||
indicatorsValues[indicator.Type] = indicator.GetIndicatorValues(candles);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Log the error but continue with other indicators
|
||||
_logger.LogError(ex, "Error calculating indicator {IndicatorName}: {ErrorMessage}",
|
||||
indicator.Name, ex.Message);
|
||||
}
|
||||
@@ -423,4 +411,14 @@ public class TradingService : ITradingService
|
||||
|
||||
return indicatorsValues;
|
||||
}
|
||||
|
||||
public async Task<IndicatorBase?> GetIndicatorByNameUserAsync(string name, User user)
|
||||
{
|
||||
return await _tradingRepository.GetStrategyByNameUserAsync(name, user);
|
||||
}
|
||||
|
||||
public async Task<Scenario?> GetScenarioByNameUserAsync(string scenarioName, User user)
|
||||
{
|
||||
return await _tradingRepository.GetScenarioByNameUserAsync(scenarioName, user);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user