Skip to main content

Crate algo_sdk

Crate algo_sdk 

Source
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§

OrderType
Order type for execution semantics.
RejectCode
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.
AlgoState
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.
NbboSnapshot
Cross-venue NBBO snapshot delivered to multi-venue algos.
OnlineFeatures
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).
OpenOrder
Open order tracked by server.
PnlSnapshot
PnL snapshot in fixed-point units (1e9 = $1.00).
PoolBooks
Per-pool depth books delivered to multi-venue algos.
PoolMeta
Per-pool metadata: compact identity for a single DEX pool.
Reject
RiskSnapshot
Current risk limits — read-only view for algos. Allows pre-checking orders before placing (avoids wasting actions on rejects).
SymbolMeta
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.
VenueBooks
Per-venue full-depth order books delivered to multi-venue algos.
WasmActions
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.
MultiVenueAlgo
Multi-venue trading algorithm trait.

Functions§

is_cex
Returns true if this venue is a CEX (centralized exchange).
is_dex
Returns true if this venue is a DEX (on-chain liquidity).
venue_name
Human-readable name for a venue ID.