Rust SDK Overview
The tradectl SDK (tradectl-sdk) provides the building blocks for writing trading strategies.
Installation
Add to your Cargo.toml (or use tradectl init which sets this up automatically):
toml
[dependencies]
tradectl-sdk = "0.1"Core Types
Events
TickerEvent— best bid/ask snapshot with quantities and timestampTradeEvent— individual trade (price, quantity, timestamp, is_buyer_maker)
Strategy
Strategytrait —on_ticker,on_trade,name,describe,params_schema,on_position_closeAction—Hold,MarketOpen,LimitOpen,ClosePosition,CloseAll,CancelPendingStrategyContext— positions, balance, PnL, trade count, timestampPositionInfo— id, side, entry price, quantity, unrealized PnLSide—Long,ShortCloseReason—TakeProfit,StopLoss,ForceClose
Parameters
Params—HashMap<String, f64>with.get(key, default)and.set(key, value)ParamDef— schema definition (key, description, default, min, max, step)
Loading Strategies
declare_strategy!macro — exports the strategy as a dynamic library entry point
Managers
Composable components injected into strategies:
TPSLManager— take-profit / stop-loss managementKlineManager— build candles from tick dataRangeBarManager— build range bars from tick data
Indicators
Built-in technical indicators (all implement the Indicator trait with .update(value), .value(), .ready()):
Sma— Simple Moving AverageEma— Exponential Moving AverageRsi— Relative Strength IndexBollingerBands— Bollinger Bands (.upper(),.lower())Macd— MACD (.signal(),.histogram())Atr— Average True Range (.update_hlc(high, low, close))StdDev— Standard DeviationVwap— Volume-Weighted Average Price (.update_pv(price, volume),.reset())
MarketAdapter
Unified async interface for all exchanges:
rust
pub trait MarketAdapter {
async fn place_order(&self, order: Order) -> Result<OrderResult>;
async fn cancel_order(&self, id: &str) -> Result<()>;
async fn get_position(&self) -> Result<Position>;
async fn get_balance(&self) -> Result<Balance>;
}Also implemented by TestExchange for unit testing without network.