Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Official Rust SDK for the Derive Protocol
A type-safe, async Rust client for trading, market data, account management, RFQs, and protocol interactions over WebSocket.
Documentation · Examples · API coverage · Contributing
Installation
Quick start
Public market data
// examples/get_all_instruments.rs
use ;
async
Authenticated trading
// examples/simple_order.rs
use BigDecimal;
use ;
async
Streaming market data
// examples/ws_stream_ticker.rs
use ;
use ;
use crateget_test_ws_client;
async
API design
Signable Actions
The SDK groups functionality by signing domain rather than exposing a single flat client API.
// Orders
client.orders.place.await?;
client.orders.replace.await?;
// RFQs
client.rfqs.send_rfq.await?;
client.rfqs.execute_best_quote.await?;
// Fund movements
client.fund_movements.deposit.await?;
client.fund_movements.withdraw.await?;
// Session keys
client.session_keys.add.await?;
Signable actions use typed argument structures and EIP-712 signing.
use ;
RPC requests
The SDK provides typed RPC requests for market data, account management, and other protocol interactions. Every RPC request is strongly typed and returns a typed response.
The RPC client is accessible via client.rpc() and is grouped by namespace.
Capabilities
| Area | Supported functionality |
|---|---|
| Market data | Instruments, order books, trades, tickers |
| Streaming | Public and private WebSocket subscriptions |
| Orders | Place, replace, cancel, post-only and reduce-only orders |
| RFQ | Create RFQs, submit quotes, execute quotes |
| Accounts | Subaccounts, positions, collateral and balances |
| Authentication | Wallet authentication and session keys |
| Risk controls | Cancel-on-disconnect and market-maker protection |
| Fund movements | Deposits, withdrawals and transfers |
The client also handles WebSocket heartbeats, reconnection, and subscription recovery.
Examples
The repository contains runnable examples and integration tests covering common workflows.
| Example | Description |
|---|---|
get_all_currencies |
Fetch supported currencies and ERC-20 details |
ws_stream_tickers |
Stream ticker updates for multiple instruments |
ws_rfq_subscriber |
Subscribe to RFQ updates |
order_lifecycle |
Create, replace, and cancel orders |
rfq |
End-to-end RFQ workflow |
Run an example with:
API coverage
get_all_instrumentsget_instrumentget_all_currenciesget_tickerget_orderbookget_trade_history
orderreplace_ordercancel_ordercancel_all_ordersget_orderget_open_orders
send_rfqpoll_rfqssend_quoteexecute_best_quotecancel_batch_rfqs
get_subaccountget_subaccountsget_positionsget_collateralset_cancel_on_disconnect
tickerticker_slimorderbooktradesinstrument
orderspositionsaccount_summarytradesrfqs
Configuration
WsClient::from_env() reads client configuration from environment variables.
// examples/env_login.rs
use WsClient;
async
The current client expects:
DERIVE_PRIVATE_KEY
DERIVE_WALLET
DERIVE_SUBACCOUNT_ID
DERIVE_ENVIRONMENT
Environments
| Environment | WebSocket URL | Network |
|---|---|---|
| Testnet | wss://testnet.api.derive.xyz/v3/ws |
Sepolia |
| Mainnet | wss://api.lyra.finance/ws |
Ethereum |
Architecture
Your application
│
▼
┌───────────────────────────────────────┐
│ derive-rs │
│ │
│ Actions RPC Subscriptions │
│ (signing) (request) (streaming) │
│ │
│ WebSocket client │
└──────────────────┬────────────────────┘
│
▼
Derive Protocol API
Testing
Run a specific test:
Enable debug logging:
RUST_LOG=debug
Development
Contributing
- Fork the repository.
- Create a feature branch.
- Make and test your changes.
- Push the branch.
- Open a pull request into
devbranch. - The PR will be reviewed and merged by the maintainers.
Resources
License
Licensed under the MIT License. See LICENSE.
Disclaimer
This software is provided as-is, without warranty. Trading derivatives involves substantial risk of loss.
