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:
@@ -0,0 +1,55 @@
|
||||
using Orleans;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Application.Abstractions.Grains;
|
||||
|
||||
/// <summary>
|
||||
/// A small serializable class to store bot metadata.
|
||||
/// This is a very lean object, perfect for fast storage and retrieval.
|
||||
/// </summary>
|
||||
[GenerateSerializer]
|
||||
public class BotRegistryEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// The unique identifier of the bot
|
||||
/// </summary>
|
||||
[Id(0)]
|
||||
public Guid Identifier { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The unique identifier of the user who owns the bot
|
||||
/// </summary>
|
||||
[Id(1)]
|
||||
public int UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The current operational status of the bot
|
||||
/// </summary>
|
||||
[Id(2)]
|
||||
public BotStatus Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// When the bot was registered in the registry
|
||||
/// </summary>
|
||||
[Id(3)]
|
||||
public DateTime RegisteredAt { get; set; } = DateTime.UtcNow;
|
||||
|
||||
/// <summary>
|
||||
/// When the bot status was last updated
|
||||
/// </summary>
|
||||
[Id(4)]
|
||||
public DateTime LastStatusUpdate { get; set; } = DateTime.UtcNow;
|
||||
|
||||
public BotRegistryEntry()
|
||||
{
|
||||
}
|
||||
|
||||
public BotRegistryEntry(Guid identifier, int userId, BotStatus status = BotStatus.None)
|
||||
{
|
||||
Identifier = identifier;
|
||||
UserId = userId;
|
||||
Status = status;
|
||||
RegisteredAt = DateTime.UtcNow;
|
||||
LastStatusUpdate = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using Orleans;
|
||||
|
||||
namespace Managing.Application.Abstractions.Grains;
|
||||
|
||||
/// <summary>
|
||||
/// Orleans grain state for BotRegistry.
|
||||
/// This class represents the persistent state of the bot registry grain.
|
||||
/// All properties must be serializable for Orleans state management.
|
||||
/// </summary>
|
||||
[GenerateSerializer]
|
||||
public class BotRegistryState
|
||||
{
|
||||
/// <summary>
|
||||
/// Dictionary containing all registered bots. The key is the identifier.
|
||||
/// </summary>
|
||||
[Id(0)]
|
||||
public Dictionary<Guid, BotRegistryEntry> Bots { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// When the registry was last updated
|
||||
/// </summary>
|
||||
[Id(1)]
|
||||
public DateTime LastUpdated { get; set; } = DateTime.UtcNow;
|
||||
|
||||
/// <summary>
|
||||
/// Total number of bots currently registered
|
||||
/// </summary>
|
||||
[Id(2)]
|
||||
public int TotalBotsCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of active bots (status = Up)
|
||||
/// </summary>
|
||||
[Id(3)]
|
||||
public int ActiveBotsCount { get; set; }
|
||||
}
|
||||
@@ -23,23 +23,5 @@ public interface IBacktestTradingBotGrain : IGrainWithGuidKey
|
||||
/// <param name="requestId">The request ID to associate with this backtest</param>
|
||||
/// <param name="metadata">Additional metadata to associate with this backtest</param>
|
||||
/// <returns>The complete backtest result</returns>
|
||||
Task<LightBacktest> RunBacktestAsync(TradingBotConfig config, List<Candle> candles, User user = null, bool save = false, bool withCandles = false, string requestId = null, object metadata = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current backtest progress
|
||||
/// </summary>
|
||||
/// <returns>Backtest progress information</returns>
|
||||
Task<BacktestProgress> GetBacktestProgressAsync();
|
||||
Task<LightBacktest> RunBacktestAsync(TradingBotConfig config, HashSet<Candle> candles, User user = null, bool save = false, bool withCandles = false, string requestId = null, object metadata = null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents the progress of a backtest
|
||||
/// </summary>
|
||||
public class BacktestProgress
|
||||
{
|
||||
public bool IsInitialized { get; set; }
|
||||
public int TotalCandles { get; set; }
|
||||
public int ProcessedCandles { get; set; }
|
||||
public double ProgressPercentage { get; set; }
|
||||
public bool IsComplete { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using Orleans;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Application.Abstractions.Grains;
|
||||
|
||||
/// <summary>
|
||||
/// Orleans grain interface for LiveBotRegistry operations.
|
||||
/// This interface defines the distributed, async operations available for the bot registry.
|
||||
/// The registry acts as a central, durable directory for all LiveTradingBot grains.
|
||||
/// </summary>
|
||||
public interface ILiveBotRegistryGrain : IGrainWithIntegerKey
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers a new bot with its user ID. This should be called by the LiveTradingBotGrain when it is first initialized.
|
||||
/// The initial status will be BotStatus.Up.
|
||||
/// </summary>
|
||||
/// <param name="identifier">The unique identifier of the bot</param>
|
||||
/// <param name="userId">The unique identifier of the user who owns the bot</param>
|
||||
/// <returns>A task that represents the asynchronous operation</returns>
|
||||
Task RegisterBot(Guid identifier, int userId);
|
||||
|
||||
/// <summary>
|
||||
/// Removes a bot from the registry. This should be a full removal, perhaps called when a user permanently deletes a bot.
|
||||
/// </summary>
|
||||
/// <param name="identifier">The unique identifier of the bot to unregister</param>
|
||||
/// <returns>A task that represents the asynchronous operation</returns>
|
||||
Task UnregisterBot(Guid identifier);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of all bots in the registry. This is for a management dashboard to see all bots in the system.
|
||||
/// </summary>
|
||||
/// <returns>A list of all BotRegistryEntry objects in the registry</returns>
|
||||
Task<List<BotRegistryEntry>> GetAllBots();
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of all bots associated with a specific user. This is the primary method for a user's watchlist.
|
||||
/// </summary>
|
||||
/// <param name="userId">The unique identifier of the user</param>
|
||||
/// <returns>A list of BotRegistryEntry objects for the specified user</returns>
|
||||
Task<List<BotRegistryEntry>> GetBotsForUser(int userId);
|
||||
|
||||
/// <summary>
|
||||
/// A dedicated method for updating only the bot's Status field (Up/Down).
|
||||
/// This will be called by LiveTradingBot's StartAsync and StopAsync methods.
|
||||
/// </summary>
|
||||
/// <param name="identifier">The unique identifier of the bot</param>
|
||||
/// <param name="status">The new status to set for the bot</param>
|
||||
/// <returns>A task that represents the asynchronous operation</returns>
|
||||
Task UpdateBotStatus(Guid identifier, BotStatus status);
|
||||
Task<BotStatus> GetBotStatus(Guid identifier);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using Managing.Application.Abstractions.Models;
|
||||
using Managing.Domain.Accounts;
|
||||
using Managing.Domain.Bots;
|
||||
using Managing.Domain.Trades;
|
||||
using Managing.Domain.Users;
|
||||
using Orleans;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Application.Abstractions.Grains;
|
||||
|
||||
/// <summary>
|
||||
/// Orleans grain interface for TradingBot operations.
|
||||
/// This interface defines the distributed, async operations available for trading bots.
|
||||
/// </summary>
|
||||
public interface ILiveTradingBotGrain : IGrainWithGuidKey
|
||||
{
|
||||
/// <summary>
|
||||
/// Manually opens a position in the specified direction
|
||||
/// </summary>
|
||||
/// <param name="direction">The direction of the trade (Long/Short)</param>
|
||||
/// <returns>The created Position object</returns>
|
||||
Task<Position> OpenPositionManuallyAsync(TradeDirection direction);
|
||||
|
||||
/// <summary>
|
||||
/// Gets comprehensive bot data including positions, signals, and performance metrics
|
||||
/// </summary>
|
||||
Task<TradingBotResponse> GetBotDataAsync();
|
||||
|
||||
Task CreateAsync(TradingBotConfig config, User user);
|
||||
Task StartAsync();
|
||||
Task StopAsync();
|
||||
|
||||
Task<bool> UpdateConfiguration(TradingBotConfig newConfig);
|
||||
Task<Account> GetAccount();
|
||||
Task<TradingBotConfig> GetConfiguration();
|
||||
Task<Position> ClosePositionAsync(Guid positionId);
|
||||
Task RestartAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the bot and cleans up all associated resources
|
||||
/// </summary>
|
||||
Task DeleteAsync();
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
using Managing.Application.Abstractions.Models;
|
||||
using Managing.Domain.Bots;
|
||||
using Managing.Domain.Trades;
|
||||
using Orleans;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Application.Abstractions.Grains;
|
||||
|
||||
/// <summary>
|
||||
/// Orleans grain interface for TradingBot operations.
|
||||
/// This interface defines the distributed, async operations available for trading bots.
|
||||
/// </summary>
|
||||
public interface ITradingBotGrain : IGrainWithGuidKey
|
||||
{
|
||||
/// <summary>
|
||||
/// Starts the trading bot asynchronously
|
||||
/// </summary>
|
||||
Task StartAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Stops the trading bot asynchronously
|
||||
/// </summary>
|
||||
Task StopAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current status of the trading bot
|
||||
/// </summary>
|
||||
Task<BotStatus> GetStatusAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current configuration of the trading bot
|
||||
/// </summary>
|
||||
Task<TradingBotConfig> GetConfigurationAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Updates the trading bot configuration
|
||||
/// </summary>
|
||||
/// <param name="newConfig">The new configuration to apply</param>
|
||||
/// <returns>True if the configuration was successfully updated</returns>
|
||||
Task<bool> UpdateConfigurationAsync(TradingBotConfig newConfig);
|
||||
|
||||
/// <summary>
|
||||
/// Manually opens a position in the specified direction
|
||||
/// </summary>
|
||||
/// <param name="direction">The direction of the trade (Long/Short)</param>
|
||||
/// <returns>The created Position object</returns>
|
||||
Task<Position> OpenPositionManuallyAsync(TradeDirection direction);
|
||||
|
||||
/// <summary>
|
||||
/// Toggles the bot between watch-only and trading mode
|
||||
/// </summary>
|
||||
Task ToggleIsForWatchOnlyAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets comprehensive bot data including positions, signals, and performance metrics
|
||||
/// </summary>
|
||||
Task<TradingBotResponse> GetBotDataAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Loads a bot backup into the grain state
|
||||
/// </summary>
|
||||
/// <param name="backup">The bot backup to load</param>
|
||||
Task LoadBackupAsync(BotBackup backup);
|
||||
|
||||
/// <summary>
|
||||
/// Forces a backup save of the current bot state
|
||||
/// </summary>
|
||||
Task SaveBackupAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current profit and loss for the bot
|
||||
/// </summary>
|
||||
Task<decimal> GetProfitAndLossAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current win rate percentage for the bot
|
||||
/// </summary>
|
||||
Task<int> GetWinRateAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bot's execution count (number of Run cycles completed)
|
||||
/// </summary>
|
||||
Task<long> GetExecutionCountAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bot's startup time
|
||||
/// </summary>
|
||||
Task<DateTime> GetStartupTimeAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bot's creation date
|
||||
/// </summary>
|
||||
Task<DateTime> GetCreateDateAsync();
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Managing.Domain.Bots;
|
||||
using Managing.Domain.Indicators;
|
||||
using Managing.Domain.Trades;
|
||||
using Orleans;
|
||||
using static Managing.Common.Enums;
|
||||
@@ -16,7 +17,7 @@ public class TradingBotResponse
|
||||
/// Bot identifier
|
||||
/// </summary>
|
||||
[Id(0)]
|
||||
public string Identifier { get; set; } = string.Empty;
|
||||
public Guid Identifier { get; set; } = Guid.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Bot display name
|
||||
@@ -37,16 +38,16 @@ public class TradingBotResponse
|
||||
public TradingBotConfig Config { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Trading positions
|
||||
/// Trading positions dictionary, keyed by position identifier
|
||||
/// </summary>
|
||||
[Id(4)]
|
||||
public List<Position> Positions { get; set; } = new();
|
||||
public Dictionary<Guid, Position> Positions { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Trading signals
|
||||
/// Trading signals dictionary, keyed by signal identifier
|
||||
/// </summary>
|
||||
[Id(5)]
|
||||
public List<LightSignal> Signals { get; set; } = new();
|
||||
public Dictionary<string, LightSignal> Signals { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Wallet balance history
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using Managing.Domain.Statistics;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Application.Abstractions.Repositories;
|
||||
|
||||
public interface IAgentSummaryRepository
|
||||
{
|
||||
Task<AgentSummary?> GetByUserIdAsync(int userId);
|
||||
Task<AgentSummary?> GetByAgentNameAsync(string agentName);
|
||||
Task<IEnumerable<AgentSummary>> GetAllAsync();
|
||||
Task InsertAsync(AgentSummary agentSummary);
|
||||
Task UpdateAsync(AgentSummary agentSummary);
|
||||
Task SaveOrUpdateAsync(AgentSummary agentSummary);
|
||||
|
||||
/// <summary>
|
||||
/// Gets paginated agent summaries with sorting and filtering
|
||||
/// </summary>
|
||||
/// <param name="page">Page number (1-based)</param>
|
||||
/// <param name="pageSize">Number of items per page</param>
|
||||
/// <param name="sortBy">Field to sort by</param>
|
||||
/// <param name="sortOrder">Sort order (asc or desc)</param>
|
||||
/// <param name="agentNames">Optional list of agent names to filter by</param>
|
||||
/// <returns>Tuple containing the paginated results and total count</returns>
|
||||
Task<(IEnumerable<AgentSummary> Results, int TotalCount)> GetPaginatedAsync(
|
||||
int page,
|
||||
int pageSize,
|
||||
SortableFields sortBy,
|
||||
string sortOrder,
|
||||
IEnumerable<string>? agentNames = null);
|
||||
}
|
||||
@@ -1,12 +1,40 @@
|
||||
using Managing.Domain.Bots;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Application.Abstractions.Repositories;
|
||||
|
||||
public interface IBotRepository
|
||||
{
|
||||
Task InsertBotAsync(BotBackup bot);
|
||||
Task<IEnumerable<BotBackup>> GetBotsAsync();
|
||||
Task UpdateBackupBot(BotBackup bot);
|
||||
Task DeleteBotBackup(string botName);
|
||||
Task<BotBackup?> GetBotByIdentifierAsync(string identifier);
|
||||
Task InsertBotAsync(Bot bot);
|
||||
Task<IEnumerable<Bot>> GetBotsAsync();
|
||||
Task UpdateBot(Bot bot);
|
||||
Task DeleteBot(Guid identifier);
|
||||
Task<Bot> GetBotByIdentifierAsync(Guid identifier);
|
||||
Task<IEnumerable<Bot>> GetBotsByIdsAsync(IEnumerable<Guid> identifiers);
|
||||
Task<IEnumerable<Bot>> GetBotsByUserIdAsync(int id);
|
||||
Task<IEnumerable<Bot>> GetBotsByStatusAsync(BotStatus status);
|
||||
Task<Bot> GetBotByNameAsync(string name);
|
||||
|
||||
/// <summary>
|
||||
/// Gets paginated bots with filtering and sorting
|
||||
/// </summary>
|
||||
/// <param name="pageNumber">Page number (1-based)</param>
|
||||
/// <param name="pageSize">Number of items per page</param>
|
||||
/// <param name="status">Filter by status (optional)</param>
|
||||
/// <param name="userId">Filter by user ID (optional)</param>
|
||||
/// <param name="name">Filter by name (partial match, case-insensitive)</param>
|
||||
/// <param name="ticker">Filter by ticker (partial match, case-insensitive)</param>
|
||||
/// <param name="agentName">Filter by agent name (partial match, case-insensitive)</param>
|
||||
/// <param name="sortBy">Sort field</param>
|
||||
/// <param name="sortDirection">Sort direction ("Asc" or "Desc")</param>
|
||||
/// <returns>Tuple containing the bots for the current page and total count</returns>
|
||||
Task<(IEnumerable<Bot> Bots, int TotalCount)> GetBotsPaginatedAsync(
|
||||
int pageNumber,
|
||||
int pageSize,
|
||||
BotStatus? status = null,
|
||||
string? name = null,
|
||||
string? ticker = null,
|
||||
string? agentName = null,
|
||||
string sortBy = "CreateDate",
|
||||
string sortDirection = "Desc");
|
||||
}
|
||||
@@ -5,18 +5,20 @@ namespace Managing.Application.Abstractions.Repositories;
|
||||
|
||||
public interface ICandleRepository
|
||||
{
|
||||
Task<IList<Candle>> GetCandles(
|
||||
Enums.TradingExchanges exchange,
|
||||
Enums.Ticker ticker,
|
||||
Enums.Timeframe timeframe,
|
||||
DateTime start);
|
||||
|
||||
Task<IList<Candle>> GetCandles(
|
||||
Task<HashSet<Candle>> GetCandles(
|
||||
Enums.TradingExchanges exchange,
|
||||
Enums.Ticker ticker,
|
||||
Enums.Timeframe timeframe,
|
||||
DateTime start,
|
||||
DateTime end);
|
||||
int? limit = null);
|
||||
|
||||
Task<HashSet<Candle>> GetCandles(
|
||||
Enums.TradingExchanges exchange,
|
||||
Enums.Ticker ticker,
|
||||
Enums.Timeframe timeframe,
|
||||
DateTime start,
|
||||
DateTime end,
|
||||
int? limit = null);
|
||||
|
||||
Task<IList<Enums.Ticker>> GetTickersAsync(
|
||||
Enums.TradingExchanges exchange,
|
||||
|
||||
@@ -13,18 +13,20 @@ public interface ITradingRepository
|
||||
Task<Signal> GetSignalByIdentifierAsync(string identifier, User user = null);
|
||||
Task InsertPositionAsync(Position position);
|
||||
Task UpdatePositionAsync(Position position);
|
||||
Task<Indicator> GetStrategyByNameAsync(string strategy);
|
||||
Task<IndicatorBase> GetStrategyByNameAsync(string strategy);
|
||||
Task InsertScenarioAsync(Scenario scenario);
|
||||
Task InsertStrategyAsync(Indicator indicator);
|
||||
Task InsertIndicatorAsync(IndicatorBase indicator);
|
||||
Task<IEnumerable<Scenario>> GetScenariosAsync();
|
||||
Task<IEnumerable<Indicator>> GetStrategiesAsync();
|
||||
Task<IEnumerable<Indicator>> GetIndicatorsAsync();
|
||||
Task<IEnumerable<IndicatorBase>> GetStrategiesAsync();
|
||||
Task<IEnumerable<IndicatorBase>> GetIndicatorsAsync();
|
||||
Task DeleteScenarioAsync(string name);
|
||||
Task DeleteIndicatorAsync(string name);
|
||||
Task<Position> GetPositionByIdentifierAsync(string identifier);
|
||||
Task<Position> GetPositionByIdentifierAsync(Guid identifier);
|
||||
Task<IEnumerable<Position>> GetPositionsAsync(PositionInitiator positionInitiator);
|
||||
Task<IEnumerable<Position>> GetPositionsByStatusAsync(PositionStatus positionStatus);
|
||||
|
||||
Task UpdateScenarioAsync(Scenario scenario);
|
||||
Task UpdateStrategyAsync(Indicator indicator);
|
||||
Task UpdateStrategyAsync(IndicatorBase indicatorBase);
|
||||
Task<IndicatorBase> GetStrategyByNameUserAsync(string name, User user);
|
||||
Task<Scenario> GetScenarioByNameUserAsync(string scenarioName, User user);
|
||||
}
|
||||
@@ -45,7 +45,7 @@ namespace Managing.Application.Abstractions.Services
|
||||
/// <returns>The lightweight backtest results</returns>
|
||||
Task<LightBacktest> RunTradingBotBacktest(
|
||||
TradingBotConfig config,
|
||||
List<Candle> candles,
|
||||
HashSet<Candle> candles,
|
||||
User user = null,
|
||||
bool withCandles = false,
|
||||
string requestId = null,
|
||||
|
||||
@@ -45,16 +45,18 @@ public interface IExchangeService
|
||||
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);
|
||||
|
||||
Task<List<Candle>> GetCandlesInflux(TradingExchanges exchange, Ticker ticker, DateTime startDate,
|
||||
Timeframe timeframe);
|
||||
Task<HashSet<Candle>> GetCandlesInflux(TradingExchanges exchange, Ticker ticker, DateTime startDate,
|
||||
Timeframe timeframe, int? limit = null);
|
||||
|
||||
Task<List<Candle>> GetCandlesInflux(TradingExchanges exchange, Ticker ticker, DateTime startDate,
|
||||
Timeframe timeframe, DateTime endDate);
|
||||
Task<HashSet<Candle>> GetCandlesInflux(TradingExchanges exchange, Ticker ticker, DateTime startDate,
|
||||
Timeframe timeframe, DateTime endDate, int? limit = null);
|
||||
|
||||
Task<decimal> GetBestPrice(Account account, Ticker ticker, decimal lastPrice, decimal quantity,
|
||||
TradeDirection direction);
|
||||
|
||||
Task<decimal> GetBestPrice(Account account, Ticker ticker, decimal lastPrice, decimal quantity, TradeDirection direction);
|
||||
Orderbook GetOrderbook(Account account, Ticker ticker);
|
||||
|
||||
Trade BuildEmptyTrade(Ticker ticker, decimal price, decimal quantity, TradeDirection direction, decimal? leverage,
|
||||
|
||||
@@ -28,4 +28,6 @@ public interface IStatisticService
|
||||
Task UpdateTopVolumeTicker(Enums.TradingExchanges exchange, int top);
|
||||
Task UpdateFundingRates();
|
||||
Task<List<FundingRate>> GetFundingRates();
|
||||
Task SaveOrUpdateAgentSummary(AgentSummary agentSummary);
|
||||
Task<IEnumerable<AgentSummary>> GetAllAgentSummaries();
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Managing.Domain.Bots;
|
||||
using Managing.Domain.Indicators;
|
||||
using Managing.Domain.Synth.Models;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
@@ -94,7 +95,7 @@ public interface ISynthPredictionService
|
||||
/// <param name="botConfig">Bot configuration with Synth settings</param>
|
||||
/// <returns>Risk assessment result</returns>
|
||||
Task<SynthRiskResult> MonitorPositionRiskAsync(Ticker ticker, TradeDirection direction, decimal currentPrice,
|
||||
decimal liquidationPrice, string positionIdentifier, TradingBotConfig botConfig);
|
||||
decimal liquidationPrice, Guid positionIdentifier, TradingBotConfig botConfig);
|
||||
|
||||
/// <summary>
|
||||
/// Estimates liquidation price based on money management settings
|
||||
@@ -103,5 +104,6 @@ public interface ISynthPredictionService
|
||||
/// <param name="direction">Position direction</param>
|
||||
/// <param name="moneyManagement">Money management settings</param>
|
||||
/// <returns>Estimated liquidation price</returns>
|
||||
decimal EstimateLiquidationPrice(decimal currentPrice, TradeDirection direction, LightMoneyManagement moneyManagement);
|
||||
decimal EstimateLiquidationPrice(decimal currentPrice, TradeDirection direction,
|
||||
LightMoneyManagement moneyManagement);
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
using Managing.Domain.Accounts;
|
||||
using Managing.Domain.Bots;
|
||||
using Managing.Domain.Candles;
|
||||
using Managing.Domain.Indicators;
|
||||
using Managing.Domain.Scenarios;
|
||||
using Managing.Domain.Statistics;
|
||||
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 static Managing.Common.Enums;
|
||||
|
||||
@@ -17,20 +19,20 @@ public interface ITradingService
|
||||
Task<Scenario> GetScenarioByNameAsync(string scenario);
|
||||
Task InsertPositionAsync(Position position);
|
||||
Task UpdatePositionAsync(Position position);
|
||||
Task<Indicator> GetStrategyByNameAsync(string strategy);
|
||||
Task<IndicatorBase> GetIndicatorByNameAsync(string strategy);
|
||||
Task InsertScenarioAsync(Scenario scenario);
|
||||
Task InsertStrategyAsync(Indicator indicator);
|
||||
Task InsertIndicatorAsync(IndicatorBase indicatorBase);
|
||||
Task<IEnumerable<Scenario>> GetScenariosAsync();
|
||||
Task<IEnumerable<Indicator>> GetStrategiesAsync();
|
||||
Task<IEnumerable<IndicatorBase>> GetIndicatorsAsync();
|
||||
Task DeleteScenarioAsync(string name);
|
||||
Task DeleteStrategyAsync(string name);
|
||||
Task<Position> GetPositionByIdentifierAsync(string identifier);
|
||||
Task DeleteIndicatorAsync(string name);
|
||||
Task<Position> GetPositionByIdentifierAsync(Guid identifier);
|
||||
Task<Position> ManagePosition(Account account, Position position);
|
||||
|
||||
Task WatchTrader();
|
||||
Task<IEnumerable<Trader>> GetTradersWatch();
|
||||
Task UpdateScenarioAsync(Scenario scenario);
|
||||
Task UpdateStrategyAsync(Indicator indicator);
|
||||
Task UpdateIndicatorAsync(IndicatorBase indicatorBase);
|
||||
Task<IEnumerable<Position>> GetBrokerPositions(Account account);
|
||||
Task<PrivyInitAddressResponse> InitPrivyWallet(string publicAddress);
|
||||
|
||||
@@ -43,7 +45,7 @@ public interface ITradingService
|
||||
TradingBotConfig botConfig, bool isBacktest);
|
||||
|
||||
Task<SynthRiskResult> MonitorSynthPositionRiskAsync(Ticker ticker, TradeDirection direction, decimal currentPrice,
|
||||
decimal liquidationPrice, string positionIdentifier, TradingBotConfig botConfig);
|
||||
decimal liquidationPrice, Guid positionIdentifier, TradingBotConfig botConfig);
|
||||
|
||||
/// <summary>
|
||||
/// Calculates indicators values for a given scenario and candles.
|
||||
@@ -53,5 +55,8 @@ public interface ITradingService
|
||||
/// <returns>A dictionary of indicator types to their calculated values.</returns>
|
||||
Dictionary<IndicatorType, IndicatorsResultBase> CalculateIndicatorsValuesAsync(
|
||||
Scenario scenario,
|
||||
List<Candle> candles);
|
||||
HashSet<Candle> candles);
|
||||
|
||||
Task<IndicatorBase?> GetIndicatorByNameUserAsync(string name, User user);
|
||||
Task<Scenario?> GetScenarioByNameUserAsync(string scenarioName, User user);
|
||||
}
|
||||
@@ -5,9 +5,10 @@ namespace Managing.Application.Abstractions.Services;
|
||||
public interface IUserService
|
||||
{
|
||||
Task<User> Authenticate(string name, string address, string message, string signature);
|
||||
Task<User> GetUserByAddressAsync(string address);
|
||||
Task<User> GetUserByAddressAsync(string address, bool useCache = true);
|
||||
Task<User> UpdateAgentName(User user, string agentName);
|
||||
Task<User> UpdateAvatarUrl(User user, string avatarUrl);
|
||||
Task<User> UpdateTelegramChannel(User user, string telegramChannel);
|
||||
Task<User> GetUser(string name);
|
||||
Task<User> GetUserByName(string name);
|
||||
Task<User> GetUserByAgentName(string agentName);
|
||||
}
|
||||
Reference in New Issue
Block a user