diff --git a/indexer/packages/kafka/src/constants.ts b/indexer/packages/kafka/src/constants.ts index 51821ea5a4..9f28e5d29e 100644 --- a/indexer/packages/kafka/src/constants.ts +++ b/indexer/packages/kafka/src/constants.ts @@ -2,6 +2,6 @@ export const TO_ENDER_TOPIC: string = 'to-ender'; export const ORDERBOOKS_WEBSOCKET_MESSAGE_VERSION: string = '1.0.0'; export const SUBACCOUNTS_WEBSOCKET_MESSAGE_VERSION: string = '2.4.0'; -export const TRADES_WEBSOCKET_MESSAGE_VERSION: string = '1.1.0'; +export const TRADES_WEBSOCKET_MESSAGE_VERSION: string = '2.1.0'; export const MARKETS_WEBSOCKET_MESSAGE_VERSION: string = '1.0.0'; export const CANDLES_WEBSOCKET_MESSAGE_VERSION: string = '1.0.0'; diff --git a/indexer/packages/postgres/src/types/websocket-message-types.ts b/indexer/packages/postgres/src/types/websocket-message-types.ts index 56b9c3f9b0..5b81b64c09 100644 --- a/indexer/packages/postgres/src/types/websocket-message-types.ts +++ b/indexer/packages/postgres/src/types/websocket-message-types.ts @@ -175,8 +175,7 @@ export interface TradeContent { price: string, side: string, createdAt: IsoString, - liquidation: boolean, - deleveraging: boolean, + type: FillType, } /* ------- MarketMessageContents ------- */ diff --git a/indexer/services/comlink/public/api-documentation.md b/indexer/services/comlink/public/api-documentation.md index 82bea70654..59a4c0395e 100644 --- a/indexer/services/comlink/public/api-documentation.md +++ b/indexer/services/comlink/public/api-documentation.md @@ -1639,6 +1639,7 @@ fetch('https://indexer.v4testnet.dydx.exchange/v4/trades/perpetualMarket/{ticker "side": "BUY", "size": "string", "price": "string", + "type": "MARKET", "createdAt": "string", "createdAtHeight": "string" } @@ -3062,6 +3063,7 @@ or "side": "BUY", "size": "string", "price": "string", + "type": "MARKET", "createdAt": "string", "createdAtHeight": "string" } @@ -3076,6 +3078,7 @@ or |side|[OrderSide](#schemaorderside)|true|none|none| |size|string|true|none|none| |price|string|true|none|none| +|type|[FillType](#schemafilltype)|true|none|none| |createdAt|[IsoString](#schemaisostring)|true|none|none| |createdAtHeight|string|true|none|none| @@ -3094,6 +3097,7 @@ or "side": "BUY", "size": "string", "price": "string", + "type": "MARKET", "createdAt": "string", "createdAtHeight": "string" } diff --git a/indexer/services/comlink/public/swagger.json b/indexer/services/comlink/public/swagger.json index 324e83501e..ac9488555e 100644 --- a/indexer/services/comlink/public/swagger.json +++ b/indexer/services/comlink/public/swagger.json @@ -859,6 +859,9 @@ "price": { "type": "string" }, + "type": { + "$ref": "#/components/schemas/FillType" + }, "createdAt": { "$ref": "#/components/schemas/IsoString" }, @@ -871,6 +874,7 @@ "side", "size", "price", + "type", "createdAt", "createdAtHeight" ], diff --git a/indexer/services/comlink/public/websocket-documentation.md b/indexer/services/comlink/public/websocket-documentation.md index e9c35463a6..bde62d3c89 100644 --- a/indexer/services/comlink/public/websocket-documentation.md +++ b/indexer/services/comlink/public/websocket-documentation.md @@ -714,7 +714,7 @@ interface TradeContent { price: string, side: string, createdAt: IsoString, - liquidation: boolean, + type: FillType, } ``` @@ -736,7 +736,7 @@ interface TradeContent { "price": "27839", "side": "BUY", "createdAt": "2023-04-04T00:29:19.353Z", - "liquidation": false + "type": "LIQUIDATION" }, { "id": "38e64479-af09-5417-a795-195f83879156", @@ -744,7 +744,7 @@ interface TradeContent { "price": "27839", "side": "BUY", "createdAt": "2023-04-04T00:29:19.353Z", - "liquidation": false + "type": "LIQUIDATION" }, { "id": "d310c32c-f066-5ba8-a97d-10a29d9a6c84", @@ -752,7 +752,7 @@ interface TradeContent { "price": "27837", "side": "SELL", "createdAt": "2023-04-04T00:29:19.353Z", - "liquidation": false + "type": "MARKET" }, { "id": "dd1088b5-5cab-518f-a59c-4d5f735ab861", @@ -760,7 +760,7 @@ interface TradeContent { "price": "27837", "side": "SELL", "createdAt": "2023-04-04T00:29:19.353Z", - "liquidation": false + "type": "LIMIT" }, ], }, diff --git a/indexer/services/comlink/src/request-helpers/request-transformer.ts b/indexer/services/comlink/src/request-helpers/request-transformer.ts index 4f6bbbcad1..ac42f78370 100644 --- a/indexer/services/comlink/src/request-helpers/request-transformer.ts +++ b/indexer/services/comlink/src/request-helpers/request-transformer.ts @@ -177,6 +177,7 @@ export function fillToTradeResponseObject( side: fill.side, size: fill.size, price: fill.price, + type: fill.type, createdAt: fill.createdAt, createdAtHeight: fill.createdAtHeight, }; diff --git a/indexer/services/comlink/src/types.ts b/indexer/services/comlink/src/types.ts index 60f7f33198..bb15fe85f0 100644 --- a/indexer/services/comlink/src/types.ts +++ b/indexer/services/comlink/src/types.ts @@ -174,6 +174,7 @@ export interface TradeResponseObject { side: OrderSide, size: string, price: string, + type: FillType, createdAt: IsoString, createdAtHeight: string, } diff --git a/indexer/services/ender/__tests__/helpers/constants.ts b/indexer/services/ender/__tests__/helpers/constants.ts index 1e4f8f5a2d..9f69cdd730 100644 --- a/indexer/services/ender/__tests__/helpers/constants.ts +++ b/indexer/services/ender/__tests__/helpers/constants.ts @@ -1,36 +1,36 @@ import { SUBACCOUNTS_WEBSOCKET_MESSAGE_VERSION } from '@dydxprotocol-indexer/kafka'; -import { testConstants, TradeContent } from '@dydxprotocol-indexer/postgres'; +import { FillType, testConstants, TradeContent } from '@dydxprotocol-indexer/postgres'; import { bigIntToBytes, + ORDER_FLAG_CONDITIONAL, ORDER_FLAG_LONG_TERM, ORDER_FLAG_SHORT_TERM, - ORDER_FLAG_CONDITIONAL, } from '@dydxprotocol-indexer/v4-proto-parser'; import { + AssetCreateEventV1, + ClobPairStatus, + DeleveragingEventV1, FundingEventV1_Type, - LiquidationOrderV1, - MarketBaseEventV1, - MarketEventV1, IndexerOrder, + IndexerOrder_ConditionType, IndexerOrder_Side, IndexerOrder_TimeInForce, - OrderFillEventV1, IndexerOrderId, - StatefulOrderEventV1, IndexerSubaccountId, + LiquidationOrderV1, + LiquidityTierUpsertEventV1, + MarketBaseEventV1, + MarketEventV1, + OrderFillEventV1, + OrderRemovalReason, + PerpetualMarketCreateEventV1, + StatefulOrderEventV1, SubaccountMessage, SubaccountUpdateEventV1, Timestamp, TransferEventV1, - IndexerOrder_ConditionType, - OrderRemovalReason, - AssetCreateEventV1, - PerpetualMarketCreateEventV1, - ClobPairStatus, - LiquidityTierUpsertEventV1, - UpdatePerpetualEventV1, UpdateClobPairEventV1, - DeleveragingEventV1, + UpdatePerpetualEventV1, } from '@dydxprotocol-indexer/v4-protos'; import Long from 'long'; import { DateTime } from 'luxon'; @@ -40,7 +40,8 @@ import { SubaccountUpdate } from '../../src/lib/translated-types'; import { ConsolidatedKafkaEvent, FundingEventMessage, - OrderFillEventWithLiquidation, OrderFillEventWithOrder, + OrderFillEventWithLiquidation, + OrderFillEventWithOrder, SingleTradeMessage, } from '../../src/lib/types'; import { contentToSingleTradeMessage, createConsolidatedKafkaEventFromTrade } from './kafka-publisher-helpers'; @@ -324,8 +325,7 @@ export const defaultTradeContent: TradeContent = { price: '10000', side: 'BUY', createdAt: 'createdAt', - liquidation: true, - deleveraging: false, + type: FillType.MARKET, }; export const defaultTradeMessage: SingleTradeMessage = contentToSingleTradeMessage( defaultTradeContent, diff --git a/indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts b/indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts index 4f5eadcaf7..684dc0665b 100644 --- a/indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts +++ b/indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts @@ -58,8 +58,6 @@ import { generateFillSubaccountMessage, generatePerpetualMarketMessage, generatePerpetualPositionsContents, - isDeleveraging, - isLiquidation, } from '../../src/helpers/kafka-helper'; import { protoTimestampToDate } from '../../src/lib/helper'; import { DydxIndexerSubtypes, VulcanMessage } from '../../src/lib/types'; @@ -807,8 +805,7 @@ export async function expectDefaultTradeKafkaMessageFromTakerFillId( price: takerFill!.price, side: takerFill!.side.toString(), createdAt: takerFill!.createdAt, - liquidation: isLiquidation(takerFill!), - deleveraging: isDeleveraging(takerFill!), + type: takerFill!.type, }, ], }; diff --git a/indexer/services/ender/__tests__/lib/kafka-publisher.test.ts b/indexer/services/ender/__tests__/lib/kafka-publisher.test.ts index f125aed5f4..6e915a86b0 100644 --- a/indexer/services/ender/__tests__/lib/kafka-publisher.test.ts +++ b/indexer/services/ender/__tests__/lib/kafka-publisher.test.ts @@ -19,11 +19,7 @@ import { import { IndexerSubaccountId, SubaccountMessage, TradeMessage } from '@dydxprotocol-indexer/v4-protos'; import Big from 'big.js'; import _ from 'lodash'; -import { - AnnotatedSubaccountMessage, - ConsolidatedKafkaEvent, - SingleTradeMessage, -} from '../../src/lib/types'; +import { AnnotatedSubaccountMessage, ConsolidatedKafkaEvent, SingleTradeMessage } from '../../src/lib/types'; import { KafkaPublisher } from '../../src/lib/kafka-publisher'; import { @@ -413,8 +409,7 @@ describe('kafka-publisher', () => { price: '10000', side: 'side', createdAt: 'today', - liquidation: false, - deleveraging: false, + type: FillType.LIMIT, }; const singleTrade1: SingleTradeMessage = contentToSingleTradeMessage( tradeContent1, @@ -427,8 +422,7 @@ describe('kafka-publisher', () => { price: '12000', side: 'side', createdAt: 'today', - liquidation: false, - deleveraging: false, + type: FillType.LIMIT, }; const singleTrade2: SingleTradeMessage = contentToSingleTradeMessage( tradeContent2, @@ -442,8 +436,7 @@ describe('kafka-publisher', () => { price: '1000', side: 'side', createdAt: 'today', - liquidation: false, - deleveraging: false, + type: FillType.LIMIT, }; const singleTrade3: SingleTradeMessage = contentToSingleTradeMessage( tradeContent3, diff --git a/indexer/services/ender/src/handlers/order-fills/abstract-order-fill-handler.ts b/indexer/services/ender/src/handlers/order-fills/abstract-order-fill-handler.ts index 0c0c864b67..d1e718817d 100644 --- a/indexer/services/ender/src/handlers/order-fills/abstract-order-fill-handler.ts +++ b/indexer/services/ender/src/handlers/order-fills/abstract-order-fill-handler.ts @@ -45,8 +45,6 @@ import { generateFillSubaccountMessage, generateOrderSubaccountMessage, generatePerpetualPositionsContents, - isDeleveraging, - isLiquidation, } from '../../helpers/kafka-helper'; import { getPrice, @@ -428,8 +426,7 @@ export abstract class AbstractOrderFillHandler extends Handler { price: fill.price, side: fill.side.toString(), createdAt: fill.createdAt, - liquidation: isLiquidation(fill), - deleveraging: isDeleveraging(fill), + type: fill.type, }, ], }; diff --git a/indexer/services/ender/src/helpers/kafka-helper.ts b/indexer/services/ender/src/helpers/kafka-helper.ts index 8e1f1fa579..169940e2cf 100644 --- a/indexer/services/ender/src/helpers/kafka-helper.ts +++ b/indexer/services/ender/src/helpers/kafka-helper.ts @@ -2,32 +2,31 @@ import { apiTranslations, AssetFromDatabase, AssetPositionFromDatabase, + AssetPositionSubaccountMessageContents, AssetsMap, FillFromDatabase, FillSubaccountMessageContents, - FillType, + helpers, + liquidityTierRefresher, + LiquidityTiersFromDatabase, + LiquidityTiersMap, MarketMessageContents, MarketsMap, OraclePriceFromDatabase, OrderFromDatabase, OrderSubaccountMessageContents, + PerpetualMarketColumns, PerpetualMarketFromDatabase, PerpetualMarketsMap, + PerpetualPositionFromDatabase, PerpetualPositionSubaccountMessageContents, PositionSide, SubaccountMessageContents, - TransferFromDatabase, - helpers, - UpdatedPerpetualPositionSubaccountKafkaObject, - PerpetualPositionFromDatabase, - AssetPositionSubaccountMessageContents, SubaccountTable, - LiquidityTiersFromDatabase, - liquidityTierRefresher, - LiquidityTiersMap, - PerpetualMarketColumns, - TradingPerpetualMarketMessage, TradingMarketMessageContents, + TradingPerpetualMarketMessage, + TransferFromDatabase, + UpdatedPerpetualPositionSubaccountKafkaObject, } from '@dydxprotocol-indexer/postgres'; import { SubaccountId } from '@dydxprotocol-indexer/v4-protos'; import Big from 'big.js'; @@ -274,14 +273,6 @@ export function generateOraclePriceContents( }; } -export function isLiquidation(fill: FillFromDatabase): boolean { - return fill.type === FillType.LIQUIDATION || fill.type === FillType.LIQUIDATED; -} - -export function isDeleveraging(fill: FillFromDatabase): boolean { - return fill.type === FillType.DELEVERAGED || fill.type === FillType.OFFSETTING; -} - export function generateFillSubaccountMessage( fill: FillFromDatabase, ticker: string,