use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
use crate::types::{BuySell, OrderType, TimeInForce};
#[derive(Debug, Clone, Serialize)]
pub struct AddOrderParams {
pub order_type: OrderType,
pub side: BuySell,
pub symbol: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub order_qty: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none")]
pub limit_price: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none")]
pub time_in_force: Option<TimeInForce>,
#[serde(skip_serializing_if = "Option::is_none")]
pub trigger_price: Option<Decimal>,
pub token: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub cl_ord_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub post_only: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reduce_only: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub display_qty: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none")]
pub fee_preference: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub validate: Option<bool>,
}
impl AddOrderParams {
pub fn new(
order_type: OrderType,
side: BuySell,
symbol: impl Into<String>,
token: impl Into<String>,
) -> Self {
Self {
order_type,
side,
symbol: symbol.into(),
order_qty: None,
limit_price: None,
time_in_force: None,
trigger_price: None,
token: token.into(),
cl_ord_id: None,
post_only: None,
reduce_only: None,
display_qty: None,
fee_preference: None,
validate: None,
}
}
pub fn order_qty(mut self, qty: Decimal) -> Self {
self.order_qty = Some(qty);
self
}
pub fn limit_price(mut self, price: Decimal) -> Self {
self.limit_price = Some(price);
self
}
pub fn time_in_force(mut self, tif: TimeInForce) -> Self {
self.time_in_force = Some(tif);
self
}
pub fn post_only(mut self, post_only: bool) -> Self {
self.post_only = Some(post_only);
self
}
pub fn cl_ord_id(mut self, id: impl Into<String>) -> Self {
self.cl_ord_id = Some(id.into());
self
}
pub fn validate(mut self, validate: bool) -> Self {
self.validate = Some(validate);
self
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct AddOrderResult {
pub order_id: String,
#[serde(default)]
pub cl_ord_id: Option<String>,
#[serde(default)]
pub order_status: Option<String>,
#[serde(default)]
pub symbol: Option<String>,
#[serde(default)]
pub exec_reports: Option<Vec<ExecReport>>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct ExecReport {
pub exec_id: String,
pub order_id: String,
pub exec_type: String,
pub order_status: String,
pub symbol: String,
pub side: String,
#[serde(default)]
pub last_qty: Option<Decimal>,
#[serde(default)]
pub last_price: Option<Decimal>,
}
#[derive(Debug, Clone, Serialize)]
pub struct CancelOrderParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub order_id: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub cl_ord_id: Option<Vec<String>>,
pub token: String,
}
impl CancelOrderParams {
pub fn by_order_id(order_ids: Vec<String>, token: impl Into<String>) -> Self {
Self {
order_id: Some(order_ids),
cl_ord_id: None,
token: token.into(),
}
}
pub fn by_cl_ord_id(cl_ord_ids: Vec<String>, token: impl Into<String>) -> Self {
Self {
order_id: None,
cl_ord_id: Some(cl_ord_ids),
token: token.into(),
}
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct CancelOrderResult {
#[serde(default)]
pub order_id: Option<String>,
#[serde(default)]
pub cl_ord_id: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
pub struct CancelAllParams {
pub token: String,
}
impl CancelAllParams {
pub fn new(token: impl Into<String>) -> Self {
Self {
token: token.into(),
}
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct CancelAllResult {
pub count: u32,
}
#[derive(Debug, Clone, Serialize)]
pub struct EditOrderParams {
pub order_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub order_qty: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none")]
pub limit_price: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none")]
pub display_qty: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none")]
pub trigger_price: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none")]
pub post_only: Option<bool>,
pub token: String,
}
impl EditOrderParams {
pub fn new(order_id: impl Into<String>, token: impl Into<String>) -> Self {
Self {
order_id: order_id.into(),
order_qty: None,
limit_price: None,
display_qty: None,
trigger_price: None,
post_only: None,
token: token.into(),
}
}
pub fn order_qty(mut self, qty: Decimal) -> Self {
self.order_qty = Some(qty);
self
}
pub fn limit_price(mut self, price: Decimal) -> Self {
self.limit_price = Some(price);
self
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct EditOrderResult {
pub order_id: String,
#[serde(default)]
pub original_order_id: Option<String>,
}