Skip to content

Commit

Permalink
Adam/remove candles main (#2045)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamfraser authored Aug 6, 2024
1 parent 6e93e00 commit bc140d4
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 598 deletions.
2 changes: 0 additions & 2 deletions indexer/packages/postgres/__tests__/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -725,8 +725,6 @@ export const defaultCandle: CandleCreateObject = {
usdVolume: '2200000',
trades: 300,
startingOpenInterest: '200000',
orderbookMidPriceOpen: '11500',
orderbookMidPriceClose: '12500',
};

export const defaultCandleId: string = CandleTable.uuid(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ describe('CandleTable', () => {
const updatedCandle: CandleUpdateObject = {
id: defaultCandleId,
open: '100',
orderbookMidPriceClose: '200',
orderbookMidPriceOpen: '300',
};

await CandleTable.update(updatedCandle);
await CandleTable.update({
id: defaultCandleId,
open: '100',
});

const candle: CandleFromDatabase | undefined = await CandleTable.findById(
defaultCandleId,
Expand Down

This file was deleted.

6 changes: 0 additions & 6 deletions indexer/packages/postgres/src/models/candle-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ export default class CandleModel extends Model {
usdVolume: { type: 'string', pattern: NonNegativeNumericPattern },
trades: { type: 'integer' },
startingOpenInterest: { type: 'string', pattern: NonNegativeNumericPattern },
orderbookMidPriceOpen: { type: ['string', 'null'], pattern: NonNegativeNumericPattern },
orderbookMidPriceClose: { type: ['string', 'null'], pattern: NonNegativeNumericPattern },
},
};
}
Expand Down Expand Up @@ -79,8 +77,4 @@ export default class CandleModel extends Model {
trades!: number;

startingOpenInterest!: string;

orderbookMidPriceOpen?: string;

orderbookMidPriceClose?: string;
}
4 changes: 0 additions & 4 deletions indexer/packages/postgres/src/types/candle-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export interface CandleCreateObject {
usdVolume: string;
trades: number;
startingOpenInterest: string;
orderbookMidPriceOpen: string | undefined;
orderbookMidPriceClose: string | undefined;
}

export interface CandleUpdateObject {
Expand All @@ -26,8 +24,6 @@ export interface CandleUpdateObject {
usdVolume?: string;
trades?: number;
startingOpenInterest?: string;
orderbookMidPriceOpen?: string;
orderbookMidPriceClose?: string;
}

export enum CandleResolution {
Expand Down
2 changes: 0 additions & 2 deletions indexer/packages/postgres/src/types/db-model-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ export interface CandleFromDatabase extends IdBasedModelFromDatabase {
usdVolume: string;
trades: number;
startingOpenInterest: string;
orderbookMidPriceOpen?: string | null;
orderbookMidPriceClose?: string | null;
}

export interface PnlTicksFromDatabase extends IdBasedModelFromDatabase {
Expand Down
133 changes: 0 additions & 133 deletions indexer/packages/redis/__tests__/caches/orderbook-levels-cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
deleteZeroPriceLevel,
getLastUpdatedKey,
deleteStalePriceLevel,
getOrderBookMidPrice,
} from '../../src/caches/orderbook-levels-cache';
import { OrderSide } from '@dydxprotocol-indexer/postgres';
import { OrderbookLevels, PriceLevel } from '../../src/types';
Expand Down Expand Up @@ -686,136 +685,4 @@ describe('orderbookLevelsCache', () => {
expect(size).toEqual('10');
});
});

describe('getMidPrice', () => {
beforeEach(() => {
jest.restoreAllMocks();
jest.restoreAllMocks();
});
afterEach(() => {
jest.restoreAllMocks();
jest.restoreAllMocks();
});

it('returns the correct mid price', async () => {
await Promise.all([
updatePriceLevel({
ticker,
side: OrderSide.BUY,
humanPrice: '45200',
sizeDeltaInQuantums: '2000',
client,
}),
updatePriceLevel({
ticker,
side: OrderSide.BUY,
humanPrice: '45100',
sizeDeltaInQuantums: '2000',
client,
}),
updatePriceLevel({
ticker,
side: OrderSide.BUY,
humanPrice: '45300',
sizeDeltaInQuantums: '2000',
client,
}),
updatePriceLevel({
ticker,
side: OrderSide.SELL,
humanPrice: '45500',
sizeDeltaInQuantums: '2000',
client,
}),
updatePriceLevel({
ticker,
side: OrderSide.SELL,
humanPrice: '45400',
sizeDeltaInQuantums: '2000',
client,
}),
updatePriceLevel({
ticker,
side: OrderSide.SELL,
humanPrice: '45600',
sizeDeltaInQuantums: '2000',
client,
}),
]);

const midPrice = await getOrderBookMidPrice(ticker, client);
expect(midPrice).toEqual('45350');
});
});

it('returns the correct mid price for very small numbers', async () => {
await Promise.all([
updatePriceLevel({
ticker,
side: OrderSide.SELL,
humanPrice: '0.000000002346',
sizeDeltaInQuantums: '2000',
client,
}),
updatePriceLevel({
ticker,
side: OrderSide.BUY,
humanPrice: '0.000000002344',
sizeDeltaInQuantums: '2000',
client,
}),
]);

const midPrice = await getOrderBookMidPrice(ticker, client);
expect(midPrice).toEqual('0.000000002345');
});

it('returns the approprite amount of decimal precision', async () => {
await Promise.all([
updatePriceLevel({
ticker,
side: OrderSide.SELL,
humanPrice: '1.02',
sizeDeltaInQuantums: '2000',
client,
}),
updatePriceLevel({
ticker,
side: OrderSide.BUY,
humanPrice: '1.01',
sizeDeltaInQuantums: '2000',
client,
}),
]);

const midPrice = await getOrderBookMidPrice(ticker, client);
expect(midPrice).toEqual('1.015');
});

it('returns undefined if there are no bids or asks', async () => {
await updatePriceLevel({
ticker,
side: OrderSide.SELL,
humanPrice: '45400',
sizeDeltaInQuantums: '2000',
client,
});

const midPrice = await getOrderBookMidPrice(ticker, client);
expect(midPrice).toBeUndefined();
});

it('returns undefined if humanPrice is NaN', async () => {
await updatePriceLevel({
ticker,
side: OrderSide.SELL,
humanPrice: 'nan',
sizeDeltaInQuantums: '2000',
client,
});

const midPrice = await getOrderBookMidPrice(ticker, client);

expect(midPrice).toBeUndefined();
});
});
24 changes: 0 additions & 24 deletions indexer/packages/redis/src/caches/orderbook-levels-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,27 +529,3 @@ function convertToPriceLevels(
};
});
}

