Pre-Trade API
The Pre-Trade API provides comprehensive analysis before order execution, answering two key questions:- Can we trade? - Validation (balance, limits, symbol, market status)
- What will it cost? - Analytics (fees, slippage, impact, liquidity)
Key Features
- Balance validation: Check sufficient funds in quote (buy) or base (sell) currency
- Daily limit enforcement: Prevent exceeding configured trading limits
- Symbol validation: Verify trading pair exists and is tradeable
- Order size checks: Validate against exchange min/max constraints
- Liquidity analysis: Order size vs depth, ADV, time-to-fill estimates
- Cost estimation: Fees + slippage + market impact with confidence scoring
- Scenario analysis: Size sensitivity and taker vs maker comparison
- Trader summary: Human-readable output with warnings
POST /oems/pretrade/analyze
Perform comprehensive pre-trade analysis including validation, liquidity metrics, cost estimation, and optional scenario analysis.Request Body (JSON)
- symbol (string, required): Trading pair in CCXT format (e.g., “BTC/USDT”)
- side (string, required): Order side: “buy” or “sell”
- quantity (number, required): Order quantity in base currency (e.g., 0.5 for 0.5 BTC)
- exchange_account_ids (array, required): List of exchange account IDs to check (e.g., [“gateio-001”, “binance-sandbox-001”])
- order_type (string, optional): Order type: “market”, “limit”, or “algo”. Default: “market”
- limit_price (number, optional): Limit price for limit orders (required if order_type is “limit”)
- urgency (string, optional): Order urgency: “low”, “normal”, or “high”. Affects scenario analysis. Default: “normal”
- include_scenarios (boolean, optional): Whether to include size sensitivity and taker/maker scenario analysis. Default: false
Request Example
Response Example (Validation Passed)
Response Example (Validation Failed)
Validation Checks
| Check | Description |
|---|---|
| balance | Verifies sufficient funds (quote for buy, base for sell) |
| daily_limit | Verifies order won’t exceed daily trading limit |
| symbol | Verifies trading pair exists and is active |
| order_size | Verifies order meets minimum ($10) and exchange constraints |
Warning Codes
| Code | Severity | Trigger |
|---|---|---|
| INSUFFICIENT_BALANCE | critical | Balance check failed |
| DAILY_LIMIT_EXCEEDED | critical | Would exceed daily limit |
| SYMBOL_NOT_FOUND | critical | Symbol not tradeable |
| BELOW_MINIMUM_ORDER | critical | Order below $10 minimum |
| LOW_LIQUIDITY | warning | Order > 20% of top-20 depth |
| VERY_LOW_LIQUIDITY | critical | Order > 50% of top-20 depth |
| LARGE_ORDER | warning | Order > 5% of ADV |
| VERY_LARGE_ORDER | critical | Order > 10% of ADV |
| STALE_FEED | warning | Venue staleness > 1s |
| WIDE_SPREAD | warning | Spread > 10 bps |
| HIGH_IMPACT | warning | Estimated impact > 10 bps |
| LOW_CONFIDENCE | warning | Confidence < 50% |
POST /oems/pretrade/validate
Perform quick validation without full cost analysis. Use this for fast pre-flight checks.Request Body (JSON)
- symbol (string, required): Trading pair in CCXT format
- side (string, required): Order side: “buy” or “sell”
- quantity (number, required): Order quantity in base currency
- exchange_account_ids (array, required): List of exchange account IDs to validate against
Request Example
Response Example
GET /oems/pretrade/liquidity
Get current liquidity metrics for a trading pair. Requires an active orderbook subscription.Query Parameters
- symbol (string, required): Trading pair in CCXT format (e.g., “BTC/USDT”)
Request Example
Response Example (With Orderbook Data)
Response Example (No Orderbook Data)
GET /oems/pretrade/fees
Get fee schedule for a venue, account, or all configured venues. Supports account-specific fees including VIP tiers, negotiated rates, and pair-specific overrides.Query Parameters
- venue (string, optional): Exchange venue name. Returns default venue fees from static configuration.
- exchange_account_id (string, optional): Exchange account ID for account-specific fees. When provided, returns actual fees for the account including VIP tier rates from exchange API, negotiated rates from database overrides, and pair-specific fees if
symbolis also provided. - symbol (string, optional): Trading pair for pair-specific fees. Only used with
exchange_account_id.
Fee Resolution Priority
Whenexchange_account_id is provided, fees are resolved in this order:
- Pair-specific DB override:
fee_overrides.pairs.{symbol}in exchange_accounts collection - Account-level DB override:
fee_overrides.maker_bps/taker_bpsin exchange_accounts collection - Exchange API: VIP tier from
fetch_trading_fees()orfetch_trading_fee(symbol) - Static config: Default venue fees from configuration
Request Examples
Response Example (Account-Specific Fees)
Response Example (Single Venue - Static Config)
Response Example (All Venues)
Fee Sources
| Source | Description |
|---|---|
db_pair_override | Pair-specific override from exchange_accounts collection |
db_account_override | Account-level override from exchange_accounts collection |
exchange_api | Real-time VIP tier from exchange API |
exchange_markets | Fee info from exchange markets data |
config | Static configuration defaults |
default | Fallback default (5 bps maker / 10 bps taker) |
Default Fee Schedule
| Venue | Maker (bps) | Taker (bps) |
|---|---|---|
| Binance | 2 | 4 |
| Bybit | 1 | 6 |
| Gate.io | 2 | 4 |
| Kraken | 2 | 5 |
| Hyperliquid | 0 | 3.5 |
| OKX | 2 | 5 |
Database Fee Overrides
Account-specific fees can be configured in theexchange_accounts collection:
Cost Model
The pre-trade cost estimation uses the following model:Total Cost
Slippage Calculation
Slippage is calculated by walking the orderbook:Market Impact Model
Uses a square-root model:- Order = 1% ADV: impact ~5 bps
- Order = 4% ADV: impact ~10 bps
- Order = 9% ADV: impact ~15 bps
Confidence Scoring
Confidence starts at 1.0 and is reduced by:| Factor | Penalty |
|---|---|
| Book staleness > 500ms | -0.1 per 500ms (max -0.3) |
| Order > 20% of depth | -0.2 |
| Spread > 10 bps | -0.1 |
| No ADV data | -0.2 |
- Greater than 0.8: “High”
- 0.5 - 0.8: “Medium”
- Less than 0.5: “Low”

