Skip to content

Commit

Permalink
[BUG2-156] Only return recent best effort canceled orders. (#2716)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentwschau authored Feb 7, 2025
1 parent ffaa0d1 commit d425749
Show file tree
Hide file tree
Showing 11 changed files with 238 additions and 21 deletions.
22 changes: 22 additions & 0 deletions indexer/packages/postgres/__tests__/stores/order-table.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,28 @@ describe('Order store', () => {
goodTilBlock: null,
},
],
[
'goodTilBlockAfter',
'goodTilBlock',
{
goodTilBlockAfter: '1',
},
{
...defaultOrder,
goodTilBlockTime: null,
},
],
[
'goodTilBlockTimeAfter',
'goodTilBlockTime',
{
goodTilBlockTimeAfter: '2022-02-01T00:00:00.000Z',
},
{
...defaultOrderGoodTilBlockTime,
goodTilBlock: null,
},
],
])(
'Successfully finds all orders by %s, excludes orders with null %s',
async (
Expand Down
20 changes: 20 additions & 0 deletions indexer/packages/postgres/src/stores/order-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ export async function findAll(
reduceOnly,
orderFlags,
goodTilBlockBeforeOrAt,
goodTilBlockAfter,
goodTilBlockTimeBeforeOrAt,
goodTilBlockTimeAfter,
clientMetadata,
triggerPrice,
page,
Expand Down Expand Up @@ -166,6 +168,15 @@ export async function findAll(
goodTilBlockBeforeOrAt,
);
}
if (goodTilBlockAfter !== undefined) {
baseQuery = baseQuery.whereNotNull(
OrderColumns.goodTilBlock,
).andWhere(
OrderColumns.goodTilBlock,
'>',
goodTilBlockAfter,
);
}

// If filtering by `goodTilBlockTime`, filter out all rows with NULL `goodTilBlockTime`
if (goodTilBlockTimeBeforeOrAt !== undefined) {
Expand All @@ -177,6 +188,15 @@ export async function findAll(
goodTilBlockTimeBeforeOrAt,
);
}
if (goodTilBlockTimeAfter !== undefined) {
baseQuery = baseQuery.whereNotNull(
OrderColumns.goodTilBlockTime,
).andWhere(
OrderColumns.goodTilBlockTime,
'>',
goodTilBlockTimeAfter,
);
}

if (options.orderBy !== undefined) {
for (const [column, order] of options.orderBy) {
Expand Down
4 changes: 4 additions & 0 deletions indexer/packages/postgres/src/types/query-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ export enum QueryableField {
EFFECTIVE_BEFORE_OR_AT = 'effectiveBeforeOrAt',
EFFECTIVE_BEFORE_OR_AT_HEIGHT = 'effectiveBeforeOrAtHeight',
GOOD_TIL_BLOCK_BEFORE_OR_AT = 'goodTilBlockBeforeOrAt',
GOOD_TIL_BLOCK_AFTER = 'goodTilBlockAfter',
GOOD_TIL_BLOCK_TIME_BEFORE_OR_AT = 'goodTilBlockTimeBeforeOrAt',
GOOD_TIL_BLOCK_TIME_AFTER = 'goodTilBlockTimeAfter',
TICKER = 'ticker',
RESOLUTION = 'resolution',
FROM_ISO = 'fromISO',
Expand Down Expand Up @@ -141,7 +143,9 @@ export interface OrderQueryConfig extends QueryConfig {
[QueryableField.POST_ONLY]?: boolean,
[QueryableField.REDUCE_ONLY]?: boolean,
[QueryableField.GOOD_TIL_BLOCK_BEFORE_OR_AT]?: string,
[QueryableField.GOOD_TIL_BLOCK_AFTER]?: string,
[QueryableField.GOOD_TIL_BLOCK_TIME_BEFORE_OR_AT]?: string,
[QueryableField.GOOD_TIL_BLOCK_TIME_AFTER]?: string,
[QueryableField.ORDER_FLAGS]?: string,
[QueryableField.CLIENT_METADATA]?: string,
[QueryableField.TRIGGER_PRICE]?: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ describe('orders-controller#V4', () => {
redisTestConstants.defaultRedisOrder,
],
[
'goodTilBlock',
'goodTilBlockBeforeOrAt',
[
redisTestConstants.defaultRedisOrder,
redisOrderWithDifferentMarket,
Expand All @@ -424,7 +424,7 @@ describe('orders-controller#V4', () => {
redisTestConstants.defaultRedisOrder,
],
[
'goodTilBlock',
'goodTilBlockBeforeOrAt with isolated market',
[
redisTestConstants.defaultRedisOrder,
{
Expand All @@ -444,7 +444,42 @@ describe('orders-controller#V4', () => {
redisTestConstants.defaultRedisOrder,
],
[
'goodTilBlockTime',
'goodTilBlockAfter',
[
redisTestConstants.defaultRedisOrder,
redisOrderWithDifferentMarket,
redisTestConstants.defaultRedisOrderGoodTilBlockTime,
],
{
...defaultQueryParams,
goodTilBlockAfter: protocolTranslations.getGoodTilBlock(
redisOrderWithDifferentMarket.order!,
)! - 1,
},
redisOrderWithDifferentMarket,
],
[
'goodTilBlockAfter with isolated market',
[
redisTestConstants.defaultRedisOrder,
{
...redisTestConstants.isolatedMarketRedisOrder,
order: {
...redisTestConstants.isolatedMarketOrder,
goodTilBlock: 1200,
},
},
],
{
...defaultQueryParams,
goodTilBlockAfter: protocolTranslations.getGoodTilBlock(
redisTestConstants.defaultRedisOrder.order!,
)! - 1,
},
redisTestConstants.defaultRedisOrder,
],
[
'goodTilBlockTimeBeforeOrAt',
[
redisTestConstants.defaultRedisOrder,
redisTestConstants.defaultRedisOrderGoodTilBlockTime,
Expand All @@ -458,6 +493,19 @@ describe('orders-controller#V4', () => {
},
redisTestConstants.defaultRedisOrderGoodTilBlockTime,
],
[
'goodTilBlockTimeAfter',
[
redisTestConstants.defaultRedisOrder,
redisTestConstants.defaultRedisOrderGoodTilBlockTime,
newerRedisOrderGoodTilBlockTime,
],
{
...defaultQueryParams,
goodTilBlockTimeAfter: '2020-09-13T12:26:39.000Z',
},
newerRedisOrderGoodTilBlockTime,
],
])('Successfully filters redis order by %s', async (
_testName: string,
redisOrders: RedisOrder[],
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 @@ -2001,7 +2001,9 @@ fetch(`${baseURL}/orders?address=string&subaccountNumber=0.1`,
|type|query|[OrderType](#schemaordertype)|false|none|
|status|query|array[any]|false|none|
|goodTilBlockBeforeOrAt|query|number(double)|false|none|
|goodTilBlockAfter|query|number(double)|false|none|
|goodTilBlockTimeBeforeOrAt|query|[IsoString](#schemaisostring)|false|none|
|goodTilBlockTimeAfter|query|[IsoString](#schemaisostring)|false|none|
|returnLatestOrders|query|boolean|false|none|

#### Enumerated Values
Expand Down Expand Up @@ -2195,7 +2197,9 @@ fetch(`${baseURL}/orders/parentSubaccountNumber?address=string&parentSubaccountN
|type|query|[OrderType](#schemaordertype)|false|none|
|status|query|array[any]|false|none|
|goodTilBlockBeforeOrAt|query|number(double)|false|none|
|goodTilBlockAfter|query|number(double)|false|none|
|goodTilBlockTimeBeforeOrAt|query|[IsoString](#schemaisostring)|false|none|
|goodTilBlockTimeAfter|query|[IsoString](#schemaisostring)|false|none|
|returnLatestOrders|query|boolean|false|none|

#### Enumerated Values
Expand Down
34 changes: 34 additions & 0 deletions indexer/services/comlink/public/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2750,6 +2750,15 @@
"type": "number"
}
},
{
"in": "query",
"name": "goodTilBlockAfter",
"required": false,
"schema": {
"format": "double",
"type": "number"
}
},
{
"in": "query",
"name": "goodTilBlockTimeBeforeOrAt",
Expand All @@ -2758,6 +2767,14 @@
"$ref": "#/components/schemas/IsoString"
}
},
{
"in": "query",
"name": "goodTilBlockTimeAfter",
"required": false,
"schema": {
"$ref": "#/components/schemas/IsoString"
}
},
{
"in": "query",
"name": "returnLatestOrders",
Expand Down Expand Up @@ -2859,6 +2876,15 @@
"type": "number"
}
},
{
"in": "query",
"name": "goodTilBlockAfter",
"required": false,
"schema": {
"format": "double",
"type": "number"
}
},
{
"in": "query",
"name": "goodTilBlockTimeBeforeOrAt",
Expand All @@ -2867,6 +2893,14 @@
"$ref": "#/components/schemas/IsoString"
}
},
{
"in": "query",
"name": "goodTilBlockTimeAfter",
"required": false,
"schema": {
"$ref": "#/components/schemas/IsoString"
}
},
{
"in": "query",
"name": "returnLatestOrders",
Expand Down
Loading

0 comments on commit d425749

Please sign in to comment.