From e8642d758e946c5b7c5de5911ad33e2495ba06a3 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Wed, 13 Jan 2021 08:57:36 +0000 Subject: [PATCH] removed positions and orders modules. created models --- rustybot/src/connectors.rs | 3 +- rustybot/src/events.rs | 2 +- rustybot/src/main.rs | 10 ++-- rustybot/src/orders.rs | 37 ------------ rustybot/src/pairs.rs | 3 +- rustybot/src/positions.rs | 118 ------------------------------------- rustybot/src/strategy.rs | 2 +- 7 files changed, 10 insertions(+), 165 deletions(-) delete mode 100644 rustybot/src/orders.rs delete mode 100644 rustybot/src/positions.rs diff --git a/rustybot/src/connectors.rs b/rustybot/src/connectors.rs index bc8647d..e1591b5 100644 --- a/rustybot/src/connectors.rs +++ b/rustybot/src/connectors.rs @@ -6,8 +6,7 @@ use bitfinex::orders::{OrderForm, OrderMeta}; use bitfinex::ticker::TradingPairTicker; use crate::currency::{Symbol, SymbolPair}; -use crate::orders::{Order, OrderKind}; -use crate::positions::{Position, PositionState}; +use crate::models::{Order, OrderKind, Position, PositionState}; use crate::BoxError; #[derive(Eq, PartialEq, Hash, Clone)] diff --git a/rustybot/src/events.rs b/rustybot/src/events.rs index 781ca60..c32b0ae 100644 --- a/rustybot/src/events.rs +++ b/rustybot/src/events.rs @@ -5,8 +5,8 @@ use tokio::stream::StreamExt; use tokio::task::JoinHandle; use crate::bot::BfxBot; +use crate::models::{Position, PositionProfitState}; use crate::pairs::PairStatus; -use crate::positions::{Position, PositionProfitState, PositionState}; use crate::BoxError; #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] diff --git a/rustybot/src/main.rs b/rustybot/src/main.rs index 9025d11..501ccae 100644 --- a/rustybot/src/main.rs +++ b/rustybot/src/main.rs @@ -3,15 +3,16 @@ use tokio::time::{delay_for, Duration}; use crate::bot::BfxBot; use crate::connectors::BfxWrapper; use crate::currency::{Symbol, SymbolPair}; +use crate::events::SignalKind; use crate::strategy::TrailingStop; +use std::thread::JoinHandle; mod bot; mod connectors; mod currency; mod events; -mod orders; +mod models; mod pairs; -mod positions; mod strategy; mod ticker; @@ -21,8 +22,9 @@ pub type BoxError = Box; async fn main() -> Result<(), BoxError> { let test_api_key = "P1EVE68DJByDAkGQvpIkTwfrbYXd2Vo2ZaIhTYb9vx2"; let test_api_secret = "1nicg8z0zKVEt5Rb7ZDpIYjVYVTgvCaCPMZqB0niFli"; - // - let bfx = BfxWrapper::new(test_api_key, test_api_secret); + let bfx = BfxWrapper::new(test_api_key, test_api_secret) + .with_affiliate_code(Some("XPebOgHxA".into())); + let mut bot = BfxBot::new( bfx, vec![Symbol::TESTBTC], diff --git a/rustybot/src/orders.rs b/rustybot/src/orders.rs deleted file mode 100644 index b307bc6..0000000 --- a/rustybot/src/orders.rs +++ /dev/null @@ -1,37 +0,0 @@ -pub struct Order { - pub id: i64, - pub group_id: Option, - 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, - pub flags: Option, - pub order_status: Option, - pub price: f64, - pub price_avg: f64, - pub price_trailing: Option, - pub price_aux_limit: Option, - pub notify: i32, - pub hidden: i32, - pub placed_id: Option, -} - -pub enum OrderKind { - Limit, - ExchangeLimit, - Market, - ExchangeMarket, - Stop, - ExchangeStop, - StopLimit, - ExchangeStopLimit, - TrailingStop, - Fok, - ExchangeFok, - Ioc, - ExchangeIoc, -} diff --git a/rustybot/src/pairs.rs b/rustybot/src/pairs.rs index aa0fb46..903285c 100644 --- a/rustybot/src/pairs.rs +++ b/rustybot/src/pairs.rs @@ -2,8 +2,7 @@ use std::collections::HashMap; use crate::currency::SymbolPair; use crate::events::{Event, EventDispatcher, SignalKind}; -use crate::orders::Order; -use crate::positions::Position; +use crate::models::{Order, Position}; use crate::strategy::Strategy; pub struct PairStatus<'a> { diff --git a/rustybot/src/positions.rs b/rustybot/src/positions.rs deleted file mode 100644 index cbbd0af..0000000 --- a/rustybot/src/positions.rs +++ /dev/null @@ -1,118 +0,0 @@ -use crate::currency::{Symbol, SymbolPair}; - -#[derive(Clone, Debug)] -pub struct Position { - pair: SymbolPair, - state: PositionState, - profit_state: Option, - amount: f64, - base_price: f64, - pl: f64, - pl_perc: f64, - price_liq: f64, - position_id: u64, - creation_date: Option, - creation_update: Option, -} - -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) -> Self { - self.creation_date = creation_date; - self - } - - pub fn with_creation_update(mut self, creation_update: Option) -> Self { - self.creation_update = creation_update; - self - } - - pub fn with_profit_state(mut self, profit_state: Option) -> 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 { - self.profit_state - } - pub fn creation_date(&self) -> Option { - self.creation_date - } - pub fn creation_update(&self) -> Option { - 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, -} diff --git a/rustybot/src/strategy.rs b/rustybot/src/strategy.rs index af4e4c1..8a67940 100644 --- a/rustybot/src/strategy.rs +++ b/rustybot/src/strategy.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; use crate::events::{Event, EventKind, EventMetadata, SignalKind}; +use crate::models::{Position, PositionProfitState}; use crate::pairs::PairStatus; -use crate::positions::{Position, PositionProfitState, PositionState}; use dyn_clone::DynClone; pub trait Strategy: DynClone {