Skip to content

Commit

Permalink
Return undefined from getOrderbookMidPriceMap (#2441)
Browse files Browse the repository at this point in the history
(cherry picked from commit 9fecfc5)

# Conflicts:
#	indexer/services/ender/__tests__/lib/candles-generator.test.ts
#	indexer/services/ender/src/lib/candles-generator.ts
  • Loading branch information
adamfraser authored and mergify[bot] committed Oct 2, 2024
1 parent f5f1617 commit 146bd26
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
25 changes: 17 additions & 8 deletions indexer/services/ender/__tests__/lib/candles-generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ describe('candleHelper', () => {
id: CandleTable.uuid(currentStartedAt, defaultCandle.ticker, resolution),
startedAt: currentStartedAt,
resolution,
orderbookMidPriceClose: '105000',
orderbookMidPriceOpen: '105000',
orderbookMidPriceClose: null,
orderbookMidPriceOpen: null,
};
},
);
Expand Down Expand Up @@ -179,8 +179,8 @@ describe('candleHelper', () => {
startedAt: currentStartedAt,
resolution,
startingOpenInterest: openInterest,
orderbookMidPriceClose: '80500',
orderbookMidPriceOpen: '80500',
orderbookMidPriceClose: null,
orderbookMidPriceOpen: null,
};
},
);
Expand Down Expand Up @@ -303,8 +303,8 @@ describe('candleHelper', () => {
usdVolume: '0',
trades: 0,
startingOpenInterest: '100',
orderbookMidPriceClose: '1000',
orderbookMidPriceOpen: '1000',
orderbookMidPriceClose: null,
orderbookMidPriceOpen: null,
},
true,
1000,
Expand Down Expand Up @@ -334,8 +334,8 @@ describe('candleHelper', () => {
startedAt,
resolution: CandleResolution.ONE_MINUTE,
startingOpenInterest: '100',
orderbookMidPriceClose: '1000',
orderbookMidPriceOpen: '1000',
orderbookMidPriceClose: null,
orderbookMidPriceOpen: null,
},
true, // contains kafka messages
1000, // orderbook mid price
Expand Down Expand Up @@ -465,6 +465,7 @@ describe('candleHelper', () => {
expectTimingStats();
});

<<<<<<< HEAD
it('Updates previous candle orderBookMidPriceClose if startTime is past candle resolution', async () => {
// Create existing candles
const existingPrice: string = '7000';
Expand Down Expand Up @@ -659,6 +660,8 @@ describe('candleHelper', () => {

});

=======
>>>>>>> 9fecfc5d (Return undefined from getOrderbookMidPriceMap (#2441))
it('successfully creates an orderbook price map for each market', async () => {
await updatePriceLevel('BTC-USD', '100000', OrderSide.BUY);
await updatePriceLevel('BTC-USD', '110000', OrderSide.SELL);
Expand All @@ -671,9 +674,15 @@ describe('candleHelper', () => {

const map = await getOrderbookMidPriceMap();
expect(map).toEqual({
<<<<<<< HEAD
'BTC-USD': '105000',
'ETH-USD': '150000',
'ISO-USD': '115000',
=======
'BTC-USD': undefined,
'ETH-USD': undefined,
'ISO-USD': undefined,
>>>>>>> 9fecfc5d (Return undefined from getOrderbookMidPriceMap (#2441))
'ISO2-USD': undefined,
'SHIB-USD': undefined,
});
Expand Down
8 changes: 7 additions & 1 deletion indexer/services/ender/src/lib/candles-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ import {
TradeMessageContents,
helpers,
} from '@dydxprotocol-indexer/postgres';
<<<<<<< HEAD
import { OrderbookLevelsCache } from '@dydxprotocol-indexer/redis';
=======
>>>>>>> 9fecfc5d (Return undefined from getOrderbookMidPriceMap (#2441))
import { CandleMessage } from '@dydxprotocol-indexer/v4-protos';
import Big from 'big.js';
import _ from 'lodash';
import { DateTime } from 'luxon';

import { getCandle } from '../caches/candle-cache';
import config from '../config';
import { redisClient } from '../helpers/redis/redis-controller';
import { KafkaPublisher } from './kafka-publisher';
import { ConsolidatedKafkaEvent, SingleTradeMessage } from './types';

Expand Down Expand Up @@ -538,11 +540,15 @@ export async function getOrderbookMidPriceMap(): Promise<{ [ticker: string]: Ord
const perpetualMarkets = Object.values(perpetualMarketRefresher.getPerpetualMarketsMap());

const promises = perpetualMarkets.map(async (perpetualMarket: PerpetualMarketFromDatabase) => {
<<<<<<< HEAD
const price = await OrderbookLevelsCache.getOrderBookMidPrice(
perpetualMarket.ticker,
redisClient,
);
return { [perpetualMarket.ticker]: price === undefined ? undefined : price };
=======
return Promise.resolve({ [perpetualMarket.ticker]: undefined });
>>>>>>> 9fecfc5d (Return undefined from getOrderbookMidPriceMap (#2441))
});

const pricesArray = await Promise.all(promises);
Expand Down

0 comments on commit 146bd26

Please # to comment.