support for balance transfer API (bitfinex)
This commit is contained in:
parent
7357d48115
commit
c930dce131
2
rustybot/Cargo.lock
generated
2
rustybot/Cargo.lock
generated
@ -107,7 +107,7 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
|
||||
|
||||
[[package]]
|
||||
name = "bitfinex"
|
||||
version = "0.4.3"
|
||||
version = "0.5.0"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"chrono",
|
||||
|
@ -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<ActiveOrder, BoxError> {
|
||||
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<Vec<ActiveOrder>, BoxError>;
|
||||
async fn submit_order(&self, order: &OrderForm) -> Result<ActiveOrder, BoxError>;
|
||||
async fn cancel_order(&self, order: &ActiveOrder) -> Result<ActiveOrder, BoxError>;
|
||||
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<Self, Self::Error> {
|
||||
@ -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<TradingPairTicker> 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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -490,3 +490,9 @@ pub enum PositionState {
|
||||
Closed,
|
||||
Open,
|
||||
}
|
||||
|
||||
pub enum WalletKind {
|
||||
Exchange,
|
||||
Margin,
|
||||
Funding,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user