Skip to content

Commit d740eb6

Browse files
committed
_
1 parent 103bb7f commit d740eb6

File tree

17 files changed

+545
-60
lines changed

17 files changed

+545
-60
lines changed

.github/workflows/warnings.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ jobs:
22
clippy:
33
if: github.event_name != 'pull_request'
44
name: Clippy
5+
needs: pre_ci
56
runs-on: ubuntu-latest
67
steps:
78
- uses: actions/checkout@v4

Cargo.lock

Lines changed: 15 additions & 15 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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ futures-util = "^0.3.31"
1717
reqwest = { version = "^0.12.12", features = ["blocking", "json"] }
1818
serde = { version = "^1.0.217", features = ["derive"] }
1919
serde_plain = "^1.0.2" #TEST
20-
serde_json = "^1.0.134"
20+
serde_json = "^1.0.135"
2121
serde_with = "^3.12.0"
22-
thiserror = "^2.0.9"
22+
thiserror = "^2.0.11"
2323
derive_more = { version = "^1.0.0", features = ["deref", "deref_mut"] }
24-
tokio = { version = "^1.42.0", features = ["full"] }
24+
tokio = { version = "^1.43.0", features = ["full"] }
2525
tracing = "^0.1.41"
2626
hmac = "^0.12.1"
2727
sha2 = "^0.10.8"
2828
hex = "^0.4.3"
2929
derive-new = "^0.7.0"
3030

