Skip to main content

Okx

Struct Okx 

Source
pub struct Okx { /* private fields */ }
Expand description

OKX exchange structure.

Implementations§

Source§

impl Okx

Source

pub async fn fetch_balance(&self) -> Result<Balance>

Fetch account balances.

§Returns

Returns a Balance structure with all currency balances.

§Errors

Returns an error if authentication fails or the API request fails.

Source

pub async fn fetch_my_trades( &self, symbol: &str, since: Option<i64>, limit: Option<u32>, ) -> Result<Vec<Trade>>

Fetch user’s trade history.

§Arguments
  • symbol - Trading pair symbol.
  • since - Optional start timestamp in milliseconds.
  • limit - Optional limit on number of trades (maximum: 100).
§Returns

Returns a vector of Trade structures representing user’s trade history.

Source§

impl Okx

Source

pub async fn fetch_funding_rate_impl(&self, symbol: &str) -> Result<FundingRate>

Fetch current funding rate for a symbol.

Uses OKX GET /api/v5/public/funding-rate (public endpoint).

Source

pub async fn fetch_funding_rates_impl( &self, symbols: &[&str], ) -> Result<Vec<FundingRate>>

Fetch funding rates for multiple symbols.

Calls fetch_funding_rate_impl for each symbol.

Source

pub async fn fetch_funding_rate_history_impl( &self, symbol: &str, since: Option<i64>, limit: Option<u32>, ) -> Result<Vec<FundingRateHistory>>

Fetch funding rate history for a symbol.

Uses OKX GET /api/v5/public/funding-rate-history (public endpoint).

Source§

impl Okx

Source

pub async fn set_leverage_impl( &self, symbol: &str, leverage: u32, margin_mode: Option<&str>, ) -> Result<()>

Set leverage for a symbol.

Uses OKX POST /api/v5/account/set-leverage endpoint.

§Arguments
  • symbol - Unified symbol (e.g., “BTC/USDT:USDT”)
  • leverage - Leverage multiplier
  • margin_mode - “cross” or “isolated”
Source

pub async fn get_leverage_impl(&self, symbol: &str) -> Result<u32>

Get current leverage for a symbol.

Uses OKX GET /api/v5/account/leverage-info endpoint.

Source§

impl Okx

Source

pub async fn set_margin_mode_impl(&self, symbol: &str, mode: &str) -> Result<()>

Set margin mode (cross or isolated) for a symbol.

Uses OKX POST /api/v5/account/set-position-mode for position mode, and the leverage endpoint implicitly sets margin mode.

Note: OKX sets margin mode per-instrument via the set-leverage endpoint’s mgnMode parameter. This method provides a dedicated interface.

Source§

impl Okx

Source

pub async fn fetch_position_impl(&self, symbol: &str) -> Result<Position>

Fetch a single position for a symbol.

Uses OKX GET /api/v5/account/positions endpoint.

Source

pub async fn fetch_positions_impl( &self, symbols: &[&str], ) -> Result<Vec<Position>>

Fetch positions for specific symbols, or all positions if empty.

Uses OKX GET /api/v5/account/positions endpoint.

Source§

impl Okx

Source

pub async fn fetch_markets(&self) -> Result<Arc<HashMap<String, Arc<Market>>>>

Fetch all trading markets.

§Returns

Returns a vector of Market structures containing market information.

§Errors

Returns an error if the API request fails or response parsing fails.

§Example
let okx = Okx::builder().build()?;
let markets = okx.fetch_markets().await?;
println!("Found {} markets", markets.len());
Source

pub async fn load_markets( &self, reload: bool, ) -> Result<Arc<HashMap<String, Arc<Market>>>>

Load and cache market data.

If markets are already loaded and reload is false, returns cached data.

§Arguments
  • reload - Whether to force reload market data from the API.
§Returns

Returns a HashMap containing all market data, keyed by symbol (e.g., “BTC/USDT”).

Source

pub async fn fetch_ticker(&self, symbol: &str) -> Result<Ticker>

Fetch ticker for a single trading pair.

§Arguments
  • symbol - Trading pair symbol (e.g., “BTC/USDT”).
§Returns

Returns Ticker data for the specified symbol.

Source

pub async fn fetch_tickers( &self, symbols: Option<Vec<String>>, ) -> Result<Vec<Ticker>>

