Skip to content

Commit

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

Co-authored-by: Christopher-Li <Christopher-Li@users.noreply.github.com>
Co-authored-by: Will Liu <will@dydx.exchange>
  • Loading branch information
3 people authored May 29, 2024
1 parent 8738aa2 commit f4e497c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion indexer/services/socks/__tests__/lib/subscriptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('Subscriptions', () => {
const initialResponseUrlPatterns: Record<Channel, string[] | undefined> = {
[Channel.V4_ACCOUNTS]: [
'/v4/addresses/.+/subaccountNumber/.+',
'/v4/orders?.+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'],
Expand Down
31 changes: 18 additions & 13 deletions indexer/services/socks/src/lib/subscription.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { AxiosSafeServerError, logger, stats } from '@dydxprotocol-indexer/base';
import {
AxiosSafeServerError,
logger,
stats,
} from '@dydxprotocol-indexer/base';
import { CandleResolution, perpetualMarketRefresher } from '@dydxprotocol-indexer/postgres';
APIOrderStatus,
BestEffortOpenedStatus,
CandleResolution,
OrderStatus,
perpetualMarketRefresher,
} from '@dydxprotocol-indexer/postgres';
import WebSocket from 'ws';

import config from '../config';
import { createErrorMessage, createSubscribedMessage } from '../helpers/message';
import { sendMessage, sendMessageString } from '../helpers/wss';
import {
Channel,
MessageToForward,
RequestMethod,
Subscription,
SubscriptionInfo,
Channel, MessageToForward, RequestMethod, Subscription, SubscriptionInfo,
} from '../types';
import { axiosRequest } from './axios';
import { V4_MARKETS_ID, WS_CLOSE_CODE_POLICY_VIOLATION } from './constants';
Expand All @@ -23,6 +21,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 @@ -468,7 +473,7 @@ export class Subscriptions {
const {
ticker,
resolution,
} : {
}: {
ticker: string,
resolution?: CandleResolution,
} = this.parseCandleChannelId(id);
Expand All @@ -494,7 +499,7 @@ export class Subscriptions {
const {
address,
subaccountNumber,
} : {
}: {
address: string,
subaccountNumber: string,
} = this.parseSubaccountChannelId(id);
Expand All @@ -518,7 +523,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

0 comments on commit f4e497c

Please sign in to comment.