Expand description
Sequence Algo SDK - Ultra Low Latency Trading
Write HFT algorithms in Rust, compile to WASM, deploy to Sequence.
§Example
ⓘ
use algo_sdk::*;
struct MyAlgo { next_id: u64 }
impl Algo for MyAlgo {
fn on_book(&mut self, book: &L2Book, state: &AlgoState, actions: &mut Actions) {
if book.spread_bps() > 10 && state.position_1e8.abs() < 100_000_000 {
self.next_id += 1;
actions.buy(self.next_id, 1_000_000, book.bids[0].px_1e9 + 100);
}
}
fn on_fill(&mut self, _: &Fill, _: &AlgoState) {}
fn on_reject(&mut self, _: &Reject) {}
fn on_shutdown(&mut self, _: &AlgoState, _: &mut Actions) {}
}
export_algo!(MyAlgo { next_id: 0 });Modules§
- Order
Type - Order type for execution semantics.
- Reject
Code - Reject codes from exchange (matches cc_proto::RejectClass).
- Status
- Order status.
- log
- Algo logging - non-blocking, ~100ns per call. Logs are batched and viewable via dashboard with 1-2s delay.
- time
- Simple timing helpers for client-controlled latency measurement. SDK/runtime does not force any logging; strategy decides how/when to log.
Macros§
- export_
algo - Stub macro for native builds (no-op).
- export_
algo_ v3 - Stub macro for native builds (no-op).
- export_
multi_ venue_ algo - Stub macro for native builds (no-op).
- log_
debug - Log debug with formatting.
- log_
error - Log error with formatting.
- log_
info - Log info message with formatting.
- log_
warn - Log warning with formatting.
Structs§
- Action
- Order action (place, cancel, or amend).
- Actions
- Actions buffer - orders to send.
- Algo
State - Algo state: position, orders, session stats, symbol metadata, and risk limits. All managed by server — read-only from algo’s perspective.
- Fill
- FillExt
- Extended fill metadata (NOT in WASM memory — delivered via separate channel).
- L2Book
- L2 order book with up to 20 levels per side. Total size: 688 bytes (fits in L1 cache).
- Level
- Single price level in the order book.
- Nbbo
Snapshot - Cross-venue NBBO snapshot delivered to multi-venue algos.
- Online
Features - Online microstructure features delivered by the CC data engine. Written to WASM memory before each algo callback. Old algos that never read 0x1A000 are unaffected (backward compatible).
- Open
Order - Open order tracked by server.
- PnlSnapshot
- PnL snapshot in fixed-point units (1e9 = $1.00).
- Pool
Books - Per-pool depth books delivered to multi-venue algos.
- Pool
Meta - Per-pool metadata: compact identity for a single DEX pool.
- Reject
- Risk
Snapshot - Current risk limits — read-only view for algos. Allows pre-checking orders before placing (avoids wasting actions on rejects).
- Symbol
Meta - Symbol trading specifications from the exchange. Injected by runtime — prevents rejects from wrong lot size / tick size. Fields set to 0 mean “unknown” — helpers return input unchanged.
- Venue
Books - Per-venue full-depth order books delivered to multi-venue algos.
- Wasm
Actions - Wire format for actions buffer.
Enums§
- LogLevel
- Log levels for algo logging.
Constants§
- ACTION_
AMEND - Amend an existing order (atomic modify price/qty).
- ACTION_
CANCEL - Cancel an existing order.
- ACTION_
NEW - New order action (place on book).
- MAX_
ACTIONS - Max actions per callback.
- MAX_
ORDERS - Maximum open orders per algo.
- MAX_
POOLS - Maximum number of individual pool slots tracked per symbol.
- MAX_
VENUES - Maximum number of venues in a multi-venue snapshot.
- ONLINE_
FEATURES_ WASM_ OFFSET - WASM offset for OnlineFeatures — page-aligned after PoolBooks. PoolBooks at 0x14000, size ~23KB -> ends well before 0x1A000.
- POOL_
BOOKS_ WASM_ OFFSET - WASM memory offset where PoolBooks is written by the runtime. Located after VenueBooks to avoid overlap.
- VENUE_
BINANCE - Binance (CEX)
- VENUE_
BITGET - Bitget (CEX)
- VENUE_
BITMART - Bitmart (CEX)
- VENUE_
BOOKS_ WASM_ OFFSET - WASM memory offset where VenueBooks is written by the runtime. Multi-venue algos read per-venue depth from this fixed address.
- VENUE_
BYBIT - Bybit (CEX)
- VENUE_
COINBASE - Coinbase (CEX)
- VENUE_
CRYPTOCOM - Crypto.com (CEX)
- VENUE_
DEX - Generic DEX (aggregated across chains)
- VENUE_
DEX_ ARB - DEX — Arbitrum (Uniswap V3, Camelot)
- VENUE_
DEX_ BASE - DEX — Base (Uniswap V3, Aerodrome)
- VENUE_
DEX_ ETH - DEX — Ethereum mainnet (Uniswap V2/V3, Curve, Balancer V2)
- VENUE_
DEX_ OP - DEX — Optimism (Uniswap V3, Velodrome)
- VENUE_
DEX_ POLY - DEX — Polygon (Uniswap V2, Balancer V2, Curve)
- VENUE_
DEX_ SOL - DEX — Solana (Raydium, Orca, Jupiter aggregated)
- VENUE_
HYPERLIQUID - Hyperliquid (CEX — L1 with on-chain settlement, EIP-712 signing)
- VENUE_
KRAKEN - Kraken (CEX)
- VENUE_
OKX - OKX (CEX)
- VENUE_
UNKNOWN - Unknown venue (wire ID 10, maps to CC VenueId::Unknown)
Traits§
- Algo
- Trading algorithm trait. All methods run on HOT PATH - avoid heap allocations.
- AlgoV3
- Extended algo trait with OnlineFeatures access.
- Multi
Venue Algo - Multi-venue trading algorithm trait.
Functions§
- is_cex
- Returns
trueif this venue is a CEX (centralized exchange). - is_dex
- Returns
trueif this venue is a DEX (on-chain liquidity). - venue_
name - Human-readable name for a venue ID.