Refactor code structure for improved readability and maintainability

This commit is contained in:
2026-08-05 10:05:20 +02:00
parent 61f1e59964
commit f96ed670ca
239 changed files with 23858 additions and 730 deletions
+12
View File
@@ -0,0 +1,12 @@
namespace TradingBot.Models;
public class AppSettings
{
public bool SimulationMode { get; set; } = true;
public bool DesktopNotifications { get; set; } = false;
public bool AutoStartBot { get; set; } = true;
public bool ConfirmManualTrades { get; set; } = false;
public int UpdateIntervalSeconds { get; set; } = 3;
public string LogLevel { get; set; } = "Info";
public bool SidebarCollapsed { get; set; } = false;
}
+45
View File
@@ -0,0 +1,45 @@
namespace TradingBot.Models;
public class AssetConfiguration
{
public string Symbol { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
public bool IsEnabled { get; set; }
public decimal InitialBalance { get; set; } = 1000m;
public decimal CurrentBalance { get; set; } = 1000m;
public decimal CurrentHoldings { get; set; }
public decimal AverageEntryPrice { get; set; }
// Strategy Settings
public string StrategyName { get; set; } = "Simple Moving Average";
public Dictionary<string, object> StrategyParameters { get; set; } = new();
// Risk Management
public decimal MaxPositionSize { get; set; } = 100m;
public decimal StopLossPercentage { get; set; } = 5m;
public decimal TakeProfitPercentage { get; set; } = 10m;
// Trading Constraints
public decimal MinTradeAmount { get; set; } = 10m;
public decimal MaxTradeAmount { get; set; } = 500m;
public int MaxDailyTrades { get; set; } = 10;
// Current State
public DateTime? LastTradeTime { get; set; }
public int DailyTradeCount { get; set; }
public DateTime DailyTradeCountReset { get; set; } = DateTime.UtcNow.Date;
// Statistics Quick Access
public decimal TotalProfit => CurrentBalance + (CurrentHoldings * AverageEntryPrice) - InitialBalance;
public decimal ProfitPercentage => InitialBalance > 0 ? (TotalProfit / InitialBalance) * 100 : 0;
public AssetConfiguration()
{
StrategyParameters = new Dictionary<string, object>
{
{ "ShortPeriod", 10 },
{ "LongPeriod", 30 },
{ "SignalThreshold", 0.5m }
};
}
}
+94
View File
@@ -0,0 +1,94 @@
namespace TradingBot.Models;
public class AssetStatistics
{
public string Symbol { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
// Trading Performance
public int TotalTrades { get; set; }
public int WinningTrades { get; set; }
public int LosingTrades { get; set; }
public decimal WinRate => TotalTrades > 0 ? (decimal)WinningTrades / TotalTrades * 100 : 0;
// Financial Metrics
public decimal TotalProfit { get; set; }
public decimal TotalLoss { get; set; }
public decimal NetProfit => TotalProfit - TotalLoss;
public decimal ProfitPercentage { get; set; }
public decimal AverageProfit => WinningTrades > 0 ? TotalProfit / WinningTrades : 0;
public decimal AverageLoss => LosingTrades > 0 ? TotalLoss / LosingTrades : 0;
public decimal ProfitFactor => TotalLoss > 0 ? TotalProfit / TotalLoss : TotalProfit > 0 ? decimal.MaxValue : 0;
// Position Information
public decimal CurrentPosition { get; set; }
public decimal AverageEntryPrice { get; set; }
public decimal CurrentPrice { get; set; }
public decimal UnrealizedPnL => CurrentPosition > 0 && AverageEntryPrice > 0
? (CurrentPrice - AverageEntryPrice) * CurrentPosition
: 0;
public decimal UnrealizedPnLPercentage => AverageEntryPrice > 0
? (CurrentPrice - AverageEntryPrice) / AverageEntryPrice * 100
: 0;
// Risk Metrics
public decimal MaxDrawdown { get; set; }
public decimal CurrentDrawdown { get; set; }
public decimal LargestWin { get; set; }
public decimal LargestLoss { get; set; }
public decimal SharpeRatio { get; set; }
// Time-based Metrics
public DateTime? FirstTradeTime { get; set; }
public DateTime? LastTradeTime { get; set; }
public TimeSpan TradingDuration => FirstTradeTime.HasValue && LastTradeTime.HasValue
? LastTradeTime.Value - FirstTradeTime.Value
: TimeSpan.Zero;
// Daily Statistics
public int TradesToday { get; set; }
public decimal ProfitToday { get; set; }
public decimal ProfitTodayPercentage { get; set; }
// Trade Details
public List<Trade> RecentTrades { get; set; } = new();
public List<decimal> EquityCurve { get; set; } = new();
// Strategy Performance
public Dictionary<string, int> TradesByStrategy { get; set; } = new();
public Dictionary<string, decimal> ProfitByStrategy { get; set; } = new();
// Additional Metrics
public decimal AverageTradeSize { get; set; }
public decimal AverageHoldingTime { get; set; } // in hours
public int ConsecutiveWins { get; set; }
public int ConsecutiveLosses { get; set; }
public int MaxConsecutiveWins { get; set; }
public int MaxConsecutiveLosses { get; set; }
}
public class PortfolioStatistics
{
public decimal TotalBalance { get; set; }
public decimal InitialBalance { get; set; }
public decimal TotalProfit => TotalBalance - InitialBalance;
public decimal TotalProfitPercentage => InitialBalance > 0 ? (TotalProfit / InitialBalance) * 100 : 0;
public int TotalAssets { get; set; }
public int ActiveAssets { get; set; }
public int TotalTrades { get; set; }
public decimal WinRate { get; set; }
public decimal BestPerformingAssetProfit { get; set; }
public string BestPerformingAssetSymbol { get; set; } = string.Empty;
public decimal WorstPerformingAssetProfit { get; set; }
public string WorstPerformingAssetSymbol { get; set; } = string.Empty;
public List<AssetStatistics> AssetStatistics { get; set; } = new();
public Dictionary<string, decimal> DailyProfits { get; set; } = new();
public Dictionary<string, int> DailyTrades { get; set; } = new();
public DateTime? StartDate { get; set; }
public DateTime LastUpdateTime { get; set; } = DateTime.UtcNow;
}
+10
View File
@@ -0,0 +1,10 @@
namespace TradingBot.Models;
public class BotStatus
{
public bool IsRunning { get; set; }
public DateTime? StartedAt { get; set; }
public decimal TotalProfit { get; set; }
public int TradesExecuted { get; set; }
public string CurrentStrategy { get; set; } = "Simple Moving Average";
}
+94
View File
@@ -0,0 +1,94 @@
namespace TradingBot.Models;
/// <summary>
/// Configuration for a trading indicator
/// </summary>
public class IndicatorConfig
{
public string Id { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public IndicatorType Type { get; set; }
public bool IsEnabled { get; set; } = true;
// Thresholds for signals
public decimal? OverboughtThreshold { get; set; }
public decimal? OversoldThreshold { get; set; }
public decimal? BuyThreshold { get; set; }
public decimal? SellThreshold { get; set; }
// Indicator-specific parameters
public int Period { get; set; } = 14;
public int FastPeriod { get; set; } = 12;
public int SlowPeriod { get; set; } = 26;
public int SignalPeriod { get; set; } = 9;
}
/// <summary>
/// Real-time indicator signal
/// </summary>
public class IndicatorSignal
{
public string IndicatorId { get; set; } = string.Empty;
public string IndicatorName { get; set; } = string.Empty;
public string Symbol { get; set; } = string.Empty;
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
public SignalStrength Strength { get; set; }
public SignalType Type { get; set; }
public string Message { get; set; } = string.Empty;
public decimal? Value { get; set; }
}
/// <summary>
/// Indicator status for a specific asset
/// </summary>
public class IndicatorStatus
{
public string IndicatorId { get; set; } = string.Empty;
public string Symbol { get; set; } = string.Empty;
public decimal CurrentValue { get; set; }
public decimal? PreviousValue { get; set; }
public MarketCondition Condition { get; set; }
public string Recommendation { get; set; } = string.Empty;
public DateTime LastUpdate { get; set; } = DateTime.UtcNow;
}
/// <summary>
/// Types of trading indicators
/// </summary>
public enum IndicatorType
{
RSI, // Relative Strength Index
MACD, // Moving Average Convergence Divergence
SMA, // Simple Moving Average
EMA, // Exponential Moving Average
BollingerBands, // Bollinger Bands
Stochastic, // Stochastic Oscillator
Volume, // Volume indicators
ATR // Average True Range (volatility)
}
/// <summary>
/// Signal strength levels
/// </summary>
public enum SignalStrength
{
Weak,
Moderate,
Strong,
VeryStrong
}
/// <summary>
/// Market condition based on indicators
/// </summary>
public enum MarketCondition
{
Neutral,
Overbought,
Oversold,
Bullish,
Bearish,
Ranging,
Trending
}
+27
View File
@@ -0,0 +1,27 @@
namespace TradingBot.Models;
/// <summary>
/// Represents a log entry with timestamp, severity and message
/// </summary>
public class LogEntry
{
public Guid Id { get; set; } = Guid.NewGuid();
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
public LogLevel Level { get; set; }
public string Category { get; set; } = string.Empty;
public string Message { get; set; } = string.Empty;
public string? Details { get; set; }
public string? Symbol { get; set; }
}
/// <summary>
/// Log severity levels
/// </summary>
public enum LogLevel
{
Debug,
Info,
Warning,
Error,
Trade
}
+10
View File
@@ -0,0 +1,10 @@
namespace TradingBot.Models;
public class MarketPrice
{
public string Symbol { get; set; } = string.Empty;
public decimal Price { get; set; }
public decimal Change24h { get; set; }
public decimal Volume24h { get; set; }
public DateTime Timestamp { get; set; }
}
+7
View File
@@ -0,0 +1,7 @@
namespace TradingBot.Models;
public class Notification
{
public string Message { get; set; } = string.Empty;
public string Type { get; set; } = "info";
}
+11
View File
@@ -0,0 +1,11 @@
namespace TradingBot.Models;
public class TechnicalIndicators
{
public decimal RSI { get; set; }
public decimal MACD { get; set; }
public decimal Signal { get; set; }
public decimal Histogram { get; set; }
public decimal EMA12 { get; set; }
public decimal EMA26 { get; set; }
}
+19
View File
@@ -0,0 +1,19 @@
namespace TradingBot.Models;
public class Trade
{
public Guid Id { get; set; } = Guid.NewGuid();
public string Symbol { get; set; } = string.Empty;
public TradeType Type { get; set; }
public decimal Price { get; set; }
public decimal Amount { get; set; }
public DateTime Timestamp { get; set; }
public string Strategy { get; set; } = string.Empty;
public bool IsBot { get; set; }
}
public enum TradeType
{
Buy,
Sell
}
+137
View File
@@ -0,0 +1,137 @@
namespace TradingBot.Models;
/// <summary>
/// Represents the mapping between an asset and its assigned trading strategies
/// </summary>
public class AssetStrategyMapping
{
public string Symbol { get; set; } = string.Empty;
public string AssetName { get; set; } = string.Empty;
public List<string> StrategyIds { get; set; } = new();
public bool IsActive { get; set; }
public DateTime ActivatedAt { get; set; }
public DateTime? DeactivatedAt { get; set; }
/// <summary>
/// Strategy-specific parameters override
/// Key: StrategyId, Value: Dictionary of parameter names and values
/// </summary>
public Dictionary<string, Dictionary<string, object>> StrategyParameters { get; set; } = new();
}
/// <summary>
/// Represents a trading strategy instance
/// </summary>
public class StrategyInfo
{
public string Id { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public string Category { get; set; } = string.Empty; // Trend, Oscillator, Volatility, etc.
public StrategyRisk RiskLevel { get; set; }
public TimeFrame RecommendedTimeFrame { get; set; }
public List<string> RequiredIndicators { get; set; } = new();
public Dictionary<string, ParameterInfo> Parameters { get; set; } = new();
}
/// <summary>
/// Parameter information for strategy configuration
/// </summary>
public class ParameterInfo
{
public string Name { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public ParameterType Type { get; set; }
public object DefaultValue { get; set; } = 0;
public object? MinValue { get; set; }
public object? MaxValue { get; set; }
}
/// <summary>
/// Trading engine status for an asset
/// </summary>
public class TradingEngineStatus
{
public string Symbol { get; set; } = string.Empty;
public bool IsRunning { get; set; }
public int ActiveStrategies { get; set; }
public DateTime? LastSignalTime { get; set; }
public List<StrategySignal> RecentSignals { get; set; } = new();
public TradingDecision? LastDecision { get; set; }
}
/// <summary>
/// Signal from a specific strategy
/// </summary>
public class StrategySignal
{
public string StrategyId { get; set; } = string.Empty;
public string StrategyName { get; set; } = string.Empty;
public TradingSignal Signal { get; set; } = new();
public DateTime GeneratedAt { get; set; } = DateTime.UtcNow;
}
/// <summary>
/// Aggregated trading decision from multiple strategies
/// </summary>
public class TradingDecision
{
public string Symbol { get; set; } = string.Empty;
public SignalType Decision { get; set; }
public decimal Confidence { get; set; }
public string Reason { get; set; } = string.Empty;
public int BuyVotes { get; set; }
public int SellVotes { get; set; }
public int HoldVotes { get; set; }
public List<string> SupportingStrategies { get; set; } = new();
public List<string> OpposingStrategies { get; set; } = new();
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
}
/// <summary>
/// Strategy performance metrics
/// </summary>
public class StrategyPerformance
{
public string StrategyId { get; set; } = string.Empty;
public string Symbol { get; set; } = string.Empty;
public int TotalSignals { get; set; }
public int CorrectSignals { get; set; }
public decimal Accuracy { get; set; }
public decimal TotalProfit { get; set; }
public decimal AverageConfidence { get; set; }
public DateTime FirstSignalTime { get; set; }
public DateTime LastSignalTime { get; set; }
}
/// <summary>
/// Risk level for strategies
/// </summary>
public enum StrategyRisk
{
Low,
Medium,
High,
VeryHigh
}
/// <summary>
/// Recommended time frame for strategy
/// </summary>
public enum TimeFrame
{
ShortTerm, // Minutes to hours
MediumTerm, // Hours to days
LongTerm // Days to weeks
}
/// <summary>
/// Parameter data type
/// </summary>
public enum ParameterType
{
Integer,
Decimal,
Boolean,
String
}
+18
View File
@@ -0,0 +1,18 @@
namespace TradingBot.Models;
public class TradingSignal
{
public string Symbol { get; set; } = string.Empty;
public SignalType Type { get; set; }
public decimal Price { get; set; }
public decimal Confidence { get; set; } // 0-100 confidence level
public string Reason { get; set; } = string.Empty;
public DateTime Timestamp { get; set; }
}
public enum SignalType
{
Buy,
Sell,
Hold
}