Skip to content

Latest commit

 

History

History
54 lines (40 loc) · 2.54 KB

File metadata and controls

54 lines (40 loc) · 2.54 KB

Technical Deep Dive (SaaS v9)

Multi-Tenant Trading Cycles

The backend operates on a hierarchical timing model to balance responsiveness with resource efficiency.

1. Fast Monitoring (every 10 seconds)

  • Scope: All users with active TradeSessions.
  • Tasks:
    • ROI check (if ROI > TrailingActivationRoiPercent, move to Trailing status).
    • Trailing stop update on exchange.
    • Verification of SL/TP existence.
    • Stale session cleanup.

2. ML Quick Scan / "ML Sniper" (every 60 seconds)

  • Scope: Global market data.
  • Tasks:
    • Fast-path execution for strong Bayesian ML signals.
    • Market data enrichment for the SignalR stream.

3. Full AI Cycle (every 30 minutes)

  • Scope: Sequential per-user execution.
  • Tasks:
    • Macro analysis (Fear/Greed, BTC.D, FOMC dates).
    • Google Gemini 1.5 Pro advisory call.
    • Portfolio rebalancing (closing weak positions, opening new grids).

Nash Equilibrium & Volume Profile

NetTrader uses Game Theory principles for order placement.

High Volume Nodes (HVN)

The system constructs a Volume Profile from historical klines. It identifies "Liquidity Walls" where significant trading volume has occurred.

Order Placement

  • Front-running: Orders are placed 2 ticks ahead of the HVN to ensure execution before the liquidity wall is hit.
  • Stop Loss: Hidden 5 ticks behind the nearest strong liquidity wall.
  • Take Profit: Placed 2 ticks before the target resistance wall.

Proportional Sizing

Investment is not distributed linearly. More capital is allocated to grid levels near high-volume nodes (higher probability of bounce/support) and less to low-volume areas.

Risk Controls

  • Leverage-Aware Sizing: Investment amounts are automatically clamped based on user leverage and available balance.
  • Dynamic SL/TP: Calculated via Volume Profile with a safety "Hard Stop" at 1.5x the fallback percentage.
  • Emergency Stop: Triggered via /panic or when balance drops below the safety threshold. Immediately cancels all orders and closes positions with reduceOnly: true.
  • Daily Drawdown: Automatic pause if daily losses exceed the configured percentage.

Security Model

  • Key Isolation: API keys are never decrypted in the API process for display. They are only decrypted in the background worker process at the moment of exchange client instantiation.
  • Encrypted Storage: AES-256-CBC with HMAC for integrity.
  • Environment Separation: User keys explicitly track the IsTestnet flag, preventing accidental live trades with testnet credentials.