|
|
|
@ -25,10 +25,11 @@ async fn fetch_candles_until_now( |
|
|
|
|
) -> AppResult<(Vec<Candle>, String)> { |
|
|
|
|
let mut result = vec![]; |
|
|
|
|
let limit = 500; |
|
|
|
|
let mut is_completed = false; |
|
|
|
|
|
|
|
|
|
loop { |
|
|
|
|
while !is_completed { |
|
|
|
|
println!( |
|
|
|
|
"pulling {}:{} candles from {start_time}", |
|
|
|
|
"{}:{}: pulling candles from {start_time}", |
|
|
|
|
pair, |
|
|
|
|
interval.as_ref() |
|
|
|
|
); |
|
|
|
@ -50,10 +51,10 @@ async fn fetch_candles_until_now( |
|
|
|
|
start_time = last_candle.ts + TimeDelta::seconds(1); |
|
|
|
|
|
|
|
|
|
if start_time.and_utc().timestamp() >= now { |
|
|
|
|
break; |
|
|
|
|
is_completed = true; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
break; |
|
|
|
|
is_completed = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let candles_count = candles.len(); |
|
|
|
@ -61,10 +62,16 @@ async fn fetch_candles_until_now( |
|
|
|
|
result.extend(candles); |
|
|
|
|
|
|
|
|
|
if candles_count < limit { |
|
|
|
|
break; |
|
|
|
|
is_completed = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
println!( |
|
|
|
|
"{}:{}: pulled {} candles", |
|
|
|
|
pair, |
|
|
|
|
interval.as_ref(), |
|
|
|
|
result.len(), |
|
|
|
|
); |
|
|
|
|
Ok((result, pair.to_string())) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -197,12 +204,6 @@ async fn _main() -> AppResult<()> { |
|
|
|
|
} |
|
|
|
|
let fetched_candles = try_join_all(fetchers).await?; |
|
|
|
|
|
|
|
|
|
// println!(
|
|
|
|
|
// "{pair}: fetched {} candles with interval {}",
|
|
|
|
|
// candles.len(),
|
|
|
|
|
// config.interval.as_ref()
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
let candles_to_upsert = fetched_candles |
|
|
|
|
.into_iter() |
|
|
|
|
.flat_map(|(candles, pair)| { |
|
|
|
|