diff --git a/rustybot/src/connectors.rs b/rustybot/src/connectors.rs index d3ea78d..9212b8d 100644 --- a/rustybot/src/connectors.rs +++ b/rustybot/src/connectors.rs @@ -1,6 +1,6 @@ use async_trait::async_trait; use bitfinex::api::Bitfinex; -use bitfinex::orders::{ActiveOrder, OrderMeta}; +use bitfinex::orders::OrderMeta; use bitfinex::ticker::TradingPairTicker; use log::debug; use std::convert::TryInto; @@ -9,7 +9,7 @@ use std::sync::Arc; use crate::currency::SymbolPair; use crate::models::{ - ExecutedOrder, OrderBook, OrderBookEntry, OrderForm, OrderKind, Position, PositionState, + ActiveOrder, OrderBook, OrderBookEntry, OrderForm, OrderKind, Position, PositionState, PriceTicker, }; use crate::BoxError; @@ -53,11 +53,11 @@ impl Client { self.inner.current_prices(pair).await } - pub async fn active_orders(&self, pair: &SymbolPair) -> Result, BoxError> { + pub async fn active_orders(&self, pair: &SymbolPair) -> Result, BoxError> { self.inner.active_orders(pair).await } - pub async fn submit_order(&self, order: OrderForm) -> Result { + pub async fn submit_order(&self, order: OrderForm) -> Result { self.inner.submit_order(order).await } @@ -72,8 +72,8 @@ pub trait Connector: Send + Sync { async fn active_positions(&self, pair: &SymbolPair) -> Result>, BoxError>; async fn current_prices(&self, pair: &SymbolPair) -> Result; async fn order_book(&self, pair: &SymbolPair) -> Result; - async fn active_orders(&self, pair: &SymbolPair) -> Result, BoxError>; - async fn submit_order(&self, order: OrderForm) -> Result; + async fn active_orders(&self, pair: &SymbolPair) -> Result, BoxError>; + async fn submit_order(&self, order: OrderForm) -> Result; } impl Debug for dyn Connector { @@ -144,11 +144,11 @@ impl Connector for BitfinexConnector { Ok(ticker) } - async fn active_orders(&self, pair: &SymbolPair) -> Result, BoxError> { + async fn active_orders(&self, pair: &SymbolPair) -> Result, BoxError> { unimplemented!() } - async fn submit_order(&self, order: OrderForm) -> Result { + async fn submit_order(&self, order: OrderForm) -> Result { // TODO: change trading pair formatting. awful. let order_form = match &self.affiliate_code { Some(affiliate_code) => bitfinex::orders::OrderForm::new( @@ -168,7 +168,7 @@ impl Connector for BitfinexConnector { let response = self.bfx.orders.submit_order(&order_form).await?; - Ok(ExecutedOrder { + Ok(ActiveOrder { id: 1, group_id: None, client_id: 0, @@ -195,7 +195,10 @@ impl Connector for BitfinexConnector { let x = self .bfx .book - .trading_pair(self.format_trading_pair(&pair), "P0".into()) + .trading_pair( + self.format_trading_pair(&pair), + bitfinex::book::BookPrecision::P0, + ) .await?; let entries = x @@ -295,8 +298,8 @@ impl From for PriceTicker { } } -impl From for ExecutedOrder { - fn from(o: ActiveOrder) -> Self { +impl From for ActiveOrder { + fn from(o: bitfinex::orders::ActiveOrder) -> Self { Self { id: o.id, group_id: o.group_id, diff --git a/rustybot/src/managers.rs b/rustybot/src/managers.rs index 53ba11e..f02e196 100644 --- a/rustybot/src/managers.rs +++ b/rustybot/src/managers.rs @@ -13,7 +13,7 @@ use tokio::sync::oneshot; use crate::connectors::{Client, ExchangeKind}; use crate::currency::SymbolPair; use crate::events::{ActorMessage, Event, Message}; -use crate::models::{ExecutedOrder, OrderBook, OrderForm, OrderKind, Position, PriceTicker}; +use crate::models::{ActiveOrder, OrderBook, OrderForm, OrderKind, Position, PriceTicker}; use crate::strategy::{FastOrderStrategy, OrderStrategy, PositionStrategy, TrailingStop}; use crate::BoxError; @@ -317,7 +317,7 @@ impl PositionManager { * ORDERS ******************/ -pub type TrackedPositionsMap = HashMap; +pub type TrackedPositionsMap = HashMap; pub struct OrderManagerHandle { sender: Sender, @@ -371,7 +371,7 @@ pub struct OrderManager { receiver: Receiver, tracked_positions: TrackedPositionsMap, pair: SymbolPair, - open_orders: Vec, + open_orders: Vec, client: Client, strategy: Box, } diff --git a/rustybot/src/models.rs b/rustybot/src/models.rs index 10fa256..c8b989a 100644 --- a/rustybot/src/models.rs +++ b/rustybot/src/models.rs @@ -107,7 +107,7 @@ impl OrderBook { } #[derive(Clone, Debug)] -pub struct ExecutedOrder { +pub struct ActiveOrder { pub id: i64, pub group_id: Option, pub client_id: i64, @@ -129,7 +129,7 @@ pub struct ExecutedOrder { pub placed_id: Option, } -impl Hash for ExecutedOrder { +impl Hash for ActiveOrder { fn hash(&self, state: &mut H) { state.write(&self.id.to_le_bytes()) } diff --git a/rustybot/src/strategy.rs b/rustybot/src/strategy.rs index e1963e4..0ca1981 100644 --- a/rustybot/src/strategy.rs +++ b/rustybot/src/strategy.rs @@ -5,7 +5,7 @@ use std::fmt::{Debug, Formatter}; use crate::events::{Event, EventKind, EventMetadata, Message}; use crate::managers::{OrderManager, PositionManager, TrackedPositionsMap}; -use crate::models::{ExecutedOrder, OrderForm, Position, PositionProfitState}; +use crate::models::{ActiveOrder, OrderForm, Position, PositionProfitState}; use tokio::sync::oneshot; /*************** @@ -37,8 +37,8 @@ pub trait OrderStrategy: DynClone + Send { /// a position that has an open order associated to it. fn on_position_close( &self, - order: &ExecutedOrder, - tracked_positions: &HashMap, + order: &ActiveOrder, + tracked_positions: &HashMap, ) -> TrackedPositionsMap; } @@ -194,8 +194,8 @@ impl OrderStrategy for FastOrderStrategy { fn on_position_close( &self, - order: &ExecutedOrder, - tracked_positions: &HashMap, + order: &ActiveOrder, + tracked_positions: &HashMap, ) -> TrackedPositionsMap { unimplemented!() }