@@ -485,10 +485,16 @@ describe('candleHelper', () => {
485
485
const usdVolume : string = Big ( existingPrice ) . times ( baseTokenVolume ) . toString ( ) ;
486
486
const orderbookMidPriceClose = '7500' ;
487
487
const orderbookMidPriceOpen = '8000' ;
488
+ // Set candle start time to be far in the past to ensure all candles are new
489
+ const startTime : IsoString = helpers . calculateNormalizedCandleStartTime (
490
+ testConstants . createdDateTime . minus ( { minutes : 100 } ) ,
491
+ CandleResolution . ONE_MINUTE ,
492
+ ) . toISO ( ) ;
493
+
488
494
await Promise . all (
489
495
_ . map ( Object . values ( CandleResolution ) , ( resolution : CandleResolution ) => {
490
496
return CandleTable . create ( {
491
- startedAt : previousStartedAt ,
497
+ startedAt : startTime ,
492
498
ticker : testConstants . defaultPerpetualMarket . ticker ,
493
499
resolution,
494
500
low : existingPrice ,
@@ -508,40 +514,39 @@ describe('candleHelper', () => {
508
514
509
515
setCachePrice ( 'BTC-USD' , '10005' ) ;
510
516
await OrderbookMidPriceMemoryCache . updateOrderbookMidPrices ( ) ;
511
-
517
+ // Add two trades for BTC-USD market
512
518
const publisher : KafkaPublisher = new KafkaPublisher ( ) ;
513
519
publisher . addEvents ( [
514
520
defaultTradeKafkaEvent ,
515
521
defaultTradeKafkaEvent2 ,
516
522
] ) ;
517
523
518
524
// Create new candles, with trades
519
- await runUpdateCandles ( publisher ) . then ( async ( ) => {
520
-
521
- // Verify previous candles have orderbookMidPriceClose updated
522
- const previousExpectedCandles : CandleFromDatabase [ ] = _ . map (
523
- Object . values ( CandleResolution ) ,
524
- ( resolution : CandleResolution ) => {
525
- return {
526
- id : CandleTable . uuid ( previousStartedAt , defaultCandle . ticker , resolution ) ,
527
- startedAt : previousStartedAt ,
528
- ticker : defaultCandle . ticker ,
529
- resolution,
530
- low : existingPrice ,
531
- high : existingPrice ,
532
- open : existingPrice ,
533
- close : existingPrice ,
534
- baseTokenVolume,
535
- usdVolume,
536
- trades : existingTrades ,
537
- startingOpenInterest,
538
- orderbookMidPriceClose : '10005' ,
539
- orderbookMidPriceOpen,
540
- } ;
541
- } ,
542
- ) ;
543
- await verifyCandlesInPostgres ( previousExpectedCandles ) ;
544
- } ) ;
525
+ await runUpdateCandles ( publisher ) ;
526
+
527
+ // Verify previous candles have orderbookMidPriceClose updated
528
+ const previousExpectedCandles : CandleFromDatabase [ ] = _ . map (
529
+ Object . values ( CandleResolution ) ,
530
+ ( resolution : CandleResolution ) => {
531
+ return {
532
+ id : CandleTable . uuid ( startTime , defaultCandle . ticker , resolution ) ,
533
+ startedAt : startTime ,
534
+ ticker : defaultCandle . ticker ,
535
+ resolution,
536
+ low : existingPrice ,
537
+ high : existingPrice ,
538
+ open : existingPrice ,
539
+ close : existingPrice ,
540
+ baseTokenVolume,
541
+ usdVolume,
542
+ trades : existingTrades ,
543
+ startingOpenInterest,
544
+ orderbookMidPriceClose : '10005' ,
545
+ orderbookMidPriceOpen,
546
+ } ;
547
+ } ,
548
+ ) ;
549
+ await verifyCandlesInPostgres ( previousExpectedCandles ) ;
545
550
546
551
// Verify new candles were created
547
552
const expectedCandles : CandleFromDatabase [ ] = _ . map (
@@ -583,11 +588,16 @@ describe('candleHelper', () => {
583
588
const usdVolume : string = Big ( existingPrice ) . times ( baseTokenVolume ) . toString ( ) ;
584
589
const orderbookMidPriceClose = '7500' ;
585
590
const orderbookMidPriceOpen = '8000' ;
591
+ // Set candle start time to be far in the past to ensure all candles are new
592
+ const startTime : IsoString = helpers . calculateNormalizedCandleStartTime (
593
+ testConstants . createdDateTime . minus ( { minutes : 100 } ) ,
594
+ CandleResolution . ONE_MINUTE ,
595
+ ) . toISO ( ) ;
586
596
587
597
await Promise . all (
588
598
_ . map ( Object . values ( CandleResolution ) , ( resolution : CandleResolution ) => {
589
599
return CandleTable . create ( {
590
- startedAt : previousStartedAt ,
600
+ startedAt : startTime ,
591
601
ticker : testConstants . defaultPerpetualMarket . ticker ,
592
602
resolution,
593
603
low : existingPrice ,
0 commit comments