Skip to content

Commit

Permalink
[IND-486] update trades api with fill type (#779)
Browse files Browse the repository at this point in the history
  • Loading branch information
dydxwill authored Nov 9, 2023
1 parent 7db0ebf commit 52c8fb7
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 64 deletions.
2 changes: 1 addition & 1 deletion indexer/packages/kafka/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ export interface TradeContent {
price: string,
side: string,
createdAt: IsoString,
liquidation: boolean,
deleveraging: boolean,
type: FillType,
}

/* ------- MarketMessageContents ------- */
Expand Down
4 changes: 4 additions & 0 deletions indexer/services/comlink/public/api-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down Expand Up @@ -3062,6 +3063,7 @@ or
"side": "BUY",
"size": "string",
"price": "string",
"type": "MARKET",
"createdAt": "string",
"createdAtHeight": "string"
}
Expand All @@ -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|

Expand All @@ -3094,6 +3097,7 @@ or
"side": "BUY",
"size": "string",
"price": "string",
"type": "MARKET",
"createdAt": "string",
"createdAtHeight": "string"
}
Expand Down
4 changes: 4 additions & 0 deletions indexer/services/comlink/public/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,9 @@
"price": {
"type": "string"
},
"type": {
"$ref": "#/components/schemas/FillType"
},
"createdAt": {
"$ref": "#/components/schemas/IsoString"
},
Expand All @@ -871,6 +874,7 @@
"side",
"size",
"price",
"type",
"createdAt",
"createdAtHeight"
],
Expand Down
10 changes: 5 additions & 5 deletions indexer/services/comlink/public/websocket-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ interface TradeContent {
price: string,
side: string,
createdAt: IsoString,
liquidation: boolean,
type: FillType,
}
```

Expand All @@ -736,31 +736,31 @@ interface TradeContent {
"price": "27839",
"side": "BUY",
"createdAt": "2023-04-04T00:29:19.353Z",
"liquidation": false
"type": "LIQUIDATION"
},
{
"id": "38e64479-af09-5417-a795-195f83879156",
"size": "0.000000004",
"price": "27839",
"side": "BUY",
"createdAt": "2023-04-04T00:29:19.353Z",
"liquidation": false
"type": "LIQUIDATION"
},
{
"id": "d310c32c-f066-5ba8-a97d-10a29d9a6c84",
"size": "0.000000005",
"price": "27837",
"side": "SELL",
"createdAt": "2023-04-04T00:29:19.353Z",
"liquidation": false
"type": "MARKET"
},
{
"id": "dd1088b5-5cab-518f-a59c-4d5f735ab861",
"size": "0.000118502",
"price": "27837",
"side": "SELL",
"createdAt": "2023-04-04T00:29:19.353Z",
"liquidation": false
"type": "LIMIT"
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
1 change: 1 addition & 0 deletions indexer/services/comlink/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export interface TradeResponseObject {
side: OrderSide,
size: string,
price: string,
type: FillType,
createdAt: IsoString,
createdAtHeight: string,
}
Expand Down
36 changes: 18 additions & 18 deletions indexer/services/ender/__tests__/helpers/constants.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
},
],
};
Expand Down
15 changes: 4 additions & 11 deletions indexer/services/ender/__tests__/lib/kafka-publisher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ import {
generateFillSubaccountMessage,
generateOrderSubaccountMessage,
generatePerpetualPositionsContents,
isDeleveraging,
isLiquidation,
} from '../../helpers/kafka-helper';
import {
getPrice,
Expand Down Expand Up @@ -428,8 +426,7 @@ export abstract class AbstractOrderFillHandler<T> extends Handler<T> {
price: fill.price,
side: fill.side.toString(),
createdAt: fill.createdAt,
liquidation: isLiquidation(fill),
deleveraging: isDeleveraging(fill),
type: fill.type,
},
],
};
Expand Down
29 changes: 10 additions & 19 deletions indexer/services/ender/src/helpers/kafka-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 52c8fb7

Please sign in to comment.