using System.Collections.Concurrent;
using PolyTraderSharp.Models;
namespace PolyTraderSharp
{
public enum TradingMode
{
Inactive,
SellOnly,
Active
}
///
/// In-Memory Hot-Path State for PolyTrader.
/// Replaces database lookups for core trading logic.
///
public class TradingState
{
// Settings
public bool GlobalTradingPaused { get; set; } = false;
public TradingMode LiveTradingMode { get; set; } = TradingMode.Inactive;
public TradingMode DemoTradingMode { get; set; } = TradingMode.Inactive;
public bool IsAlchemyHealthy { get; set; } = false;
public bool EnableBlockchainParser { get; set; } = true;
public bool DebugPollingLog { get; set; } = false;
public bool DebugOrderPayloadLog { get; set; } = false;
public bool SixSharesMinimum { get; set; } = true;
// Accounts (AccountId -> State)
public ConcurrentDictionary Accounts { get; } = new();
// Tracked Traders (TraderId -> TrackedTrader)
public ConcurrentDictionary Traders { get; } = new();
private int _totalCopyTrades = 0;
public int TotalCopyTrades
{
get => _totalCopyTrades;
set => _totalCopyTrades = value;
}
public int GetNextTradeId()
{
return Interlocked.Increment(ref _totalCopyTrades);
}
public decimal GlobalPnl { get; set; } = 0.0m;
// Analytics Cache (AccountId -> List)
public ConcurrentDictionary> TraderAnalyticsCache { get; } = new();
// Tracks when live orders were placed for stale order cleanup
// Key: "AccountId_TokenId", Value: (PlacedAt, SourceTraderId)
public ConcurrentDictionary PendingOrderTimestamps { get; } = new();
// High-Performance Global Market Cache to prevent LiteDB bottlenecks during signal processing
public ConcurrentDictionary MarketCache { get; } = new(StringComparer.OrdinalIgnoreCase);
// Master Trader Position Tracker: Tracks how many shares each master trader holds per token.
// Key: "{TraderId}_{TokenId}", Value: (Shares, LastUpdated)
// Used to determine if a SELL signal is a partial sell (ignore) or a full exit (copy).
public ConcurrentDictionary MasterTraderPositions { get; } = new();
}
}