removed extra api keys

This commit is contained in:
Giulio De Pasquale 2021-01-26 16:19:10 +00:00
parent 15c1d5b84a
commit ef618ad754

View File

@ -28,14 +28,7 @@ pub enum Exchange {
#[derive(Eq, PartialEq, Hash, Clone, Debug)] #[derive(Eq, PartialEq, Hash, Clone, Debug)]
pub enum ExchangeDetails { pub enum ExchangeDetails {
Bitfinex { Bitfinex { api_key: String, api_secret: String },
prices_api_key: String,
prices_api_secret: String,
orders_api_key: String,
orders_api_secret: String,
positions_api_key: String,
positions_api_secret: String,
},
} }
/// You do **not** have to wrap the `Client` in an [`Rc`] or [`Arc`] to **reuse** it, /// 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)] #[derive(Clone, Debug)]
pub struct Client { pub struct Client {
exchange: Exchange, exchange: Exchange,
prices_connector: Arc<Box<dyn Connector>>, inner: Arc<Box<dyn Connector>>,
orders_connector: Arc<Box<dyn Connector>>,
positions_connector: Arc<Box<dyn Connector>>,
} }
impl Client { impl Client {
pub fn new(exchange: &ExchangeDetails) -> Self { pub fn new(exchange: &ExchangeDetails) -> Self {
match exchange { match exchange {
ExchangeDetails::Bitfinex { ExchangeDetails::Bitfinex {
prices_api_key, api_key,
prices_api_secret, api_secret,
orders_api_key,
orders_api_secret,
positions_api_key,
positions_api_secret,
} => Self { } => Self {
exchange: Exchange::Bitfinex, exchange: Exchange::Bitfinex,
prices_connector: Arc::new(Box::new( inner: Arc::new(Box::new((BitfinexConnector::new(api_key, api_secret)))),
(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)),
)),
}, },
} }
} }
@ -79,8 +58,8 @@ impl Client {
) -> Result<Option<Vec<Position>>, BoxError> { ) -> Result<Option<Vec<Position>>, BoxError> {
// retrieving open positions and order book to calculate effective profit/loss // retrieving open positions and order book to calculate effective profit/loss
let (positions, order_book) = tokio::join!( let (positions, order_book) = tokio::join!(
self.positions_connector.active_positions(pair), self.inner.active_positions(pair),
self.orders_connector.order_book(pair) self.inner.order_book(pair)
); );
let (mut positions, order_book) = (positions?, order_book?); let (mut positions, order_book) = (positions?, order_book?);
@ -100,23 +79,23 @@ impl Client {
} }
pub async fn current_prices(&self, pair: &SymbolPair) -> Result<TradingPairTicker, BoxError> { pub async fn current_prices(&self, pair: &SymbolPair) -> Result<TradingPairTicker, BoxError> {
self.prices_connector.current_prices(pair).await self.inner.current_prices(pair).await
} }
pub async fn active_orders(&self, pair: &SymbolPair) -> Result<Vec<ActiveOrder>, BoxError> { pub async fn active_orders(&self, pair: &SymbolPair) -> Result<Vec<ActiveOrder>, BoxError> {
self.orders_connector.active_orders(pair).await self.inner.active_orders(pair).await
} }
pub async fn submit_order(&self, order: &OrderForm) -> Result<ActiveOrder, BoxError> { pub async fn submit_order(&self, order: &OrderForm) -> Result<ActiveOrder, BoxError> {
self.orders_connector.submit_order(order).await self.inner.submit_order(order).await
} }
pub async fn order_book(&self, pair: &SymbolPair) -> Result<OrderBook, BoxError> { pub async fn order_book(&self, pair: &SymbolPair) -> Result<OrderBook, BoxError> {
self.orders_connector.order_book(pair).await self.inner.order_book(pair).await
} }
pub async fn cancel_order(&self, order: &ActiveOrder) -> Result<ActiveOrder, BoxError> { pub async fn cancel_order(&self, order: &ActiveOrder) -> Result<ActiveOrder, BoxError> {
self.orders_connector.cancel_order(order).await self.inner.cancel_order(order).await
} }
} }