pub struct OKXRawHttpClient { /* private fields */ }Expand description
Provides a raw HTTP client for interacting with the OKX REST API.
This client wraps the underlying HttpClient to handle functionality
specific to OKX, such as request signing (for authenticated endpoints),
forming request URLs, and deserializing responses into OKX specific data models.
Implementations§
Source§impl OKXRawHttpClient
impl OKXRawHttpClient
Sourcepub fn cancel_all_requests(&self)
pub fn cancel_all_requests(&self)
Cancel all pending HTTP requests.
Sourcepub fn cancellation_token(&self) -> &CancellationToken
pub fn cancellation_token(&self) -> &CancellationToken
Get the cancellation token for this client.
Sourcepub fn new(
base_url: Option<String>,
timeout_secs: Option<u64>,
max_retries: Option<u32>,
retry_delay_ms: Option<u64>,
retry_delay_max_ms: Option<u64>,
is_demo: bool,
proxy_url: Option<String>,
) -> Result<Self, OKXHttpError>
pub fn new( base_url: Option<String>, timeout_secs: Option<u64>, max_retries: Option<u32>, retry_delay_ms: Option<u64>, retry_delay_max_ms: Option<u64>, is_demo: bool, proxy_url: Option<String>, ) -> Result<Self, OKXHttpError>
Creates a new OKXHttpClient using the default OKX HTTP URL,
optionally overridden with a custom base URL.
This version of the client has no credentials, so it can only call publicly accessible endpoints.
§Errors
Returns an error if the retry manager cannot be created.
Sourcepub fn with_credentials(
api_key: String,
api_secret: String,
api_passphrase: String,
base_url: String,
timeout_secs: Option<u64>,
max_retries: Option<u32>,
retry_delay_ms: Option<u64>,
retry_delay_max_ms: Option<u64>,
is_demo: bool,
proxy_url: Option<String>,
) -> Result<Self, OKXHttpError>
pub fn with_credentials( api_key: String, api_secret: String, api_passphrase: String, base_url: String, timeout_secs: Option<u64>, max_retries: Option<u32>, retry_delay_ms: Option<u64>, retry_delay_max_ms: Option<u64>, is_demo: bool, proxy_url: Option<String>, ) -> Result<Self, OKXHttpError>
Creates a new OKXHttpClient configured with credentials
for authenticated requests, optionally using a custom base URL.
§Errors
Returns an error if the retry manager cannot be created.
Sourcepub async fn set_position_mode(
&self,
params: SetPositionModeParams,
) -> Result<Vec<Value>, OKXHttpError>
pub async fn set_position_mode( &self, params: SetPositionModeParams, ) -> Result<Vec<Value>, OKXHttpError>
Sets the position mode for an account.
§Errors
Returns an error if JSON serialization of params fails, if the HTTP
request fails, or if the response body cannot be deserialized.
§References
https://www.okx.com/docs-v5/en/#trading-account-rest-api-set-position-mode
Sourcepub async fn get_position_tiers(
&self,
params: GetPositionTiersParams,
) -> Result<Vec<OKXPositionTier>, OKXHttpError>
pub async fn get_position_tiers( &self, params: GetPositionTiersParams, ) -> Result<Vec<OKXPositionTier>, OKXHttpError>
Requests position tiers information, maximum leverage depends on your borrowings and margin ratio.
§Errors
Returns an error if the HTTP request fails, authentication is rejected or the response cannot be deserialized.
§References
https://www.okx.com/docs-v5/en/#public-data-rest-api-get-position-tiers
Sourcepub async fn get_instruments(
&self,
params: GetInstrumentsParams,
) -> Result<Vec<OKXInstrument>, OKXHttpError>
pub async fn get_instruments( &self, params: GetInstrumentsParams, ) -> Result<Vec<OKXInstrument>, OKXHttpError>
Requests a list of instruments with open contracts.
§Errors
Returns an error if JSON serialization of params fails, if the HTTP
request fails, or if the response body cannot be deserialized.
§References
https://www.okx.com/docs-v5/en/#public-data-rest-api-get-instruments
Sourcepub async fn get_server_time(&self) -> Result<u64, OKXHttpError>
pub async fn get_server_time(&self) -> Result<u64, OKXHttpError>
Requests the current server time from OKX.
Retrieves the OKX system time in Unix timestamp (milliseconds). This is useful for synchronizing local clocks with the exchange server and logging time drift.
§Errors
Returns an error if the HTTP request fails or if the response body
cannot be parsed into OKXServerTime.
§References
https://www.okx.com/docs-v5/en/#public-data-rest-api-get-system-time
Sourcepub async fn get_mark_price(
&self,
params: GetMarkPriceParams,
) -> Result<Vec<OKXMarkPrice>, OKXHttpError>
pub async fn get_mark_price( &self, params: GetMarkPriceParams, ) -> Result<Vec<OKXMarkPrice>, OKXHttpError>
Requests a mark price.
We set the mark price based on the SPOT index and at a reasonable basis to prevent individual users from manipulating the market and causing the contract price to fluctuate.
§Errors
Returns an error if the HTTP request fails or if the response body
cannot be parsed into OKXMarkPrice.
§References
https://www.okx.com/docs-v5/en/#public-data-rest-api-get-mark-price
Sourcepub async fn get_index_tickers(
&self,
params: GetIndexTickerParams,
) -> Result<Vec<OKXIndexTicker>, OKXHttpError>
pub async fn get_index_tickers( &self, params: GetIndexTickerParams, ) -> Result<Vec<OKXIndexTicker>, OKXHttpError>
Requests the latest index price.
§Errors
Returns an error if the operation fails.
§References
https://www.okx.com/docs-v5/en/#public-data-rest-api-get-index-tickers
Sourcepub async fn get_history_trades(
&self,
params: GetTradesParams,
) -> Result<Vec<OKXTrade>, OKXHttpError>
pub async fn get_history_trades( &self, params: GetTradesParams, ) -> Result<Vec<OKXTrade>, OKXHttpError>
Requests trades history.
§Errors
Returns an error if the operation fails.
§References
https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-trades-history
Sourcepub async fn get_candles(
&self,
params: GetCandlesticksParams,
) -> Result<Vec<OKXCandlestick>, OKXHttpError>
pub async fn get_candles( &self, params: GetCandlesticksParams, ) -> Result<Vec<OKXCandlestick>, OKXHttpError>
Requests recent candlestick data.
§Errors
Returns an error if the operation fails.
§References
https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-candlesticks
Sourcepub async fn get_history_candles(
&self,
params: GetCandlesticksParams,
) -> Result<Vec<OKXCandlestick>, OKXHttpError>
pub async fn get_history_candles( &self, params: GetCandlesticksParams, ) -> Result<Vec<OKXCandlestick>, OKXHttpError>
Requests historical candlestick data.
§Errors
Returns an error if the operation fails.
§References
https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-candlesticks-history
Sourcepub async fn get_balance(&self) -> Result<Vec<OKXAccount>, OKXHttpError>
pub async fn get_balance(&self) -> Result<Vec<OKXAccount>, OKXHttpError>
Requests a list of assets (with non-zero balance), remaining balance, and available amount in the trading account.
§Errors
Returns an error if the operation fails.
§References
https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-balance
Sourcepub async fn get_trade_fee(
&self,
params: GetTradeFeeParams,
) -> Result<Vec<OKXFeeRate>, OKXHttpError>
pub async fn get_trade_fee( &self, params: GetTradeFeeParams, ) -> Result<Vec<OKXFeeRate>, OKXHttpError>
Requests fee rates for the account.
Returns fee rates for the specified instrument type and the user’s VIP level.
§Errors
Returns an error if the operation fails.
§References
https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-fee-rates
Sourcepub async fn get_order(
&self,
params: GetOrderParams,
) -> Result<Vec<OKXOrderHistory>, OKXHttpError>
pub async fn get_order( &self, params: GetOrderParams, ) -> Result<Vec<OKXOrderHistory>, OKXHttpError>
Retrieves a single order’s details.
§Errors
Returns an error if the operation fails.
§References
https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-order
Sourcepub async fn get_orders_pending(
&self,
params: GetOrderListParams,
) -> Result<Vec<OKXOrderHistory>, OKXHttpError>
pub async fn get_orders_pending( &self, params: GetOrderListParams, ) -> Result<Vec<OKXOrderHistory>, OKXHttpError>
Requests order list (pending orders).
§Errors
Returns an error if the operation fails.
§References
https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-order-list
Sourcepub async fn get_orders_history(
&self,
params: GetOrderHistoryParams,
) -> Result<Vec<OKXOrderHistory>, OKXHttpError>
pub async fn get_orders_history( &self, params: GetOrderHistoryParams, ) -> Result<Vec<OKXOrderHistory>, OKXHttpError>
Requests historical order records.
§Errors
Returns an error if the operation fails.
§References
https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-orders-history
Sourcepub async fn get_order_algo_pending(
&self,
params: GetAlgoOrdersParams,
) -> Result<Vec<OKXOrderAlgo>, OKXHttpError>
pub async fn get_order_algo_pending( &self, params: GetAlgoOrdersParams, ) -> Result<Vec<OKXOrderAlgo>, OKXHttpError>
Sourcepub async fn get_order_algo_history(
&self,
params: GetAlgoOrdersParams,
) -> Result<Vec<OKXOrderAlgo>, OKXHttpError>
pub async fn get_order_algo_history( &self, params: GetAlgoOrdersParams, ) -> Result<Vec<OKXOrderAlgo>, OKXHttpError>
Sourcepub async fn get_fills(
&self,
params: GetTransactionDetailsParams,
) -> Result<Vec<OKXTransactionDetail>, OKXHttpError>
pub async fn get_fills( &self, params: GetTransactionDetailsParams, ) -> Result<Vec<OKXTransactionDetail>, OKXHttpError>
Requests transaction details (fills) for the given parameters.
§Errors
Returns an error if the operation fails.
§References
https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-transaction-details-last-3-days
Sourcepub async fn get_positions(
&self,
params: GetPositionsParams,
) -> Result<Vec<OKXPosition>, OKXHttpError>
pub async fn get_positions( &self, params: GetPositionsParams, ) -> Result<Vec<OKXPosition>, OKXHttpError>
Requests information on your positions. When the account is in net mode, net positions will be displayed, and when the account is in long/short mode, long or short positions will be displayed. Returns in reverse chronological order using ctime.
§Errors
Returns an error if the operation fails.
§References
https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-positions
Sourcepub async fn get_positions_history(
&self,
params: GetPositionsHistoryParams,
) -> Result<Vec<OKXPositionHistory>, OKXHttpError>
pub async fn get_positions_history( &self, params: GetPositionsHistoryParams, ) -> Result<Vec<OKXPositionHistory>, OKXHttpError>
Requests closed or historical position data.
§Errors
Returns an error if the operation fails.
§References
https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-positions-history
Trait Implementations§
Source§impl Debug for OKXRawHttpClient
impl Debug for OKXRawHttpClient
Auto Trait Implementations§
impl Freeze for OKXRawHttpClient
impl !RefUnwindSafe for OKXRawHttpClient
impl Send for OKXRawHttpClient
impl Sync for OKXRawHttpClient
impl Unpin for OKXRawHttpClient
impl !UnwindSafe for OKXRawHttpClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more