Skip to content

Commit a6c029f

Browse files
cursoragentxsa-dev
andcommitted
Update time handling and data fetching in multi-asset backtest example
Co-authored-by: saleksey67 <saleksey67@gmail.com>
1 parent 9cc9f33 commit a6c029f

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

examples/multi_asset_backtest.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use chrono::{Duration, Utc};
22
use hyperliquid_backtest::prelude::*;
3-
use rs_backtester::prelude::*;
43
use std::fs::File;
54
use std::io::Write;
65
use std::collections::HashMap;
@@ -48,18 +47,23 @@ async fn main() -> Result<()> {
4847
let mut asset_data = HashMap::new();
4948

5049
// Fetch historical data for all assets
51-
let end_time = Utc::now().timestamp() as u64;
52-
let start_time = end_time - (120 * 24 * 3600); // 120 days of data
50+
let end_time = Utc::now();
51+
let start_time = end_time - Duration::days(30);
52+
let start_timestamp = start_time.timestamp_millis() as u64;
53+
let end_timestamp = end_time.timestamp_millis() as u64;
54+
55+
println!("Time range debug:");
56+
println!(" Current time: {}", end_time);
57+
println!(" Start time: {}", start_time);
58+
println!(" Start timestamp: {}", start_timestamp);
59+
println!(" End timestamp: {}", end_timestamp);
60+
println!();
5361

5462
println!("Fetching historical data for {} assets...", assets.len());
5563

5664
for asset in &assets {
5765
println!("Fetching {} data...", asset);
58-
let data = match asset {
59-
&"BTC" => HyperliquidData::fetch_btc("1h", start_time, end_time).await?,
60-
&"ETH" => HyperliquidData::fetch_eth("1h", start_time, end_time).await?,
61-
_ => HyperliquidData::fetch(asset, "1h", start_time, end_time).await?,
62-
};
66+
let data = HyperliquidData::fetch(asset, "1h", start_timestamp, end_timestamp).await?;
6367

6468
println!(" {} data points fetched", data.len());
6569
asset_data.insert(asset.to_string(), data);

test_time.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use chrono::{Duration, Utc};
2+
3+
fn main() {
4+
let end_time = Utc::now();
5+
let start_time = end_time - Duration::days(30);
6+
let start_timestamp = start_time.timestamp_millis() as u64;
7+
let end_timestamp = end_time.timestamp_millis() as u64;
8+
9+
println!("Current time: {}", end_time);
10+
println!("Start time: {}", start_time);
11+
println!("Start timestamp: {}", start_timestamp);
12+
println!("End timestamp: {}", end_timestamp);
13+
println!("Difference: {} ms", end_timestamp - start_timestamp);
14+
}

0 commit comments

Comments
 (0)