Skip to content

Commit 6a0ed29

Browse files
committed
refactor: _
1 parent 83d8e67 commit 6a0ed29

File tree

10 files changed

+44
-46
lines changed

10 files changed

+44
-46
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,22 @@ v_utils = { version = "^2.0", path = "../v_utils/v_utils", features = ["trades",
1616

1717
chrono = "^0.4.39"
1818
color-eyre = "^0.6.3"
19-
derive-new = "^0"
2019
futures-util = "^0.3.31"
2120
reqwest = { version = "^0.12.12", features = ["blocking", "json"] }
2221
serde = { version = "^1.0.217", features = ["derive"] }
2322
serde_plain = "^1.0.2" #TEST
2423
serde_json = "^1.0.134"
2524
serde_with = "^3.12.0"
2625
thiserror = "^2.0.9"
26+
derive_more = { version = "^1.0.0", features = ["deref", "deref_mut"] }
2727
tokio = { version = "^1.42.0", features = ["full"] }
2828
tokio-tungstenite = { version = "^0.26.1", features = ["native-tls"] }
2929
tracing = "^0.1.41"
3030
url = "^2.5.4"
3131
hmac = "^0.12.1"
3232
sha2 = "^0.10.8"
3333
hex = "^0.4.3"
34+
derive-new = "^0.7.0"
3435

3536
#[dev-dependencies]
3637
insta = "1.41.1"

v_exchanges/Cargo.toml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,14 @@ serde_with.workspace = true
3232
tokio.workspace = true
3333
tracing.workspace = true
3434
thiserror.workspace = true
35-
v_exchanges_adapters = { version = "^0.1.1", path = "../v_exchanges_adapters/", features = ["full"] }
35+
derive_more.workspace = true
36+
derive-new.workspace = true
3637
v_utils = { workspace = true }
38+
39+
v_exchanges_adapters = { version = "^0.1.1", path = "../v_exchanges_adapters/", features = ["full"] }
3740
chrono = "0.4.39"
38-
derive-new.workspace = true
3941
env_logger = "0.11.5"
4042

41-
# #dbg
42-
rust_decimal = { version = "1.36.0", features = ["serde-with-str", "serde-with-float"] }
43-
derive_more = { version = "1.0.0", features = ["deref", "deref_mut"] }
44-
4543
insta.workspace = true #dbg (for some reason is not loading in dev-dependencies rn
4644

4745
[dev-dependencies]

v_exchanges/src/binance/futures/market.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,17 @@ use color_eyre::eyre::{Report, eyre};
77
use serde::{Deserialize, Serialize};
88
use serde_json::{Value, json};
99
use serde_with::{DisplayFromStr, serde_as};
10-
use v_exchanges_adapters::binance::{BinanceHttpUrl, BinanceOption};
10+
use v_exchanges_adapters::{
11+
binance::{BinanceHttpUrl, BinanceOption},
12+
errors::LimitOutOfRangeError,
13+
};
1114
use v_utils::{
1215
trades::{Kline, Ohlc, Pair, Timeframe},
1316
utils::filter_nulls,
1417
};
1518

1619
use crate::core::{Klines, KlinesRequestRange};
1720

18-
//MOVE: centralized error module
19-
#[derive(Debug)]
20-
struct LimitOutOfRangeError {
21-
allowed: std::ops::RangeInclusive<u32>,
22-
provided: u32,
23-
}
24-
impl fmt::Display for LimitOutOfRangeError {
25-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26-
write!(f, "Limit out of range. Allowed: {:?}, provided: {}", self.allowed, self.provided)
27-
}
28-
}
29-
impl std::error::Error for LimitOutOfRangeError {}
30-
3121
// klines {{{
3222
pub async fn klines(client: &v_exchanges_adapters::Client, pair: Pair, tf: Timeframe, range: KlinesRequestRange) -> Result<Klines> {
3323
let range_json = match range {
@@ -38,11 +28,7 @@ pub async fn klines(client: &v_exchanges_adapters::Client, pair: Pair, tf: Timef
3828
KlinesRequestRange::Limit(limit) => {
3929
let allowed_range = 1..=1000;
4030
if !allowed_range.contains(&limit) {
41-
return Err(LimitOutOfRangeError {
42-
allowed: allowed_range,
43-
provided: limit,
44-
}
45-
.into());
31+
return Err(LimitOutOfRangeError::new(allowed_range, limit).into());
4632
}
4733
json!({
4834
"limit": limit,

v_exchanges/src/bybit/market.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,17 @@ use serde::{Deserialize, Serialize};
66
use serde_json::{Value, json};
77
use serde_with::{DisplayFromStr, serde_as};
88
use thiserror::Error;
9-
use v_exchanges_adapters::bybit::{BybitHttpUrl, BybitOption};
9+
use v_exchanges_adapters::{
10+
bybit::{BybitHttpUrl, BybitOption},
11+
errors::LimitOutOfRangeError,
12+
};
1013
use v_utils::{
1114
trades::{Kline, Ohlc, Pair, Timeframe},
1215
utils::filter_nulls,
1316
};
1417

1518
use crate::core::{Klines, KlinesRequestRange};
1619

17-
//MOVE: centralized error module
18-
#[derive(Debug)]
19-
struct LimitOutOfRangeError {
20-
allowed: std::ops::RangeInclusive<u32>,
21-
provided: u32,
22-
}
23-
impl fmt::Display for LimitOutOfRangeError {
24-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25-
write!(f, "Limit out of range. Allowed: {:?}, provided: {}", self.allowed, self.provided)
26-
}
27-
}
28-
impl std::error::Error for LimitOutOfRangeError {}
29-
3020
pub async fn klines(client: &v_exchanges_adapters::Client, pair: Pair, tf: Timeframe, range: KlinesRequestRange) -> Result<Klines> {
3121
let range_json = match range {
3222
KlinesRequestRange::StartEnd { start, end } => json!({
@@ -36,11 +26,7 @@ pub async fn klines(client: &v_exchanges_adapters::Client, pair: Pair, tf: Timef
3626
KlinesRequestRange::Limit(limit) => {
3727
let allowed_range = 1..=1000;
3828
if !allowed_range.contains(&limit) {
39-
return Err(LimitOutOfRangeError {
40-
allowed: allowed_range,
41-
provided: limit,
42-
}
43-
.into());
29+
return Err(LimitOutOfRangeError::new(allowed_range, limit).into());
4430
}
4531
json!({
4632
"limit": limit,

v_exchanges/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
pub mod core;
22

33
pub mod binance;
4+
pub use binance::Binance;
5+
46
pub mod bybit;
7+
pub use bybit::Bybit;

v_exchanges_adapters/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ serde.workspace = true
4040
serde_json.workspace = true
4141
serde_with.workspace = true
4242
sha2.workspace = true
43+
thiserror.workspace = true
44+
derive-new.workspace = true
45+
derive_more.workspace = true
4346
tracing.workspace = true
4447
v_exchanges_api_generics = { version = "^0.3.1", path = "../v_exchanges_api_generics" }
4548
rand = { version = "0.8.5", optional = true }
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use std::fmt;
2+
3+
use derive_more::Debug;
4+
use thiserror::Error;
5+
6+
#[derive(Debug, derive_new::new)]
7+
pub struct LimitOutOfRangeError {
8+
allowed: std::ops::RangeInclusive<u32>,
9+
provided: u32,
10+
}
11+
impl fmt::Display for LimitOutOfRangeError {
12+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13+
write!(f, "Limit out of range. Allowed: {:?}, provided: {}", self.allowed, self.provided)
14+
}
15+
}
16+
impl std::error::Error for LimitOutOfRangeError {}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod market;
2+
pub use market::*;

v_exchanges_adapters/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use v_exchanges_api_generics::{
99
websocket::*,
1010
};
1111

12+
pub mod errors;
1213
mod exchanges;
1314
pub mod traits;
1415

0 commit comments

Comments
 (0)