Skip to content

Commit 3e37a82

Browse files
committed
refactor: _
1 parent ba77f54 commit 3e37a82

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
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-3916-lightblue)
5+
![Lines Of Code](https://img.shields.io/badge/LoC-3924-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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ async fn main() {
1010
dbg!(&bvol);
1111

1212
let bn = Binance::default();
13-
let lsr = bn.lsr(("BTC", "USDT").into(), "5m".into(), (24 * 12 + 1).into(), "Global".into()).await.unwrap();
14-
dbg!(&lsr[..2]);
13+
let lsrs = bn.lsr(("BTC", "USDT").into(), "5m".into(), (24 * 12 + 1).into(), "Global".into()).await.unwrap();
14+
dbg!(&lsrs[..2]);
1515
}
1616

1717
#[cfg(test)]

v_exchanges/src/binance/data.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl From<&str> for LsrWho {
2424
}
2525

2626
impl Binance {
27-
pub async fn lsr(&self, pair: Pair, tf: Timeframe, range: RequestRange, who: LsrWho) -> Result<Vec<Lsr>> {
27+
pub async fn lsr(&self, pair: Pair, tf: Timeframe, range: RequestRange, who: LsrWho) -> Result<Lsrs> {
2828
range.ensure_allowed(0..=500, tf)?;
2929
let range_json = range.serialize();
3030

@@ -42,7 +42,10 @@ impl Binance {
4242
.get(&format!("/futures/data/{ending}"), &params, [BinanceOption::HttpUrl(BinanceHttpUrl::FuturesUsdM)])
4343
.await?;
4444
let r: Vec<LsrResponse> = serde_json::from_value(r).unwrap();
45-
Ok(r.into_iter().map(|r| r.into()).collect())
45+
Ok(Lsrs {
46+
values: r.into_iter().map(|r| r.into()).collect(),
47+
pair,
48+
})
4649
}
4750
}
4851
#[derive(Clone, Debug, Default, Deserialize)]
@@ -57,9 +60,15 @@ pub struct LsrResponse {
5760
#[derive(Clone, Debug, Default, Copy)]
5861
pub struct Lsr {
5962
pub time: DateTime<Utc>,
60-
pub pair: Pair,
6163
pub long: Percent,
6264
}
65+
#[derive(Clone, Debug, Default, derive_more::Deref, derive_more::DerefMut)]
66+
pub struct Lsrs {
67+
#[deref_mut]
68+
#[deref]
69+
pub values: Vec<Lsr>,
70+
pub pair: Pair,
71+
}
6372
//Q: couldn't decide if `short()` and `long(0` should return `f64` or `Percent`. Postponing the decision.
6473
impl Lsr {
6574
pub fn ratio(&self) -> f64 {
@@ -80,7 +89,6 @@ impl From<LsrResponse> for Lsr {
8089
fn from(r: LsrResponse) -> Self {
8190
Self {
8291
time: DateTime::from_timestamp_millis(r.timestamp).unwrap(),
83-
pair: Pair::from_str(&r.symbol).unwrap(),
8492
long: Percent::from_str(&r.long_account).unwrap(),
8593
}
8694
}

0 commit comments

Comments
 (0)