use std::borrow::Cow;
use serde::Serialize;
use crate::model::InstType;
#[derive(Debug, Clone, Serialize)]
pub struct InstIdRequest<'a> {
#[serde(rename = "instId")]
inst_id: Cow<'a, str>,
}
impl<'a> InstIdRequest<'a> {
pub fn new(inst_id: impl Into<Cow<'a, str>>) -> Self {
Self {
inst_id: inst_id.into(),
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct TickersRequest<'a> {
#[serde(rename = "instType")]
inst_type: InstType,
#[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
inst_family: Option<Cow<'a, str>>,
}
impl<'a> TickersRequest<'a> {
pub fn new(inst_type: InstType) -> Self {
Self {
inst_type,
inst_family: None,
}
}
pub fn inst_family(mut self, inst_family: impl Into<Cow<'a, str>>) -> Self {
self.inst_family = Some(inst_family.into());
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct IndexTickersRequest<'a> {
#[serde(rename = "quoteCcy", skip_serializing_if = "Option::is_none")]
quote_ccy: Option<Cow<'a, str>>,
#[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
inst_id: Option<Cow<'a, str>>,
}
impl<'a> IndexTickersRequest<'a> {
pub fn new() -> Self {
Self::default()
}
pub fn quote_currency(mut self, quote_ccy: impl Into<Cow<'a, str>>) -> Self {
self.quote_ccy = Some(quote_ccy.into());
self
}
pub fn inst_id(mut self, inst_id: impl Into<Cow<'a, str>>) -> Self {
self.inst_id = Some(inst_id.into());
self
}
}
#[derive(Debug, Clone, Serialize)]
pub struct OrderBookRequest<'a> {
#[serde(rename = "instId")]
inst_id: Cow<'a, str>,
#[serde(skip_serializing_if = "Option::is_none")]
sz: Option<u32>,
}
impl<'a> OrderBookRequest<'a> {
pub fn new(inst_id: impl Into<Cow<'a, str>>) -> Self {
Self {
inst_id: inst_id.into(),
sz: None,
}
}
pub fn size(mut self, sz: u32) -> Self {
self.sz = Some(sz);
self
}
}
#[derive(Debug, Clone, Serialize)]
pub struct CandlesRequest<'a> {
#[serde(rename = "instId")]
inst_id: Cow<'a, str>,
#[serde(skip_serializing_if = "Option::is_none")]
bar: Option<Cow<'a, str>>,
#[serde(skip_serializing_if = "Option::is_none")]
limit: Option<u32>,
}
impl<'a> CandlesRequest<'a> {
pub fn new(inst_id: impl Into<Cow<'a, str>>) -> Self {
Self {
inst_id: inst_id.into(),
bar: None,
limit: None,
}
}
pub fn bar(mut self, bar: impl Into<Cow<'a, str>>) -> Self {
self.bar = Some(bar.into());
self
}
pub fn limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
}
#[derive(Debug, Clone, Serialize)]
pub struct TradesRequest<'a> {
#[serde(rename = "instId")]
inst_id: Cow<'a, str>,
#[serde(skip_serializing_if = "Option::is_none")]
limit: Option<u32>,
}
impl<'a> TradesRequest<'a> {
pub fn new(inst_id: impl Into<Cow<'a, str>>) -> Self {
Self {
inst_id: inst_id.into(),
limit: None,
}
}
pub fn limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
}
#[derive(Debug, Clone, Serialize)]
pub struct InstFamilyRequest<'a> {
#[serde(rename = "instFamily")]
inst_family: Cow<'a, str>,
}
impl<'a> InstFamilyRequest<'a> {
pub fn new(inst_family: impl Into<Cow<'a, str>>) -> Self {
Self {
inst_family: inst_family.into(),
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct IndexRequest<'a> {
index: Cow<'a, str>,
}
impl<'a> IndexRequest<'a> {
pub fn new(index: impl Into<Cow<'a, str>>) -> Self {
Self {
index: index.into(),
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct CandlesticksRequest<'a> {
#[serde(rename = "instId")]
inst_id: Cow<'a, str>,
#[serde(skip_serializing_if = "Option::is_none")]
after: Option<Cow<'a, str>>,
#[serde(skip_serializing_if = "Option::is_none")]
before: Option<Cow<'a, str>>,
#[serde(skip_serializing_if = "Option::is_none")]
bar: Option<Cow<'a, str>>,
#[serde(skip_serializing_if = "Option::is_none")]
limit: Option<u32>,
}
impl<'a> CandlesticksRequest<'a> {
pub fn new(inst_id: impl Into<Cow<'a, str>>) -> Self {
Self {
inst_id: inst_id.into(),
after: None,
before: None,
bar: None,
limit: None,
}
}
pub fn after(mut self, after: impl Into<Cow<'a, str>>) -> Self {
self.after = Some(after.into());
self
}
pub fn before(mut self, before: impl Into<Cow<'a, str>>) -> Self {
self.before = Some(before.into());
self
}
pub fn bar(mut self, bar: impl Into<Cow<'a, str>>) -> Self {
self.bar = Some(bar.into());
self
}
pub fn limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
}
#[derive(Debug, Clone, Serialize)]
pub struct HistoryTradesRequest<'a> {
#[serde(rename = "instId")]
inst_id: Cow<'a, str>,
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
trade_type: Option<Cow<'a, str>>,
#[serde(skip_serializing_if = "Option::is_none")]
after: Option<Cow<'a, str>>,
#[serde(skip_serializing_if = "Option::is_none")]
before: Option<Cow<'a, str>>,
#[serde(skip_serializing_if = "Option::is_none")]
limit: Option<u32>,
}
impl<'a> HistoryTradesRequest<'a> {
pub fn new(inst_id: impl Into<Cow<'a, str>>) -> Self {
Self {
inst_id: inst_id.into(),
trade_type: None,
after: None,
before: None,
limit: None,
}
}
pub fn trade_type(mut self, trade_type: impl Into<Cow<'a, str>>) -> Self {
self.trade_type = Some(trade_type.into());
self
}
pub fn after(mut self, after: impl Into<Cow<'a, str>>) -> Self {
self.after = Some(after.into());
self
}
pub fn before(mut self, before: impl Into<Cow<'a, str>>) -> Self {
self.before = Some(before.into());
self
}
pub fn limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
}