Skip to content

Commit 945da81

Browse files
committed
chore: _
1 parent 98c861d commit 945da81

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

v_exchanges/src/binance/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod futures;
33
mod market;
44
mod spot;
55
use adapters::binance::BinanceOption;
6-
use derive_more::{Deref, DerefMut};
6+
use derive_more::{Deref, DerefMut, Display, FromStr};
77
use eyre::Result;
88
use v_exchanges_adapters::Client;
99
use v_utils::trades::{Asset, Pair, Timeframe};
@@ -49,7 +49,7 @@ impl Exchange for Binance {
4949
}
5050
}
5151

52-
#[derive(Clone, Debug, Default, derive_new::new, Copy)]
52+
#[derive(Debug, Clone, Default, Copy, Display, FromStr)]
5353
pub enum Market {
5454
#[default]
5555
Futures,

v_exchanges/src/bybit/mod.rs

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

4+
use derive_more::{Display, FromStr};
45
use adapters::bybit::BybitOption;
56
use derive_more::derive::{Deref, DerefMut};
67
use eyre::Result;
@@ -49,3 +50,12 @@ impl Exchange for Bybit {
4950

5051
//DO: async fn balance(&self,
5152
}
53+
54+
55+
#[derive(Debug, Clone, Default, Copy, Display, FromStr)]
56+
pub enum Market {
57+
#[default]
58+
Linear,
59+
Spot,
60+
Inverse,
61+
}

v_exchanges/src/core.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ pub enum KlinesRequestRange {
7878
/// Preferred way of defining the range
7979
StartEnd { start: DateTime<Utc>, end: Option<DateTime<Utc>> },
8080
/// For quick and dirty
81+
//TODO!: have it contain an enum, with either exact value, either just `Max`, then each exchange matches on it
8182
Limit(u32),
8283
}
8384
impl Default for KlinesRequestRange {

v_exchanges/src/lib.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,43 @@ pub use bybit::Bybit;
1010

1111
pub mod bitmex;
1212
pub use bitmex::Bitmex;
13+
use eyre::Result;
14+
15+
#[derive(Debug, Clone, Copy)]
16+
pub enum Market {
17+
Binance(binance::Market),
18+
Bybit(bybit::Market),
19+
//TODO
20+
}
21+
impl Default for Market {
22+
fn default() -> Self {
23+
Self::Binance(binance::Market::default())
24+
}
25+
}
26+
27+
impl std::fmt::Display for Market {
28+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29+
match self {
30+
Market::Binance(m) => write!(f, "Binance/{}", m),
31+
Market::Bybit(m) => write!(f, "Bybit/{}", m),
32+
}
33+
}
34+
}
35+
36+
impl std::str::FromStr for Market {
37+
type Err = eyre::Error;
38+
39+
fn from_str(s: &str) -> Result<Self> {
40+
let parts: Vec<&str> = s.split('/').collect();
41+
if parts.len() != 2 {
42+
return Err(eyre::eyre!("Invalid market string: {}", s));
43+
}
44+
let market = parts[0];
45+
let exchange = parts[1];
46+
match market.to_lowercase().as_str() {
47+
"binance" => Ok(Self::Binance(exchange.parse()?)),
48+
"bybit" => Ok(Self::Bybit(exchange.parse()?)),
49+
_ => Err(eyre::eyre!("Invalid market string: {}", s)),
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)