use serde::Serialize;
use crate::model::{InstType, PositionSide, RequestParams, TradeMode};
pub type VipInterestAccruedRequest = RequestParams;
pub type VipInterestDeductedRequest = RequestParams;
pub type VipLoanOrderListRequest = RequestParams;
pub type VipLoanOrderDetailRequest = RequestParams;
pub type FixedLoanBorrowingLimitRequest = RequestParams;
pub type FixedLoanBorrowingQuoteRequest = RequestParams;
pub type FixedLoanBorrowingOrderRequest = RequestParams;
pub type FixedLoanAmendBorrowingOrderRequest = RequestParams;
pub type FixedLoanManualReborrowRequest = RequestParams;
pub type FixedLoanRepayBorrowingOrderRequest = RequestParams;
pub type FixedLoanBorrowingOrdersListRequest = RequestParams;
pub type SpotManualBorrowRepayRequest = RequestParams;
pub type SetAutoRepayRequest = RequestParams;
pub type SpotBorrowRepayHistoryRequest = RequestParams;
pub type SetAutoEarnRequest = RequestParams;
#[derive(Debug, Clone, Default, Serialize)]
pub struct BillsRequest {
#[serde(rename = "instType", skip_serializing_if = "Option::is_none")]
inst_type: Option<InstType>,
#[serde(skip_serializing_if = "Option::is_none")]
ccy: Option<String>,
#[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<String>,
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
bill_type: Option<String>,
#[serde(rename = "subType", skip_serializing_if = "Option::is_none")]
sub_type: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
after: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
before: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
limit: Option<u32>,
}
impl BillsRequest {
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<String>) -> 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<String>) -> Self {
self.ct_type = Some(ct_type.into());
self
}
pub fn bill_type(mut self, bill_type: impl Into<String>) -> Self {
self.bill_type = Some(bill_type.into());
self
}
pub fn sub_type(mut self, sub_type: impl Into<String>) -> Self {
self.sub_type = Some(sub_type.into());
self
}
pub fn after(mut self, after: impl Into<String>) -> Self {
self.after = Some(after.into());
self
}
pub fn before(mut self, before: impl Into<String>) -> Self {
self.before = Some(before.into());
self
}
pub fn limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct BillsArchiveRequest {
#[serde(flatten)]
base: BillsRequest,
#[serde(skip_serializing_if = "Option::is_none")]
begin: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
end: Option<String>,
}
impl BillsArchiveRequest {
pub fn new() -> Self {
Self::default()
}
pub fn filters(mut self, base: BillsRequest) -> Self {
self.base = base;
self
}
pub fn begin(mut self, begin: impl Into<String>) -> Self {
self.begin = Some(begin.into());
self
}
pub fn end(mut self, end: impl Into<String>) -> Self {
self.end = Some(end.into());
self
}
}
#[derive(Debug, Clone, Serialize)]
pub struct SetLeverageRequest {
lever: String,
#[serde(rename = "mgnMode")]
mgn_mode: TradeMode,
#[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
inst_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
ccy: Option<String>,
#[serde(rename = "posSide", skip_serializing_if = "Option::is_none")]
pos_side: Option<PositionSide>,
}
impl SetLeverageRequest {
pub fn new(lever: impl Into<String>, mgn_mode: TradeMode) -> Self {
Self {
lever: lever.into(),
mgn_mode,
inst_id: None,
ccy: None,
pos_side: None,
}
}
pub fn inst_id(mut self, inst_id: impl Into<String>) -> Self {
self.inst_id = Some(inst_id.into());
self
}
pub fn currency(mut self, ccy: impl Into<String>) -> Self {
self.ccy = Some(ccy.into());
self
}
pub fn position_side(mut self, pos_side: PositionSide) -> Self {
self.pos_side = Some(pos_side);
self
}
}
#[derive(Debug, Clone, Serialize)]
pub struct LeverageRequest {
#[serde(rename = "mgnMode")]
mgn_mode: TradeMode,
#[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
inst_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
ccy: Option<String>,
}
impl LeverageRequest {
pub fn new(mgn_mode: TradeMode) -> Self {
Self {
mgn_mode,
inst_id: None,
ccy: None,
}
}
pub fn inst_id(mut self, inst_id: impl Into<String>) -> Self {
self.inst_id = Some(inst_id.into());
self
}
pub fn currency(mut self, ccy: impl Into<String>) -> Self {
self.ccy = Some(ccy.into());
self
}
}
#[derive(Debug, Clone, Serialize)]
pub struct MaxOrderSizeRequest {
#[serde(rename = "instId")]
inst_id: String,
#[serde(rename = "tdMode")]
td_mode: TradeMode,
#[serde(skip_serializing_if = "Option::is_none")]
ccy: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
px: Option<String>,
#[serde(rename = "tradeQuoteCcy", skip_serializing_if = "Option::is_none")]
trade_quote_ccy: Option<String>,
}
impl MaxOrderSizeRequest {
pub fn new(inst_id: impl Into<String>, td_mode: TradeMode) -> Self {
Self {
inst_id: inst_id.into(),
td_mode,
ccy: None,
px: None,
trade_quote_ccy: None,
}
}
pub fn currency(mut self, ccy: impl Into<String>) -> Self {
self.ccy = Some(ccy.into());
self
}
pub fn price(mut self, px: impl Into<String>) -> Self {
self.px = Some(px.into());
self
}
pub fn trade_quote_currency(mut self, trade_quote_ccy: impl Into<String>) -> Self {
self.trade_quote_ccy = Some(trade_quote_ccy.into());
self
}
}
#[derive(Debug, Clone, Serialize)]
pub struct MaxAvailableSizeRequest {
#[serde(rename = "instId")]
inst_id: String,
#[serde(rename = "tdMode")]
td_mode: TradeMode,
#[serde(skip_serializing_if = "Option::is_none")]
ccy: Option<String>,
#[serde(rename = "reduceOnly", skip_serializing_if = "Option::is_none")]
reduce_only: Option<bool>,
#[serde(rename = "unSpotOffset", skip_serializing_if = "Option::is_none")]
un_spot_offset: Option<bool>,
#[serde(rename = "quickMgnType", skip_serializing_if = "Option::is_none")]
quick_mgn_type: Option<String>,
#[serde(rename = "tradeQuoteCcy", skip_serializing_if = "Option::is_none")]
trade_quote_ccy: Option<String>,
}
impl MaxAvailableSizeRequest {
pub fn new(inst_id: impl Into<String>, td_mode: TradeMode) -> Self {
Self {
inst_id: inst_id.into(),
td_mode,
ccy: None,
reduce_only: None,
un_spot_offset: None,
quick_mgn_type: None,
trade_quote_ccy: None,
}
}
pub fn currency(mut self, ccy: impl Into<String>) -> Self {
self.ccy = Some(ccy.into());
self
}
pub fn reduce_only(mut self, reduce_only: bool) -> Self {
self.reduce_only = Some(reduce_only);
self
}
pub fn un_spot_offset(mut self, un_spot_offset: bool) -> Self {
self.un_spot_offset = Some(un_spot_offset);
self
}
pub fn quick_margin_type(mut self, quick_mgn_type: impl Into<String>) -> Self {
self.quick_mgn_type = Some(quick_mgn_type.into());
self
}
pub fn trade_quote_currency(mut self, trade_quote_ccy: impl Into<String>) -> Self {
self.trade_quote_ccy = Some(trade_quote_ccy.into());
self
}
}
#[derive(Debug, Clone, Serialize)]
pub struct AdjustMarginRequest {
#[serde(rename = "instId")]
inst_id: String,
#[serde(rename = "posSide")]
pos_side: PositionSide,
#[serde(rename = "type")]
action: String,
amt: String,
#[serde(rename = "loanTrans", skip_serializing_if = "Option::is_none")]
loan_trans: Option<bool>,
}
impl AdjustMarginRequest {
pub fn new(
inst_id: impl Into<String>,
pos_side: PositionSide,
action: impl Into<String>,
amt: impl Into<String>,
) -> Self {
Self {
inst_id: inst_id.into(),
pos_side,
action: action.into(),
amt: amt.into(),
loan_trans: None,
}
}
pub fn loan_transfer(mut self, loan_trans: bool) -> Self {
self.loan_trans = Some(loan_trans);
self
}
}
#[derive(Debug, Clone, Serialize)]
pub struct FeeRatesRequest {
#[serde(rename = "instType")]
inst_type: InstType,
#[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
inst_id: Option<String>,
#[serde(rename = "uly", skip_serializing_if = "Option::is_none")]
underlying: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
category: Option<String>,
#[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
inst_family: Option<String>,
}
impl FeeRatesRequest {
pub fn new(inst_type: InstType) -> Self {
Self {
inst_type,
inst_id: None,
underlying: None,
category: None,
inst_family: None,
}
}
pub fn inst_id(mut self, inst_id: impl Into<String>) -> Self {
self.inst_id = Some(inst_id.into());
self
}
pub fn underlying(mut self, underlying: impl Into<String>) -> Self {
self.underlying = Some(underlying.into());
self
}
pub fn category(mut self, category: impl Into<String>) -> Self {
self.category = Some(category.into());
self
}
pub fn inst_family(mut self, inst_family: impl Into<String>) -> Self {
self.inst_family = Some(inst_family.into());
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct AccountInstrumentsRequest {
#[serde(rename = "instType", skip_serializing_if = "Option::is_none")]
inst_type: Option<InstType>,
#[serde(rename = "uly", skip_serializing_if = "Option::is_none")]
underlying: Option<String>,
#[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
inst_family: Option<String>,
#[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
inst_id: Option<String>,
}
impl AccountInstrumentsRequest {
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 underlying(mut self, underlying: impl Into<String>) -> Self {
self.underlying = Some(underlying.into());
self
}
pub fn inst_family(mut self, inst_family: impl Into<String>) -> Self {
self.inst_family = Some(inst_family.into());
self
}
pub fn inst_id(mut self, inst_id: impl Into<String>) -> Self {
self.inst_id = Some(inst_id.into());
self
}
}
#[derive(Debug, Clone, Serialize)]
pub struct MaxLoanRequest {
#[serde(rename = "instId")]
inst_id: String,
#[serde(rename = "mgnMode")]
mgn_mode: TradeMode,
#[serde(rename = "mgnCcy", skip_serializing_if = "Option::is_none")]
mgn_ccy: Option<String>,
#[serde(rename = "tradeQuoteCcy", skip_serializing_if = "Option::is_none")]
trade_quote_ccy: Option<String>,
}
impl MaxLoanRequest {
pub fn new(inst_id: impl Into<String>, mgn_mode: TradeMode) -> Self {
Self {
inst_id: inst_id.into(),
mgn_mode,
mgn_ccy: None,
trade_quote_ccy: None,
}
}
pub fn margin_currency(mut self, mgn_ccy: impl Into<String>) -> Self {
self.mgn_ccy = Some(mgn_ccy.into());
self
}
pub fn trade_quote_currency(mut self, trade_quote_ccy: impl Into<String>) -> Self {
self.trade_quote_ccy = Some(trade_quote_ccy.into());
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct InterestAccruedRequest {
#[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
inst_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
ccy: Option<String>,
#[serde(rename = "mgnMode", skip_serializing_if = "Option::is_none")]
mgn_mode: Option<TradeMode>,
#[serde(skip_serializing_if = "Option::is_none")]
after: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
before: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
limit: Option<u32>,
}
impl InterestAccruedRequest {
pub fn new() -> Self {
Self::default()
}
pub fn inst_id(mut self, inst_id: impl Into<String>) -> Self {
self.inst_id = Some(inst_id.into());
self
}
pub fn currency(mut self, ccy: impl Into<String>) -> 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 after(mut self, after: impl Into<String>) -> Self {
self.after = Some(after.into());
self
}
pub fn before(mut self, before: impl Into<String>) -> Self {
self.before = Some(before.into());
self
}
pub fn limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
}
#[derive(Debug, Clone, Serialize)]
pub struct BorrowRepayRequest {
ccy: String,
side: String,
amt: String,
#[serde(rename = "ordId", skip_serializing_if = "Option::is_none")]
ord_id: Option<String>,
}
impl BorrowRepayRequest {
pub fn new(ccy: impl Into<String>, side: impl Into<String>, amt: impl Into<String>) -> Self {
Self {
ccy: ccy.into(),
side: side.into(),
amt: amt.into(),
ord_id: None,
}
}
pub fn order_id(mut self, ord_id: impl Into<String>) -> Self {
self.ord_id = Some(ord_id.into());
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct BorrowRepayHistoryRequest {
#[serde(skip_serializing_if = "Option::is_none")]
ccy: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
after: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
before: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
limit: Option<u32>,
}
impl BorrowRepayHistoryRequest {
pub fn new() -> Self {
Self::default()
}
pub fn currency(mut self, ccy: impl Into<String>) -> Self {
self.ccy = Some(ccy.into());
self
}
pub fn after(mut self, after: impl Into<String>) -> Self {
self.after = Some(after.into());
self
}
pub fn before(mut self, before: impl Into<String>) -> Self {
self.before = Some(before.into());
self
}
pub fn limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct InterestLimitsRequest {
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
limit_type: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
ccy: Option<String>,
}
impl InterestLimitsRequest {
pub fn new() -> Self {
Self::default()
}
pub fn limit_type(mut self, limit_type: impl Into<String>) -> Self {
self.limit_type = Some(limit_type.into());
self
}
pub fn currency(mut self, ccy: impl Into<String>) -> Self {
self.ccy = Some(ccy.into());
self
}
}
#[derive(Debug, Clone, Serialize)]
pub struct SimulatedPosition {
#[serde(rename = "instId")]
inst_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pos: Option<String>,
#[serde(rename = "avgPx", skip_serializing_if = "Option::is_none")]
avg_px: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
lever: Option<String>,
}
impl SimulatedPosition {
pub fn new(inst_id: impl Into<String>) -> Self {
Self {
inst_id: inst_id.into(),
pos: None,
avg_px: None,
lever: None,
}
}
pub fn position(mut self, pos: impl Into<String>) -> Self {
self.pos = Some(pos.into());
self
}
pub fn average_price(mut self, avg_px: impl Into<String>) -> Self {
self.avg_px = Some(avg_px.into());
self
}
pub fn leverage(mut self, lever: impl Into<String>) -> Self {
self.lever = Some(lever.into());
self
}
}
#[derive(Debug, Clone, Serialize)]
pub struct SimulatedAsset {
ccy: String,
#[serde(skip_serializing_if = "Option::is_none")]
eq: Option<String>,
}
impl SimulatedAsset {
pub fn new(ccy: impl Into<String>) -> Self {
Self {
ccy: ccy.into(),
eq: None,
}
}
pub fn equity(mut self, eq: impl Into<String>) -> Self {
self.eq = Some(eq.into());
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct SimulatedMarginRequest {
#[serde(rename = "instType", skip_serializing_if = "Option::is_none")]
inst_type: Option<InstType>,
#[serde(rename = "inclRealPos", skip_serializing_if = "Option::is_none")]
include_real_positions: Option<bool>,
#[serde(rename = "spotOffsetType", skip_serializing_if = "Option::is_none")]
spot_offset_type: Option<String>,
#[serde(rename = "simPos", skip_serializing_if = "Option::is_none")]
simulated_positions: Option<Vec<SimulatedPosition>>,
}
impl SimulatedMarginRequest {
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 include_real_positions(mut self, include_real_positions: bool) -> Self {
self.include_real_positions = Some(include_real_positions);
self
}
pub fn spot_offset_type(mut self, spot_offset_type: impl Into<String>) -> Self {
self.spot_offset_type = Some(spot_offset_type.into());
self
}
pub fn simulated_positions(mut self, simulated_positions: Vec<SimulatedPosition>) -> Self {
self.simulated_positions = Some(simulated_positions);
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct AccountPositionTiersRequest {
#[serde(rename = "instType", skip_serializing_if = "Option::is_none")]
inst_type: Option<InstType>,
#[serde(rename = "uly", skip_serializing_if = "Option::is_none")]
underlying: Option<String>,
#[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
inst_family: Option<String>,
}
impl AccountPositionTiersRequest {
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 underlying(mut self, underlying: impl Into<String>) -> Self {
self.underlying = Some(underlying.into());
self
}
pub fn inst_family(mut self, inst_family: impl Into<String>) -> Self {
self.inst_family = Some(inst_family.into());
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct PositionBuilderRequest {
#[serde(rename = "acctLv", skip_serializing_if = "Option::is_none")]
acct_lv: Option<String>,
#[serde(rename = "inclRealPosAndEq", skip_serializing_if = "Option::is_none")]
include_real_positions_and_equity: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
lever: Option<String>,
#[serde(rename = "greeksType", skip_serializing_if = "Option::is_none")]
greeks_type: Option<String>,
#[serde(rename = "simPos", skip_serializing_if = "Option::is_none")]
simulated_positions: Option<Vec<SimulatedPosition>>,
#[serde(rename = "simAsset", skip_serializing_if = "Option::is_none")]
simulated_assets: Option<Vec<SimulatedAsset>>,
#[serde(rename = "idxVol", skip_serializing_if = "Option::is_none")]
index_volatility: Option<String>,
}
impl PositionBuilderRequest {
pub fn new() -> Self {
Self::default()
}
pub fn account_level(mut self, acct_lv: impl Into<String>) -> Self {
self.acct_lv = Some(acct_lv.into());
self
}
pub fn include_real_positions_and_equity(mut self, include: bool) -> Self {
self.include_real_positions_and_equity = Some(include);
self
}
pub fn leverage(mut self, lever: impl Into<String>) -> Self {
self.lever = Some(lever.into());
self
}
pub fn greeks_type(mut self, greeks_type: impl Into<String>) -> Self {
self.greeks_type = Some(greeks_type.into());
self
}
pub fn simulated_positions(mut self, simulated_positions: Vec<SimulatedPosition>) -> Self {
self.simulated_positions = Some(simulated_positions);
self
}
pub fn simulated_assets(mut self, simulated_assets: Vec<SimulatedAsset>) -> Self {
self.simulated_assets = Some(simulated_assets);
self
}
pub fn index_volatility(mut self, index_volatility: impl Into<String>) -> Self {
self.index_volatility = Some(index_volatility.into());
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct PositionsHistoryRequest {
#[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<String>,
#[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<String>,
#[serde(rename = "posId", skip_serializing_if = "Option::is_none")]
pos_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
after: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
before: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
limit: Option<u32>,
}
impl PositionsHistoryRequest {
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<String>) -> 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<String>) -> Self {
self.close_type = Some(close_type.into());
self
}
pub fn position_id(mut self, pos_id: impl Into<String>) -> Self {
self.pos_id = Some(pos_id.into());
self
}
pub fn after(mut self, after: impl Into<String>) -> Self {
self.after = Some(after.into());
self
}
pub fn before(mut self, before: impl Into<String>) -> Self {
self.before = Some(before.into());
self
}
pub fn limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
}