use std::borrow::Cow;
use serde::Serialize;
use crate::model::{InstType, TradeMode};
#[derive(Debug, Clone, Default, Serialize)]
pub struct BillsRequest<'a> {
#[serde(rename = "instType", skip_serializing_if = "Option::is_none")]
inst_type: Option<InstType>,
#[serde(skip_serializing_if = "Option::is_none")]
ccy: Option<Cow<'a, str>>,
#[serde(rename = "mgnMode", skip_serializing_if = "Option::is_none")]
mgn_mode: Option<TradeMode>,
#[serde(rename = "ctType", skip_serializing_if = "Option::is_none")]
ct_type: Option<Cow<'a, str>>,
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
bill_type: Option<Cow<'a, str>>,
#[serde(rename = "subType", skip_serializing_if = "Option::is_none")]
sub_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")]
begin: Option<Cow<'a, str>>,
#[serde(skip_serializing_if = "Option::is_none")]
end: Option<Cow<'a, str>>,
#[serde(skip_serializing_if = "Option::is_none")]
limit: Option<u32>,
}
impl<'a> BillsRequest<'a> {
pub fn new() -> Self {
Self::default()
}
pub fn inst_type(mut self, inst_type: InstType) -> Self {
self.inst_type = Some(inst_type);
self
}
pub fn currency(mut self, ccy: impl Into<Cow<'a, str>>) -> Self {
self.ccy = Some(ccy.into());
self
}
pub fn margin_mode(mut self, mgn_mode: TradeMode) -> Self {
self.mgn_mode = Some(mgn_mode);
self
}
pub fn contract_type(mut self, ct_type: impl Into<Cow<'a, str>>) -> Self {
self.ct_type = Some(ct_type.into());
self
}
pub fn bill_type(mut self, bill_type: impl Into<Cow<'a, str>>) -> Self {
self.bill_type = Some(bill_type.into());
self
}
pub fn sub_type(mut self, sub_type: impl Into<Cow<'a, str>>) -> Self {
self.sub_type = Some(sub_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 begin(mut self, begin: impl Into<Cow<'a, str>>) -> Self {
self.begin = Some(begin.into());
self
}
pub fn end(mut self, end: impl Into<Cow<'a, str>>) -> Self {
self.end = Some(end.into());
self
}
pub fn limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct BillsArchiveRequest<'a> {
#[serde(flatten)]
base: BillsRequest<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
begin: Option<Cow<'a, str>>,
#[serde(skip_serializing_if = "Option::is_none")]
end: Option<Cow<'a, str>>,
}
impl<'a> BillsArchiveRequest<'a> {
pub fn new() -> Self {
Self::default()
}
pub fn filters(mut self, base: BillsRequest<'a>) -> Self {
self.base = base;
self
}
pub fn begin(mut self, begin: impl Into<Cow<'a, str>>) -> Self {
self.begin = Some(begin.into());
self
}
pub fn end(mut self, end: impl Into<Cow<'a, str>>) -> Self {
self.end = Some(end.into());
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct BillSubtypesRequest<'a> {
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
bill_type: Option<Cow<'a, str>>,
}
impl<'a> BillSubtypesRequest<'a> {
pub fn new() -> Self {
Self::default()
}
pub fn bill_type(mut self, bill_type: impl Into<Cow<'a, str>>) -> Self {
self.bill_type = Some(bill_type.into());
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize)]
#[non_exhaustive]
pub enum BillsHistoryArchiveQuarter {
#[serde(rename = "Q1")]
Q1,
#[serde(rename = "Q2")]
Q2,
#[serde(rename = "Q3")]
Q3,
#[serde(rename = "Q4")]
Q4,
}
#[derive(Debug, Clone, Serialize)]
pub struct BillsHistoryArchiveRequest<'a> {
year: Cow<'a, str>,
quarter: BillsHistoryArchiveQuarter,
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
bill_type: Option<Cow<'a, str>>,
}
impl<'a> BillsHistoryArchiveRequest<'a> {
pub fn new(year: impl Into<Cow<'a, str>>, quarter: BillsHistoryArchiveQuarter) -> Self {
Self {
year: year.into(),
quarter,
bill_type: None,
}
}
pub fn bill_type(mut self, bill_type: impl Into<Cow<'a, str>>) -> Self {
self.bill_type = Some(bill_type.into());
self
}
}
pub type ApplyBillsHistoryArchiveRequest<'a> = BillsHistoryArchiveRequest<'a>;
#[derive(Debug, Clone, Default, Serialize)]
pub struct PositionsHistoryRequest<'a> {
#[serde(rename = "instType", skip_serializing_if = "Option::is_none")]
inst_type: Option<InstType>,
#[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
inst_id: Option<Cow<'a, str>>,
#[serde(rename = "mgnMode", skip_serializing_if = "Option::is_none")]
mgn_mode: Option<TradeMode>,
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
close_type: Option<Cow<'a, str>>,
#[serde(rename = "posId", skip_serializing_if = "Option::is_none")]
pos_id: 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> PositionsHistoryRequest<'a> {
pub fn new() -> Self {
Self::default()
}
pub fn inst_type(mut self, inst_type: InstType) -> Self {
self.inst_type = Some(inst_type);
self
}
pub fn inst_id(mut self, inst_id: impl Into<Cow<'a, str>>) -> Self {
self.inst_id = Some(inst_id.into());
self
}
pub fn margin_mode(mut self, mgn_mode: TradeMode) -> Self {
self.mgn_mode = Some(mgn_mode);
self
}
pub fn close_type(mut self, close_type: impl Into<Cow<'a, str>>) -> Self {
self.close_type = Some(close_type.into());
self
}
pub fn position_id(mut self, pos_id: impl Into<Cow<'a, str>>) -> Self {
self.pos_id = Some(pos_id.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
}
}