Skip to content

Commit 68da311

Browse files
committed
chore: auth method (closes: #10)
1 parent 906d4d4 commit 68da311

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

v_exchanges/src/binance/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
pub mod futures;
2+
use adapters::binance::BinanceOption;
23
use color_eyre::eyre::Result;
34
use derive_more::{Deref, DerefMut};
45
use v_exchanges_adapters::{Client, binance};
5-
use v_utils::{
6-
macros::WrapNew,
7-
trades::{Asset, Pair, Timeframe},
8-
};
6+
use v_utils::trades::{Asset, Pair, Timeframe};
97

108
use crate::core::{AssetBalance, Exchange, Klines, KlinesRequestRange};
119

@@ -14,6 +12,11 @@ pub struct Binance(pub Client);
1412

1513
//? currently client ends up importing this from crate::binance, but could it be possible to lift the [Client] reexport up, and still have the ability to call all exchange methods right on it?
1614
impl Exchange for Binance {
15+
fn auth<S: Into<String>>(&mut self, key: S, secret: S) {
16+
self.update_default_option(BinanceOption::Key(key.into()));
17+
self.update_default_option(BinanceOption::Secret(secret.into()));
18+
}
19+
1720
async fn futures_klines(&self, symbol: Pair, tf: Timeframe, range: KlinesRequestRange) -> Result<Klines> {
1821
futures::market::klines(&self.0, symbol, tf, range).await
1922
}

v_exchanges/src/bybit/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod account;
22
mod market;
33

4+
use adapters::bybit::BybitOption;
45
use color_eyre::eyre::Result;
56
use derive_more::derive::{Deref, DerefMut};
67
use v_exchanges_adapters::{Client, bybit};
@@ -13,6 +14,11 @@ pub struct Bybit(pub Client);
1314

1415
//? currently client ends up importing this from crate::binance, but could it be possible to lift the [Client] reexport up, and still have the ability to call all exchange methods right on it?
1516
impl Exchange for Bybit {
17+
fn auth<S: Into<String>>(&mut self, key: S, secret: S) {
18+
self.update_default_option(BybitOption::Key(key.into()));
19+
self.update_default_option(BybitOption::Secret(secret.into()));
20+
}
21+
1622
async fn futures_klines(&self, symbol: Pair, tf: Timeframe, range: KlinesRequestRange) -> Result<Klines> {
1723
market::klines(&self.0, symbol, tf, range).await
1824
}

v_exchanges/src/core.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use chrono::{DateTime, TimeDelta, Utc};
22
use color_eyre::eyre::Result;
3-
use v_utils::trades::{Asset, Kline, Pair, Timeframe};
43
use derive_more::{Deref, DerefMut};
4+
use v_utils::trades::{Asset, Kline, Pair, Timeframe};
55

66
//TODO!!!!!!!!!!!!!: klines switch to defining the range via an Enum over either limit either start and end times
77

88
pub trait Exchange {
9+
fn auth<S: Into<String>>(&mut self, key: S, secret: S);
10+
911
//? should I have Self::Pair too? Like to catch the non-existent ones immediately? Although this would increase the error surface on new listings.
1012
fn futures_klines(&self, symbol: Pair, tf: Timeframe, range: KlinesRequestRange) -> impl std::future::Future<Output = Result<Klines>> + Send;
1113
fn futures_price(&self, symbol: Pair) -> impl std::future::Future<Output = Result<f64>> + Send;
@@ -79,10 +81,7 @@ impl From<DateTime<Utc>> for KlinesRequestRange {
7981
impl From<TimeDelta> for KlinesRequestRange {
8082
fn from(value: TimeDelta) -> Self {
8183
let now = Utc::now();
82-
KlinesRequestRange::StartEnd {
83-
start: now - value,
84-
end: None,
85-
}
84+
KlinesRequestRange::StartEnd { start: now - value, end: None }
8685
}
8786
}
8887
impl From<u32> for KlinesRequestRange {

0 commit comments

Comments
 (0)