Fetch tickers for multiple trading pairs.

§Arguments
  • symbols - Optional list of trading pair symbols; fetches all if None.
§Returns

Returns a vector of Ticker structures.

Source

pub async fn fetch_order_book( &self, symbol: &str, limit: Option<u32>, ) -> Result<OrderBook>

Fetch order book for a trading pair.

§Arguments
  • symbol - Trading pair symbol.
  • limit - Optional depth limit (valid values: 1-400; default: 100).
§Returns

Returns OrderBook data containing bids and asks.

Source

pub async fn fetch_trades( &self, symbol: &str, limit: Option<u32>, ) -> Result<Vec<Trade>>

Fetch recent public trades.

§Arguments
  • symbol - Trading pair symbol.
  • limit - Optional limit on number of trades (maximum: 500).
§Returns

Returns a vector of Trade structures, sorted by timestamp in descending order.

Source

pub async fn fetch_ohlcv_v2(&self, request: OhlcvRequest) -> Result<Vec<OHLCV>>

Fetch OHLCV (candlestick) data using the builder pattern.

This is the preferred method for fetching OHLCV data. It accepts an OhlcvRequest built using the builder pattern, which provides validation and a more ergonomic API.

§Arguments
§Returns

Returns a vector of OHLCV structures.

§Errors

Returns an error if the market is not found or the API request fails.

Requirements: 2.3, 2.6

Source

pub async fn fetch_ohlcv( &self, symbol: &str, timeframe: &str, since: Option<i64>, limit: Option<u32>, ) -> Result<Vec<OHLCV>>

👎Deprecated since 0.2.0: Use fetch_ohlcv_v2 with OhlcvRequest::builder() instead

Fetch OHLCV (candlestick) data (deprecated).

§Deprecated

This method is deprecated. Use fetch_ohlcv_v2 with OhlcvRequest::builder() instead for a more ergonomic API.

§Arguments
  • symbol - Trading pair symbol.
  • timeframe - Candlestick timeframe (e.g., “1m”, “5m”, “1h”, “1d”).
  • since - Optional start timestamp in milliseconds.
  • limit - Optional limit on number of candles (maximum: 300).
§Returns

Returns a vector of OHLCV structures.

Source§

impl Okx

Source

pub async fn create_order_v2(&self, request: OrderRequest) -> Result<Order>

Create a new order using the builder pattern.

This is the preferred method for creating orders. It accepts an OrderRequest built using the builder pattern, which provides compile-time validation of required fields and a more ergonomic API.

§Arguments
§Returns

Returns the created Order structure with order details.

§Errors

Returns an error if authentication fails, market is not found, or the API request fails.

Requirements: 2.2, 2.6

Source

pub async fn create_order( &self, symbol: &str, order_type: OrderType, side: OrderSide, amount: Amount, price: Option<Price>, ) -> Result<Order>

👎Deprecated since 0.2.0: Use create_order_v2 with OrderRequest::builder() instead

Create a new order (deprecated).

§Deprecated

This method is deprecated. Use create_order_v2 with OrderRequest::builder() instead for a more ergonomic API.

§Arguments
  • symbol - Trading pair symbol.
  • order_type - Order type (Market, Limit).
  • side - Order side (Buy or Sell).
  • amount - Order quantity.
  • price - Optional price (required for limit orders).
§Returns

Returns the created Order structure with order details.

Source

pub async fn cancel_order(&self, id: &str, symbol: &str) -> Result<Order>

Cancel an existing order.

§Arguments
  • id - Order ID to cancel.
  • symbol - Trading pair symbol.
§Returns

Returns the canceled Order structure.

Source

pub async fn fetch_order(&self, id: &str, symbol: &str) -> Result<Order>

Fetch a single order by ID.

§Arguments
  • id - Order ID to fetch.
  • symbol - Trading pair symbol.
§Returns

Returns the Order structure with current status.

Source

pub async fn fetch_open_orders( &self, symbol: Option<&str>, since: Option<i64>, limit: Option<u32>, ) -> Result<Vec<Order>>

Fetch open orders.

§Arguments
  • symbol - Optional trading pair symbol. If None, fetches all open orders.
  • since - Optional start timestamp in milliseconds.
  • limit - Optional limit on number of orders (maximum: 100).
§Returns

