Symbols and markets#
Market types#
A trader is created for one market type and keeps it for its lifetime.
pub enum MarketType { Spot, Swap } // Spot is the default
Swap means a perpetual contract. Create separate traders if you trade both on one exchange:
let spot = create_trader("binance", creds.clone(), MarketType::Spot)?;
let perp = create_trader("binance", creds, MarketType::Swap)?;
MarketType converts from strings: "swap", "futures", "perp" and "perpetual" give Swap; anything else gives Spot. It serializes as "spot" or "swap".
Dated futures and options exist as capability fields but are not selectable market types today.
Symbol format#
Pass symbols the way you would write them on the exchange, in the form BASEQUOTE:
trader.get_current_price("BTCUSDT").await?;
Methods run the symbol through the adapter's format_symbol where an exchange uses a different notation. The default rules:
| Input | Result |
|---|---|
"BTCUSDT" |
"BTCUSDT" |
"BTC/USDT" |
"BTCUSDT" |
"btc" |
"BTCUSDT" |
"ETHUSD" |
"ETHUSD" |
If the input already ends with USDT or USD it is kept. Otherwise USDT is appended. Do not rely on this for quotes other than USDT or USD.
You can call trader.format_symbol("BTC") yourself to see what an adapter will send.
Units#
| Quantity | Unit |
|---|---|
Order quantity |
Base asset (BTC for BTCUSDT). |
usdt_amount in fast entry and dry-run helpers |
USDT. |
| Timestamps | Milliseconds since the Unix epoch (i64). |
funding_rate |
As reported by the exchange, usually a fraction per funding interval. Check your venue. |
Percentages in fast entry (tp_percent, sl_percent) |
Percent, so 2.0 means 2%. |
Intervals#
Interval lists candlestick intervals M1, M5, M15, M30, H1, H4, D1, W1, with to_seconds() for the duration. get_open_interest_history takes the interval as a plain string because the accepted values differ per exchange. Check the exchange's own documentation for the values it accepts.
Helpers in tradersdk-core#
The utils module in the core crate has small helpers used by adapters. They are public if you want them:
| Function | Purpose |
|---|---|
timestamp_ms(), timestamp_secs() |
Current time. |
hmac_sign, hmac_sign_base64 |
HMAC request signing. |
format_quantity(qty, precision), format_price(price, precision) |
Fixed-precision strings. |
parse_symbol(symbol) |
Split into (base, quote) if recognized. |
normalize_symbol(symbol) |
Normalize a symbol string. |
calculate_slippage(expected, actual) |
Slippage between two prices. |