Capabilities#
Exchanges differ. One has funding-rate history, another does not. One streams private order updates, another only has REST. Instead of finding that out when a call fails in production, every adapter reports a capability matrix, similar to the has property in CCXT.
let caps = trader.capabilities();
if caps.is_supported("get_funding_rate_history") {
let history = trader.get_funding_rate_history("BTCUSDT", 100).await?;
}
CapabilityStatus#
Each capability is one of four values:
| Status | Meaning |
|---|---|
Supported |
Supported natively. |
Emulated |
Supported through a workaround. |
NotSupported |
The adapter does not support it. |
Unknown |
Not determined yet. This is the default. |
Unknownis not "no". An adapter that has not declared a capability reportsUnknown. Treat it as "not verified". Calling the method may still work, or may return a "not implemented" error.
ExchangeCapabilities#
ExchangeCapabilities is a struct with one CapabilityStatus field per capability. The fields fall in groups:
| Group | Fields |
|---|---|
| Market types | spot, swap, futures, option, margin |
| Order creation | create_market_order, create_limit_order, create_stop_market_order, create_stop_limit_order, create_take_profit_order, create_trailing_stop_order, create_post_only_order, create_reduce_only_order, create_orders_batch |
| Order management | cancel_order, cancel_all_orders, edit_order |
| Order queries | get_order_status, get_open_orders, get_order_history, get_order_trades |
| Positions | set_leverage, set_margin_mode, set_position_mode, close_position, get_position, get_positions |
| Market data | get_current_price, get_ticker, get_orderbook, get_ohlcv, get_trades, get_funding_rate, get_funding_rate_history, get_open_interest, get_open_interest_history |
| Account | get_balance, get_server_time, test_connection |
| WebSocket | ws_orderbook, ws_trades, ws_ticker, ws_orders, ws_positions, ws_balance |
| Fast entry | execute_fast_entry, format_symbol |
| Transfers | withdraw, get_deposit_address, transfer |
A field being present does not mean the trait has a method for it. Some capabilities describe features the SDK does not expose yet. Today the adapters declare a subset; see the exchange matrix.
Helper methods#
| Method | Returns |
|---|---|
is_supported(name) |
true for Supported or Emulated. name is the snake_case field name. Unknown names return false. |
supported_count() |
How many capabilities are Supported or Emulated. |
total_count() |
How many capabilities exist. |
Declaring capabilities in an adapter#
The exchange_capabilities! macro fills in the fields you list and leaves the rest Unknown:
use tradersdk_core::exchange_capabilities;
fn capabilities(&self) -> ExchangeCapabilities {
exchange_capabilities! {
spot: Supported,
swap: Supported,
ws_orderbook: NotSupported,
}
}
See Adding an exchange.