From ef618ad7542d4ea62b563e3db5b1779e76dfc71c Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Tue, 26 Jan 2021 16:19:10 +0000 Subject: [PATCH] removed extra api keys --- rustybot/src/connectors.rs | 45 ++++++++++---------------------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/rustybot/src/connectors.rs b/rustybot/src/connectors.rs index 626a995..3e27ff1 100644 --- a/rustybot/src/connectors.rs +++ b/rustybot/src/connectors.rs @@ -28,14 +28,7 @@ pub enum Exchange { #[derive(Eq, PartialEq, Hash, Clone, Debug)] pub enum ExchangeDetails { - Bitfinex { - prices_api_key: String, - prices_api_secret: String, - orders_api_key: String, - orders_api_secret: String, - positions_api_key: String, - positions_api_secret: String, - }, + Bitfinex { api_key: String, api_secret: String }, } /// You do **not** have to wrap the `Client` in an [`Rc`] or [`Arc`] to **reuse** it, @@ -43,32 +36,18 @@ pub enum ExchangeDetails { #[derive(Clone, Debug)] pub struct Client { exchange: Exchange, - prices_connector: Arc>, - orders_connector: Arc>, - positions_connector: Arc>, + inner: Arc>, } impl Client { pub fn new(exchange: &ExchangeDetails) -> Self { match exchange { ExchangeDetails::Bitfinex { - prices_api_key, - prices_api_secret, - orders_api_key, - orders_api_secret, - positions_api_key, - positions_api_secret, + api_key, + api_secret, } => Self { exchange: Exchange::Bitfinex, - prices_connector: Arc::new(Box::new( - (BitfinexConnector::new(prices_api_key, prices_api_secret)), - )), - orders_connector: Arc::new(Box::new( - (BitfinexConnector::new(orders_api_key, orders_api_secret)), - )), - positions_connector: Arc::new(Box::new( - (BitfinexConnector::new(positions_api_key, positions_api_secret)), - )), + inner: Arc::new(Box::new((BitfinexConnector::new(api_key, api_secret)))), }, } } @@ -79,8 +58,8 @@ impl Client { ) -> Result>, BoxError> { // retrieving open positions and order book to calculate effective profit/loss let (positions, order_book) = tokio::join!( - self.positions_connector.active_positions(pair), - self.orders_connector.order_book(pair) + self.inner.active_positions(pair), + self.inner.order_book(pair) ); let (mut positions, order_book) = (positions?, order_book?); @@ -100,23 +79,23 @@ impl Client { } pub async fn current_prices(&self, pair: &SymbolPair) -> Result { - self.prices_connector.current_prices(pair).await + self.inner.current_prices(pair).await } pub async fn active_orders(&self, pair: &SymbolPair) -> Result, BoxError> { - self.orders_connector.active_orders(pair).await + self.inner.active_orders(pair).await } pub async fn submit_order(&self, order: &OrderForm) -> Result { - self.orders_connector.submit_order(order).await + self.inner.submit_order(order).await } pub async fn order_book(&self, pair: &SymbolPair) -> Result { - self.orders_connector.order_book(pair).await + self.inner.order_book(pair).await } pub async fn cancel_order(&self, order: &ActiveOrder) -> Result { - self.orders_connector.cancel_order(order).await + self.inner.cancel_order(order).await } }