Skip to content

Commit cbc3f1b

Browse files
committed
feat: bitmex's BVOL
1 parent bf1faa4 commit cbc3f1b

File tree

6 files changed

+72
-3
lines changed

6 files changed

+72
-3
lines changed

Cargo.lock

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

examples/data.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use v_exchanges::bitmex::Bitmex;
2+
3+
#[tokio::main]
4+
async fn main() {
5+
color_eyre::install().unwrap();
6+
v_utils::utils::init_subscriber(v_utils::utils::LogDestination::xdg("v_exchanges"));
7+
let bm = Bitmex::default();
8+
let bvol = bm.bvol(2).await.unwrap();
9+
dbg!(&bvol);
10+
}

v_exchanges/Cargo.toml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ derive-new.workspace = true
3636
v_utils = { workspace = true }
3737

3838
v_exchanges_adapters = { version = "^0.2.1", path = "../v_exchanges_adapters/", features = ["full"] }
39-
chrono = "0.4.39"
39+
chrono = { version = "0.4.39", features = ["serde"] }
4040
env_logger = "0.11.5"
4141

42+
reqwest = { version = "^0.12.12", optional = true}
43+
4244
insta.workspace = true #dbg (for some reason is not loading in dev-dependencies rn
4345
eyre = "0.6.12"
4446

@@ -48,13 +50,14 @@ color-eyre = "^0.6.3"
4850
#
4951

5052
[features]
51-
default = ["binance"]
53+
default = ["full"]
5254

53-
full = ["binance", "bitflyer", "bybit", "coincheck"]
55+
full = ["binance", "bitflyer", "bybit", "coincheck", "data"]
5456
binance = ["v_exchanges_adapters/binance"]
5557
bybit = ["v_exchanges_adapters/bybit"]
5658
bitflyer = ["v_exchanges_adapters/bitflyer"]
5759
coincheck = ["v_exchanges_adapters/coincheck"]
60+
data = ["dep:reqwest"]
5861

5962
[[example]]
6063
name = "binance_market_futures"
@@ -67,3 +70,7 @@ path = "../examples/binance/market_spot.rs"
6770
[[example]]
6871
name = "bybit_market"
6972
path = "../examples/bybit/market.rs"
73+
74+
[[example]]
75+
name = "data"
76+
path = "../examples/data.rs"

v_exchanges/src/bitmex/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Does not implement `Exchange`, as mostly I couldn't care less for price movements on this exchange (for now at least), but it is here for the purposes of exposing some of its data endpoints outside of `Exchange` spec

v_exchanges/src/bitmex/mod.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use chrono::{DateTime, Utc};
2+
use eyre::Result;
3+
use reqwest::Client;
4+
use serde::Deserialize;
5+
6+
#[derive(Clone, Debug, Default)]
7+
pub struct Bitmex {}
8+
impl Bitmex {
9+
pub async fn bvol(&self, limit: u32) -> Result<Vec<BvolPoint>> {
10+
let client = Client::new();
11+
let r = client
12+
.get(format!("https://www.bitmex.com/api/v1/trade?symbol=.BVOL24H&count={limit}&reverse=true"))
13+
.send()
14+
.await?
15+
.json::<Vec<BvolResponse>>()
16+
.await?;
17+
let out = r.into_iter().map(|r| r.into()).collect();
18+
Ok(out)
19+
}
20+
}
21+
22+
#[derive(Clone, Debug, Default)]
23+
pub struct BvolPoint {
24+
pub timestamp: DateTime<Utc>,
25+
pub price: f64,
26+
}
27+
28+
#[derive(Clone, Debug, Default, derive_new::new, Deserialize)]
29+
#[serde(rename_all = "camelCase")]
30+
pub struct BvolResponse {
31+
pub timestamp: DateTime<Utc>,
32+
pub price: f64,
33+
pub symbol: String,
34+
pub side: String,
35+
pub size: u64,
36+
pub tick_direction: String,
37+
pub trd_type: String,
38+
}
39+
40+
impl From<BvolResponse> for BvolPoint {
41+
fn from(r: BvolResponse) -> Self {
42+
Self {
43+
timestamp: r.timestamp,
44+
price: r.price,
45+
}
46+
}
47+
}

v_exchanges/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ pub use binance::Binance;
77

88
pub mod bybit;
99
pub use bybit::Bybit;
10+
11+
pub mod bitmex;
12+
pub use bitmex::Bitmex;

0 commit comments

Comments
 (0)