Skip to content

Commit ad6b321

Browse files
[ENG-1102] Setup Indexer Endpoints for TWAP Orders/Fills (#3242)
1 parent c462a7a commit ad6b321

File tree

9 files changed

+378
-44
lines changed

9 files changed

+378
-44
lines changed

indexer/packages/postgres/src/stores/fill-table.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { getUuid } from '../helpers/uuid';
1414
import { getSubaccountQueryForParent } from '../lib/parent-subaccount-helpers';
1515
import FillModel from '../models/fill-model';
1616
import {
17+
CostOfFills,
1718
FillColumns,
1819
FillCreateObject,
1920
FillFromDatabase,
@@ -26,7 +27,6 @@ import {
2627
OrderedFillsWithFundingIndices,
2728
Ordering,
2829
OrderSide,
29-
CostOfFills,
3030
PaginationFromDatabase,
3131
QueryableField,
3232
QueryConfig,
@@ -96,6 +96,8 @@ export async function findAll(
9696
side,
9797
liquidity,
9898
type,
99+
includeTypes,
100+
excludeTypes,
99101
clobPairId,
100102
eventId,
101103
transactionHash,
@@ -165,6 +167,14 @@ export async function findAll(
165167
baseQuery = baseQuery.where(FillColumns.type, type);
166168
}
167169

170+
if (includeTypes !== undefined && includeTypes.length > 0) {
171+
baseQuery = baseQuery.whereIn(FillColumns.type, includeTypes);
172+
}
173+
174+
if (excludeTypes !== undefined && excludeTypes.length > 0) {
175+
baseQuery = baseQuery.whereNotIn(FillColumns.type, excludeTypes);
176+
}
177+
168178
if (clobPairId !== undefined) {
169179
baseQuery = baseQuery.where(FillColumns.clobPairId, clobPairId);
170180
}
@@ -246,8 +256,8 @@ export async function update(
246256
): Promise<FillFromDatabase | undefined> {
247257
const fill = await FillModel.query(
248258
Transaction.get(options.txId),
249-
// TODO fix expression typing so we dont have to use any
250-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
259+
// TODO fix expression typing so we dont have to use any
260+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
251261
).findById(fields.id).patch(fields as any).returning('*');
252262
// The objection types mistakenly think the query returns an array of fills.
253263
return fill as unknown as (FillFromDatabase | undefined);

indexer/packages/postgres/src/stores/order-table.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ export async function findAll(
6565
totalFilled,
6666
price,
6767
type,
68+
includeTypes,
69+
excludeTypes,
6870
statuses,
6971
reduceOnly,
7072
orderFlags,
@@ -153,6 +155,14 @@ export async function findAll(
153155
baseQuery = baseQuery.where(OrderColumns.type, type);
154156
}
155157

158+
if (includeTypes !== undefined && includeTypes.length > 0) {
159+
baseQuery = baseQuery.whereIn(OrderColumns.type, includeTypes);
160+
}
161+
162+
if (excludeTypes !== undefined && excludeTypes.length > 0) {
163+
baseQuery = baseQuery.whereNotIn(OrderColumns.type, excludeTypes);
164+
}
165+
156166
if (statuses !== undefined) {
157167
baseQuery = baseQuery.whereIn(OrderColumns.status, statuses);
158168
}

indexer/packages/postgres/src/types/query-types.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* ------- QUERY TYPES ------- */
22

33
import { CandleResolution } from './candle-types';
4-
import { Liquidity } from './fill-types';
4+
import { FillType, Liquidity } from './fill-types';
55
import { OrderSide, OrderStatus, OrderType } from './order-types';
66
import { PerpetualPositionStatus } from './perpetual-position-types';
77
import { PositionSide } from './position-types';
@@ -29,6 +29,8 @@ export enum QueryableField {
2929
TYPE = 'type',
3030
STATUS = 'status',
3131
STATUSES = 'statuses',
32+
INCLUDE_TYPES = 'includeTypes',
33+
EXCLUDE_TYPES = 'excludeTypes',
3234
POST_ONLY = 'postOnly',
3335
REDUCE_ONLY = 'reduceOnly',
3436
PERPETUAL_ID = 'perpetualId',
@@ -149,6 +151,8 @@ export interface OrderQueryConfig extends QueryConfig {
149151
[QueryableField.TOTAL_FILLED]?: string,
150152
[QueryableField.PRICE]?: string,
151153
[QueryableField.TYPE]?: OrderType,
154+
[QueryableField.INCLUDE_TYPES]?: OrderType[],
155+
[QueryableField.EXCLUDE_TYPES]?: OrderType[],
152156
[QueryableField.STATUSES]?: OrderStatus[],
153157
[QueryableField.POST_ONLY]?: boolean,
154158
[QueryableField.REDUCE_ONLY]?: boolean,
@@ -173,7 +177,9 @@ export interface FillQueryConfig extends QueryConfig {
173177
[QueryableField.SUBACCOUNT_ID]?: string[],
174178
[QueryableField.SIDE]?: OrderSide,
175179
[QueryableField.LIQUIDITY]?: Liquidity,
176-
[QueryableField.TYPE]?: OrderType,
180+
[QueryableField.TYPE]?: FillType,
181+
[QueryableField.INCLUDE_TYPES]?: FillType[],
182+
[QueryableField.EXCLUDE_TYPES]?: FillType[],
177183
[QueryableField.CLOB_PAIR_ID]?: string,
178184
[QueryableField.EVENT_ID]?: Buffer,
179185
[QueryableField.TRANSACTION_HASH]?: string,

indexer/services/comlink/public/api-documentation.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,8 @@ fetch(`${baseURL}/fills?address=string&subaccountNumber=0.1`,
12531253
|subaccountNumber|query|number(double)|true|none|
12541254
|market|query|string|false|none|
12551255
|marketType|query|[MarketType](#schemamarkettype)|false|none|
1256+
|includeTypes|query|array[string]|false|none|
1257+
|excludeTypes|query|array[string]|false|none|
12561258
|limit|query|number(double)|false|none|
12571259
|createdBeforeOrAtHeight|query|number(double)|false|none|
12581260
|createdBeforeOrAt|query|[IsoString](#schemaisostring)|false|none|
@@ -1264,6 +1266,18 @@ fetch(`${baseURL}/fills?address=string&subaccountNumber=0.1`,
12641266
|---|---|
12651267
|marketType|PERPETUAL|
12661268
|marketType|SPOT|
1269+
|includeTypes|LIMIT|
1270+
|includeTypes|LIQUIDATED|
1271+
|includeTypes|LIQUIDATION|
1272+
|includeTypes|DELEVERAGED|
1273+
|includeTypes|OFFSETTING|
1274+
|includeTypes|TWAP_SUBORDER|
1275+
|excludeTypes|LIMIT|
1276+
|excludeTypes|LIQUIDATED|
1277+
|excludeTypes|LIQUIDATION|
1278+
|excludeTypes|DELEVERAGED|
1279+
|excludeTypes|OFFSETTING|
1280+
|excludeTypes|TWAP_SUBORDER|
12671281

12681282
> Example responses
12691283
@@ -1366,9 +1380,28 @@ fetch(`${baseURL}/fills/parentSubaccount?address=string&parentSubaccountNumber=0
13661380
|---|---|---|---|---|
13671381
|address|query|string|true|none|
13681382
|parentSubaccountNumber|query|number(double)|true|none|
1383+
|includeTypes|query|array[string]|false|none|
1384+
|excludeTypes|query|array[string]|false|none|
13691385
|limit|query|number(double)|false|none|
13701386
|page|query|number(double)|false|none|
13711387

1388+
#### Enumerated Values
1389+
1390+
|Parameter|Value|
1391+
|---|---|
1392+
|includeTypes|LIMIT|
1393+
|includeTypes|LIQUIDATED|
1394+
|includeTypes|LIQUIDATION|
1395+
|includeTypes|DELEVERAGED|
1396+
|includeTypes|OFFSETTING|
1397+
|includeTypes|TWAP_SUBORDER|
1398+
|excludeTypes|LIMIT|
1399+
|excludeTypes|LIQUIDATED|
1400+
|excludeTypes|LIQUIDATION|
1401+
|excludeTypes|DELEVERAGED|
1402+
|excludeTypes|OFFSETTING|
1403+
|excludeTypes|TWAP_SUBORDER|
1404+
13721405
> Example responses
13731406
13741407
> 200 Response
@@ -2279,6 +2312,8 @@ fetch(`${baseURL}/orders?address=string&subaccountNumber=0.1`,
22792312
|ticker|query|string|false|none|
22802313
|side|query|[OrderSide](#schemaorderside)|false|none|
22812314
|type|query|[OrderType](#schemaordertype)|false|none|
2315+
|includeTypes|query|array[string]|false|none|
2316+
|excludeTypes|query|array[string]|false|none|
22822317
|status|query|array[any]|false|none|
22832318
|goodTilBlockBeforeOrAt|query|number(double)|false|none|
22842319
|goodTilBlockAfter|query|number(double)|false|none|
@@ -2301,6 +2336,24 @@ fetch(`${baseURL}/orders?address=string&subaccountNumber=0.1`,
23012336
|type|TAKE_PROFIT_MARKET|
23022337
|type|TWAP|
23032338
|type|TWAP_SUBORDER|
2339+
|includeTypes|LIMIT|
2340+
|includeTypes|MARKET|
2341+
|includeTypes|STOP_LIMIT|
2342+
|includeTypes|STOP_MARKET|
2343+
|includeTypes|TRAILING_STOP|
2344+
|includeTypes|TAKE_PROFIT|
2345+
|includeTypes|TAKE_PROFIT_MARKET|
2346+
|includeTypes|TWAP|
2347+
|includeTypes|TWAP_SUBORDER|
2348+
|excludeTypes|LIMIT|
2349+
|excludeTypes|MARKET|
2350+
|excludeTypes|STOP_LIMIT|
2351+
|excludeTypes|STOP_MARKET|
2352+
|excludeTypes|TRAILING_STOP|
2353+
|excludeTypes|TAKE_PROFIT|
2354+
|excludeTypes|TAKE_PROFIT_MARKET|
2355+
|excludeTypes|TWAP|
2356+
|excludeTypes|TWAP_SUBORDER|
23042357

23052358
> Example responses
23062359
@@ -2492,6 +2545,8 @@ fetch(`${baseURL}/orders/parentSubaccountNumber?address=string&parentSubaccountN
24922545
|ticker|query|string|false|none|
24932546
|side|query|[OrderSide](#schemaorderside)|false|none|
24942547
|type|query|[OrderType](#schemaordertype)|false|none|
2548+
|includeTypes|query|array[string]|false|none|
2549+
|excludeTypes|query|array[string]|false|none|
24952550
|status|query|array[any]|false|none|
24962551
|goodTilBlockBeforeOrAt|query|number(double)|false|none|
24972552
|goodTilBlockAfter|query|number(double)|false|none|
@@ -2514,6 +2569,24 @@ fetch(`${baseURL}/orders/parentSubaccountNumber?address=string&parentSubaccountN
25142569
|type|TAKE_PROFIT_MARKET|
25152570
|type|TWAP|
25162571
|type|TWAP_SUBORDER|
2572+
|includeTypes|LIMIT|
2573+
|includeTypes|MARKET|
2574+
|includeTypes|STOP_LIMIT|
2575+
|includeTypes|STOP_MARKET|
2576+
|includeTypes|TRAILING_STOP|
2577+
|includeTypes|TAKE_PROFIT|
2578+
|includeTypes|TAKE_PROFIT_MARKET|
2579+
|includeTypes|TWAP|
2580+
|includeTypes|TWAP_SUBORDER|
2581+
|excludeTypes|LIMIT|
2582+
|excludeTypes|MARKET|
2583+
|excludeTypes|STOP_LIMIT|
2584+
|excludeTypes|STOP_MARKET|
2585+
|excludeTypes|TRAILING_STOP|
2586+
|excludeTypes|TAKE_PROFIT|
2587+
|excludeTypes|TAKE_PROFIT_MARKET|
2588+
|excludeTypes|TWAP|
2589+
|excludeTypes|TWAP_SUBORDER|
25172590

25182591
> Example responses
25192592

indexer/services/comlink/public/swagger.json

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,6 +2508,28 @@
25082508
"$ref": "#/components/schemas/MarketType"
25092509
}
25102510
},
2511+
{
2512+
"in": "query",
2513+
"name": "includeTypes",
2514+
"required": false,
2515+
"schema": {
2516+
"type": "array",
2517+
"items": {
2518+
"$ref": "#/components/schemas/FillType"
2519+
}
2520+
}
2521+
},
2522+
{
2523+
"in": "query",
2524+
"name": "excludeTypes",
2525+
"required": false,
2526+
"schema": {
2527+
"type": "array",
2528+
"items": {
2529+
"$ref": "#/components/schemas/FillType"
2530+
}
2531+
}
2532+
},
25112533
{
25122534
"in": "query",
25132535
"name": "limit",
@@ -2580,6 +2602,28 @@
25802602
"type": "number"
25812603
}
25822604
},
2605+
{
2606+
"in": "query",
2607+
"name": "includeTypes",
2608+
"required": false,
2609+
"schema": {
2610+
"type": "array",
2611+
"items": {
2612+
"$ref": "#/components/schemas/FillType"
2613+
}
2614+
}
2615+
},
2616+
{
2617+
"in": "query",
2618+
"name": "excludeTypes",
2619+
"required": false,
2620+
"schema": {
2621+
"type": "array",
2622+
"items": {
2623+
"$ref": "#/components/schemas/FillType"
2624+
}
2625+
}
2626+
},
25832627
{
25842628
"in": "query",
25852629
"name": "limit",
@@ -3205,6 +3249,28 @@
32053249
"$ref": "#/components/schemas/OrderType"
32063250
}
32073251
},
3252+
{
3253+
"in": "query",
3254+
"name": "includeTypes",
3255+
"required": false,
3256+
"schema": {
3257+
"type": "array",
3258+
"items": {
3259+
"$ref": "#/components/schemas/OrderType"
3260+
}
3261+
}
3262+
},
3263+
{
3264+
"in": "query",
3265+
"name": "excludeTypes",
3266+
"required": false,
3267+
"schema": {
3268+
"type": "array",
3269+
"items": {
3270+
"$ref": "#/components/schemas/OrderType"
3271+
}
3272+
}
3273+
},
32083274
{
32093275
"in": "query",
32103276
"name": "status",
@@ -3331,6 +3397,28 @@
33313397
"$ref": "#/components/schemas/OrderType"
33323398
}
33333399
},
3400+
{
3401+
"in": "query",
3402+
"name": "includeTypes",
3403+
"required": false,
3404+
"schema": {
3405+
"type": "array",
3406+
"items": {
3407+
"$ref": "#/components/schemas/OrderType"
3408+
}
3409+
}
3410+
},
3411+
{
3412+
"in": "query",
3413+
"name": "excludeTypes",
3414+
"required": false,
3415+
"schema": {
3416+
"type": "array",
3417+
"items": {
3418+
"$ref": "#/components/schemas/OrderType"
3419+
}
3420+
}
3421+
},
33343422
{
33353423
"in": "query",
33363424
"name": "status",

0 commit comments

Comments
 (0)