pub struct OkxSignedRequestBuilder<'a> { /* private fields */ }Expand description
Builder for creating authenticated OKX API requests.
This builder encapsulates the common signing workflow:
- Credential validation
- ISO 8601 timestamp generation
- Parameter signing with HMAC-SHA256
- Authentication header injection
- HTTP request execution
§Example
let okx = Okx::new(ExchangeConfig::default())?;
let data = okx.signed_request("/api/v5/account/balance")
.param("instId", "BTC-USDT")
.optional_param("limit", Some(100))
.execute()
.await?;Implementations§
Source§impl<'a> OkxSignedRequestBuilder<'a>
impl<'a> OkxSignedRequestBuilder<'a>
Sourcepub fn method(self, method: HttpMethod) -> Self
pub fn method(self, method: HttpMethod) -> Self
Sourcepub fn param(self, key: impl Into<String>, value: impl ToString) -> Self
pub fn param(self, key: impl Into<String>, value: impl ToString) -> Self
Adds a required parameter.
§Arguments
key- Parameter namevalue- Parameter value (will be converted to string)
§Example
let okx = Okx::new(ExchangeConfig::default())?;
let data = okx.signed_request("/api/v5/trade/orders-history")
.param("instId", "BTC-USDT")
.param("limit", 100)
.execute()
.await?;Sourcepub fn optional_param<T: ToString>(
self,
key: impl Into<String>,
value: Option<T>,
) -> Self
pub fn optional_param<T: ToString>( self, key: impl Into<String>, value: Option<T>, ) -> Self
Adds an optional parameter (only if value is Some).
§Arguments
key- Parameter namevalue- Optional parameter value
§Example
let okx = Okx::new(ExchangeConfig::default())?;
let since: Option<i64> = Some(1234567890000);
let limit: Option<u32> = None;
let data = okx.signed_request("/api/v5/trade/orders-history")
.param("instId", "BTC-USDT")
.optional_param("after", since)
.optional_param("limit", limit) // Won't be added since it's None
.execute()
.await?;Sourcepub fn params(self, params: BTreeMap<String, String>) -> Self
pub fn params(self, params: BTreeMap<String, String>) -> Self
Adds multiple parameters from a BTreeMap.
§Arguments
params- Map of parameter key-value pairs
§Example
let okx = Okx::new(ExchangeConfig::default())?;
let mut params = BTreeMap::new();
params.insert("instId".to_string(), "BTC-USDT".to_string());
params.insert("tdMode".to_string(), "cash".to_string());
let data = okx.signed_request("/api/v5/trade/order")
.params(params)
.execute()
.await?;Sourcepub fn body(self, body: Value) -> Self
pub fn body(self, body: Value) -> Self
Sets the request body for POST/DELETE requests.
§Arguments
body- JSON value to use as request body
§Example
let okx = Okx::new(ExchangeConfig::default())?;
let body = json!({
"instId": "BTC-USDT",
"tdMode": "cash",
"side": "buy"
});
let data = okx.signed_request("/api/v5/trade/order")
.method(ccxt_exchanges::okx::signed_request::HttpMethod::Post)
.body(body)
.execute()
.await?;Sourcepub async fn execute(self) -> Result<Value>
pub async fn execute(self) -> Result<Value>
Executes the signed request and returns the response.
This method:
- Validates that credentials are configured
- Gets the current ISO 8601 timestamp
- Signs the request with HMAC-SHA256
- Adds authentication headers
- Executes the HTTP request
§Returns
Returns the raw serde_json::Value response for further parsing.
§Errors
- Returns authentication error if credentials are missing
- Returns network error if the request fails
- Returns parse error if response parsing fails
§Example
let okx = Okx::new(ExchangeConfig::default())?;
let data = okx.signed_request("/api/v5/account/balance")
.execute()
.await?;
println!("Response: {:?}", data);Auto Trait Implementations§
impl<'a> Freeze for OkxSignedRequestBuilder<'a>
impl<'a> !RefUnwindSafe for OkxSignedRequestBuilder<'a>
impl<'a> Send for OkxSignedRequestBuilder<'a>
impl<'a> Sync for OkxSignedRequestBuilder<'a>
impl<'a> Unpin for OkxSignedRequestBuilder<'a>
impl<'a> !UnwindSafe for OkxSignedRequestBuilder<'a>
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
Mutably borrows from an owned value. Read more