Skip to content

Commit

Permalink
Revert "Add Orderbook Mid Price Cache (#2289)" (#2333)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamfraser authored Sep 24, 2024
1 parent c34d56d commit 1a33334
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 438 deletions.

This file was deleted.

107 changes: 0 additions & 107 deletions indexer/packages/redis/src/caches/orderbook-mid-prices-cache.ts

This file was deleted.

4 changes: 0 additions & 4 deletions indexer/packages/redis/src/caches/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ export const removeOrderScript: LuaScript = newLuaScript('removeOrder', '../scri
export const addCanceledOrderIdScript: LuaScript = newLuaScript('addCanceledOrderId', '../scripts/add_canceled_order_id.lua');
export const addStatefulOrderUpdateScript: LuaScript = newLuaScript('addStatefulOrderUpdate', '../scripts/add_stateful_order_update.lua');
export const removeStatefulOrderUpdateScript: LuaScript = newLuaScript('removeStatefulOrderUpdate', '../scripts/remove_stateful_order_update.lua');
export const addMarketPriceScript: LuaScript = newLuaScript('addMarketPrice', '../scripts/add_market_price.lua');
export const getMarketMedianScript: LuaScript = newLuaScript('getMarketMedianPrice', '../scripts/get_market_median_price.lua');

export const allLuaScripts: LuaScript[] = [
deleteZeroPriceLevelScript,
Expand All @@ -77,6 +75,4 @@ export const allLuaScripts: LuaScript[] = [
addCanceledOrderIdScript,
addStatefulOrderUpdateScript,
removeStatefulOrderUpdateScript,
addMarketPriceScript,
getMarketMedianScript,
];
1 change: 0 additions & 1 deletion indexer/packages/redis/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export * as CanceledOrdersCache from './caches/canceled-orders-cache';
export * as StatefulOrderUpdatesCache from './caches/stateful-order-updates-cache';
export * as StateFilledQuantumsCache from './caches/state-filled-quantums-cache';
export * as LeaderboardPnlProcessedCache from './caches/leaderboard-processed-cache';
export * as OrderbookMidPricesCache from './caches/orderbook-mid-prices-cache';
export { placeOrder } from './caches/place-order';
export { removeOrder } from './caches/remove-order';
export { updateOrder } from './caches/update-order';
Expand Down
17 changes: 0 additions & 17 deletions indexer/packages/redis/src/scripts/add_market_price.lua

This file was deleted.

23 changes: 0 additions & 23 deletions indexer/packages/redis/src/scripts/get_market_median_price.lua

This file was deleted.

53 changes: 27 additions & 26 deletions indexer/services/ender/__tests__/lib/candles-generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
testMocks,
Transaction,
helpers,
OrderSide,
} from '@dydxprotocol-indexer/postgres';
import { CandleMessage, CandleMessage_Resolution } from '@dydxprotocol-indexer/v4-protos';
import Big from 'big.js';
Expand All @@ -31,11 +32,9 @@ import { KafkaPublisher } from '../../src/lib/kafka-publisher';
import { ConsolidatedKafkaEvent } from '../../src/lib/types';
import { defaultTradeContent, defaultTradeKafkaEvent } from '../helpers/constants';
import { contentToSingleTradeMessage, createConsolidatedKafkaEventFromTrade } from '../helpers/kafka-publisher-helpers';
import { updatePriceLevel } from '../helpers/redis-helpers';
import { redisClient } from '../../src/helpers/redis/redis-controller';
import {
redis,
OrderbookMidPricesCache,
} from '@dydxprotocol-indexer/redis';
import { redis } from '@dydxprotocol-indexer/redis';

describe('candleHelper', () => {
beforeAll(async () => {
Expand Down Expand Up @@ -114,12 +113,9 @@ describe('candleHelper', () => {
defaultTradeKafkaEvent2,
]);

const ticker = 'BTC-USD';
await Promise.all([
OrderbookMidPricesCache.setPrice(redisClient, ticker, '100000'),
OrderbookMidPricesCache.setPrice(redisClient, ticker, '105000'),
OrderbookMidPricesCache.setPrice(redisClient, ticker, '110000'),
]);
// Create Orderbook levels to set orderbookMidPrice open & close
await updatePriceLevel('BTC-USD', '100000', OrderSide.BUY);
await updatePriceLevel('BTC-USD', '110000', OrderSide.SELL);

await runUpdateCandles(publisher);

Expand Down Expand Up @@ -159,12 +155,8 @@ describe('candleHelper', () => {
defaultTradeKafkaEvent2,
]);

const ticker = 'BTC-USD';
await Promise.all([
OrderbookMidPricesCache.setPrice(redisClient, ticker, '80000'),
OrderbookMidPricesCache.setPrice(redisClient, ticker, '81000'),
OrderbookMidPricesCache.setPrice(redisClient, ticker, '80500'),
]);
await updatePriceLevel('BTC-USD', '80000', OrderSide.BUY);
await updatePriceLevel('BTC-USD', '81000', OrderSide.SELL);

// Create Perpetual Position to set open position
const openInterest: string = '100';
Expand Down Expand Up @@ -435,7 +427,9 @@ describe('candleHelper', () => {
containsKafkaMessages: boolean = true,
orderbookMidPrice: number,
) => {
await OrderbookMidPricesCache.setPrice(redisClient, 'BTC-USD', orderbookMidPrice.toFixed());
const midPriceSpread = 10;
await updatePriceLevel('BTC-USD', String(orderbookMidPrice + midPriceSpread), OrderSide.SELL);
await updatePriceLevel('BTC-USD', String(orderbookMidPrice - midPriceSpread), OrderSide.BUY);

if (initialCandle !== undefined) {
await CandleTable.create(initialCandle);
Expand Down Expand Up @@ -500,7 +494,9 @@ describe('candleHelper', () => {
);
await startCandleCache();

await OrderbookMidPricesCache.setPrice(redisClient, 'BTC-USD', '10005');
// Update Orderbook levels
await updatePriceLevel('BTC-USD', '10010', OrderSide.SELL);
await updatePriceLevel('BTC-USD', '10000', OrderSide.BUY);

const publisher: KafkaPublisher = new KafkaPublisher();
publisher.addEvents([
Expand Down Expand Up @@ -598,7 +594,9 @@ describe('candleHelper', () => {
);
await startCandleCache();

await OrderbookMidPricesCache.setPrice(redisClient, 'BTC-USD', '10005');
// Update Orderbook levels
await updatePriceLevel('BTC-USD', '10010', OrderSide.SELL);
await updatePriceLevel('BTC-USD', '10000', OrderSide.BUY);

const publisher: KafkaPublisher = new KafkaPublisher();
publisher.addEvents([]);
Expand Down Expand Up @@ -662,19 +660,22 @@ describe('candleHelper', () => {
});

it('successfully creates an orderbook price map for each market', async () => {
await Promise.all([
OrderbookMidPricesCache.setPrice(redisClient, 'BTC-USD', '105000'),
OrderbookMidPricesCache.setPrice(redisClient, 'ISO-USD', '115000'),
OrderbookMidPricesCache.setPrice(redisClient, 'ETH-USD', '150000'),
]);
await updatePriceLevel('BTC-USD', '100000', OrderSide.BUY);
await updatePriceLevel('BTC-USD', '110000', OrderSide.SELL);

await updatePriceLevel('ISO-USD', '110000', OrderSide.BUY);
await updatePriceLevel('ISO-USD', '120000', OrderSide.SELL);

await updatePriceLevel('ETH-USD', '100000', OrderSide.BUY);
await updatePriceLevel('ETH-USD', '200000', OrderSide.SELL);

const map = await getOrderbookMidPriceMap();
expect(map).toEqual({
'BTC-USD': '105000',
'ETH-USD': '150000',
'ISO-USD': '115000',
'ISO2-USD': null,
'SHIB-USD': null,
'ISO2-USD': undefined,
'SHIB-USD': undefined,
});
});
});
Expand Down
Loading

0 comments on commit 1a33334

Please sign in to comment.