removed positions and orders modules. created models
This commit is contained in:
parent
e8642d758e
commit
7e8a5cc580
156
rustybot/src/models.rs
Normal file
156
rustybot/src/models.rs
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
use crate::currency::SymbolPair;
|
||||||
|
|
||||||
|
pub struct Order {
|
||||||
|
pub id: i64,
|
||||||
|
pub group_id: Option<i32>,
|
||||||
|
pub client_id: i64,
|
||||||
|
pub symbol: String,
|
||||||
|
pub creation_timestamp: i64,
|
||||||
|
pub update_timestamp: i64,
|
||||||
|
pub amount: f64,
|
||||||
|
pub amount_original: f64,
|
||||||
|
pub order_type: String,
|
||||||
|
pub previous_order_type: Option<String>,
|
||||||
|
pub flags: Option<i32>,
|
||||||
|
pub order_status: Option<String>,
|
||||||
|
pub price: f64,
|
||||||
|
pub price_avg: f64,
|
||||||
|
pub price_trailing: Option<f64>,
|
||||||
|
pub price_aux_limit: Option<f64>,
|
||||||
|
pub notify: i32,
|
||||||
|
pub hidden: i32,
|
||||||
|
pub placed_id: Option<i32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum OrderKind {
|
||||||
|
Limit,
|
||||||
|
ExchangeLimit,
|
||||||
|
Market,
|
||||||
|
ExchangeMarket,
|
||||||
|
Stop,
|
||||||
|
ExchangeStop,
|
||||||
|
StopLimit,
|
||||||
|
ExchangeStopLimit,
|
||||||
|
TrailingStop,
|
||||||
|
Fok,
|
||||||
|
ExchangeFok,
|
||||||
|
Ioc,
|
||||||
|
ExchangeIoc,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct Position {
|
||||||
|
pair: SymbolPair,
|
||||||
|
state: PositionState,
|
||||||
|
profit_state: Option<PositionProfitState>,
|
||||||
|
amount: f64,
|
||||||
|
base_price: f64,
|
||||||
|
pl: f64,
|
||||||
|
pl_perc: f64,
|
||||||
|
price_liq: f64,
|
||||||
|
position_id: u64,
|
||||||
|
creation_date: Option<u64>,
|
||||||
|
creation_update: Option<u64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Position {
|
||||||
|
pub fn new(
|
||||||
|
pair: SymbolPair,
|
||||||
|
state: PositionState,
|
||||||
|
amount: f64,
|
||||||
|
base_price: f64,
|
||||||
|
pl: f64,
|
||||||
|
pl_perc: f64,
|
||||||
|
price_liq: f64,
|
||||||
|
position_id: u64,
|
||||||
|
) -> Self {
|
||||||
|
Position {
|
||||||
|
pair,
|
||||||
|
state,
|
||||||
|
amount,
|
||||||
|
base_price,
|
||||||
|
pl,
|
||||||
|
pl_perc,
|
||||||
|
price_liq,
|
||||||
|
position_id,
|
||||||
|
creation_date: None,
|
||||||
|
creation_update: None,
|
||||||
|
profit_state: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_creation_date(mut self, creation_date: Option<u64>) -> Self {
|
||||||
|
self.creation_date = creation_date;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_creation_update(mut self, creation_update: Option<u64>) -> Self {
|
||||||
|
self.creation_update = creation_update;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_profit_state(mut self, profit_state: Option<PositionProfitState>) -> Self {
|
||||||
|
self.profit_state = profit_state;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pair(&self) -> &SymbolPair {
|
||||||
|
&self.pair
|
||||||
|
}
|
||||||
|
pub fn state(&self) -> PositionState {
|
||||||
|
self.state
|
||||||
|
}
|
||||||
|
pub fn amount(&self) -> f64 {
|
||||||
|
self.amount
|
||||||
|
}
|
||||||
|
pub fn base_price(&self) -> f64 {
|
||||||
|
self.base_price
|
||||||
|
}
|
||||||
|
pub fn pl(&self) -> f64 {
|
||||||
|
self.pl
|
||||||
|
}
|
||||||
|
pub fn pl_perc(&self) -> f64 {
|
||||||
|
self.pl_perc
|
||||||
|
}
|
||||||
|
pub fn price_liq(&self) -> f64 {
|
||||||
|
self.price_liq
|
||||||
|
}
|
||||||
|
pub fn position_id(&self) -> u64 {
|
||||||
|
self.position_id
|
||||||
|
}
|
||||||
|
pub fn profit_state(&self) -> Option<PositionProfitState> {
|
||||||
|
self.profit_state
|
||||||
|
}
|
||||||
|
pub fn creation_date(&self) -> Option<u64> {
|
||||||
|
self.creation_date
|
||||||
|
}
|
||||||
|
pub fn creation_update(&self) -> Option<u64> {
|
||||||
|
self.creation_update
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
|
||||||
|
pub enum PositionProfitState {
|
||||||
|
Critical,
|
||||||
|
Loss,
|
||||||
|
BreakEven,
|
||||||
|
MinimumProfit,
|
||||||
|
Profit,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PositionProfitState {
|
||||||
|
fn color(self) -> String {
|
||||||
|
match self {
|
||||||
|
PositionProfitState::Critical | PositionProfitState::Loss => "red",
|
||||||
|
PositionProfitState::BreakEven => "yellow",
|
||||||
|
PositionProfitState::MinimumProfit | PositionProfitState::Profit => "green",
|
||||||
|
}
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
|
||||||
|
pub enum PositionState {
|
||||||
|
Closed,
|
||||||
|
Open,
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user