diff --git a/rustybot/Cargo.lock b/rustybot/Cargo.lock index 2d62993..cba87b0 100644 --- a/rustybot/Cargo.lock +++ b/rustybot/Cargo.lock @@ -107,7 +107,7 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "bitfinex" -version = "0.4.3" +version = "0.5.0" dependencies = [ "bitflags", "chrono", diff --git a/rustybot/src/connectors.rs b/rustybot/src/connectors.rs index 55644f2..cc60ea7 100644 --- a/rustybot/src/connectors.rs +++ b/rustybot/src/connectors.rs @@ -1,25 +1,24 @@ use std::convert::{TryFrom, TryInto}; - use std::fmt::{Debug, Formatter}; use std::str::FromStr; use std::sync::Arc; use async_trait::async_trait; use bitfinex::api::Bitfinex; -use bitfinex::orders::{CancelOrderForm, OrderMeta, OrderResponse}; +use bitfinex::orders::{CancelOrderForm, OrderMeta}; use bitfinex::ticker::TradingPairTicker; use futures_retry::{FutureRetry, RetryPolicy}; - use log::trace; use tokio::macros::support::Future; use tokio::time::Duration; -use crate::currency::SymbolPair; +use crate::currency::{Symbol, SymbolPair}; use crate::models::{ ActiveOrder, OrderBook, OrderBookEntry, OrderForm, OrderKind, Position, PositionState, - PriceTicker, TradingPlatform, + PriceTicker, TradingPlatform, WalletKind, }; use crate::BoxError; +use bitfinex::responses::OrderResponse; #[derive(PartialEq, Eq, Clone, Copy, Debug)] pub enum Exchange { @@ -103,6 +102,18 @@ impl Client { pub async fn cancel_order(&self, order: &ActiveOrder) -> Result { self.inner.cancel_order(order).await } + + pub async fn transfer_between_wallets( + &self, + from: &WalletKind, + to: &WalletKind, + symbol: Symbol, + amount: f64, + ) -> Result<(), BoxError> { + self.inner + .transfer_between_wallets(from, to, symbol, amount) + .await + } } #[async_trait] @@ -114,6 +125,13 @@ pub trait Connector: Send + Sync { async fn active_orders(&self, pair: &SymbolPair) -> Result, BoxError>; async fn submit_order(&self, order: &OrderForm) -> Result; async fn cancel_order(&self, order: &ActiveOrder) -> Result; + async fn transfer_between_wallets( + &self, + from: &WalletKind, + to: &WalletKind, + symbol: Symbol, + amount: f64, + ) -> Result<(), BoxError>; } impl Debug for dyn Connector { @@ -305,6 +323,24 @@ impl Connector for BitfinexConnector { Ok((&response).try_into()?) } + + async fn transfer_between_wallets( + &self, + from: &WalletKind, + to: &WalletKind, + symbol: Symbol, + amount: f64, + ) -> Result<(), BoxError> { + let result = self + .bfx + .account + .transfer_between_wallets(from.into(), to.into(), symbol.to_string(), amount) + .await?; + + println!("{:?}", result); + + Ok(()) + } } impl From<&ActiveOrder> for CancelOrderForm { @@ -313,7 +349,7 @@ impl From<&ActiveOrder> for CancelOrderForm { } } -impl TryFrom<&bitfinex::orders::OrderResponse> for ActiveOrder { +impl TryFrom<&bitfinex::responses::OrderResponse> for ActiveOrder { type Error = BoxError; fn try_from(response: &OrderResponse) -> Result { @@ -387,7 +423,7 @@ impl From<&OrderForm> for bitfinex::orders::OrderKind { } } -impl From<&bitfinex::orders::OrderResponse> for TradingPlatform { +impl From<&bitfinex::responses::OrderResponse> for TradingPlatform { fn from(response: &OrderResponse) -> Self { match response.order_type() { bitfinex::orders::OrderKind::Limit @@ -417,7 +453,7 @@ impl From<&bitfinex::orders::ActiveOrder> for TradingPlatform { } } -impl From<&bitfinex::orders::OrderResponse> for OrderKind { +impl From<&bitfinex::responses::OrderResponse> for OrderKind { fn from(response: &OrderResponse) -> Self { match response.order_type() { bitfinex::orders::OrderKind::Limit | bitfinex::orders::OrderKind::ExchangeLimit => { @@ -544,3 +580,13 @@ impl From for PriceTicker { } } } + +impl From<&WalletKind> for &bitfinex::account::WalletKind { + fn from(k: &WalletKind) -> Self { + match k { + WalletKind::Exchange => &bitfinex::account::WalletKind::Exchange, + WalletKind::Margin => &bitfinex::account::WalletKind::Margin, + WalletKind::Funding => &bitfinex::account::WalletKind::Funding, + } + } +} diff --git a/rustybot/src/managers.rs b/rustybot/src/managers.rs index bb6e3f8..cc8485e 100644 --- a/rustybot/src/managers.rs +++ b/rustybot/src/managers.rs @@ -11,10 +11,11 @@ use tokio::sync::oneshot; use tokio::time::Duration; use crate::connectors::{Client, ExchangeDetails}; -use crate::currency::SymbolPair; +use crate::currency::{Symbol, SymbolPair}; use crate::events::{ActorMessage, Event, Message}; use crate::models::{ ActiveOrder, OrderBook, OrderForm, OrderKind, Position, PriceTicker, TradingPlatform, + WalletKind, }; use crate::strategy::{FastOrderStrategy, OrderStrategy, PositionStrategy, TrailingStop}; use crate::BoxError; diff --git a/rustybot/src/models.rs b/rustybot/src/models.rs index 04e833b..42cfa87 100644 --- a/rustybot/src/models.rs +++ b/rustybot/src/models.rs @@ -490,3 +490,9 @@ pub enum PositionState { Closed, Open, } + +pub enum WalletKind { + Exchange, + Margin, + Funding, +}