Skip to content

Commit 296758d

Browse files
committed
fix: _
1 parent d906fa6 commit 296758d

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

v_exchanges/src/binance/futures/market.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::fmt;
1+
use std::{collections::VecDeque, fmt};
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>.
@@ -48,7 +48,7 @@ pub async fn klines(client: &v_exchanges_adapters::Client, pair: Pair, tf: Timef
4848
let kline_responses: Vec<KlineResponse> = client.get("/fapi/v1/klines", &params, [BinanceOption::HttpUrl(BinanceHttpUrl::FuturesUsdM)]).await.unwrap();
4949

5050
let r_len = kline_responses.len();
51-
let mut klines = Vec::with_capacity(r_len);
51+
let mut klines = VecDeque::with_capacity(r_len);
5252
for (i, k) in kline_responses.into_iter().enumerate() {
5353
//HACK: have to check against [now](Utc::now) instead, because binance returns some dumb shit instead of actual close. Here structured this way in case they fix it in the future.
5454
let close_time = Utc::now().timestamp_millis();
@@ -60,7 +60,7 @@ pub async fn klines(client: &v_exchanges_adapters::Client, pair: Pair, tf: Timef
6060
low: k.low,
6161
close: k.close,
6262
};
63-
klines.push(Kline {
63+
klines.push_front(Kline {
6464
open_time: DateTime::from_timestamp_millis(k.open_time).unwrap(),
6565
ohlc,
6666
volume_quote: k.quote_asset_volume,

v_exchanges/src/bybit/market.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use chrono::{TimeZone, Utc};
1+
use std::collections::VecDeque;
2+
3+
use chrono::{DateTime, TimeZone, Utc};
24
use color_eyre::eyre::Result;
35
use serde::{Deserialize, Serialize};
46
use serde_json::{Value, json};
@@ -44,11 +46,11 @@ pub async fn klines(client: &v_exchanges_adapters::Client, pair: Pair, tf: Timef
4446

4547
let kline_response: KlineResponse = client.get("/v5/market/kline", &params, [BybitOption::Default]).await.unwrap();
4648

47-
let mut klines = Vec::new();
49+
let mut klines = VecDeque::with_capacity(kline_response.result.list.len());
4850
for k in kline_response.result.list {
4951
if kline_response.time > k.0 + tf.duration().num_milliseconds() {
50-
klines.push(Kline {
51-
open_time: Utc.timestamp_millis(k.0),
52+
klines.push_back(Kline {
53+
open_time: DateTime::from_timestamp_millis(k.0).unwrap(),
5254
ohlc: Ohlc {
5355
open: k.1,
5456
close: k.2,

v_exchanges/src/core.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::collections::VecDeque;
2+
13
use chrono::{DateTime, TimeDelta, Utc};
24
use color_eyre::eyre::Result;
35
use derive_more::{Deref, DerefMut};
@@ -34,15 +36,24 @@ pub struct Oi {
3436
pub timestamp: DateTime<Utc>,
3537
}
3638

39+
//Q: maybe add a `vectorize` method? Should add, question is really if it should be returning a) df b) all fields, including optional and oi c) t, o, h, l, c, v
40+
// probably should figure out rust-typed dataframes for this first
3741
#[derive(Clone, Debug, Default, Deref, DerefMut)]
3842
pub struct Klines {
3943
#[deref_mut]
4044
#[deref]
41-
pub v: Vec<Kline>,
45+
pub v: VecDeque<Kline>,
4246
pub tf: Timeframe,
4347
/// Doesn't have to be synchronized with klines; each track has its own timestamps.
4448
pub oi: Vec<Oi>,
4549
}
50+
impl Iterator for Klines {
51+
type Item = Kline;
52+
53+
fn next(&mut self) -> Option<Self::Item> {
54+
self.v.pop_front()
55+
}
56+
}
4657

4758
//MOVE: v_utils (along with [Klines])
4859
//? not sure what to do about oi here

0 commit comments

Comments
 (0)