use std::collections::HashMap;
use positions::{prelude::Str, Asset};
use rust_decimal::Decimal;
use super::place::Place;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TimeInForce {
GoodTilCancelled,
FillOrKill,
ImmediateOrCancel,
}
impl Default for TimeInForce {
fn default() -> Self {
Self::GoodTilCancelled
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OrderKind {
Market,
Limit(Decimal, TimeInForce),
PostOnly(Decimal),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OrderStatus {
Pending,
Finished,
Unknown,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct OrderState {
pub filled: Decimal,
pub cost: Decimal,
pub status: OrderStatus,
pub fees: HashMap<Asset, Decimal>,
}
impl Default for OrderState {
fn default() -> Self {
Self {
filled: Decimal::ZERO,
cost: Decimal::ONE,
status: OrderStatus::Pending,
fees: HashMap::default(),
}
}
}
#[derive(Debug, Clone)]
pub struct Order {
pub id: OrderId,
pub target: Place,
pub state: OrderState,
pub trade: Option<OrderTrade>,
}
impl Order {
pub fn new(id: OrderId, target: Place) -> Self {
Self {
id,
target,
state: OrderState::default(),
trade: None,
}
}
pub fn with_state(&mut self, state: OrderState) -> &mut Self {
self.state = state;
self
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct OrderId {
inner: Str,
}
impl From<String> for OrderId {
fn from(inner: String) -> Self {
Self {
inner: Str::new(inner),
}
}
}
impl From<Str> for OrderId {
fn from(inner: Str) -> Self {
Self { inner }
}
}
impl OrderId {
pub fn as_str(&self) -> &str {
self.inner.as_str()
}
pub fn as_smol_str(&self) -> &Str {
&self.inner
}
}
#[derive(Debug, Clone)]
pub struct OrderTrade {
pub price: Decimal,
pub size: Decimal,
pub fee: Decimal,
pub fee_asset: Option<Asset>,
}