diff --git a/rustybot/src/connectors.rs b/rustybot/src/connectors.rs index 2abbfbc..09ec11e 100644 --- a/rustybot/src/connectors.rs +++ b/rustybot/src/connectors.rs @@ -8,10 +8,38 @@ use bitfinex::ticker::TradingPairTicker; use crate::currency::{Symbol, SymbolPair}; use crate::models::{Order, OrderKind, Position, PositionState}; use crate::BoxError; +use std::sync::Arc; #[derive(Eq, PartialEq, Hash, Clone)] pub enum ExchangeKind { - Bitfinex, + Bitfinex { + api_key: String, + api_secret: String, + affiliate_code: Option, + }, +} + +/// You do **not** have to wrap the `Client` it in an [`Rc`] or [`Arc`] to **reuse** it, +/// because it already uses an [`Arc`] internally. +#[derive(Clone)] +pub struct Client { + inner: Arc>, +} + +impl Client { + pub fn new(exchange: ExchangeKind) -> Self { + let inner = match exchange { + ExchangeKind::Bitfinex { + api_key, + api_secret, + affiliate_code, + } => BitfinexConnector::new(&api_key, &api_secret).with_affiliate_code(affiliate_code), + }; + + Client { + inner: Arc::new(Box::new(inner)), + } + } } #[async_trait] diff --git a/rustybot/src/managers.rs b/rustybot/src/managers.rs index 11e5758..997a033 100644 --- a/rustybot/src/managers.rs +++ b/rustybot/src/managers.rs @@ -1,5 +1,18 @@ +use crate::connectors::{Client, Connector}; +use crate::models::{Order, Position}; +use crate::ticker::Ticker; +use std::collections::VecDeque; + struct EventManager {} -struct PositionManager {} +struct PositionManager { + queue: VecDeque, + open_positions: Vec, + client: Client, +} -struct OrderManager {} +struct OrderManager { + queue: VecDeque, + open_orders: Vec, + client: Client, +}