Skip to content

Commit 9037e74

Browse files
committed
_
1 parent 352d8d0 commit 9037e74

File tree

7 files changed

+96
-68
lines changed

7 files changed

+96
-68
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
![Minimum Supported Rust Version](https://img.shields.io/badge/nightly-1.85+-ab6000.svg)
33
[<img alt="crates.io" src="https://img.shields.io/crates/v/v_exchanges.svg?color=fc8d62&logo=rust" height="20" style=flat-square>](https://crates.io/crates/v_exchanges)
44
[<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs&style=flat-square" height="20">](https://docs.rs/v_exchanges)
5-
![Lines Of Code](https://img.shields.io/badge/LoC-3894-lightblue)
5+
![Lines Of Code](https://img.shields.io/badge/LoC-3919-lightblue)
66
<br>
77
[<img alt="ci errors" src="https://img.shields.io/github/actions/workflow/status/valeratrades/v_exchanges/errors.yml?branch=master&style=for-the-badge&style=flat-square&label=errors&labelColor=420d09" height="20">](https://github.com/valeratrades/v_exchanges/actions?query=branch%3Amaster) <!--NB: Won't find it if repo is private-->
88
[<img alt="ci warnings" src="https://img.shields.io/github/actions/workflow/status/valeratrades/v_exchanges/warnings.yml?branch=master&style=for-the-badge&style=flat-square&label=warnings&labelColor=d16002" height="20">](https://github.com/valeratrades/v_exchanges/actions?query=branch%3Amaster) <!--NB: Won't find it if repo is private-->

examples/binance/market_futures.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,11 @@ async fn main() {
2727
eprintln!("BINANCE_TIGER_READ_KEY or BINANCE_TIGER_READ_SECRET is missing, skipping private API methods.");
2828
}
2929
}
30+
31+
#[cfg(test)]
32+
mod tests {
33+
#[test]
34+
fn test_main() {
35+
super::main();
36+
}
37+
}

examples/binance/market_spot.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,11 @@ async fn main() {
1414
let spot_prices = c.prices(None, m).await.unwrap();
1515
dbg!(&spot_prices[..5]);
1616
}
17+
18+
#[cfg(test)]
19+
mod tests {
20+
#[test]
21+
fn test_main() {
22+
super::main();
23+
}
24+
}

examples/bybit/market.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,11 @@ async fn private(c: &mut Box<dyn Exchange>, m: AbsMarket) {
3131
let balances = c.balances(m).await.unwrap();
3232
dbg!(&balances);
3333
}
34+
35+
#[cfg(test)]
36+
mod tests {
37+
#[test]
38+
fn test_main() {
39+
super::main();
40+
}
41+
}

v_exchanges/src/bybit/mod.rs

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -14,82 +14,82 @@ use crate::core::{AbsMarket, AssetBalance, Exchange, ExchangeInfo, Klines, Reque
1414

1515
#[derive(Clone, Debug, Default, Deref, DerefMut)]
1616
pub struct Bybit {
17-
#[deref_mut]
18-
#[deref]
19-
client: Client,
20-
source_market: AbsMarket,
17+
#[deref_mut]
18+
#[deref]
19+
client: Client,
20+
source_market: AbsMarket,
2121
}
2222

2323
//? 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?
2424
#[async_trait::async_trait]
2525
impl Exchange for Bybit {
26-
fn source_market(&self) -> AbsMarket {
27-
todo!()
28-
}
29-
fn exchange_name(&self) -> &'static str {
30-
self.source_market().exchange_name()
31-
}
26+
fn source_market(&self) -> AbsMarket {
27+
todo!()
28+
}
3229

33-
fn auth(&mut self, key: String, secret: String) {
34-
self.update_default_option(BybitOption::Key(key));
35-
self.update_default_option(BybitOption::Secret(secret));
36-
}
30+
fn exchange_name(&self) -> &'static str {
31+
self.source_market().exchange_name()
32+
}
3733

38-
async fn exchange_info(&self, am: AbsMarket) -> Result<ExchangeInfo> {
39-
match am {
40-
AbsMarket::Bybit(_) => todo!(),
41-
_ => Err(WrongExchangeError::new(self.exchange_name(), am).into()),
42-
}
43-
}
34+
fn auth(&mut self, key: String, secret: String) {
35+
self.update_default_option(BybitOption::Key(key));
36+
self.update_default_option(BybitOption::Secret(secret));
37+
}
4438

45-
async fn klines(&self, pair: Pair, tf: Timeframe, range: RequestRange, am: AbsMarket) -> Result<Klines> {
46-
match am {
47-
AbsMarket::Bybit(m) => match m {
48-
Market::Linear => market::klines(&self.client, pair, tf, range).await,
49-
_ => unimplemented!(),
50-
},
51-
_ => Err(WrongExchangeError::new(self.exchange_name(), am).into()),
52-
}
53-
}
39+
async fn exchange_info(&self, am: AbsMarket) -> Result<ExchangeInfo> {
40+
match am {
41+
AbsMarket::Bybit(_) => todo!(),
42+
_ => Err(WrongExchangeError::new(self.exchange_name(), am).into()),
43+
}
44+
}
5445

55-
async fn price(&self, pair: Pair, am: AbsMarket) -> Result<f64> {
56-
match am {
57-
AbsMarket::Bybit(m) => match m {
58-
Market::Linear => market::price(&self.client, pair).await,
59-
_ => unimplemented!(),
60-
},
61-
_ => Err(WrongExchangeError::new(self.exchange_name(), am).into()),
62-
}
63-
}
46+
async fn klines(&self, pair: Pair, tf: Timeframe, range: RequestRange, am: AbsMarket) -> Result<Klines> {
47+
match am {
48+
AbsMarket::Bybit(m) => match m {
49+
Market::Linear => market::klines(&self.client, pair, tf, range).await,
50+
_ => unimplemented!(),
51+
},
52+
_ => Err(WrongExchangeError::new(self.exchange_name(), am).into()),
53+
}
54+
}
6455

65-
async fn prices(&self, pairs: Option<Vec<Pair>>, am: AbsMarket) -> Result<Vec<(Pair, f64)>> {
66-
match am {
67-
AbsMarket::Bybit(_) => todo!(),
68-
_ => Err(WrongExchangeError::new(self.exchange_name(), am).into()),
69-
}
70-
}
56+
async fn price(&self, pair: Pair, am: AbsMarket) -> Result<f64> {
57+
match am {
58+
AbsMarket::Bybit(m) => match m {
59+
Market::Linear => market::price(&self.client, pair).await,
60+
_ => unimplemented!(),
61+
},
62+
_ => Err(WrongExchangeError::new(self.exchange_name(), am).into()),
63+
}
64+
}
7165

72-
async fn asset_balance(&self, asset: Asset, am: AbsMarket) -> Result<AssetBalance> {
73-
match am {
74-
AbsMarket::Bybit(m) => match m {
75-
Market::Linear => account::asset_balance(&self.client, asset).await,
76-
_ => unimplemented!(),
77-
},
78-
_ => Err(WrongExchangeError::new(self.exchange_name(), am).into()),
79-
}
80-
}
66+
async fn prices(&self, pairs: Option<Vec<Pair>>, am: AbsMarket) -> Result<Vec<(Pair, f64)>> {
67+
match am {
68+
AbsMarket::Bybit(_) => todo!(),
69+
_ => Err(WrongExchangeError::new(self.exchange_name(), am).into()),
70+
}
71+
}
8172

82-
async fn balances(&self, am: AbsMarket) -> Result<Vec<AssetBalance>> {
83-
match am {
84-
AbsMarket::Bybit(m) => match m {
85-
Market::Linear => account::balances(&self.client).await,
86-
_ => unimplemented!()
87-
},
88-
_ => Err(WrongExchangeError::new(self.exchange_name(), am).into()),
89-
}
90-
}
91-
}
73+
async fn asset_balance(&self, asset: Asset, am: AbsMarket) -> Result<AssetBalance> {
74+
match am {
75+
AbsMarket::Bybit(m) => match m {
76+
Market::Linear => account::asset_balance(&self.client, asset).await,
77+
_ => unimplemented!(),
78+
},
79+
_ => Err(WrongExchangeError::new(self.exchange_name(), am).into()),
80+
}
81+
}
9282

83+
async fn balances(&self, am: AbsMarket) -> Result<Vec<AssetBalance>> {
84+
match am {
85+
AbsMarket::Bybit(m) => match m {
86+
Market::Linear => account::balances(&self.client).await,
87+
_ => unimplemented!(),
88+
},
89+
_ => Err(WrongExchangeError::new(self.exchange_name(), am).into()),
90+
}
91+
}
92+
}
9393

9494
#[derive(Debug, Clone, Default, Copy, Display, FromStr)]
9595
pub enum Market {

v_exchanges/src/core.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ pub trait Exchange: std::fmt::Debug {
3939
//? could implement many things that are _explicitly_ combinatorial. I can imagine several cases, where knowing that say the specified limit for the klines is wayyy over the max and that you may be opting into a long wait by calling it, could be useful.
4040
}
4141

42-
4342
// AbsMarket {{{
4443
#[derive(derive_more::Debug, derive_new::new, thiserror::Error)]
4544
pub struct WrongExchangeError {
@@ -48,7 +47,11 @@ pub struct WrongExchangeError {
4847
}
4948
impl std::fmt::Display for WrongExchangeError {
5049
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51-
write!(f, "Wrong exchange provided. Accessible object: {:?}, provided \"abs market path\": {}", self.correct, self.provided)
50+
write!(
51+
f,
52+
"Wrong exchange provided. Accessible object: {:?}, provided \"abs market path\": {}",
53+
self.correct, self.provided
54+
)
5255
}
5356
}
5457

@@ -71,6 +74,7 @@ impl AbsMarket {
7174
Self::Bybit(m) => m.client(),
7275
}
7376
}
77+
7478
pub fn exchange_name(&self) -> &'static str {
7579
match self {
7680
Self::Binance(_) => "Binance",
@@ -110,7 +114,7 @@ impl std::str::FromStr for AbsMarket {
110114
Err(e) => match sub_market.to_lowercase() == "futures" {
111115
true => crate::bybit::Market::Linear,
112116
false => bail!(e),
113-
}
117+
},
114118
}
115119
})),
116120
_ => bail!("Invalid market string: {}", s),

0 commit comments

Comments
 (0)