Skip to content

Commit 906d4d4

Browse files
committed
chore: switch KlinesRange to have Optional end_time
1 parent 9ddc4c9 commit 906d4d4

File tree

5 files changed

+38
-29
lines changed

5 files changed

+38
-29
lines changed

.github/workflows/errors.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,6 @@ jobs:
1717
- uses: dtolnay/install@cargo-docs-rs
1818
- run: cargo docs-rs
1919
timeout-minutes: 45
20-
miri:
21-
if: needs.pre_ci.outputs.continue
22-
name: Miri
23-
needs: pre_ci
24-
runs-on: ubuntu-latest
25-
steps:
26-
- uses: actions/checkout@v4
27-
- uses: dtolnay/rust-toolchain@miri
28-
- run: cargo miri setup
29-
- env:
30-
MIRIFLAGS: -Zmiri-strict-provenance
31-
run: cargo miri test
32-
timeout-minutes: 45
3320
pre_ci:
3421
uses: valeratrades/.github/.github/workflows/pre_ci.yml@master
3522
tests:

.github/workflows/warnings.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
run: "\t\t\t\t\t\tcargo machete\n\t\t\t\t\t\texit_code=$?\n\t\t\t\t\t\tif [\
2121
\ $exit_code = 0 ]; then\n\t\t\t\t\t\t\techo \"Found unused dependencies\"\
2222
\n\t\t\t\t\t\t\texit $exit_code\n\t\t\t\t\t\tfi\n\t\t\t"
23+
pre_ci:
24+
uses: valeratrades/.github/.github/workflows/pre_ci.yml@master
2325
sort:
2426
name: Cargo Sorted
2527
runs-on: ubuntu-latest

v_exchanges/src/binance/futures/market.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub async fn klines(client: &v_exchanges_adapters::Client, pair: Pair, tf: Timef
2323
let range_json = match range {
2424
KlinesRequestRange::StartEnd { start, end } => json!({
2525
"startTime": start.timestamp_millis(),
26-
"endTime": end.timestamp_millis(),
26+
"endTime": end.map(|dt| dt.timestamp_millis()),
2727
}),
2828
KlinesRequestRange::Limit(limit) => {
2929
let allowed_range = 1..=1000;
@@ -35,7 +35,7 @@ pub async fn klines(client: &v_exchanges_adapters::Client, pair: Pair, tf: Timef
3535
})
3636
}
3737
};
38-
let mut base_params = filter_nulls(json!({
38+
let base_params = filter_nulls(json!({
3939
"symbol": pair.to_string(),
4040
"interval": tf.format_binance()?,
4141
}));

v_exchanges/src/bybit/market.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
use std::fmt;
2-
3-
use chrono::{DateTime, TimeZone, Utc};
1+
use chrono::{TimeZone, Utc};
42
use color_eyre::eyre::Result;
53
use serde::{Deserialize, Serialize};
64
use serde_json::{Value, json};
75
use serde_with::{DisplayFromStr, serde_as};
8-
use thiserror::Error;
96
use v_exchanges_adapters::{
107
bybit::{BybitHttpUrl, BybitOption},
118
errors::LimitOutOfRangeError,
@@ -22,7 +19,7 @@ pub async fn klines(client: &v_exchanges_adapters::Client, pair: Pair, tf: Timef
2219
let range_json = match range {
2320
KlinesRequestRange::StartEnd { start, end } => json!({
2421
"startTime": start.timestamp_millis(),
25-
"endTime": end.timestamp_millis(),
22+
"endTime": end.map(|dt| dt.timestamp_millis()),
2623
}),
2724
KlinesRequestRange::Limit(limit) => {
2825
let allowed_range = 1..=1000;
@@ -34,7 +31,7 @@ pub async fn klines(client: &v_exchanges_adapters::Client, pair: Pair, tf: Timef
3431
})
3532
}
3633
};
37-
let mut base_params = filter_nulls(json!({
34+
let base_params = filter_nulls(json!({
3835
"category": "linear", // can be ["linear", "inverse", "spot"] afaiu, could drive some generics with this later, but for now hardcode
3936
"symbol": pair.to_string(),
4037
"interval": tf.format_bybit()?,

v_exchanges/src/core.rs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
use chrono::{DateTime, Utc};
2-
use color_eyre::eyre::{Error, Result};
3-
use tokio::sync::mpsc;
4-
use v_exchanges_adapters::traits::HandlerOptions;
1+
use chrono::{DateTime, TimeDelta, Utc};
2+
use color_eyre::eyre::Result;
53
use v_utils::trades::{Asset, Kline, Pair, Timeframe};
64
use derive_more::{Deref, DerefMut};
75

@@ -60,15 +58,30 @@ impl TryFrom<Klines> for FullKlines {
6058
#[derive(Clone, Debug, Copy)]
6159
pub enum KlinesRequestRange {
6260
/// Preferred way of defining the range
63-
StartEnd { start: DateTime<Utc>, end: DateTime<Utc> },
61+
StartEnd { start: DateTime<Utc>, end: Option<DateTime<Utc>> },
6462
/// For quick and dirty
6563
Limit(u32),
6664
}
6765
impl Default for KlinesRequestRange {
6866
fn default() -> Self {
6967
KlinesRequestRange::StartEnd {
7068
start: DateTime::default(),
71-
end: DateTime::default(),
69+
end: None,
70+
}
71+
}
72+
}
73+
impl From<DateTime<Utc>> for KlinesRequestRange {
74+
fn from(value: DateTime<Utc>) -> Self {
75+
KlinesRequestRange::StartEnd { start: value, end: None }
76+
}
77+
}
78+
/// funky
79+
impl From<TimeDelta> for KlinesRequestRange {
80+
fn from(value: TimeDelta) -> Self {
81+
let now = Utc::now();
82+
KlinesRequestRange::StartEnd {
83+
start: now - value,
84+
end: None,
7285
}
7386
}
7487
}
@@ -77,16 +90,26 @@ impl From<u32> for KlinesRequestRange {
7790
KlinesRequestRange::Limit(value)
7891
}
7992
}
93+
impl From<u16> for KlinesRequestRange {
94+
fn from(value: u16) -> Self {
95+
KlinesRequestRange::Limit(value as u32)
96+
}
97+
}
98+
impl From<u8> for KlinesRequestRange {
99+
fn from(value: u8) -> Self {
100+
KlinesRequestRange::Limit(value as u32)
101+
}
102+
}
80103
impl From<(DateTime<Utc>, DateTime<Utc>)> for KlinesRequestRange {
81104
fn from(value: (DateTime<Utc>, DateTime<Utc>)) -> Self {
82-
KlinesRequestRange::StartEnd { start: value.0, end: value.1 }
105+
KlinesRequestRange::StartEnd { start: value.0, end: Some(value.1) }
83106
}
84107
}
85108
impl From<(i64, i64)> for KlinesRequestRange {
86109
fn from(value: (i64, i64)) -> Self {
87110
KlinesRequestRange::StartEnd {
88111
start: DateTime::from_timestamp_millis(value.0).unwrap(),
89-
end: DateTime::from_timestamp_millis(value.1).unwrap(),
112+
end: Some(DateTime::from_timestamp_millis(value.1).unwrap()),
90113
}
91114
}
92115
}

0 commit comments

Comments
 (0)