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

Restore prior API ordering when page param is not specified #1560

Merged
merged 3 commits into from
May 21, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,13 @@ describe('fills-controller#V4', () => {
);
});

it('Get /fills with market gets fills ordered by createdAtHeight descending', async () => {
it('Get /fills with market gets correctly ordered fills', async () => {
// Order and fill for BTC-USD
await OrderTable.create(testConstants.defaultOrder);
await FillTable.create(testConstants.defaultFill);
await FillTable.create({
...testConstants.defaultFill,
eventId: testConstants.defaultTendermintEventId2,
});

// Order and fill for ETH-USD
const ethOrder: OrderFromDatabase = await OrderTable.create({
Expand All @@ -140,11 +143,10 @@ describe('fills-controller#V4', () => {
...testConstants.defaultFill,
orderId: ethOrder.id,
clobPairId: testConstants.defaultPerpetualMarket2.clobPairId,
eventId: testConstants.defaultTendermintEventId2,
createdAtHeight: '1',
});

const response: request.Response = await sendRequest({
let response: request.Response = await sendRequest({
type: RequestMethod.GET,
path: `/v4/fills?address=${testConstants.defaultAddress}` +
`&subaccountNumber=${testConstants.defaultSubaccount.subaccountNumber}`,
Expand Down Expand Up @@ -179,17 +181,36 @@ describe('fills-controller#V4', () => {
},
];

// Fills should be returned sorted by createdAtHeight in descending order.
// Page is not specified, so fills should be returned sorted by createdAtHeight
// in descending order.
expect(response.body.fills).toHaveLength(2);
expect(response.body.fills).toEqual(
expect.arrayContaining([
[
expect.objectContaining({
...expected[0],
}),
expect.objectContaining({
...expected[1],
}),
]),
],
);

response = await sendRequest({
type: RequestMethod.GET,
path: `/v4/fills?address=${testConstants.defaultAddress}` +
`&subaccountNumber=${testConstants.defaultSubaccount.subaccountNumber}&page=1&limit=2`,
});
// Page is specified, so fills should be sorted by eventId in ascending order.
expect(response.body.fills).toHaveLength(2);
expect(response.body.fills).toEqual(
[
expect.objectContaining({
...expected[1],
}),
expect.objectContaining({
...expected[0],
}),
],
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class FillsController extends Controller {
page,
},
[QueryableField.LIMIT],
{ orderBy: [[FillColumns.eventId, Ordering.ASC]] },
page !== undefined ? { orderBy: [[FillColumns.eventId, Ordering.ASC]] } : undefined,
);

const clobPairIdToPerpetualMarket: Record<
Expand Down Expand Up @@ -168,7 +168,7 @@ class FillsController extends Controller {
page,
},
[QueryableField.LIMIT],
{ orderBy: [[FillColumns.eventId, Ordering.ASC]] },
page !== undefined ? { orderBy: [[FillColumns.eventId, Ordering.ASC]] } : undefined,
);

const clobPairIdToPerpetualMarket: Record<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class TradesController extends Controller {
page,
},
[QueryableField.LIQUIDITY, QueryableField.CLOB_PAIR_ID, QueryableField.LIMIT],
{ orderBy: [[FillColumns.eventId, Ordering.ASC]] },
page !== undefined ? { orderBy: [[FillColumns.eventId, Ordering.ASC]] } : undefined,
);

return {
Expand Down
Loading