pass list of markets into DLOBSubscriberIO
This commit is contained in:
@@ -2,16 +2,11 @@ import {
|
|||||||
BN,
|
BN,
|
||||||
DLOBSubscriber,
|
DLOBSubscriber,
|
||||||
DLOBSubscriptionConfig,
|
DLOBSubscriptionConfig,
|
||||||
DevnetPerpMarkets,
|
|
||||||
DevnetSpotMarkets,
|
|
||||||
L2OrderBookGenerator,
|
L2OrderBookGenerator,
|
||||||
MainnetPerpMarkets,
|
|
||||||
MainnetSpotMarkets,
|
|
||||||
MarketType,
|
MarketType,
|
||||||
groupL2,
|
groupL2,
|
||||||
isVariant,
|
isVariant,
|
||||||
} from '@drift-labs/sdk';
|
} from '@drift-labs/sdk';
|
||||||
import { driftEnv } from '../publishers/dlobPublisher';
|
|
||||||
import { RedisClient } from '../utils/redisClient';
|
import { RedisClient } from '../utils/redisClient';
|
||||||
import {
|
import {
|
||||||
SubscriberLookup,
|
SubscriberLookup,
|
||||||
@@ -33,6 +28,11 @@ type wsMarketL2Args = {
|
|||||||
updateOnChange?: boolean;
|
updateOnChange?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type wsMarketInfo = {
|
||||||
|
marketIndex: number;
|
||||||
|
marketName: string;
|
||||||
|
};
|
||||||
|
|
||||||
export class DLOBSubscriberIO extends DLOBSubscriber {
|
export class DLOBSubscriberIO extends DLOBSubscriber {
|
||||||
public marketL2Args: wsMarketL2Args[] = [];
|
public marketL2Args: wsMarketL2Args[] = [];
|
||||||
public lastSeenL2Formatted: Map<MarketType, Map<number, any>>;
|
public lastSeenL2Formatted: Map<MarketType, Map<number, any>>;
|
||||||
@@ -41,6 +41,8 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
constructor(
|
constructor(
|
||||||
config: DLOBSubscriptionConfig & {
|
config: DLOBSubscriptionConfig & {
|
||||||
redisClient: RedisClient;
|
redisClient: RedisClient;
|
||||||
|
perpMarketsInfos: wsMarketInfo[];
|
||||||
|
spotMarketsInfos: wsMarketInfo[];
|
||||||
spotMarketSubscribers: SubscriberLookup;
|
spotMarketSubscribers: SubscriberLookup;
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
@@ -52,17 +54,11 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
this.lastSeenL2Formatted.set(MarketType.SPOT, new Map());
|
this.lastSeenL2Formatted.set(MarketType.SPOT, new Map());
|
||||||
this.lastSeenL2Formatted.set(MarketType.PERP, new Map());
|
this.lastSeenL2Formatted.set(MarketType.PERP, new Map());
|
||||||
|
|
||||||
// Add all active markets to the market L2Args
|
for (const market of config.perpMarketsInfos) {
|
||||||
const perpMarkets =
|
|
||||||
driftEnv === 'devnet' ? DevnetPerpMarkets : MainnetPerpMarkets;
|
|
||||||
const spotMarkets =
|
|
||||||
driftEnv === 'devnet' ? DevnetSpotMarkets : MainnetSpotMarkets;
|
|
||||||
|
|
||||||
for (const market of perpMarkets) {
|
|
||||||
this.marketL2Args.push({
|
this.marketL2Args.push({
|
||||||
marketIndex: market.marketIndex,
|
marketIndex: market.marketIndex,
|
||||||
marketType: MarketType.PERP,
|
marketType: MarketType.PERP,
|
||||||
marketName: market.symbol,
|
marketName: market.marketName,
|
||||||
depth: -1,
|
depth: -1,
|
||||||
numVammOrders: 100,
|
numVammOrders: 100,
|
||||||
includeVamm: true,
|
includeVamm: true,
|
||||||
@@ -70,11 +66,11 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
fallbackL2Generators: [],
|
fallbackL2Generators: [],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
for (const market of spotMarkets) {
|
for (const market of config.spotMarketsInfos) {
|
||||||
this.marketL2Args.push({
|
this.marketL2Args.push({
|
||||||
marketIndex: market.marketIndex,
|
marketIndex: market.marketIndex,
|
||||||
marketType: MarketType.SPOT,
|
marketType: MarketType.SPOT,
|
||||||
marketName: market.symbol,
|
marketName: market.marketName,
|
||||||
depth: -1,
|
depth: -1,
|
||||||
includeVamm: false,
|
includeVamm: false,
|
||||||
updateOnChange: true,
|
updateOnChange: true,
|
||||||
|
|||||||
@@ -25,7 +25,10 @@ import {
|
|||||||
getSerumSubscriber,
|
getSerumSubscriber,
|
||||||
sleep,
|
sleep,
|
||||||
} from '../utils/utils';
|
} from '../utils/utils';
|
||||||
import { DLOBSubscriberIO } from '../dlob-subscriber/DLOBSubscriberIO';
|
import {
|
||||||
|
DLOBSubscriberIO,
|
||||||
|
wsMarketInfo,
|
||||||
|
} from '../dlob-subscriber/DLOBSubscriberIO';
|
||||||
import { RedisClient } from '../utils/redisClient';
|
import { RedisClient } from '../utils/redisClient';
|
||||||
import {
|
import {
|
||||||
DLOBProvider,
|
DLOBProvider,
|
||||||
@@ -86,20 +89,17 @@ let MARKET_SUBSCRIBERS: SubscriberLookup = {};
|
|||||||
const getMarketsAndOraclesToLoad = (
|
const getMarketsAndOraclesToLoad = (
|
||||||
sdkConfig: any
|
sdkConfig: any
|
||||||
): {
|
): {
|
||||||
perpMarketIndexes?: number[];
|
perpMarketInfos: wsMarketInfo[];
|
||||||
spotMarketIndexes?: number[];
|
spotMarketInfos: wsMarketInfo[];
|
||||||
oracleInfos?: OracleInfo[];
|
oracleInfos?: OracleInfo[];
|
||||||
} => {
|
} => {
|
||||||
const oracleInfos: OracleInfo[] = [];
|
const oracleInfos: OracleInfo[] = [];
|
||||||
const oraclesTracked = new Set();
|
const oraclesTracked = new Set();
|
||||||
let perpMarketIndexes: number[] = [];
|
const perpMarketInfos: wsMarketInfo[] = [];
|
||||||
let spotMarketIndexes: number[] = [];
|
const spotMarketInfos: wsMarketInfo[] = [];
|
||||||
|
|
||||||
if (PERP_MARKETS_TO_LOAD!.length > 0) {
|
if (PERP_MARKETS_TO_LOAD!.length > 0) {
|
||||||
perpMarketIndexes = PERP_MARKETS_TO_LOAD;
|
for (const idx of PERP_MARKETS_TO_LOAD) {
|
||||||
logger.info(`DlobPublisher tracking perp markets: ${perpMarketIndexes}`);
|
|
||||||
|
|
||||||
for (const idx of perpMarketIndexes) {
|
|
||||||
const perpMarketConfig = sdkConfig.PERP_MARKETS[idx] as PerpMarketConfig;
|
const perpMarketConfig = sdkConfig.PERP_MARKETS[idx] as PerpMarketConfig;
|
||||||
if (!perpMarketConfig) {
|
if (!perpMarketConfig) {
|
||||||
throw new Error(`Perp market config for ${idx} not found`);
|
throw new Error(`Perp market config for ${idx} not found`);
|
||||||
@@ -113,14 +113,18 @@ const getMarketsAndOraclesToLoad = (
|
|||||||
});
|
});
|
||||||
oraclesTracked.add(oracleKey);
|
oraclesTracked.add(oracleKey);
|
||||||
}
|
}
|
||||||
|
perpMarketInfos.push({
|
||||||
|
marketIndex: perpMarketConfig.marketIndex,
|
||||||
|
marketName: perpMarketConfig.symbol,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
logger.info(
|
||||||
|
`DlobPublisher tracking perp markets: ${JSON.stringify(perpMarketInfos)}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SPOT_MARKETS_TO_LOAD!.length > 0) {
|
if (SPOT_MARKETS_TO_LOAD!.length > 0) {
|
||||||
spotMarketIndexes = SPOT_MARKETS_TO_LOAD;
|
for (const idx of SPOT_MARKETS_TO_LOAD) {
|
||||||
logger.info(`DlobPublisher tracking spot markets: ${spotMarketIndexes}`);
|
|
||||||
|
|
||||||
for (const idx of spotMarketIndexes) {
|
|
||||||
const spotMarketConfig = sdkConfig.PERP_MARKETS[idx] as PerpMarketConfig;
|
const spotMarketConfig = sdkConfig.PERP_MARKETS[idx] as PerpMarketConfig;
|
||||||
if (!spotMarketConfig) {
|
if (!spotMarketConfig) {
|
||||||
throw new Error(`Spot market config for ${idx} not found`);
|
throw new Error(`Spot market config for ${idx} not found`);
|
||||||
@@ -134,12 +138,19 @@ const getMarketsAndOraclesToLoad = (
|
|||||||
});
|
});
|
||||||
oraclesTracked.add(oracleKey);
|
oraclesTracked.add(oracleKey);
|
||||||
}
|
}
|
||||||
|
spotMarketInfos.push({
|
||||||
|
marketIndex: spotMarketConfig.marketIndex,
|
||||||
|
marketName: spotMarketConfig.symbol,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
logger.info(
|
||||||
|
`DlobPublisher tracking spot markets: ${JSON.stringify(spotMarketInfos)}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
perpMarketIndexes,
|
perpMarketInfos,
|
||||||
spotMarketIndexes,
|
spotMarketInfos,
|
||||||
oracleInfos,
|
oracleInfos,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -259,7 +270,7 @@ const main = async () => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const { perpMarketIndexes, spotMarketIndexes, oracleInfos } =
|
const { perpMarketInfos, spotMarketInfos, oracleInfos } =
|
||||||
getMarketsAndOraclesToLoad(sdkConfig);
|
getMarketsAndOraclesToLoad(sdkConfig);
|
||||||
driftClient = new DriftClient({
|
driftClient = new DriftClient({
|
||||||
connection,
|
connection,
|
||||||
@@ -267,8 +278,8 @@ const main = async () => {
|
|||||||
programID: clearingHousePublicKey,
|
programID: clearingHousePublicKey,
|
||||||
accountSubscription,
|
accountSubscription,
|
||||||
env: driftEnv,
|
env: driftEnv,
|
||||||
perpMarketIndexes,
|
perpMarketIndexes: perpMarketInfos.map((m) => m.marketIndex),
|
||||||
spotMarketIndexes,
|
spotMarketIndexes: spotMarketInfos.map((m) => m.marketIndex),
|
||||||
oracleInfos,
|
oracleInfos,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -358,6 +369,8 @@ const main = async () => {
|
|||||||
updateFrequency: ORDERBOOK_UPDATE_INTERVAL,
|
updateFrequency: ORDERBOOK_UPDATE_INTERVAL,
|
||||||
redisClient,
|
redisClient,
|
||||||
spotMarketSubscribers: MARKET_SUBSCRIBERS,
|
spotMarketSubscribers: MARKET_SUBSCRIBERS,
|
||||||
|
perpMarketsInfos,
|
||||||
|
spotMarketsInfos,
|
||||||
});
|
});
|
||||||
await dlobSubscriber.subscribe();
|
await dlobSubscriber.subscribe();
|
||||||
if (useWebsocket && !FEATURE_FLAGS.DISABLE_GPA_REFRESH) {
|
if (useWebsocket && !FEATURE_FLAGS.DISABLE_GPA_REFRESH) {
|
||||||
|
|||||||
Reference in New Issue
Block a user