Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IND-491]: Remove unused lastPrice from perpetual_markets table #813

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions indexer/packages/postgres/__tests__/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ export const defaultPerpetualMarket: PerpetualMarketCreateObject = {
ticker: 'BTC-USD',
marketId: 0,
status: PerpetualMarketStatus.ACTIVE,
lastPrice: '15000',
priceChange24H: '23',
volume24H: '1000000',
trades24H: 250,
Expand All @@ -169,7 +168,6 @@ export const defaultPerpetualMarket2: PerpetualMarketCreateObject = {
ticker: 'ETH-USD',
marketId: 1,
status: PerpetualMarketStatus.ACTIVE,
lastPrice: '1500',
priceChange24H: '23',
volume24H: '100000',
trades24H: 200,
Expand All @@ -187,7 +185,6 @@ export const defaultPerpetualMarket3: PerpetualMarketCreateObject = {
ticker: 'SHIB-USD',
marketId: 2,
status: PerpetualMarketStatus.ACTIVE,
lastPrice: '0.000000065',
priceChange24H: '0.000000001',
volume24H: '10000000',
trades24H: 200,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as Knex from 'knex';

export async function up(knex: Knex): Promise<void> {
return knex
.schema
.alterTable('perpetual_markets', (table) => {
table.dropColumn('lastPrice');
});
}

export async function down(knex: Knex): Promise<void> {
return knex
.schema
.alterTable('perpetual_markets', (table) => {
table.decimal('lastPrice', null).defaultTo('0').notNullable();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'down' migration function should specify the precision and scale for the decimal type of the 'lastPrice' column to ensure that it matches the original column specification before it was dropped.

-      table.decimal('lastPrice', null).defaultTo('0').notNullable();
+      table.decimal('lastPrice', precision, scale).defaultTo('0').notNullable();

Replace precision and scale with the appropriate values that were used when the 'lastPrice' column was originally created.


Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
table.decimal('lastPrice', null).defaultTo('0').notNullable();
table.decimal('lastPrice', precision, scale).defaultTo('0').notNullable();

});
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export default class PerpetualMarketModel extends Model {
'ticker',
'marketId',
'status',
'lastPrice',
'priceChange24H',
'volume24H',
'trades24H',
Expand All @@ -74,7 +73,6 @@ export default class PerpetualMarketModel extends Model {
ticker: { type: 'string' },
marketId: { type: 'integer' },
status: { type: 'string', enum: [...Object.values(PerpetualMarketStatus)] },
lastPrice: { type: 'string', pattern: NonNegativeNumericPattern },
priceChange24H: { type: 'string', pattern: NumericPattern },
volume24H: { type: 'string', pattern: NonNegativeNumericPattern },
trades24H: { type: 'integer' },
Expand Down Expand Up @@ -102,7 +100,6 @@ export default class PerpetualMarketModel extends Model {
ticker: 'string',
marketId: 'integer',
status: 'string',
lastPrice: 'string',
priceChange24H: 'string',
volume24H: 'string',
trades24H: 'integer',
Expand All @@ -126,8 +123,6 @@ export default class PerpetualMarketModel extends Model {

status!: PerpetualMarketStatus;

lastPrice!: string;

priceChange24H!: string;

volume24H!: string;
Expand Down
1 change: 0 additions & 1 deletion indexer/packages/postgres/src/types/db-model-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export interface PerpetualMarketFromDatabase {
ticker: string;
marketId: number;
status: PerpetualMarketStatus;
lastPrice: string;
priceChange24H: string;
volume24H: string;
trades24H: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export interface PerpetualMarketCreateObject {
ticker: string;
marketId: number;
status: PerpetualMarketStatus;
lastPrice: string;
priceChange24H: string;
volume24H: string;
trades24H: number;
Expand All @@ -25,7 +24,6 @@ export interface PerpetualMarketUpdateObject {
ticker?: string;
marketId?: number;
status?: PerpetualMarketStatus;
lastPrice?: string;
priceChange24H?: string;
volume24H?: string;
trades24H?: number;
Expand All @@ -44,7 +42,6 @@ export enum PerpetualMarketColumns {
ticker = 'ticker',
marketId = 'marketId',
status = 'status',
lastPrice = 'lastPrice',
priceChange24H = 'priceChange24H',
volume24H = 'volume24H',
trades24H = 'trades24H',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ export interface TradingPerpetualMarketMessage {
stepBaseQuantums?: number;

// Fields that are likely to change
lastPrice?: string;
priceChange24H?: string;
volume24H?: string;
trades24H?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ describe('request-transformer', () => {
clobPairId: perpetualMarket.clobPairId,
ticker: perpetualMarket.ticker,
status: perpetualMarket.status,
lastPrice: perpetualMarket.lastPrice,
oraclePrice: market.oraclePrice,
priceChange24H: perpetualMarket.priceChange24H,
volume24H: perpetualMarket.volume24H,
Expand Down
6 changes: 0 additions & 6 deletions indexer/services/comlink/public/api-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,6 @@ fetch('https://indexer.v4testnet.dydx.exchange/v4/perpetualMarkets?limit=0',
"clobPairId": "string",
"ticker": "string",
"status": "ACTIVE",
"lastPrice": "string",
"oraclePrice": "string",
"priceChange24H": "string",
"volume24H": "string",
Expand All @@ -1303,7 +1302,6 @@ fetch('https://indexer.v4testnet.dydx.exchange/v4/perpetualMarkets?limit=0',
"clobPairId": "string",
"ticker": "string",
"status": "ACTIVE",
"lastPrice": "string",
"oraclePrice": "string",
"priceChange24H": "string",
"volume24H": "string",
Expand Down Expand Up @@ -2831,7 +2829,6 @@ or
"clobPairId": "string",
"ticker": "string",
"status": "ACTIVE",
"lastPrice": "string",
"oraclePrice": "string",
"priceChange24H": "string",
"volume24H": "string",
Expand All @@ -2858,7 +2855,6 @@ or
|clobPairId|string|true|none|none|
|ticker|string|true|none|none|
|status|[PerpetualMarketStatus](#schemaperpetualmarketstatus)|true|none|none|
|lastPrice|string|true|none|none|
|oraclePrice|string|true|none|none|
|priceChange24H|string|true|none|none|
|volume24H|string|true|none|none|
Expand Down Expand Up @@ -2889,7 +2885,6 @@ or
"clobPairId": "string",
"ticker": "string",
"status": "ACTIVE",
"lastPrice": "string",
"oraclePrice": "string",
"priceChange24H": "string",
"volume24H": "string",
Expand All @@ -2910,7 +2905,6 @@ or
"clobPairId": "string",
"ticker": "string",
"status": "ACTIVE",
"lastPrice": "string",
"oraclePrice": "string",
"priceChange24H": "string",
"volume24H": "string",
Expand Down
4 changes: 0 additions & 4 deletions indexer/services/comlink/public/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,6 @@
"status": {
"$ref": "#/components/schemas/PerpetualMarketStatus"
},
"lastPrice": {
"type": "string"
},
"oraclePrice": {
"type": "string"
},
Expand Down Expand Up @@ -759,7 +756,6 @@
"clobPairId",
"ticker",
"status",
"lastPrice",
"oraclePrice",
"priceChange24H",
"volume24H",
Expand Down
3 changes: 0 additions & 3 deletions indexer/services/comlink/public/websocket-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,6 @@ Returns everything from `v4/perpetualMarkets` endpoint.
"status": "ACTIVE",
"baseAsset": "",
"quoteAsset": "",
"lastPrice": "0",
"oraclePrice": "27752.92",
"priceChange24H": "0",
"volume24H": "63894023.044245577",
Expand All @@ -830,7 +829,6 @@ Returns everything from `v4/perpetualMarkets` endpoint.
"status": "ACTIVE",
"baseAsset": "",
"quoteAsset": "",
"lastPrice": "0",
"oraclePrice": "1808.2",
"priceChange24H": "0",
"volume24H": "67487133.70842158",
Expand Down Expand Up @@ -894,7 +892,6 @@ interface TradingPerpetualMarketMessage {
atomicResolution?: number;
subticksPerTick?: number;
stepBaseQuantums?: number;
lastPrice?: string;
priceChange24H?: string;
volume24H?: string;
trades24H?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ export function perpetualMarketToResponseObject(
clobPairId: perpetualMarket.clobPairId,
ticker: perpetualMarket.ticker,
status: perpetualMarket.status,
lastPrice: perpetualMarket.lastPrice,
oraclePrice: market.oraclePrice!,
priceChange24H: perpetualMarket.priceChange24H,
volume24H: perpetualMarket.volume24H,
Expand Down
1 change: 0 additions & 1 deletion indexer/services/comlink/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ export interface PerpetualMarketResponseObject {
clobPairId: string;
ticker: string;
status: PerpetualMarketStatus;
lastPrice: string;
oraclePrice: string;
priceChange24H: string;
volume24H: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,6 @@ export async function expectPerpetualPosition(
// Values of the `PerpetualMarketCreateObject` which are hard-coded and not derived
// from PerpetualMarketCreate events.
export const HARDCODED_PERPETUAL_MARKET_VALUES: Object = {
lastPrice: '0',
priceChange24H: '0',
trades24H: 0,
volume24H: '0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ BEGIN
perpetual_market_record."ticker" = event_data->>'ticker';
perpetual_market_record."marketId" = (event_data->'marketId')::integer;
perpetual_market_record."status" = dydx_clob_pair_status_to_market_status(event_data->'status');
perpetual_market_record."lastPrice" = 0;
perpetual_market_record."priceChange24H" = 0;
perpetual_market_record."trades24H" = 0;
perpetual_market_record."volume24H" = 0;
Expand All @@ -33,4 +32,4 @@ BEGIN
dydx_to_jsonb(perpetual_market_record)
);
END;
$$ LANGUAGE plpgsql;
$$ LANGUAGE plpgsql;
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const RAW_TABLE_COLUMNS: string = `
\`ticker\` string,
\`marketId\` int,
\`status\` string,
\`lastPrice\` string,
\`priceChange24H\` string,
\`volume24H\` string,
\`trades24H\` int,
Expand All @@ -29,7 +28,6 @@ const TABLE_COLUMNS: string = `
"ticker",
"marketId",
"status",
${castToDouble('lastPrice')},
${castToDouble('priceChange24H')},
${castToDouble('volume24H')},
"trades24H",
Expand Down