use serde::Serialize;
#[derive(Debug, Clone, Serialize)]
pub struct OptionSummaryRequest {
#[serde(rename = "instFamily")]
inst_family: String,
#[serde(rename = "expTime", skip_serializing_if = "Option::is_none")]
exp_time: Option<String>,
}
impl OptionSummaryRequest {
pub fn new(inst_family: impl Into<String>) -> Self {
Self {
inst_family: inst_family.into(),
exp_time: None,
}
}
pub fn expiration(mut self, value: impl Into<String>) -> Self {
self.exp_time = Some(value.into());
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct InterestRateLoanQuotaRequest {}
impl InterestRateLoanQuotaRequest {
pub fn new() -> Self {
Self::default()
}
}
#[derive(Debug, Clone, Serialize)]
pub struct InstrumentTickBandsRequest {
#[serde(rename = "instType")]
inst_type: String,
}
impl InstrumentTickBandsRequest {
pub fn new(inst_type: impl Into<String>) -> Self {
Self {
inst_type: inst_type.into(),
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct UnderlyingRequest {
#[serde(rename = "instType")]
inst_type: String,
}
impl UnderlyingRequest {
pub fn new(inst_type: impl Into<String>) -> Self {
Self {
inst_type: inst_type.into(),
}
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct PublicOptionTradesRequest {
#[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
inst_id: Option<String>,
#[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
inst_family: Option<String>,
#[serde(rename = "optType", skip_serializing_if = "Option::is_none")]
option_type: Option<String>,
}
impl PublicOptionTradesRequest {
pub fn new() -> Self {
Self::default()
}
pub fn inst_id(mut self, value: impl Into<String>) -> Self {
self.inst_id = Some(value.into());
self
}
pub fn inst_family(mut self, value: impl Into<String>) -> Self {
self.inst_family = Some(value.into());
self
}
pub fn option_type(mut self, value: impl Into<String>) -> Self {
self.option_type = Some(value.into());
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct MarketDataHistoryRequest {
#[serde(skip_serializing_if = "Option::is_none")]
module: Option<String>,
#[serde(rename = "instType", skip_serializing_if = "Option::is_none")]
inst_type: Option<String>,
#[serde(rename = "instIdList", skip_serializing_if = "Option::is_none")]
inst_id_list: Option<String>,
#[serde(rename = "dateAggrType", skip_serializing_if = "Option::is_none")]
date_aggr_type: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
begin: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
end: Option<String>,
}
impl MarketDataHistoryRequest {
pub fn new() -> Self {
Self::default()
}
pub fn module(mut self, value: impl Into<String>) -> Self {
self.module = Some(value.into());
self
}
pub fn inst_type(mut self, value: impl Into<String>) -> Self {
self.inst_type = Some(value.into());
self
}
pub fn inst_id_list(mut self, value: impl Into<String>) -> Self {
self.inst_id_list = Some(value.into());
self
}
pub fn date_aggregation(mut self, value: impl Into<String>) -> Self {
self.date_aggr_type = Some(value.into());
self
}
pub fn begin(mut self, value: impl Into<String>) -> Self {
self.begin = Some(value.into());
self
}
pub fn end(mut self, value: impl Into<String>) -> Self {
self.end = Some(value.into());
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn market_history_uses_okx_field_names() {
let request = MarketDataHistoryRequest::new()
.module("2")
.inst_type("SPOT")
.inst_id_list("BTC-USDT")
.date_aggregation("daily");
let value = serde_json::to_value(request).unwrap();
assert_eq!(value["instType"], "SPOT");
assert_eq!(value["instIdList"], "BTC-USDT");
assert_eq!(value["dateAggrType"], "daily");
}
}