Venue-agnostic strategy runtime primitives for the Mantis low-latency financial SDK.
This crate provides the building blocks for implementing trading strategies. All types are no_std compatible, use fixed-size arrays, and allocate nothing on the heap.
Prediction-market-specific types (YES/NO positions, settlement PnL, merge operations) belong in mantis-prediction, not here.
| Type | Purpose |
|---|---|
Strategy |
Event-driven trait — on_event(&mut self, event, intents) -> usize |
OrderIntent |
Post/Cancel/Amend intent, repr(C), Copy, flows through SPSC rings |
Position |
Signed inventory (SignedLots), VWAP entry, realized/unrealized PnL |
OrderTracker |
Fixed-size [Option<TrackedOrder>; 64] order state machine |
QueueEstimator |
L2 probabilistic queue position model (PowerProbQueueFunc) |
ExposureView |
Composes position + open orders for worst-case risk calculation |
RiskLimits |
Per-strategy risk configuration (position, capital, rate limits) |
StrategyContext |
Optional helper bundling engine + queue + orders + risk + positions |
use mantis_strategy::{Strategy, OrderIntent, MAX_INTENTS_PER_TICK};
use mantis_events::HotEvent;
struct MyStrategy { /* ... */ }
impl Strategy for MyStrategy {
const STRATEGY_ID: u8 = 0;
const NAME: &'static str = "my-strategy";
fn on_event(
&mut self,
event: &HotEvent,
intents: &mut [OrderIntent; MAX_INTENTS_PER_TICK],
) -> usize {
// Process event, return number of intents written
0
}
}- No generics on trait —
OrderBooktype andMAXinstruments are implementation details inside each concrete strategy, not on the trait surface - Associated consts —
STRATEGY_IDandNAMEare compile-time, not runtime methods - Enum dispatch — bot binaries use enum dispatch (not
dyn) for zero vtable overhead LotsvsSignedLots— unsigned for order sizes, signed for position inventory- Fixed arrays —
[Option<T>; 64]everywhere, no HashMap, no Vec, no heap - Replay-friendly — strategy is a pure event→intent state machine. Same tape = same intents
The QueueEstimator uses a probabilistic model based on the PowerProbQueueFunc from hftbacktest:
- Cancels are biased toward the back of the queue (parameter
n=2-3) - Fill probability estimated via Poisson model:
P[Poisson(take_rate * time) >= ahead_qty + order_qty] - Take rate tracked per instrument per side via EWMA
- Calibrate
nfrom live fill data
Apache-2.0