TraderSDKdocs

Guides

Adding an exchange#

An adapter is one crate that implements ExchangeTrader for one exchange. The steps below follow how the existing twenty are laid out.

1. Create the crate#

Add crates/tradersdk-<name>/ to the workspace with a dependency on tradersdk-core. Keep the layout of an existing adapter such as tradersdk-bybit: a client that signs and sends requests, and a trader.rs (or client.rs) that implements the trait.

2. Implement ExchangeTrader#

The trait is async_trait and Send + Sync. The required methods are the core ones: connection test, server time, balance, current price, leverage, fast entry, market and limit orders, cancel, and close position. Optional ones (ticker, order book, funding and open-interest history, order status, WebSocket tests, order updates) have defaults that return a "not implemented" error, so you can ship a partial adapter and fill in the rest later. See The ExchangeTrader trait.

Rules that keep adapters interchangeable:

  • Accept the symbol as BTCUSDT and convert inside format_symbol.
  • Return numbers as f64 and timestamps as Unix milliseconds.
  • Map the exchange's order states onto OrderStatus.
  • Return exchange rejections as errors or as OrderResult::failure, and say which in the docs for the adapter.

3. Declare capabilities#

Override capabilities() and list what works with the exchange_capabilities! macro. Use Supported for native endpoints, Emulated when the adapter builds the feature from other calls, and NotSupported for the rest. Fields you leave out stay Unknown. Callers rely on this table, so keep it honest. See Capabilities.

4. Register it#

In tradersdk-providers:

  1. Add an optional dependency and a feature named after the exchange.
  2. Add a match arm in create_trader for the lowercase name, gated by that feature.
  3. Add the name to supported_exchanges().

In the facade crate, add the feature to the list and to full. If the exchange needs a passphrase, forward ExchangeCredentials::passphrase in the arm.

5. Test#

  • Unit-test request signing against known vectors from the exchange docs.
  • Run against the testnet if there is one. Otherwise stick to read-only methods until signing is proven.
  • Check test_connection and get_server_time first; they prove signing and clock handling.

6. Document#

Add the exchange to the capability data, note passphrase and testnet support, and mention any quirks (quantity units, hedge mode, rate limits) so users do not find them the hard way.

Send a pull request to suenot/tradersdk.

Edit this page on GitHub ↗