rust #10
@ -13,11 +13,7 @@ use crate::BoxError;
|
||||
|
||||
#[derive(Eq, PartialEq, Hash, Clone, Debug)]
|
||||
pub enum ExchangeKind {
|
||||
Bitfinex {
|
||||
api_key: String,
|
||||
api_secret: String,
|
||||
affiliate_code: Option<String>,
|
||||
},
|
||||
Bitfinex { api_key: String, api_secret: String },
|
||||
}
|
||||
|
||||
/// You do **not** have to wrap the `Client` in an [`Rc`] or [`Arc`] to **reuse** it,
|
||||
@ -34,9 +30,7 @@ impl Client {
|
||||
ExchangeKind::Bitfinex {
|
||||
api_key,
|
||||
api_secret,
|
||||
affiliate_code,
|
||||
} => BitfinexConnector::new(&api_key, &api_secret)
|
||||
.with_affiliate_code(affiliate_code.clone()),
|
||||
} => BitfinexConnector::new(&api_key, &api_secret),
|
||||
};
|
||||
|
||||
Client {
|
||||
@ -73,6 +67,7 @@ impl Client {
|
||||
|
||||
#[async_trait]
|
||||
pub trait Connector: Send + Sync {
|
||||
fn name(&self) -> String;
|
||||
async fn active_positions(&self, pair: &SymbolPair) -> Result<Option<Vec<Position>>, BoxError>;
|
||||
async fn current_prices(&self, pair: &SymbolPair) -> Result<TradingPairTicker, 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 {
|
||||
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 {
|
||||
const AFFILIATE_CODE: &'static str = "XPebOgHxA";
|
||||
|
||||
pub fn new(api_key: &str, api_secret: &str) -> Self {
|
||||
BitfinexConnector {
|
||||
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 {
|
||||
if pair.to_string().to_lowercase().contains("test") {
|
||||
format!("{}:{}", pair.base(), pair.quote())
|
||||
@ -126,6 +118,10 @@ impl BitfinexConnector {
|
||||
|
||||
#[async_trait]
|
||||
impl Connector for BitfinexConnector {
|
||||
fn name(&self) -> String {
|
||||
"Bitfinex".into()
|
||||
}
|
||||
|
||||
async fn active_positions(&self, pair: &SymbolPair) -> Result<Option<Vec<Position>>, BoxError> {
|
||||
let active_positions = self.bfx.positions.active_positions().await?;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user