From 89e2fa71780195348508a8ebd86ad30e1a4a98ad Mon Sep 17 00:00:00 2001 From: Riordan Panayides Date: Thu, 1 Jun 2023 15:30:54 +0100 Subject: [PATCH] temp: add debugging output to candle batching, mark old candles as completed --- src/worker/candle_batching/minute_candles.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/worker/candle_batching/minute_candles.rs b/src/worker/candle_batching/minute_candles.rs index cf20446..a53bef4 100644 --- a/src/worker/candle_batching/minute_candles.rs +++ b/src/worker/candle_batching/minute_candles.rs @@ -22,6 +22,7 @@ pub async fn batch_1m_candles(pool: &Pool, market: &MarketInfo) -> anyhow::Resul match latest_candle { Some(candle) => { + println!("{}: latest finished candle time {}", market_name, candle.end_time); let start_time = candle.end_time; let end_time = min( start_time + day(), @@ -29,6 +30,7 @@ pub async fn batch_1m_candles(pool: &Pool, market: &MarketInfo) -> anyhow::Resul ); let mut fills = fetch_fills_from(pool, market_address, start_time, end_time).await?; let existing_candles = fetch_candles_from(pool, market_name, Resolution::R1m, candle.start_time, end_time).await?; + println!("{}: combining {} fills from {} to {}", market_name, fills.clone().len(), start_time, end_time); let candles = combine_fills_into_1m_candles( &mut fills, @@ -37,9 +39,12 @@ pub async fn batch_1m_candles(pool: &Pool, market: &MarketInfo) -> anyhow::Resul end_time, Some(candle.close), ); + + println!("{}: filtering {} new candles on {} existing candles from {} to {}", market_name, candles.clone().len(), existing_candles.clone().len(), start_time, end_time); Ok(filter_redundant_candles(existing_candles, candles.clone())) } None => { + println!("{}: no finished candle", market_name); let earliest_fill = fetch_earliest_fill(pool, market_address).await?; if earliest_fill.is_none() { @@ -56,6 +61,7 @@ pub async fn batch_1m_candles(pool: &Pool, market: &MarketInfo) -> anyhow::Resul Utc::now().duration_trunc(Duration::minutes(1))?, ); let mut fills = fetch_fills_from(pool, market_address, start_time, end_time).await?; + println!("{}: combining {} fills from {} to {}", market_name, fills.clone().len(), start_time, end_time); if !fills.is_empty() { let candles = combine_fills_into_1m_candles(&mut fills, market, start_time, end_time, None); @@ -101,7 +107,7 @@ fn combine_fills_into_1m_candles( while matches!(fills_iter.peek(), Some(f) if f.time < end_time) { let fill = fills_iter.next().unwrap(); - + println!("adding fill from {}", fill.time); let (price, volume) = calculate_fill_price_and_size(*fill, market.base_decimals, market.quote_decimals); @@ -115,8 +121,16 @@ fn combine_fills_into_1m_candles( candles[i].start_time = start_time; candles[i].end_time = end_time; - candles[i].complete = matches!(fills_iter.peek(), Some(f) if f.time > end_time); - + candles[i].complete = matches!(fills_iter.peek(), Some(f) if f.time > end_time) || end_time < Utc::now() - Duration::days(1); + if candles[i].complete { + println!("candle {} complete with end time {}", i, end_time); + } else { + let peeked_fill = fills_iter.peek(); + match peeked_fill { + Some(f) => println!("candle {} incomplete, peeked fill was at {} and end time was {}", i, f.time, end_time), + None => {} + } + } start_time = end_time; end_time += Duration::minutes(1); }