Skip to content

Commit

Permalink
Fix bug with socks subaccount subscription with best effort canceled …
Browse files Browse the repository at this point in the history
…logic. (#2718)
  • Loading branch information
vincentwschau authored Feb 10, 2025
1 parent d425749 commit a601005
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,23 @@ router.get(
options: { gt: 0 },
},
},
goodTilBlockAfter: {
in: 'query',
optional: true,
isInt: {
options: { gt: 0 },
},
},
goodTilBlockTimeBeforeOrAt: {
in: 'query',
optional: true,
isISO8601: true,
},
goodTilBlockTimeAfter: {
in: 'query',
optional: true,
isISO8601: true,
},
returnLatestOrders: {
in: 'query',
isBoolean: true,
Expand Down
4 changes: 2 additions & 2 deletions indexer/services/socks/__tests__/lib/subscriptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('Subscriptions', () => {
[Channel.V4_ACCOUNTS]: [
'/v4/addresses/.+/subaccountNumber/.+',
'/v4/orders?.+subaccountNumber.+OPEN,UNTRIGGERED,BEST_EFFORT_OPENED',
'/v4/orders?.+subaccountNumber.+BEST_EFFORT_CANCELED.+goodTilBlockAfter.+',
'/v4/orders?.+subaccountNumber.+BEST_EFFORT_CANCELED.+goodTilBlockAfter=[0-9]+',
],
[Channel.V4_CANDLES]: ['/v4/candles/perpetualMarkets/.+?resolution=.+'],
[Channel.V4_MARKETS]: ['/v4/perpetualMarkets'],
Expand All @@ -68,7 +68,7 @@ describe('Subscriptions', () => {
[Channel.V4_PARENT_ACCOUNTS]: [
'/v4/addresses/.+/parentSubaccountNumber/.+',
'/v4/orders/parentSubaccountNumber?.+parentSubaccountNumber.+OPEN,UNTRIGGERED,BEST_EFFORT_OPENED',
'/v4/orders/parentSubaccountNumber?.+parentSubaccountNumber.+BEST_EFFORT_CANCELED.+goodTilBlockAfter.+',
'/v4/orders/parentSubaccountNumber?.+parentSubaccountNumber.+BEST_EFFORT_CANCELED.+goodTilBlockAfter=[0-9]+',
],
[Channel.V4_BLOCK_HEIGHT]: ['v4/height'],
};
Expand Down
14 changes: 13 additions & 1 deletion indexer/services/socks/src/lib/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ export class Subscriptions {
}),
axiosRequest({
method: RequestMethod.GET,
url: `${COMLINK_URL}/v4/orders?address=${address}&subaccountNumber=${subaccountNumber}&status=BEST_EFFORT_CANCELED&goodTilBlockAfter=$${Math.max(numBlockHeight - 20, 1)}`,
url: `${COMLINK_URL}/v4/orders?address=${address}&subaccountNumber=${subaccountNumber}&status=BEST_EFFORT_CANCELED&goodTilBlockAfter=${Math.max(numBlockHeight - 20, 1)}`,
timeout: config.INITIAL_GET_TIMEOUT_MS,
headers: {
'cf-ipcountry': country,
Expand All @@ -608,6 +608,12 @@ export class Subscriptions {
blockHeight,
});
} catch (error) {
logger.error({
at: 'getInitialResponseForSubaccountSubscription',
message: 'Error on getting initial response for subaccount subscription',
id,
error,
});
// The subaccounts API endpoint returns a 404 for subaccounts that are not indexed, however
// such subaccounts can be subscribed to and events can be sent when the subaccounts are
// indexed to an existing subscription.
Expand Down Expand Up @@ -694,6 +700,12 @@ export class Subscriptions {
blockHeight,
});
} catch (error) {
logger.error({
at: 'getInitialResponseForParentSubaccountSubscription',
message: 'Error on getting initial response for subaccount subscription',
id,
error,
});
// The subaccounts API endpoint returns a 404 for subaccounts that are not indexed, however
// such subaccounts can be subscribed to and events can be sent when the subaccounts are
// indexed to an existing subscription.
Expand Down

0 comments on commit a601005

Please # to comment.