Expand description
Async Rust client for the OKX v5 REST API.
The crate is built around three layers that map cleanly onto the OKX request lifecycle:
- Request building — typed request/response models live under
api. - Authentication — credentials and HMAC-SHA256 request signing.
- Transport — sending raw HTTP. The
Transporttrait abstracts this so the defaultReqwestTransportcan be swapped for a custom or mock implementation without changing any calling code.
§Example
use rust_okx::{Credentials, OkxClient, api::market::InstIdRequest};
// Public, unauthenticated client.
let client = OkxClient::builder().build();
let ticker = client
.market()
.get_ticker(&InstIdRequest {
inst_id: "BTC-USDT",
})
.await?;
println!("last price: {}", ticker[0].last.as_str());
// Authenticated client.
let creds = Credentials::new("key", "secret", "passphrase");
let client = OkxClient::builder().credentials(creds).build();
let balance = client.account().get_balance(rust_okx::api::account::BalanceRequest::default()).await?;Re-exports§
pub use error::WsError;pub use model::NumberString;pub use transport::ReqwestTransport;pub use transport::Transport;pub use transport::TransportError;pub use ws::Arg;pub use ws::OkxWs;pub use ws::OkxWsBuilder;pub use ws::Push;pub use ws::WsChannelConnectionCount;pub use ws::WsChannelGroup;pub use ws::WsConn;pub use ws::WsConnector;pub use ws::WsEvent;pub use ws::WsFrame;pub use ws::WsNotice;pub use ws::WsOperation;
Modules§
- api
- Typed request/response models and endpoint methods, grouped by OKX API area.
- model
- Shared data types: the
NumberStringwrapper, the response envelope, and the common string enums used across the API modules. - transport
- The HTTP transport abstraction.
- ws
- OKX WebSocket client.
Structs§
- Credentials
- OKX API credentials: an API key, secret key, and passphrase.
- OkxClient
- An OKX v5 REST API client, generic over the HTTP
Transport. - OkxClient
Builder - Builder for
OkxClient.
Enums§
Constants§
- API_URL
- Default global OKX REST API base URL.
- EEA_
API_ URL - EEA OKX REST API base URL.
- GLOBAL_
API_ URL - Global OKX REST API base URL.
- US_
API_ URL - US and AU OKX REST API base URL.
Type Aliases§
- Result
- A type alias for
std::result::Resultusing this crate’sError.