openbook integration (#208)

This commit is contained in:
frank
2024-08-07 11:47:25 -05:00
committed by GitHub
parent f9fd110ebc
commit bb83b4789b
5 changed files with 94 additions and 3 deletions

View File

@@ -45,6 +45,7 @@ import {
validateDlobQuery,
getAccountFromId,
getRawAccountFromId,
getOpenbookSubscriber,
} from './utils/utils';
import FEATURE_FLAGS from './utils/featureFlags';
import { getDLOBProviderFromOrderSubscriber } from './dlobProvider';
@@ -144,6 +145,7 @@ const initializeAllMarketSubscribers = async (driftClient: DriftClient) => {
for (const market of sdkConfig.SPOT_MARKETS) {
markets[market.marketIndex] = {
phoenix: undefined,
openbook: undefined,
};
if (market.phoenixMarket) {
@@ -177,6 +179,28 @@ const initializeAllMarketSubscribers = async (driftClient: DriftClient) => {
}
}
}
if (market.openbookMarket) {
const openbookConfigAccount =
await driftClient.getOpenbookV2FulfillmentConfig(market.openbookMarket);
if (isVariant(openbookConfigAccount.status, 'enabled')) {
const openbookSubscriber = getOpenbookSubscriber(
driftClient,
market,
sdkConfig
);
await openbookSubscriber.subscribe();
try {
openbookSubscriber.getL2Asks();
openbookSubscriber.getL2Bids();
markets[market.marketIndex].openbook = openbookSubscriber;
} catch (e) {
logger.info(
`Excluding openbook for ${market.marketIndex}, error: ${e}`
);
}
}
}
}
return markets;
@@ -633,6 +657,7 @@ const main = async (): Promise<void> => {
numVammOrders,
includeVamm,
includePhoenix,
includeOpenbook,
includeOracle,
} = req.query;
@@ -676,7 +701,11 @@ const main = async (): Promise<void> => {
}
}
}
} else if (isSpot && `${includePhoenix}`?.toLowerCase() === 'true') {
} else if (
isSpot &&
`${includePhoenix}`?.toLowerCase() === 'true' &&
`${includeOpenbook}`?.toLowerCase() === 'true'
) {
const redisClient = spotMarketRedisMap.get(normedMarketIndex).client;
const redisL2 = await redisClient.get(
`last_update_orderbook_spot_${normedMarketIndex}`
@@ -720,6 +749,8 @@ const main = async (): Promise<void> => {
? [
`${includePhoenix}`.toLowerCase() === 'true' &&
MARKET_SUBSCRIBERS[normedMarketIndex].phoenix,
`${includeOpenbook}`.toLowerCase() === 'true' &&
MARKET_SUBSCRIBERS[normedMarketIndex].openbook,
].filter((a) => !!a)
: [],
});
@@ -755,6 +786,7 @@ const main = async (): Promise<void> => {
depth,
includeVamm,
includePhoenix,
includeOpenbook,
includeOracle,
} = req.query;
@@ -765,6 +797,7 @@ const main = async (): Promise<void> => {
depth: depth as string | undefined,
includeVamm: includeVamm as string | undefined,
includePhoenix: includePhoenix as string | undefined,
includeOpenbook: includeOpenbook as string | undefined,
includeOracle: includeOracle as string | undefined,
});
@@ -831,7 +864,8 @@ const main = async (): Promise<void> => {
}
} else if (
isSpot &&
normedParam['includePhoenix']?.toLowerCase() === 'true'
normedParam['includePhoenix']?.toLowerCase() === 'true' &&
normedParam['includeOpenbook']?.toLowerCase() === 'true'
) {
const redisClient =
spotMarketRedisMap.get(normedMarketIndex).client;
@@ -880,6 +914,8 @@ const main = async (): Promise<void> => {
? [
`${normedParam['includePhoenix']}`.toLowerCase() === 'true' &&
MARKET_SUBSCRIBERS[normedMarketIndex].phoenix,
`${normedParam['includeOpenbook']}`.toLowerCase() ===
'true' && MARKET_SUBSCRIBERS[normedMarketIndex].openbook,
].filter((a) => !!a)
: [],
});