Returns a vector of open Order structures.

Source

pub async fn fetch_closed_orders( &self, symbol: Option<&str>, since: Option<i64>, limit: Option<u32>, ) -> Result<Vec<Order>>

Fetch closed orders.

§Arguments
  • symbol - Optional trading pair symbol. If None, fetches all closed orders.
  • since - Optional start timestamp in milliseconds.
  • limit - Optional limit on number of orders (maximum: 100).
§Returns

Returns a vector of closed Order structures.

Source§

impl Okx

Source

pub fn get_auth(&self) -> Result<OkxAuth>

Get the authentication instance if credentials are configured.

Source

pub fn check_required_credentials(&self) -> Result<()>

Check that required credentials are configured.

Source

pub fn get_inst_type(&self) -> &str

Get the instrument type for API requests.

Maps the configured default_type to OKX’s instrument type (instType) parameter. OKX uses a unified V5 API, so this primarily affects market filtering.

§Returns

Returns the OKX instrument type string:

  • “SPOT” for spot trading
  • “MARGIN” for margin trading
  • “SWAP” for perpetual contracts
  • “FUTURES” for delivery contracts
  • “OPTION” for options trading
Source§

impl Okx

Source

pub fn builder() -> OkxBuilder

Creates a new OKX instance using the builder pattern.

This is the recommended way to create an OKX instance.

§Example
use ccxt_exchanges::okx::Okx;

let okx = Okx::builder()
    .api_key("your-api-key")
    .secret("your-secret")
    .passphrase("your-passphrase")
    .sandbox(true)
    .build()
    .unwrap();
Source

pub fn new(config: ExchangeConfig) -> Result<Self>

Creates a new OKX instance.

§Arguments
  • config - Exchange configuration.
Source

pub fn new_with_options( config: ExchangeConfig, options: OkxOptions, ) -> Result<Self>

Creates a new OKX instance with custom options.

This is used internally by the builder pattern.

§Arguments
  • config - Exchange configuration.
  • options - OKX-specific options.
Source

pub fn base(&self) -> &BaseExchange

Returns a reference to the base exchange.

Source

pub fn base_mut(&mut self) -> &mut BaseExchange

Returns a mutable reference to the base exchange.

Source

pub fn options(&self) -> &OkxOptions

Returns the OKX options.

Source

pub fn set_options(&mut self, options: OkxOptions)

Sets the OKX options.

Source

pub fn id(&self) -> &'static str

Returns the exchange ID.

Source

pub fn name(&self) -> &'static str

Returns the exchange name.

Source

pub fn version(&self) -> &'static str

Returns the API version.

Source

pub fn certified(&self) -> bool

Returns true if the exchange is CCXT-certified.

Source

pub fn pro(&self) -> bool

Returns true if Pro version (WebSocket) is supported.

Source

pub fn rate_limit(&self) -> u32

Returns the rate limit in requests per second.

Source

pub fn is_sandbox(&self) -> bool

Returns true if sandbox/demo mode is enabled.

Sandbox mode is enabled when either:

  • config.sandbox is set to true
  • options.demo is set to true
§Returns

true if sandbox mode is enabled, false otherwise.

§Example
use ccxt_exchanges::okx::Okx;
use ccxt_core::ExchangeConfig;

let config = ExchangeConfig {
    sandbox: true,
    ..Default::default()
};
let okx = Okx::new(config).unwrap();
assert!(okx.is_sandbox());
Source

pub fn is_testnet_trading(&self) -> bool

Returns true if demo trading mode is enabled.

This is an OKX-specific alias for is_sandbox(). Demo trading mode is enabled when either:

  • config.sandbox is set to true
  • options.demo is set to true

