Skip to main content

Crate rust_okx

Crate rust_okx 

Source
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:

  1. Request building — typed request/response models live under api.
  2. Authentication — credentials and HMAC-SHA256 request signing.
  3. Transport — sending raw HTTP. The Transport trait abstracts this so the default ReqwestTransport can 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 NumberString wrapper, 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.
OkxClientBuilder
Builder for OkxClient.

Enums§

Error
Top-level error type.
OkxRegion
OKX REST API region.
RestError
Errors from the REST API layer.

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::Result using this crate’s Error.