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,109 @@
using Managing.Domain.Bots;
using Managing.Domain.MoneyManagements;
using Managing.Domain.Strategies;
using Managing.Domain.Synth.Models;
using static Managing.Common.Enums;
namespace Managing.Application.Abstractions.Services;
/// <summary>
/// Service interface for Synth prediction business logic and probability calculations
/// </summary>
public interface ISynthPredictionService
{
/// <summary>
/// Calculates the probability of price reaching a target within a specified time horizon
/// </summary>
/// <param name="asset">Asset symbol (e.g., "BTC", "ETH")</param>
/// <param name="currentPrice">Current market price</param>
/// <param name="targetPrice">Target price to reach</param>
/// <param name="timeHorizonSeconds">Time horizon in seconds</param>
/// <param name="isLongPosition">True for long positions (liquidation when price drops), false for short positions (liquidation when price rises)</param>
/// <param name="config">Synth configuration for this operation</param>
/// <returns>Probability as a decimal between 0.0 and 1.0</returns>
Task<decimal> GetProbabilityOfTargetPriceAsync(
string asset,
decimal currentPrice,
decimal targetPrice,
int timeHorizonSeconds,
bool isLongPosition,
SynthConfiguration config);
/// <summary>
/// Gets probabilities for multiple price thresholds at once
/// </summary>
/// <param name="asset">Asset symbol</param>
/// <param name="currentPrice">Current market price</param>
/// <param name="priceThresholds">Dictionary of threshold names to prices</param>
/// <param name="timeHorizonSeconds">Time horizon in seconds</param>
/// <param name="isLongPosition">True for long positions, false for short positions</param>
/// <param name="config">Synth configuration for this operation</param>
/// <param name="isBacktest">Parameter for backtest</param>
/// <param name="signalDate">Signal date</param>
/// <returns>Dictionary of threshold names to probabilities</returns>
Task<Dictionary<string, decimal>> GetMultipleThresholdProbabilitiesAsync(
string asset,
decimal currentPrice,
Dictionary<string, decimal> priceThresholds,
int timeHorizonSeconds,
bool isLongPosition,
SynthConfiguration config,
bool isBacktest,
DateTime signalDate);
/// <summary>
/// Clears cached predictions (useful for testing or forced refresh)
/// </summary>
void ClearCache();
/// <summary>
/// Clears cached predictions from MongoDB asynchronously
/// </summary>
Task ClearCacheAsync();
/// <summary>
/// Validates a trading signal using Synth predictions to check for adverse price movements
/// </summary>
/// <param name="signal">The trading signal containing ticker, direction, candle data, and other context</param>
/// <param name="currentPrice">Current market price (required)</param>
/// <param name="botConfig">Bot configuration with Synth settings</param>
/// <param name="isBacktest">Whether this is a backtest</param>
/// <param name="customThresholds">Custom probability thresholds for decision-making. If null, uses default thresholds.</param>
/// <returns>Comprehensive signal validation result including confidence, probabilities, and risk analysis</returns>
Task<SignalValidationResult> ValidateSignalAsync(Signal signal, decimal currentPrice,
TradingBotConfig botConfig, bool isBacktest, Dictionary<string, decimal> customThresholds = null);
/// <summary>
/// Performs risk assessment before opening a position
/// </summary>
/// <param name="ticker">Trading ticker</param>
/// <param name="direction">Position direction</param>
/// <param name="currentPrice">Current market price</param>
/// <param name="botConfig">Bot configuration with Synth settings</param>
/// <param name="isBacktest">Whether this is a backtest</param>
/// <returns>True if position should be allowed, false if blocked</returns>
Task<bool> AssessPositionRiskAsync(Ticker ticker, TradeDirection direction, decimal currentPrice,
TradingBotConfig botConfig, bool isBacktest);
/// <summary>
/// Monitors liquidation risk for an open position
/// </summary>
/// <param name="ticker">Trading ticker</param>
/// <param name="direction">Position direction</param>
/// <param name="currentPrice">Current market price</param>
/// <param name="liquidationPrice">Position liquidation price</param>
/// <param name="positionIdentifier">Position identifier for logging</param>
/// <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);
/// <summary>
/// Estimates liquidation price based on money management settings
/// </summary>
/// <param name="currentPrice">Current market price</param>
/// <param name="direction">Position direction</param>
/// <param name="moneyManagement">Money management settings</param>
/// <returns>Estimated liquidation price</returns>
decimal EstimateLiquidationPrice(decimal currentPrice, TradeDirection direction, MoneyManagement moneyManagement);
}