Skip to content

Commit 099d935

Browse files
committed
fix: _
1 parent 001196a commit 099d935

File tree

5 files changed

+111
-4
lines changed

5 files changed

+111
-4
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ derive-new = "^0"
2323
futures-util = "^0.3.31"
2424
reqwest = { version = "^0.12.9", features = ["blocking", "json"] }
2525
serde = { version = "^1.0.216", features = ["derive"] }
26+
serde_plain = "^1.0.2" #TEST
2627
serde_json = "^1.0.133"
2728
serde_with = "^3.11.0"
2829
thiserror = "^2.0.7"
@@ -33,3 +34,6 @@ url = "^2.5.4"
3334
hmac = "^0.12.1"
3435
sha2 = "^0.10.8"
3536
hex = "^0.4.3"
37+
38+
#[dev-dependencies]
39+
insta = "1.41.1"

examples/binance/market.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::env;
22

33
use v_exchanges::{binance::Client, core::Exchange};
4-
use v_exchanges_adapters::binance::{BinanceHttpUrl, BinanceOption};
4+
use v_exchanges_adapters::binance::{self, BinanceHttpUrl, BinanceOption};
55

66
#[tokio::main]
77
async fn main() {
@@ -11,14 +11,19 @@ async fn main() {
1111
let mut client = Client::new();
1212

1313
client.update_default_option(BinanceOption::HttpUrl(BinanceHttpUrl::FuturesUsdM));
14-
let klines = client.futures_klines(("BTC", "USDT").into(), "1m".into(), 2, None, None).await.unwrap();
15-
let price = client.futures_price(("BTC", "USDT").into()).await.unwrap();
14+
15+
//before implementing the trait for bybit too, was able to just do eg: `let klines = client.futures_klines(("BTC", "USDT").into(), "1m".into(), 2, None, None).await.unwrap();`
16+
17+
let klines = <Client as Exchange<binance::BinanceOptions>>::futures_klines(&client, ("BTC", "USDT").into(), "1m".into(), 2, None, None)
18+
.await
19+
.unwrap();
20+
let price = <Client as Exchange<binance::BinanceOptions>>::futures_price(&client, ("BTC", "USDT").into()).await.unwrap();
1621
dbg!(&klines, price);
1722

1823
if let (Ok(key), Ok(secret)) = (env::var("BINANCE_TIGER_READ_KEY"), env::var("BINANCE_TIGER_READ_SECRET")) {
1924
client.update_default_option(BinanceOption::Key(key));
2025
client.update_default_option(BinanceOption::Secret(secret));
21-
let balance = client.futures_asset_balance("USDT".into()).await.unwrap();
26+
let balance = <Client as Exchange<binance::BinanceOptions>>::futures_asset_balance(&client, "USDT".into()).await.unwrap();
2227
dbg!(&balance);
2328
} else {
2429
eprintln!("BINANCE_TIGER_READ_KEY or BINANCE_TIGER_READ_SECRET is missing, skipping private API methods.");

v_exchanges/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ tokio.workspace = true
3030
tracing.workspace = true
3131
serde.workspace = true
3232
serde_json.workspace = true
33+
serde_plain.workspace = true
3334
serde_with.workspace = true
3435
v_utils.workspace = true
3536
color-eyre.workspace = true
@@ -40,6 +41,11 @@ env_logger = "0.11.5"
4041
derive-new.workspace = true
4142
chrono = "0.4.39"
4243

44+
insta.workspace = true #dbg (for some reason is not loading in dev-dependencies rn
45+
46+
[dev-dependencies]
47+
insta.workspace = true
48+
4349
#
4450

4551
[features]

v_exchanges/src/bybit/account.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,47 @@
1+
use std::str::FromStr;
2+
13
use color_eyre::eyre::Result;
4+
use serde::{Deserialize, Serialize};
25

36
use crate::core::AssetBalance;
47

58
pub async fn balances(client: &v_exchanges_adapters::Client) -> Result<Vec<AssetBalance>> {
69
println!("bybit::account::balances");
710
todo!();
811
}
12+
13+
#[derive(Serialize, Deserialize)]
14+
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
15+
pub enum AccountType {
16+
Spot,
17+
Contract,
18+
Unified,
19+
Funding,
20+
Option,
21+
}
22+
impl std::fmt::Display for AccountType {
23+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24+
let s = serde_plain::to_string(self).map_err(|_| std::fmt::Error)?;
25+
write!(f, "{s}")
26+
}
27+
}
28+
impl FromStr for AccountType {
29+
type Err = ();
30+
31+
fn from_str(s: &str) -> Result<Self, Self::Err> {
32+
serde_plain::from_str(s).map_err(|_| ())
33+
}
34+
}
35+
36+
mod tests {
37+
use insta;
38+
39+
use super::*;
40+
41+
#[test]
42+
fn test_account_type_serde() {
43+
insta::assert_debug_snapshot!(format!("{}", AccountType::Unified), @r#""UNIFIED""#);
44+
let s = "UNIFIED";
45+
let _: AccountType = s.parse().unwrap();
46+
}
47+
}

0 commit comments

Comments
 (0)