Skip to content

Commit 4875267

Browse files
committed
_
1 parent e39a803 commit 4875267

File tree

6 files changed

+19
-4
lines changed

6 files changed

+19
-4
lines changed

examples/binance/market_spot.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ async fn main() {
99
v_utils::utils::init_subscriber(v_utils::utils::LogDestination::xdg("v_exchanges"));
1010

1111
//let m: Market = "Binance/Spot".into(); // would be nice to be able to do it like this, without having to carry around exchange-specific type
12+
// Currently if I want to pass around the market struct in my code after initializing it, I have to pass around eg `binance::Market`, which is a ridiculous thing to hardcode into function signatures
1213
let m = binance::Market::Spot;
1314
let bn = m.client();
1415

v_exchanges/src/binance/futures/general.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::collections::HashMap;
21

32
use adapters::binance::{BinanceHttpUrl, BinanceOption};
43
use chrono::DateTime;

v_exchanges/src/binance/market.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::VecDeque;
22

3-
use chrono::{DateTime, TimeZone, Utc};
3+
use chrono::{DateTime, TimeZone as _, Utc};
44
//HACK: Methods should be implemented on the central interface struct, following <https://github.com/wisespace-io/binance-rs>.
55
use eyre::Result;
66
use serde::{Deserialize, Serialize};
@@ -58,7 +58,7 @@ pub async fn klines(client: &v_exchanges_adapters::Client, pair: Pair, tf: Timef
5858
Market::Margin => unimplemented!(),
5959
};
6060

61-
let kline_responses: Vec<KlineResponse> = client.get(&format!("{endpoint_prefix}/klines"), &params, [BinanceOption::HttpUrl(base_url)]).await.unwrap();
61+
let kline_responses: Vec<KlineResponse> = client.get(&format!("{endpoint_prefix}/klines"), &params, [BinanceOption::HttpUrl(base_url)]).await?;
6262

6363
let r_len = kline_responses.len();
6464
let mut klines = VecDeque::with_capacity(r_len);

v_exchanges/src/binance/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,8 @@ impl crate::core::MarketTrait for Market {
7676
fn client(&self) -> Binance {
7777
Binance::default()
7878
}
79+
80+
fn fmt_abs(&self) -> String {
81+
format!("Binance/{self}")
82+
}
7983
}

v_exchanges/src/bybit/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl Exchange for Bybit {
2525
}
2626

2727
async fn exchange_info(&self, m: Self::M) -> Result<ExchangeInfo> {
28-
todo!();
28+
todo!();
2929
}
3030

3131
async fn klines(&self, pair: Pair, tf: Timeframe, range: KlinesRequestRange, m: Self::M) -> Result<Klines> {
@@ -74,4 +74,8 @@ impl crate::core::MarketTrait for Market {
7474
fn client(&self) -> Bybit {
7575
Bybit::default()
7676
}
77+
78+
fn fmt_abs(&self) -> String {
79+
format!("Bybit/{self}")
80+
}
7781
}

v_exchanges/src/core.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ pub trait Exchange {
3939
pub trait MarketTrait {
4040
type Client: Exchange;
4141
fn client(&self) -> Self::Client;
42+
fn fmt_abs(&self) -> String;
43+
//TODO; require them to impl Display and FromStr
4244
}
4345
//TODO!: figure out how can I expose one central `Market` enum, so client doesn't have to bring into the scope `MarketTrait` and deal with the exchange-specific `Market`'s type
4446
// Maybe [enum_dispatch](<https://docs.rs/enum_dispatch/latest/enum_dispatch/>) crate could help?
@@ -227,6 +229,11 @@ pub struct ExchangeInfo {
227229
pub server_time: DateTime<Utc>,
228230
pub pairs: HashMap<Pair, PairInfo>,
229231
}
232+
impl ExchangeInfo {
233+
pub fn usdt_pairs(&self) -> impl Iterator<Item = Pair> {
234+
self.pairs.keys().filter(|p| p.is_usdt()).copied()
235+
}
236+
}
230237
#[derive(Clone, Debug, Default)]
231238
pub struct PairInfo {
232239
pub price_precision: u8,

0 commit comments

Comments
 (0)