Add synthApi (#27)

* Add synthApi

* Put confidence for Synth proba

* Update the code

* Update readme

* Fix bootstraping

* fix github build

* Update the endpoints for scenario

* Add scenario and update backtest modal

* Update bot modal

* Update interfaces for synth

* add synth to backtest

* Add Kelly criterion and better signal

* Update signal confidence

* update doc

* save leaderboard and prediction

* Update nswag to generate ApiClient in the correct path

* Unify the trading modal

* Save miner and prediction

* Update messaging and block new signal until position not close when flipping off

* Rename strategies to indicators

* Update doc

* Update chart + add signal name

* Fix signal direction

* Update docker webui

* remove crypto npm

* Clean
This commit is contained in:
Oda
2025-07-03 00:13:42 +07:00
committed by GitHub
parent 453806356d
commit a547c4a040
103 changed files with 9916 additions and 810 deletions

View File

@@ -0,0 +1,73 @@
using System.ComponentModel.DataAnnotations;
using static Managing.Common.Enums;
namespace Managing.Api.Models.Requests;
/// <summary>
/// Request model for indicator configuration without user information
/// </summary>
public class IndicatorRequest
{
/// <summary>
/// The name of the indicator
/// </summary>
[Required]
public string Name { get; set; }
/// <summary>
/// The type of indicator
/// </summary>
[Required]
public IndicatorType Type { get; set; }
/// <summary>
/// The signal type for this indicator
/// </summary>
[Required]
public SignalType SignalType { get; set; }
/// <summary>
/// Minimum history required for this indicator
/// </summary>
public int MinimumHistory { get; set; }
/// <summary>
/// Period parameter for the indicator
/// </summary>
public int? Period { get; set; }
/// <summary>
/// Fast periods parameter for indicators like MACD
/// </summary>
public int? FastPeriods { get; set; }
/// <summary>
/// Slow periods parameter for indicators like MACD
/// </summary>
public int? SlowPeriods { get; set; }
/// <summary>
/// Signal periods parameter for indicators like MACD
/// </summary>
public int? SignalPeriods { get; set; }
/// <summary>
/// Multiplier parameter for indicators like SuperTrend
/// </summary>
public double? Multiplier { get; set; }
/// <summary>
/// Smooth periods parameter
/// </summary>
public int? SmoothPeriods { get; set; }
/// <summary>
/// Stochastic periods parameter
/// </summary>
public int? StochPeriods { get; set; }
/// <summary>
/// Cycle periods parameter
/// </summary>
public int? CyclePeriods { get; set; }
}

View File

@@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations;
using Managing.Common;
namespace Managing.Api.Models.Requests;
public class MoneyManagementRequest
{
[Required] public string Name { get; set; }
[Required] public Enums.Timeframe Timeframe { get; set; }
[Required] public decimal StopLoss { get; set; }
[Required] public decimal TakeProfit { get; set; }
[Required] public decimal Leverage { get; set; }
}

View File

@@ -1,15 +1,49 @@
using static Managing.Common.Enums;
using Managing.Domain.MoneyManagements;
namespace Managing.Api.Models.Requests
namespace Managing.Api.Models.Requests;
/// <summary>
/// Request model for running a backtest
/// </summary>
public class RunBacktestRequest
{
public class RunBacktestRequest
{
public TradingExchanges Exchange { get; set; }
public BotType BotType { get; set; }
public Ticker Ticker { get; set; }
public Timeframe Timeframe { get; set; }
public RiskLevel RiskLevel { get; set; }
public bool WatchOnly { get; set; }
public int Days { get; set; }
}
/// <summary>
/// The trading bot configuration request to use for the backtest
/// </summary>
public TradingBotConfigRequest Config { get; set; }
/// <summary>
/// The start date for the backtest
/// </summary>
public DateTime StartDate { get; set; }
/// <summary>
/// The end date for the backtest
/// </summary>
public DateTime EndDate { get; set; }
/// <summary>
/// The starting balance for the backtest
/// </summary>
public decimal Balance { get; set; }
/// <summary>
/// Whether to only watch the backtest without executing trades
/// </summary>
public bool WatchOnly { get; set; } = false;
/// <summary>
/// Whether to save the backtest results
/// </summary>
public bool Save { get; set; } = false;
/// <summary>
/// The name of the money management to use (optional if MoneyManagement is provided)
/// </summary>
public string? MoneyManagementName { get; set; }
/// <summary>
/// The money management details (optional if MoneyManagementName is provided)
/// </summary>
public MoneyManagement? MoneyManagement { get; set; }
}

View File

@@ -0,0 +1,26 @@
using System.ComponentModel.DataAnnotations;
namespace Managing.Api.Models.Requests;
/// <summary>
/// Request model for scenario configuration without user information
/// </summary>
public class ScenarioRequest
{
/// <summary>
/// The name of the scenario
/// </summary>
[Required]
public string Name { get; set; }
/// <summary>
/// List of indicator configurations for this scenario
/// </summary>
[Required]
public List<IndicatorRequest> Indicators { get; set; } = new();
/// <summary>
/// The loopback period for the scenario
/// </summary>
public int? LoopbackPeriod { get; set; }
}

View File

@@ -1,31 +1,16 @@
using System.ComponentModel.DataAnnotations;
using static Managing.Common.Enums;
namespace Managing.Api.Models.Requests
{
/// <summary>
/// Request model for starting a bot
/// </summary>
public class StartBotRequest
{
[Required] public BotType BotType { get; set; }
[Required] public string BotName { get; set; }
[Required] public Ticker Ticker { get; set; }
[Required] public Timeframe Timeframe { get; set; }
[Required] public bool IsForWatchOnly { get; set; }
[Required] public string Scenario { get; set; }
[Required] public string AccountName { get; set; }
[Required] public string MoneyManagementName { get; set; }
/// <summary>
/// Initial trading balance in USD for the bot
/// The trading bot configuration request with primary properties
/// </summary>
[Required]
[Range(10.00, double.MaxValue, ErrorMessage = "Initial trading balance must be greater than ten")]
public decimal InitialTradingBalance { get; set; }
/// <summary>
/// Cooldown period in minutes between trades
/// </summary>
[Required]
[Range(1, 1440, ErrorMessage = "Cooldown period must be between 1 and 1440 minutes (24 hours)")]
public decimal CooldownPeriod { get; set; } = 1; // Default to 1 minute if not specified
public TradingBotConfigRequest Config { get; set; }
}
}

View File

@@ -0,0 +1,119 @@
using System.ComponentModel.DataAnnotations;
using static Managing.Common.Enums;
namespace Managing.Api.Models.Requests;
/// <summary>
/// Simplified trading bot configuration request with only primary properties
/// </summary>
public class TradingBotConfigRequest
{
/// <summary>
/// The account name to use for trading
/// </summary>
[Required]
public string AccountName { get; set; }
/// <summary>
/// The ticker/symbol to trade
/// </summary>
[Required]
public Ticker Ticker { get; set; }
/// <summary>
/// The timeframe for trading decisions
/// </summary>
[Required]
public Timeframe Timeframe { get; set; }
/// <summary>
/// Whether this bot is for watching only (no actual trading)
/// </summary>
[Required]
public bool IsForWatchingOnly { get; set; }
/// <summary>
/// The initial trading balance for the bot
/// </summary>
[Required]
public decimal BotTradingBalance { get; set; }
/// <summary>
/// The type of bot (SimpleBot, ScalpingBot, FlippingBot)
/// </summary>
[Required]
public BotType BotType { get; set; }
/// <summary>
/// The name/identifier for this bot
/// </summary>
[Required]
public string Name { get; set; }
/// <summary>
/// Cooldown period between trades (in candles)
/// </summary>
[Required]
public int CooldownPeriod { get; set; }
/// <summary>
/// Maximum consecutive losses before stopping the bot
/// </summary>
[Required]
public int MaxLossStreak { get; set; }
/// <summary>
/// The scenario configuration (takes precedence over ScenarioName)
/// </summary>
public ScenarioRequest? Scenario { get; set; }
/// <summary>
/// The scenario name to load from database (only used when Scenario is not provided)
/// </summary>
public string? ScenarioName { get; set; }
/// <summary>
/// The money management name to load from database (only used when MoneyManagement is not provided)
/// </summary>
public string? MoneyManagementName { get; set; }
/// <summary>
/// The money management object to use for the bot
/// </summary>
public MoneyManagementRequest? MoneyManagement { get; set; }
/// <summary>
/// Maximum time in hours that a position can remain open before being automatically closed
/// </summary>
public decimal? MaxPositionTimeHours { get; set; }
/// <summary>
/// Whether to close positions early when they become profitable
/// </summary>
public bool CloseEarlyWhenProfitable { get; set; } = false;
/// <summary>
/// Whether to only flip positions when the current position is in profit
/// </summary>
public bool FlipOnlyWhenInProfit { get; set; } = true;
/// <summary>
/// Whether to use Synth API for predictions and risk assessment
/// </summary>
public bool UseSynthApi { get; set; } = false;
/// <summary>
/// Whether to use Synth predictions for position sizing adjustments
/// </summary>
public bool UseForPositionSizing { get; set; } = true;
/// <summary>
/// Whether to use Synth predictions for signal filtering
/// </summary>
public bool UseForSignalFiltering { get; set; } = true;
/// <summary>
/// Whether to use Synth predictions for dynamic stop-loss/take-profit adjustments
/// </summary>
public bool UseForDynamicStopLoss { get; set; } = true;
}

View File

@@ -0,0 +1,32 @@
using System.ComponentModel.DataAnnotations;
using Managing.Domain.MoneyManagements;
namespace Managing.Api.Models.Requests;
/// <summary>
/// Request model for updating bot configuration
/// </summary>
public class UpdateBotConfigRequest
{
/// <summary>
/// The unique identifier of the bot to update
/// </summary>
[Required]
public string Identifier { get; set; }
/// <summary>
/// The new trading bot configuration request
/// </summary>
[Required]
public TradingBotConfigRequest Config { get; set; }
/// <summary>
/// Optional: Money management name to load from database (if MoneyManagement object is not provided)
/// </summary>
public string? MoneyManagementName { get; set; }
/// <summary>
/// Optional: Money management object for custom configurations (takes precedence over MoneyManagementName)
/// </summary>
public MoneyManagement? MoneyManagement { get; set; }
}

View File

@@ -0,0 +1,31 @@
using System.ComponentModel.DataAnnotations;
using static Managing.Common.Enums;
namespace Managing.Api.Models.Responses;
public class IndicatorViewModel
{
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public IndicatorType Type { get; set; }
[Required]
public SignalType SignalType { get; set; }
[Required]
public int MinimumHistory { get; set; }
public int? Period { get; set; }
public int? FastPeriods { get; set; }
public int? SlowPeriods { get; set; }
public int? SignalPeriods { get; set; }
public double? Multiplier { get; set; }
public int? SmoothPeriods { get; set; }
public int? StochPeriods { get; set; }
public int? CyclePeriods { get; set; }
[Required]
public string UserName { get; set; } = string.Empty;
}

View File

@@ -0,0 +1,17 @@
using System.ComponentModel.DataAnnotations;
namespace Managing.Api.Models.Responses;
public class ScenarioViewModel
{
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public List<IndicatorViewModel> Indicators { get; set; } = new();
public int? LoopbackPeriod { get; set; }
[Required]
public string UserName { get; set; } = string.Empty;
}