pass list of markets into DLOBSubscriberIO

This commit is contained in:
wphan
2023-12-24 01:35:17 -08:00
parent 70d9227b6c
commit eb4faa6cf1
2 changed files with 42 additions and 33 deletions

View File

@@ -2,16 +2,11 @@ import {
BN,
DLOBSubscriber,
DLOBSubscriptionConfig,
DevnetPerpMarkets,
DevnetSpotMarkets,
L2OrderBookGenerator,
MainnetPerpMarkets,
MainnetSpotMarkets,
MarketType,
groupL2,
isVariant,
} from '@drift-labs/sdk';
import { driftEnv } from '../publishers/dlobPublisher';
import { RedisClient } from '../utils/redisClient';
import {
SubscriberLookup,
@@ -33,6 +28,11 @@ type wsMarketL2Args = {
updateOnChange?: boolean;
};
export type wsMarketInfo = {
marketIndex: number;
marketName: string;
};
export class DLOBSubscriberIO extends DLOBSubscriber {
public marketL2Args: wsMarketL2Args[] = [];
public lastSeenL2Formatted: Map<MarketType, Map<number, any>>;
@@ -41,6 +41,8 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
constructor(
config: DLOBSubscriptionConfig & {
redisClient: RedisClient;
perpMarketsInfos: wsMarketInfo[];
spotMarketsInfos: wsMarketInfo[];
spotMarketSubscribers: SubscriberLookup;
}
) {
@@ -52,17 +54,11 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
this.lastSeenL2Formatted.set(MarketType.SPOT, new Map());
this.lastSeenL2Formatted.set(MarketType.PERP, new Map());
// Add all active markets to the market L2Args
const perpMarkets =
driftEnv === 'devnet' ? DevnetPerpMarkets : MainnetPerpMarkets;
const spotMarkets =
driftEnv === 'devnet' ? DevnetSpotMarkets : MainnetSpotMarkets;
for (const market of perpMarkets) {
for (const market of config.perpMarketsInfos) {
this.marketL2Args.push({
marketIndex: market.marketIndex,
marketType: MarketType.PERP,
marketName: market.symbol,
marketName: market.marketName,
depth: -1,
numVammOrders: 100,
includeVamm: true,
@@ -70,11 +66,11 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
fallbackL2Generators: [],
});
}
for (const market of spotMarkets) {
for (const market of config.spotMarketsInfos) {
this.marketL2Args.push({
marketIndex: market.marketIndex,
marketType: MarketType.SPOT,
marketName: market.symbol,
marketName: market.marketName,
depth: -1,
includeVamm: false,
updateOnChange: true,