hybrid-perps-spec

L2 Order Routing Layer

Routing Mode Overview

The system supports three routing modes, controlled by admin via the admin panel (see 11-admin.md).

Mode Trigger Scenario Routing Behavior
HL_MODE (Hyperliquid Mode) Net exposure too large, high risk All new opens → HL; no internalization
NORMAL_MODE (Default) Net exposure within acceptable range Route by standard threshold
BETTING_MODE (Aggressive Mode) Net exposure very low, book balanced Route by elevated betting threshold

Routing Decision Logic

Notional Value = Order Quantity × Current HL Mark Price

switch (current routing mode):

  case HL_MODE:
    → All new open orders → HYPERLIQUID (regardless of size)

  case NORMAL_MODE:
    if Notional Value ≤ Normal Mode Threshold (default $10,000)
      → INTERNAL (platform internalization)
    else
      → HYPERLIQUID

  case BETTING_MODE:
    if Notional Value ≤ Betting Mode Threshold (default $50,000)
      → INTERNAL (platform internalization)
    else
      → HYPERLIQUID

Routing decision latency target: < 5ms P99

Routing Rule Details

Threshold Configuration

Setting Default Applies To
Normal mode routing threshold $10,000 NORMAL_MODE
Betting mode routing threshold $50,000 BETTING_MODE

Multiple Opens — Same Asset & Direction

Normal mode, threshold $10,000:

Result: User holds two independent BTC long positions, each with its own entry price.

Force-Route to HL (all modes, highest priority)

Condition Description
Volatility spike (>5%/hour) No internalization during extreme price moves
HL latency exceeded (>500ms) Conservative fallback to HL

Note: Routing modes already cover “net exposure at limit” and “manual halt” scenarios — these are no longer listed as independent force-route conditions.

Close Order Routing

Close order must follow the original position source:

Cross-system offset is forbidden: an INTERNAL position cannot offset a HYPERLIQUID position.

Cancel Order Routing

Order Type Handling
INTERNAL pending limit order Remove from internal queue; release frozen margin
HYPERLIQUID pending limit order Send cancel instruction to HL

Routing Transparency

Users cannot detect routing differences:

MVP Routing Limitations

Single-order cross-threshold splitting is not supported in MVP:

Routing Log

Every routing decision must be logged: