Skip to content

Commit ba5ad50

Browse files
committed
feat: binance: spot prices (kinda)
1 parent d1298b3 commit ba5ad50

File tree

19 files changed

+144
-90
lines changed

19 files changed

+144
-90
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.

Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ tabs_in_doc_comments = "allow"
1313

1414
[workspace.dependencies]
1515
v_utils = { version = "^2.0", path = "../v_utils/v_utils", features = ["trades", "tracing", "macros"] } #ga: rm path
16-
17-
chrono = "^0.4.39"
18-
color-eyre = "^0.6.3"
1916
futures-util = "^0.3.31"
2017
reqwest = { version = "^0.12.12", features = ["blocking", "json"] }
2118
serde = { version = "^1.0.217", features = ["derive"] }
@@ -25,9 +22,7 @@ serde_with = "^3.12.0"
2522
thiserror = "^2.0.9"
2623
derive_more = { version = "^1.0.0", features = ["deref", "deref_mut"] }
2724
tokio = { version = "^1.42.0", features = ["full"] }
28-
tokio-tungstenite = { version = "^0.26.1", features = ["native-tls"] }
2925
tracing = "^0.1.41"
30-
url = "^2.5.4"
3126
hmac = "^0.12.1"
3227
sha2 = "^0.10.8"
3328
hex = "^0.4.3"
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ async fn main() {
1616
let price = bn.futures_price(("BTC", "USDT").into()).await.unwrap();
1717
dbg!(&klines, price);
1818

19-
let spot_klines = bn.spot_klines(("BTC", "USDT").into(), "1m".into(), 2.into()).await.unwrap();
20-
dbg!(&spot_klines);
21-
2219
if let (Ok(key), Ok(secret)) = (env::var("BINANCE_TIGER_READ_KEY"), env::var("BINANCE_TIGER_READ_SECRET")) {
2320
bn.auth(key, secret);
2421
let balance = bn.futures_asset_balance("USDT".into()).await.unwrap();

examples/binance/market_spot.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use v_exchanges::{binance::Binance, core::Exchange};
2+
use v_exchanges_adapters::binance::{BinanceHttpUrl, BinanceOption};
3+
4+
#[tokio::main]
5+
async fn main() {
6+
color_eyre::install().unwrap();
7+
v_utils::utils::init_subscriber(v_utils::utils::LogDestination::xdg("v_exchanges"));
8+
9+
let mut bn = Binance::default();
10+
bn.update_default_option(BinanceOption::HttpUrl(BinanceHttpUrl::Spot));
11+
12+
let spot_klines = bn.spot_klines(("BTC", "USDT").into(), "1m".into(), 2.into()).await.unwrap();
13+
dbg!(&spot_klines);
14+
15+
let spot_prices = bn.spot_prices(None).await.unwrap();
16+
dbg!(&spot_prices[..5]);
17+
}

v_exchanges/Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ rustdoc-args = ["--cfg", "docsrs"]
2424
ignored = ["derive-new", "color-eyre", "serde", "tokio", "v_utils"]
2525

2626
[dependencies]
27-
color-eyre.workspace = true
2827
serde.workspace = true
2928
serde_json.workspace = true
3029
serde_plain.workspace = true
@@ -41,9 +40,11 @@ chrono = "0.4.39"
4140
env_logger = "0.11.5"
4241

4342
insta.workspace = true #dbg (for some reason is not loading in dev-dependencies rn
43+
eyre = "0.6.12"
4444

4545
[dev-dependencies]
4646
insta.workspace = true
47+
color-eyre = "^0.6.3"
4748
#
4849

4950
[features]
@@ -56,8 +57,12 @@ bitflyer = ["v_exchanges_adapters/bitflyer"]
5657
coincheck = ["v_exchanges_adapters/coincheck"]
5758

5859
[[example]]
59-
name = "binance_market"
60-
path = "../examples/binance/market.rs"
60+
name = "binance_market_futures"
61+
path = "../examples/binance/market_futures.rs"
62+
63+
[[example]]
64+
name = "binance_market_spot"
65+
path = "../examples/binance/market_spot.rs"
6166

6267
[[example]]
6368
name = "bybit_market"

v_exchanges/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

v_exchanges/src/binance/futures/account.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use color_eyre::eyre::Result;
1+
use eyre::Result;
22
use serde::Deserialize;
33
use serde_with::{DisplayFromStr, serde_as};
44
use v_exchanges_adapters::binance::{BinanceAuth, BinanceHttpUrl, BinanceOption};

v_exchanges/src/binance/futures/market.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
1-
use std::collections::VecDeque;
2-
3-
use chrono::{DateTime, TimeZone, Utc};
41
//HACK: Methods should be implemented on the central interface struct, following <https://github.com/wisespace-io/binance-rs>.
5-
use color_eyre::eyre::Result;
2+
use eyre::Result;
63
use serde::{Deserialize, Serialize};
7-
use serde_json::{Value, json};
4+
use serde_json::json;
85
use serde_with::{DisplayFromStr, serde_as};
9-
use v_exchanges_adapters::{
10-
binance::{BinanceHttpUrl, BinanceOption},
11-
errors::LimitOutOfRangeError,
12-
};
13-
use v_utils::{
14-
trades::{Kline, Ohlc, Pair, Timeframe},
15-
utils::filter_nulls,
16-
};
17-
18-
use crate::core::{Klines, KlinesRequestRange};
6+
use v_exchanges_adapters::binance::{BinanceHttpUrl, BinanceOption};
7+
use v_utils::trades::Pair;
198

209
// price {{{
2110
//HACK: not sure this is _the_ thing to use for that (throwing away A LOT of data)

v_exchanges/src/binance/futures/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
pub mod core;
2-
pub use core::*;
32

43
pub mod account;
54
pub mod general;

v_exchanges/src/binance/market.rs

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::VecDeque;
22

33
use chrono::{DateTime, TimeZone, Utc};
44
//HACK: Methods should be implemented on the central interface struct, following <https://github.com/wisespace-io/binance-rs>.
5-
use color_eyre::eyre::Result;
5+
use eyre::Result;
66
use serde::{Deserialize, Serialize};
77
use serde_json::{Value, json};
88
use serde_with::{DisplayFromStr, serde_as};
@@ -122,37 +122,6 @@ pub struct KlineResponse {
122122
}
123123
//,}}}
124124

125-
//// price {{{
126-
////HACK: not sure this is _the_ thing to use for that (throwing away A LOT of data)
127-
//pub async fn price(client: &v_exchanges_adapters::Client, pair: Pair) -> Result<f64> {
128-
// let params = json!({
129-
// "symbol": pair.to_string(),
130-
// });
131-
//
132-
// let r: MarkPriceResponse = client.get("/fapi/v1/premiumIndex", &params, [BinanceOption::HttpUrl(BinanceHttpUrl::FuturesUsdM)]).await.unwrap();
133-
// let price = r.index_price; // when using this framework, we care for per-exchange price, obviously
134-
// Ok(price)
135-
//}
136-
//
137-
//#[serde_as]
138-
//#[derive(Debug, Serialize, Deserialize, Clone)]
139-
//#[serde(rename_all = "camelCase")]
140-
//pub struct MarkPriceResponse {
141-
// pub symbol: String,
142-
// #[serde_as(as = "DisplayFromStr")]
143-
// pub mark_price: f64,
144-
// #[serde_as(as = "DisplayFromStr")]
145-
// pub index_price: f64,
146-
// #[serde_as(as = "DisplayFromStr")]
147-
// pub estimated_settle_price: f64,
148-
// #[serde_as(as = "DisplayFromStr")]
149-
// pub last_funding_rate: f64,
150-
// pub next_funding_time: u64,
151-
// pub time: u64,
152-
//}
153-
//
154-
////,}}}
155-
156125
#[cfg(test)]
157126
mod tests {
158127
#[test]

0 commit comments

Comments
 (0)