When demo trading is enabled, the client will:

  • Add the x-simulated-trading: 1 header to all REST API requests
  • Use demo WebSocket URLs (wss://wspap.okx.com:8443/ws/v5/*?brokerId=9999)
  • Continue using the production REST domain (https://www.okx.com)
§Returns

true if demo trading mode is enabled, false otherwise.

§Example
use ccxt_exchanges::okx::Okx;
use ccxt_core::ExchangeConfig;

let config = ExchangeConfig {
    sandbox: true,
    ..Default::default()
};
let okx = Okx::new(config).unwrap();
assert!(okx.is_testnet_trading());
Source

pub fn timeframes(&self) -> HashMap<String, String>

Returns the supported timeframes.

Source

pub fn urls(&self) -> OkxUrls

Returns the API URLs.

Source

pub fn default_type(&self) -> DefaultType

Returns the default type configuration.

Source

pub fn default_sub_type(&self) -> Option<DefaultSubType>

Returns the default sub-type configuration.

Source

pub fn is_contract_type(&self) -> bool

Checks if the current default_type is a contract type (Swap, Futures, or Option).

This is useful for determining whether contract-specific API parameters should be used.

§Returns

true if the default_type is Swap, Futures, or Option; false otherwise.

Source

pub fn is_inverse(&self) -> bool

Checks if the current configuration uses inverse (coin-margined) contracts.

§Returns

true if default_sub_type is Inverse; false otherwise.

Source

pub fn is_linear(&self) -> bool

Checks if the current configuration uses linear (USDT-margined) contracts.

§Returns

true if default_sub_type is Linear or not specified (defaults to Linear); false otherwise.

Source

pub fn create_ws(&self) -> OkxWs

Creates a new WebSocket client for OKX.

Returns an OkxWs instance configured with the appropriate WebSocket URL based on the exchange configuration (production or demo).

§Example
use ccxt_exchanges::okx::Okx;
use ccxt_core::ExchangeConfig;

let okx = Okx::new(ExchangeConfig::default())?;
let ws = okx.create_ws();
ws.connect().await?;
Source

pub fn create_private_ws(&self) -> OkxWs

Creates a new private WebSocket client for OKX.

Returns an OkxWs instance configured with the private WebSocket URL. The caller must call login() on the returned client before subscribing to private channels.

Source

pub fn signed_request( &self, endpoint: impl Into<String>, ) -> OkxSignedRequestBuilder<'_>

Creates a new signed request builder for authenticated API requests.

This builder encapsulates the common signing workflow for OKX API requests, including credential validation, timestamp generation, HMAC-SHA256 signing, and authentication header injection.

§Arguments
  • endpoint - API endpoint path (e.g., “/api/v5/account/balance”)
§Returns

A OkxSignedRequestBuilder instance for fluent API construction.

§Example
use ccxt_exchanges::okx::Okx;
use ccxt_exchanges::okx::signed_request::HttpMethod;
use ccxt_core::ExchangeConfig;

let okx = Okx::new(ExchangeConfig::default())?;

// Simple GET request
let data = okx.signed_request("/api/v5/account/balance")
    .execute()
    .await?;

// POST request with parameters
let data = okx.signed_request("/api/v5/trade/order")
    .method(HttpMethod::Post)
    .param("instId", "BTC-USDT")
    .param("tdMode", "cash")
    .param("side", "buy")
    .execute()
    .await?;

Trait Implementations§

Source§

impl Debug for Okx

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Exchange for Okx

Source§

fn id(&self) -> &'static str

Returns the exchange identifier (e.g., “binance”, “coinbase”) Read more
Source§

fn name(&self) -> &'static str

Returns the human-readable exchange name (e.g., “Binance”, “Coinbase”)
Source§

fn version(&self) -> &'static str

Returns the API version string
Source§

fn certified(&self) -> bool

Returns whether this exchange is CCXT certified Read more
Source§

fn has_websocket(&self) -> bool

Returns whether this exchange supports WebSocket (pro features)
Source§

fn capabilities(&self) -> ExchangeCapabilities

Returns the exchange capabilities Read more
Source§

fn timeframes(&self) -> Vec<Timeframe>

Returns supported timeframes for OHLCV data
Source§

fn rate_limit(&self) -> u32

Returns the rate limit (requests per second)
Source§

fn fetch_markets<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<Market>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Fetch all available markets Read more
Source§

fn load_markets<'life0, 'async_trait>( &'life0 self, reload: bool, ) -> Pin<Box<dyn Future<Output = Result<Arc<HashMap<String, Arc<Market>>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Load markets and cache them Read more
Source§

fn fetch_ticker<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Ticker>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetch ticker for a single symbol Read more
Source§

fn fetch_tickers<'life0, 'life1, 'async_trait>( &'life0 self, symbols: Option<&'life1 [String]>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Ticker>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetch tickers for multiple symbols (or all if None) Read more
Source§

fn fetch_order_book<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<OrderBook>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetch order book for a symbol Read more
Source§

fn fetch_trades<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Trade>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetch recent public trades Read more
Source§

fn fetch_ohlcv<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, timeframe: Timeframe, since: Option<i64>, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Ohlcv>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetch OHLCV candlestick data Read more
Source§

fn create_order<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, order_type: OrderType, side: OrderSide, amount: Amount, price: Option<Price>, ) -> Pin<Box<dyn Future<Output = Result<Order>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Create a new order Read more
Source§

fn cancel_order<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id: &'life1 str, symbol: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<Order>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Cancel an existing order Read more
Source§

fn cancel_all_orders<'life0, 'life1, 'async_trait>( &'life0 self, _symbol: Option<&'life1 str>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Order>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Cancel all orders (optionally for a specific symbol) Read more
Source§

fn fetch_order<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id: &'life1 str, symbol: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<Order>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Fetch a specific order by ID Read more
Source§

fn fetch_open_orders<'life0, 'life1, 'async_trait>( &'life0 self, symbol: Option<&'life1 str>, since: Option<i64>, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Order>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetch all open orders Read more
Source§

fn fetch_closed_orders<'life0, 'life1, 'async_trait>( &'life0 self, symbol: Option<&'life1 str>, since: Option<i64>, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Order>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetch closed orders Read more
Source§

fn fetch_balance<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Balance>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Fetch account balance Read more
Source§

fn fetch_my_trades<'life0, 'life1, 'async_trait>( &'life0 self, symbol: Option<&'life1 str>, since: Option<i64>, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Trade>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetch user’s trade history Read more
Source§

fn market<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Arc<Market>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get a specific market by symbol Read more
Source§

fn markets<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Arc<HashMap<String, Arc<Market>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get all cached markets Read more
Source§

fn is_symbol_active<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Check if a symbol is valid and active Read more
Source§

impl HasHttpClient for Okx

Source§

fn http_client(&self) -> &HttpClient

Get reference to the HTTP client.
Source§

fn base_url(&self) -> &'static str

Get the base URL for API requests.
Source§

impl Margin for Okx

Source§

fn fetch_positions_for<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, symbols: &'life1 [&'life2 str], ) -> Pin<Box<dyn Future<Output = Result<Vec<Position>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Fetch positions for specific symbols. Read more
Source§

