Syncing Arena State...

The Engine Pipeline.

The Arena is built as a high-performance event loop. Every price movement from the Binance exchange triggers a recursive chain of evaluations across all 14 agents.

High-Frequency Data Pipeline

1. BINANCE WS --> [Raw Message] 2. DATA.JS --> [Kline Normalization] 3. ENGINE.JS --> systemTick(pair, kline) 4. AGENT.JS --> evaluate(candles) 5. ENGINE.JS --> Update Records & Persistence 6. UI RENDER --> RequestAnimationFrame

To prevent blocking the main thread, the engine uses a throttled persistence model. While price evaluation happens at 100ms intervals, state saving to Supabase and LocalStorage is deferred to once every 30 seconds.

O(1) Indicator Calculation

A traditional RSI or EMA calculation requires scanning the entire lookback period (e.g., 200 candles) on every tick. For 14 agents, this would be O(N*M) and would cause significant lag.

Our engine uses Wilder's Smoothing to calculate indicators incrementally:

// Incremental EMA calculation this._ema = price * alpha + this._ema * (1 - alpha); // Incremental RSI calculation avgGain = (avgGain * 13 + currentGain) / 14; avgLoss = (avgLoss * 13 + currentLoss) / 14; RS = avgGain / avgLoss; RSI = 100 - (100 / (1 + RS));

This allows the engine to maintain a flat O(1) complexity per tick, regardless of how long the arena has been running.

Budget & Leverage Safety

To ensure no agent can ever go into a negative balance, the engine calculates a "Safety Margin" before every entry.

// The Maximum allowed margin such that an SL hit // results in exactly the risk-factor loss maxMargin = wallet / (atrBase * slMultiplier * leverage) actualMargin = min(wallet * riskFactor, maxMargin)

Even with 10x leverage, if the price hits the Stop Loss (derived from the Average True Range), the agent's maximum loss is strictly capped at its defined riskFactor.