use std::borrow::Cow;
use serde::Serialize;
use crate::model::InstType;
#[derive(Debug, Clone, Serialize)]
pub struct SimulatedPosition<'a> {
#[serde(rename = "instId")]
inst_id: Cow<'a, str>,
#[serde(skip_serializing_if = "Option::is_none")]
pos: Option<Cow<'a, str>>,
#[serde(rename = "avgPx", skip_serializing_if = "Option::is_none")]
avg_px: Option<Cow<'a, str>>,
#[serde(skip_serializing_if = "Option::is_none")]
lever: Option<Cow<'a, str>>,
}
impl<'a> SimulatedPosition<'a> {
pub fn new(inst_id: impl Into<Cow<'a, str>>) -> Self {
Self {
inst_id: inst_id.into(),
pos: None,
avg_px: None,
lever: None,
}
}
pub fn position(mut self, pos: impl Into<Cow<'a, str>>) -> Self {
self.pos = Some(pos.into());
self
}
pub fn average_price(mut self, avg_px: impl Into<Cow<'a, str>>) -> Self {
self.avg_px = Some(avg_px.into());
self
}
pub fn leverage(mut self, lever: impl Into<Cow<'a, str>>) -> Self {
self.lever = Some(lever.into());
self
}
}
#[derive(Debug, Clone, Serialize)]
pub struct SimulatedAsset<'a> {
ccy: Cow<'a, str>,
#[serde(skip_serializing_if = "Option::is_none")]
eq: Option<Cow<'a, str>>,
}
impl<'a> SimulatedAsset<'a> {
pub fn new(ccy: impl Into<Cow<'a, str>>) -> Self {
Self {
ccy: ccy.into(),
eq: None,
}
}
pub fn equity(mut self, eq: impl Into<Cow<'a, str>>) -> Self {
self.eq = Some(eq.into());
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct SimulatedMarginRequest<'a> {
#[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<Cow<'a, str>>,
#[serde(rename = "simPos", skip_serializing_if = "Option::is_none")]
simulated_positions: Option<Vec<SimulatedPosition<'a>>>,
}
impl<'a> SimulatedMarginRequest<'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 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<Cow<'a, str>>) -> Self {
self.spot_offset_type = Some(spot_offset_type.into());
self
}
pub fn simulated_positions(mut self, simulated_positions: Vec<SimulatedPosition<'a>>) -> Self {
self.simulated_positions = Some(simulated_positions);
self
}
}
#[derive(Debug, Clone, Serialize)]
pub struct AccountPositionTiersRequest<'a> {
#[serde(rename = "instType")]
inst_type: InstType,
#[serde(rename = "uly", skip_serializing_if = "Option::is_none")]
underlying: Option<Cow<'a, str>>,
#[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
inst_family: Option<Cow<'a, str>>,
}
impl<'a> AccountPositionTiersRequest<'a> {
pub fn new(inst_type: InstType) -> Self {
Self {
inst_type,
underlying: None,
inst_family: None,
}
}
pub fn underlying(mut self, underlying: impl Into<Cow<'a, str>>) -> Self {
self.underlying = Some(underlying.into());
self
}
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, Serialize)]
pub struct SetRiskOffsetAmountRequest<'a> {
ccy: Cow<'a, str>,
#[serde(rename = "clSpotInUseAmt")]
cl_spot_in_use_amt: Cow<'a, str>,
}
impl<'a> SetRiskOffsetAmountRequest<'a> {
pub fn new(ccy: impl Into<Cow<'a, str>>, cl_spot_in_use_amt: impl Into<Cow<'a, str>>) -> Self {
Self {
ccy: ccy.into(),
cl_spot_in_use_amt: cl_spot_in_use_amt.into(),
}
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct PositionBuilderRequest<'a> {
#[serde(rename = "acctLv", skip_serializing_if = "Option::is_none")]
acct_lv: Option<Cow<'a, str>>,
#[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<Cow<'a, str>>,
#[serde(rename = "greeksType", skip_serializing_if = "Option::is_none")]
greeks_type: Option<Cow<'a, str>>,
#[serde(rename = "simPos", skip_serializing_if = "Option::is_none")]
simulated_positions: Option<Vec<SimulatedPosition<'a>>>,
#[serde(rename = "simAsset", skip_serializing_if = "Option::is_none")]
simulated_assets: Option<Vec<SimulatedAsset<'a>>>,
#[serde(rename = "idxVol", skip_serializing_if = "Option::is_none")]
index_volatility: Option<Cow<'a, str>>,
}
impl<'a> PositionBuilderRequest<'a> {
pub fn new() -> Self {
Self::default()
}
pub fn account_level(mut self, acct_lv: impl Into<Cow<'a, str>>) -> 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<Cow<'a, str>>) -> Self {
self.lever = Some(lever.into());
self
}
pub fn greeks_type(mut self, greeks_type: impl Into<Cow<'a, str>>) -> Self {
self.greeks_type = Some(greeks_type.into());
self
}
pub fn simulated_positions(mut self, simulated_positions: Vec<SimulatedPosition<'a>>) -> Self {
self.simulated_positions = Some(simulated_positions);
self
}
pub fn simulated_assets(mut self, simulated_assets: Vec<SimulatedAsset<'a>>) -> Self {
self.simulated_assets = Some(simulated_assets);
self
}
pub fn index_volatility(mut self, index_volatility: impl Into<Cow<'a, str>>) -> Self {
self.index_volatility = Some(index_volatility.into());
self
}
}