fn fetch_position<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Position>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetch a single position for a symbol. Read more
Source§

fn set_leverage_with_params<'life0, 'async_trait>( &'life0 self, params: LeverageParams, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Set leverage with full parameters. Read more
Source§

fn get_leverage<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<u32>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get current leverage for a symbol. Read more
Source§

fn set_margin_mode<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, mode: MarginMode, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Set margin mode for a symbol. Read more
Source§

fn fetch_funding_rate<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<FundingRate>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetch current funding rate for a symbol. Read more
Source§

fn fetch_funding_rates<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, symbols: &'life1 [&'life2 str], ) -> Pin<Box<dyn Future<Output = Result<Vec<FundingRate>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Fetch funding rates for multiple symbols. Read more
Source§

fn fetch_funding_rate_history<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, since: Option<i64>, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<Vec<FundingRateHistory>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetch funding rate history for a symbol. Read more
Source§

fn fetch_positions<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<Position>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: Sync + 'async_trait,

Fetch all positions. Read more
Source§

fn set_leverage<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, leverage: u32, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: Sync + 'async_trait,

Set leverage for a symbol. Read more
Source§

fn fetch_funding_rate_history_u64<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, since: Option<u64>, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<Vec<FundingRateHistory>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: Sync + 'async_trait,

👎Deprecated since 0.1.0: Use fetch_funding_rate_history with i64 timestamps. Convert using TimestampUtils::u64_to_i64()
Fetch funding rate history with u64 timestamp filtering (deprecated). Read more
Source§

impl OkxEndpointRouter for Okx

Source§

fn rest_endpoint(&self) -> &'static str

Returns the REST API endpoint. Read more
Source§

fn ws_endpoint(&self, channel_type: OkxChannelType) -> &str

Returns the WebSocket endpoint for a specific channel type. Read more
Source§

fn is_demo_trading(&self) -> bool

Returns whether demo trading mode is enabled. Read more
Source§

impl PublicExchange for Okx

Source§