3131
#[dev-dependencies]
32-
insta = "1.41.1"
32+
insta = "1.42.0"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
![Minimum Supported Rust Version](https://img.shields.io/badge/nightly-1.85+-ab6000.svg)
33
[<img alt="crates.io" src="https://img.shields.io/crates/v/v_exchanges.svg?color=fc8d62&logo=rust" height="20" style=flat-square>](https://crates.io/crates/v_exchanges)
44
[<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs&style=flat-square" height="20">](https://docs.rs/v_exchanges)
5-
![Lines Of Code](https://img.shields.io/badge/LoC-3923-lightblue)
5+
![Lines Of Code](https://img.shields.io/badge/LoC-4308-lightblue)
66
<br>
77
[<img alt="ci errors" src="https://img.shields.io/github/actions/workflow/status/valeratrades/v_exchanges/errors.yml?branch=master&style=for-the-badge&style=flat-square&label=errors&labelColor=420d09" height="20">](https://github.com/valeratrades/v_exchanges/actions?query=branch%3Amaster) <!--NB: Won't find it if repo is private-->
88
[<img alt="ci warnings" src="https://img.shields.io/github/actions/workflow/status/valeratrades/v_exchanges/warnings.yml?branch=master&style=for-the-badge&style=flat-square&label=warnings&labelColor=d16002" height="20">](https://github.com/valeratrades/v_exchanges/actions?query=branch%3Amaster) <!--NB: Won't find it if repo is private-->

examples/mexc.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use v_exchanges::prelude::*;
2+
3+
#[tokio::main]
4+
async fn main() {
5+
v_utils::clientside!();
6+
7+
let m: AbsMarket = "Mexc/Futures".into();
8+
let c = m.client_authenticated("temp".into(), "temp".into());
9+
10+
let balance_usdt = c.asset_balance("USDT".into(), m).await.unwrap();
11+
dbg!(&balance_usdt);
12+
}
13+
14+
#[cfg(test)]
15+
#[test]
16+
fn test_main() {
17+
main();
18+
}

flake.lock

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

v_exchanges/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ path = "../examples/binance/market_spot.rs"
7373
name = "bybit_market"
7474
path = "../examples/bybit/market.rs"
7575

76+
[[example]]
77+
name = "mexc"
78+
path = "../examples/mexc.rs"
79+
7680
[[example]]
7781
name = "data"
7882
path = "../examples/data.rs"

v_exchanges/src/binance/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ impl Exchange for Binance {
2525
self.source_market
2626
}
2727

28-
fn exchange_name(&self) -> &'static str {
29-
self.source_market().exchange_name()
30-
}
31-
3228
fn auth(&mut self, key: String, secret: String) {
3329
self.update_default_option(BinanceOption::Key(key));
3430
self.update_default_option(BinanceOption::Secret(secret));
@@ -104,8 +100,4 @@ impl crate::core::MarketTrait for Market {
104100
fn client(&self) -> Box<dyn Exchange> {
105101
Box::new(Binance::default())
106102
}
107-
108-
fn fmt_abs(&self) -> String {
109-
format!("Binance/{self}")
110-
}
111103
}

v_exchanges/src/bybit/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ impl Exchange for Bybit {
2727
self.source_market
2828
}
2929

30-
fn exchange_name(&self) -> &'static str {
31-
self.source_market().exchange_name()
32-
}
33-
3430
fn auth(&mut self, key: String, secret: String) {
3531
self.update_default_option(BybitOption::Key(key));
3632
self.update_default_option(BybitOption::Secret(secret));
@@ -102,8 +98,4 @@ impl crate::core::MarketTrait for Market {
10298
fn client(&self) -> Box<dyn Exchange> {
10399
Box::new(Bybit::default())
104100
}
105-
106-
fn fmt_abs(&self) -> String {
107-
format!("Bybit/{self}")
108-
}
109101
}

v_exchanges/src/core.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ use v_utils::{
1313
#[async_trait::async_trait]
1414
pub trait Exchange: std::fmt::Debug + Send {
1515
fn source_market(&self) -> AbsMarket;
16-
fn exchange_name(&self) -> &'static str;
16+
fn exchange_name(&self) -> &'static str {
17+
self.source_market().exchange_name()
18+
}
19+
1720
fn auth(&mut self, key: String, secret: String);
1821

1922
async fn exchange_info(&self, m: AbsMarket) -> Result<ExchangeInfo>;
@@ -57,28 +60,41 @@ impl std::fmt::Display for WrongExchangeError {
5760

5861
pub trait MarketTrait {
5962
fn client(&self) -> Box<dyn Exchange>;
60-
fn fmt_abs(&self) -> String;
61-
//TODO; require them to impl Display and FromStr
63+
fn client_authenticated(&self, key: String, secret: String) -> Box<dyn Exchange> {
64+
let mut client = self.client();
65+
client.auth(key, secret);
66+
client
67+
}
6268
}
6369

6470
#[derive(Debug, Clone, Copy)]
6571
pub enum AbsMarket {
6672
Binance(crate::binance::Market),
6773
Bybit(crate::bybit::Market),
68-
//TODO
74+
Mexc(crate::mexc::Market),
6975
}
7076
impl AbsMarket {
7177
pub fn client(&self) -> Box<dyn Exchange> {
7278
match self {
7379
Self::Binance(m) => m.client(),
7480
Self::Bybit(m) => m.client(),
81+
Self::Mexc(m) => m.client(),
82+
}
83+
}
84+
85+
pub fn client_authenticated(&self, key: String, secret: String) -> Box<dyn Exchange> {
86+
match self {
87+
Self::Binance(m) => m.client_authenticated(key, secret),
88+
Self::Bybit(m) => m.client_authenticated(key, secret),
89+
Self::Mexc(m) => m.client_authenticated(key, secret),
7590
}
7691
}
7792

7893
pub fn exchange_name(&self) -> &'static str {
7994
match self {
8095
Self::Binance(_) => "Binance",
8196
Self::Bybit(_) => "Bybit",
97+
Self::Mexc(_) => "Mexc",
8298
}
8399
}
84100
}
@@ -90,8 +106,9 @@ impl Default for AbsMarket {
90106
impl std::fmt::Display for AbsMarket {
91107
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
92108
match self {
93-
Self::Binance(m) => write!(f, "Binance/{}", m),
94-
Self::Bybit(m) => write!(f, "Bybit/{}", m),
109+
Self::Binance(m) => write!(f, "{}/{}", self.exchange_name(), m),
110+
Self::Bybit(m) => write!(f, "{}/{}", self.exchange_name(), m),
111+
Self::Mexc(m) => write!(f, "{}/{}", self.exchange_name(), m),
95112
}
96113
}
97114
}

0 commit comments

Comments
 (0)