export async function getOrderBookMidPrice(
ticker: string,
client: RedisClient,
): Promise<string | undefined> {
const levels = await getOrderBookLevels(ticker, client, {
removeZeros: true,
sortSides: true,
uncrossBook: true,
limitPerSide: 1,
});

if (levels.bids.length === 0 || levels.asks.length === 0) {
return undefined;
}

const bestAsk = Big(levels.asks[0].humanPrice);
const bestBid = Big(levels.bids[0].humanPrice);

if (bestAsk === undefined || bestBid === undefined) {
return undefined;
}
return bestBid.plus(bestAsk).div(2).toFixed();
}
8 changes: 0 additions & 8 deletions indexer/services/comlink/public/api-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,6 @@ fetch(`${baseURL}/candles/perpetualMarkets/{ticker}?resolution=1MIN`,
"usdVolume": "string",
"trades": 0.1,
"startingOpenInterest": "string",
"orderbookMidPriceOpen": "string",
"orderbookMidPriceClose": "string",
"id": "string"
}
]
Expand Down Expand Up @@ -3657,8 +3655,6 @@ This operation does not require authentication
"usdVolume": "string",
"trades": 0.1,
"startingOpenInterest": "string",
"orderbookMidPriceOpen": "string",
"orderbookMidPriceClose": "string",
"id": "string"
}

Expand All @@ -3679,8 +3675,6 @@ This operation does not require authentication
|usdVolume|string|true|none|none|
|trades|number(double)|true|none|none|
|startingOpenInterest|string|true|none|none|
|orderbookMidPriceOpen|string¦null|false|none|none|
|orderbookMidPriceClose|string¦null|false|none|none|
|id|string|true|none|none|

## CandleResponse
Expand All @@ -3705,8 +3699,6 @@ This operation does not require authentication
"usdVolume": "string",
"trades": 0.1,
"startingOpenInterest": "string",
"orderbookMidPriceOpen": "string",
"orderbookMidPriceClose": "string",
"id": "string"
}
]
Expand Down
8 changes: 0 additions & 8 deletions indexer/services/comlink/public/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,6 @@
"startingOpenInterest": {
"type": "string"
},
"orderbookMidPriceOpen": {
"type": "string",
"nullable": true
},
"orderbookMidPriceClose": {
"type": "string",
"nullable": true
},
"id": {
"type": "string"
}
Expand Down
18 changes: 0 additions & 18 deletions indexer/services/ender/__tests__/helpers/redis-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { OrderSide } from '@dydxprotocol-indexer/postgres';
import {
NextFundingCache,
OrderbookLevelsCache,
StateFilledQuantumsCache,
} from '@dydxprotocol-indexer/redis';
import Big from 'big.js';
Expand Down Expand Up @@ -31,19 +29,3 @@ export async function expectStateFilledQuantums(
expect(stateFilledQuantums).toBeDefined();
expect(stateFilledQuantums).toEqual(quantums);
}

export async function updatePriceLevel(
ticker: string,
price: string,
side: OrderSide,
): Promise<void> {
const quantums: string = '30';

await OrderbookLevelsCache.updatePriceLevel({
ticker,
side,
humanPrice: price,
sizeDeltaInQuantums: quantums,
client: redisClient,
});
}
Loading

0 comments on commit bc140d4

Please sign in to comment.