fn id(&self) -> &'static str

Returns the exchange identifier (e.g., “binance”, “okx”). Read more
Source§

fn name(&self) -> &'static str

Returns the human-readable exchange name (e.g., “Binance”, “OKX”).
Source§

fn version(&self) -> &'static str

Returns the API version string. Read more
Source§

fn certified(&self) -> bool

Returns whether this exchange implementation is CCXT certified. Read more
Source§

fn capabilities(&self) -> ExchangeCapabilities

Returns the exchange capabilities. Read more
Source§

fn timeframes(&self) -> Vec<Timeframe>

Returns supported timeframes for OHLCV data. Read more
Source§

fn rate_limit(&self) -> u32

Returns the rate limit (requests per second). Read more
Source§

fn has_websocket(&self) -> bool

Returns whether WebSocket is supported. Read more
Source§

fn is_sandbox(&self) -> bool

Returns whether the exchange is in sandbox/testnet mode. Read more
Source§

fn countries(&self) -> Vec<&'static str>

Returns the exchange’s countries of operation. Read more
Source§

fn urls(&self) -> Vec<&'static str>

Returns the exchange’s website URLs. Read more
Source§

fn has_capability(&self, name: &str) -> bool

Check if a specific capability is supported. Read more
Source§

impl WsExchange for Okx

Source§

fn ws_connect<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Connect to the WebSocket server Read more
Source§

fn ws_disconnect<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Disconnect from the WebSocket server Read more
Source§

fn ws_is_connected(&self) -> bool

Check if WebSocket is connected Read more
Source§

fn ws_state(&self) -> WsConnectionState

Get WebSocket connection state Read more
Source§

fn watch_ticker<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<MessageStream<Ticker>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Watch ticker updates for a symbol Read more
Source§

fn watch_tickers<'life0, 'life1, 'async_trait>( &'life0 self, symbols: &'life1 [String], ) -> Pin<Box<dyn Future<Output = Result<MessageStream<Vec<Ticker>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Watch tickers for multiple symbols Read more
Source§

fn watch_order_book<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<MessageStream<OrderBook>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Watch order book updates Read more
Source§

fn watch_trades<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<MessageStream<Vec<Trade>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Watch public trades Read more
Source§

fn watch_ohlcv<'life0, 'life1, 'async_trait>( &'life0 self, _symbol: &'life1 str, _timeframe: Timeframe, ) -> Pin<Box<dyn Future<Output = Result<MessageStream<Ohlcv>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Watch OHLCV candlestick updates Read more
Source§

fn watch_balance<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<MessageStream<Balance>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Watch account balance updates Read more
Source§

fn watch_orders<'life0, 'life1, 'async_trait>( &'life0 self, symbol: Option<&'life1 str>, ) -> Pin<Box<dyn Future<Output = Result<MessageStream<Order>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Watch order updates Read more
Source§

fn watch_my_trades<'life0, 'life1, 'async_trait>( &'life0 self, symbol: Option<&'life1 str>, ) -> Pin<Box<dyn Future<Output = Result<MessageStream<Trade>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Watch user trade updates Read more
Source§

fn subscribe<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _channel: &'life1 str, _symbol: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Subscribe to a channel Read more
Source§

fn unsubscribe<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _channel: &'life1 str, _symbol: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Unsubscribe from a channel Read more
Source§

fn subscriptions(&self) -> Vec<String>

Get list of active subscriptions Read more

Auto Trait Implementations§

§

impl Freeze for Okx

§

impl !RefUnwindSafe for Okx

§

impl Send for Okx

§

impl Sync for Okx

§

impl Unpin for Okx

§

impl UnsafeUnpin for Okx

§

impl !UnwindSafe for Okx

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ExchangeExt for T
where T: Exchange + ?Sized,

Source§

fn supports_market_data(&self) -> bool

Check if this exchange implements the MarketData trait. Read more
Source§

fn supports_trading(&self) -> bool

Check if this exchange implements the Trading trait. Read more
Source§

fn supports_account(&self) -> bool

Check if this exchange implements the Account trait. Read more
Source§

fn supports_margin(&self) -> bool

Check if this exchange implements the Margin trait. Read more
Source§

fn supports_funding(&self) -> bool

Check if this exchange implements the Funding trait. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> FullExchange for T
where T: Exchange + WsExchange,