Skip to content

Commit

Permalink
Add BEC to initial subaccount orders socks channel (#1500)
Browse files Browse the repository at this point in the history
* Add BEC to initial subaccount orders socks channel

* fix tests
  • Loading branch information
Christopher-Li authored May 13, 2024
1 parent bbcf4ff commit 54ceae6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
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 @@ -51,15 +51,15 @@ describe('Subscriptions', () => {
const initialResponseUrlPatterns: Record<Channel, string[] | undefined> = {
[Channel.V4_ACCOUNTS]: [
'/v4/addresses/.+/subaccountNumber/.+',
'/v4/orders?.+subaccountNumber.+OPEN,UNTRIGGERED,BEST_EFFORT_OPENED',
'/v4/orders?.+subaccountNumber.+OPEN,UNTRIGGERED,BEST_EFFORT_OPENED,BEST_EFFORT_CANCELED',
],
[Channel.V4_CANDLES]: ['/v4/candles/perpetualMarkets/.+?resolution=.+'],
[Channel.V4_MARKETS]: ['/v4/perpetualMarkets'],
[Channel.V4_ORDERBOOK]: ['/v4/orderbooks/perpetualMarket/.+'],
[Channel.V4_TRADES]: ['/v4/trades/perpetualMarket/.+'],
[Channel.V4_PARENT_ACCOUNTS]: [
'/v4/addresses/.+/parentSubaccountNumber/.+',
'/v4/orders/parentSubaccountNumber?.+parentSubaccountNumber.+OPEN,UNTRIGGERED,BEST_EFFORT_OPENED',
'/v4/orders/parentSubaccountNumber?.+parentSubaccountNumber.+OPEN,UNTRIGGERED,BEST_EFFORT_OPENED,BEST_EFFORT_CANCELED',
],
};
const initialMessage: Object = { a: 'b' };
Expand Down
19 changes: 16 additions & 3 deletions indexer/services/socks/src/lib/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import {
stats,
} from '@dydxprotocol-indexer/base';
import {
CHILD_SUBACCOUNT_MULTIPLIER, CandleResolution, MAX_PARENT_SUBACCOUNTS, perpetualMarketRefresher,
APIOrderStatus,
BestEffortOpenedStatus,
CHILD_SUBACCOUNT_MULTIPLIER,
CandleResolution,
MAX_PARENT_SUBACCOUNTS,
OrderStatus,
perpetualMarketRefresher,
} from '@dydxprotocol-indexer/postgres';
import WebSocket from 'ws';

Expand All @@ -25,6 +31,13 @@ import { RateLimiter } from './rate-limit';

const COMLINK_URL: string = `http://${config.COMLINK_URL}`;
const EMPTY_INITIAL_RESPONSE: string = '{}';
const VALID_ORDER_STATUS_FOR_INITIAL_SUBACCOUNT_RESPONSE: APIOrderStatus[] = [
OrderStatus.OPEN,
OrderStatus.UNTRIGGERED,
BestEffortOpenedStatus.BEST_EFFORT_OPENED,
OrderStatus.BEST_EFFORT_CANCELED,
];
const VALID_ORDER_STATUS: string = VALID_ORDER_STATUS_FOR_INITIAL_SUBACCOUNT_RESPONSE.join(',');

export class Subscriptions {
// Maps channels and ids to a list of websocket connections subscribed to them
Expand Down Expand Up @@ -537,7 +550,7 @@ export class Subscriptions {
// TODO(DEC-1462): Use the /active-orders endpoint once it's added.
axiosRequest({
method: RequestMethod.GET,
url: `${COMLINK_URL}/v4/orders?address=${address}&subaccountNumber=${subaccountNumber}&status=OPEN,UNTRIGGERED,BEST_EFFORT_OPENED`,
url: `${COMLINK_URL}/v4/orders?address=${address}&subaccountNumber=${subaccountNumber}&status=${VALID_ORDER_STATUS}`,
timeout: config.INITIAL_GET_TIMEOUT_MS,
headers: {
'cf-ipcountry': country,
Expand Down Expand Up @@ -602,7 +615,7 @@ export class Subscriptions {
// TODO(DEC-1462): Use the /active-orders endpoint once it's added.
axiosRequest({
method: RequestMethod.GET,
url: `${COMLINK_URL}/v4/orders/parentSubaccountNumber?address=${address}&parentSubaccountNumber=${subaccountNumber}&status=OPEN,UNTRIGGERED,BEST_EFFORT_OPENED`,
url: `${COMLINK_URL}/v4/orders/parentSubaccountNumber?address=${address}&parentSubaccountNumber=${subaccountNumber}&status=${VALID_ORDER_STATUS}`,
timeout: config.INITIAL_GET_TIMEOUT_MS,
headers: {
'cf-ipcountry': country,
Expand Down

0 comments on commit 54ceae6

Please sign in to comment.