added name into Connector trait. hardcoded affiliate code
This commit is contained in:
parent
f707f62ce3
commit
f541599fed
@ -13,11 +13,7 @@ use crate::BoxError;
|
|||||||
|
|
||||||
#[derive(Eq, PartialEq, Hash, Clone, Debug)]
|
#[derive(Eq, PartialEq, Hash, Clone, Debug)]
|
||||||
pub enum ExchangeKind {
|
pub enum ExchangeKind {
|
||||||
Bitfinex {
|
Bitfinex { api_key: String, api_secret: String },
|
||||||
api_key: String,
|
|
||||||
api_secret: String,
|
|
||||||
affiliate_code: Option<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,
|
||||||
@ -34,9 +30,7 @@ impl Client {
|
|||||||
ExchangeKind::Bitfinex {
|
ExchangeKind::Bitfinex {
|
||||||
api_key,
|
api_key,
|
||||||
api_secret,
|
api_secret,
|
||||||
affiliate_code,
|
} => BitfinexConnector::new(&api_key, &api_secret),
|
||||||
} => BitfinexConnector::new(&api_key, &api_secret)
|
|
||||||
.with_affiliate_code(affiliate_code.clone()),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Client {
|
Client {
|
||||||
@ -73,6 +67,7 @@ impl Client {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Connector: Send + Sync {
|
pub trait Connector: Send + Sync {
|
||||||
|
fn name(&self) -> String;
|
||||||
async fn active_positions(&self, pair: &SymbolPair) -> Result<Option<Vec<Position>>, BoxError>;
|
async fn active_positions(&self, pair: &SymbolPair) -> Result<Option<Vec<Position>>, BoxError>;
|
||||||
async fn current_prices(&self, pair: &SymbolPair) -> Result<TradingPairTicker, BoxError>;
|
async fn current_prices(&self, pair: &SymbolPair) -> Result<TradingPairTicker, BoxError>;
|
||||||
async fn active_orders(&self, pair: &SymbolPair) -> Result<Vec<Order>, BoxError>;
|
async fn active_orders(&self, pair: &SymbolPair) -> Result<Vec<Order>, BoxError>;
|
||||||
@ -87,7 +82,7 @@ pub trait Connector: Send + Sync {
|
|||||||
|
|
||||||
impl Debug for dyn Connector {
|
impl Debug for dyn Connector {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
|
||||||
write!(f, "Connector")
|
write!(f, "{}", self.name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,18 +98,15 @@ pub struct BitfinexConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl BitfinexConnector {
|
impl BitfinexConnector {
|
||||||
|
const AFFILIATE_CODE: &'static str = "XPebOgHxA";
|
||||||
|
|
||||||
pub fn new(api_key: &str, api_secret: &str) -> Self {
|
pub fn new(api_key: &str, api_secret: &str) -> Self {
|
||||||
BitfinexConnector {
|
BitfinexConnector {
|
||||||
bfx: Bitfinex::new(Some(api_key.into()), Some(api_secret.into())),
|
bfx: Bitfinex::new(Some(api_key.into()), Some(api_secret.into())),
|
||||||
affiliate_code: None,
|
affiliate_code: Some(BitfinexConnector::AFFILIATE_CODE.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_affiliate_code(mut self, affiliate_code: Option<String>) -> Self {
|
|
||||||
self.affiliate_code = affiliate_code;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
fn format_trading_pair(&self, pair: &SymbolPair) -> String {
|
fn format_trading_pair(&self, pair: &SymbolPair) -> String {
|
||||||
if pair.to_string().to_lowercase().contains("test") {
|
if pair.to_string().to_lowercase().contains("test") {
|
||||||
format!("{}:{}", pair.base(), pair.quote())
|
format!("{}:{}", pair.base(), pair.quote())
|
||||||
@ -126,6 +118,10 @@ impl BitfinexConnector {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Connector for BitfinexConnector {
|
impl Connector for BitfinexConnector {
|
||||||
|
fn name(&self) -> String {
|
||||||
|
"Bitfinex".into()
|
||||||
|
}
|
||||||
|
|
||||||
async fn active_positions(&self, pair: &SymbolPair) -> Result<Option<Vec<Position>>, BoxError> {
|
async fn active_positions(&self, pair: &SymbolPair) -> Result<Option<Vec<Position>>, BoxError> {
|
||||||
let active_positions = self.bfx.positions.active_positions().await?;
|
let active_positions = self.bfx.positions.active_positions().await?;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user