Skip to content

Commit e06af11

Browse files
committed
refactor: _
1 parent 2b04ce7 commit e06af11

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

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-3736-lightblue)
5+
![Lines Of Code](https://img.shields.io/badge/LoC-3745-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/data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ async fn main() {
99
dbg!(&bvol);
1010

1111
let bn = Binance::default();
12-
let lsr = bn.global_lsr_account(("BTC", "USDT").into(), "5m".into(), 24 * 12 + 1, "Global".into()).await.unwrap();
12+
let lsr = bn.lsr(("BTC", "USDT").into(), "5m".into(), 24 * 12 + 1, "Global".into()).await.unwrap();
1313
dbg!(&lsr[..2]);
1414
}

v_exchanges/src/binance/data.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl From<&str> for LsrWho {
2323
}
2424

2525
impl Binance {
26-
pub async fn global_lsr_account(&self, pair: Pair, tf: Timeframe, limit: u32, who: LsrWho) -> Result<Vec<Lsr>> {
26+
pub async fn lsr(&self, pair: Pair, tf: Timeframe, limit: u32, who: LsrWho) -> Result<Vec<Lsr>> {
2727
let allowed_range = 1..=500;
2828
//TODO!!: add a `limit outside of range` error, generic for all exchanges
2929
assert!(allowed_range.contains(&limit));
@@ -58,21 +58,30 @@ pub struct LsrResponse {
5858
pub struct Lsr {
5959
pub time: DateTime<Utc>,
6060
pub pair: Pair,
61-
pub long: Percent,
62-
pub short: Percent,
61+
pub p_long: Percent,
6362
}
63+
//Q: couldn't decide if `short()` and `long(0` should return `f64` or `Percent`. Postponing the decision.
6464
impl Lsr {
6565
pub fn ratio(&self) -> f64 {
66-
*self.long / *self.short
66+
*self.p_long / self.short()
67+
}
68+
69+
/// Percentage of short positions
70+
pub fn short(&self) -> f64 {
71+
1.0 - *self.p_long
72+
}
73+
74+
/// Percentage of long positions. // here only for consistency with `short`
75+
pub fn long(&self) -> f64 {
76+
*self.p_long
6777
}
6878
}
6979
impl From<LsrResponse> for Lsr {
7080
fn from(r: LsrResponse) -> Self {
7181
Self {
7282
time: DateTime::from_timestamp_millis(r.timestamp).unwrap(),
7383
pair: Pair::from_str(&r.symbol).unwrap(),
74-
long: Percent::from_str(&r.long_account).unwrap(),
75-
short: Percent::from_str(&r.short_account).unwrap(),
84+
p_long: Percent::from_str(&r.long_account).unwrap(),
7685
}
7786
}
7887
}

v_exchanges/src/core.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ pub trait MarketTrait {
4545
//TODO!: figure out how can I expose one central `Market` enum, so client doesn't have to bring into the scope `MarketTrait` and deal with the exchange-specific `Market`'s type
4646
// Maybe [enum_dispatch](<https://docs.rs/enum_dispatch/latest/enum_dispatch/>) crate could help?
4747

48-
//#[derive(Debug, Clone, Copy)]
49-
//pub enum Market {
50-
// Binance(crate::binance::Market),
51-
// Bybit(crate::bybit::Market),
52-
// //TODO
53-
//}
48+
#[derive(Debug, Clone, Copy)]
49+
pub enum Market {
50+
Binance(crate::binance::Market),
51+
Bybit(crate::bybit::Market),
52+
//TODO
53+
}
5454
//
5555
//impl Default for Market {
5656
// fn default() -> Self {

0 commit comments

Comments
 (0)