add /debug to dlobPublisher
This commit is contained in:
@@ -247,7 +247,7 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
||||
l2Formatted['marketSlot'] !== lastMarketSlotAndTime.slot
|
||||
) {
|
||||
logger.warn(
|
||||
`Updating market slot for ${marketArgs.marketName} with slot ${l2Formatted['marketSlot']}`
|
||||
`Updating market slot for ${marketArgs.marketName} from ${lastMarketSlotAndTime.slot} -> ${l2Formatted['marketSlot']}`
|
||||
);
|
||||
this.lastMarketSlotMap
|
||||
.get(marketArgs.marketType)
|
||||
@@ -262,6 +262,13 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
||||
asks: l2Formatted.asks.slice(0, 100),
|
||||
});
|
||||
|
||||
console.log(
|
||||
`bbo: ${l2Formatted['marketName']}`,
|
||||
(+l2Formatted.bids[0].price / 1e6).toFixed(4),
|
||||
'//',
|
||||
(+l2Formatted.asks[0].price / 1e6).toFixed(4)
|
||||
);
|
||||
|
||||
this.redisClient.publish(
|
||||
`${clientPrefix}orderbook_${marketType}_${marketArgs.marketIndex}`,
|
||||
l2Formatted
|
||||
|
||||
@@ -18,6 +18,8 @@ import {
|
||||
PerpMarketConfig,
|
||||
SpotMarketConfig,
|
||||
PhoenixSubscriber,
|
||||
MarketType,
|
||||
OraclePriceData,
|
||||
} from '@drift-labs/sdk';
|
||||
import { RedisClient, RedisClientPrefix } from '@drift/common/clients';
|
||||
|
||||
@@ -25,6 +27,7 @@ import { logger, setLogLevel } from '../utils/logger';
|
||||
import {
|
||||
SubscriberLookup,
|
||||
getOpenbookSubscriber,
|
||||
l2WithBNToStrings,
|
||||
parsePositiveIntArray,
|
||||
sleep,
|
||||
} from '../utils/utils';
|
||||
@@ -40,7 +43,7 @@ import {
|
||||
} from '../dlobProvider';
|
||||
import FEATURE_FLAGS from '../utils/featureFlags';
|
||||
import { GeyserOrderSubscriber } from '../grpc/OrderSubscriberGRPC';
|
||||
import express from 'express';
|
||||
import express, { Response, Request } from 'express';
|
||||
import { handleHealthCheck } from '../core/metrics';
|
||||
import { setGlobalDispatcher, Agent } from 'undici';
|
||||
|
||||
@@ -453,6 +456,50 @@ const main = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleDebug = async (req: Request, res: Response) => {
|
||||
const marketIndex = +req.query.marketIndex;
|
||||
let marketType: MarketType = MarketType.PERP;
|
||||
let oraclePriceData: OraclePriceData;
|
||||
if (req.query.marketType === 'spot') {
|
||||
marketType = MarketType.SPOT;
|
||||
oraclePriceData = driftClient.getOracleDataForSpotMarket(marketIndex);
|
||||
} else {
|
||||
oraclePriceData = driftClient.getOracleDataForPerpMarket(marketIndex);
|
||||
}
|
||||
try {
|
||||
const slot = slotSource.getSlot();
|
||||
const dlob = await dlobProvider.getDLOB(slot);
|
||||
const l2 = dlob.getL2({
|
||||
marketIndex,
|
||||
marketType,
|
||||
depth: 5,
|
||||
slot,
|
||||
oraclePriceData,
|
||||
});
|
||||
const l3 = dlob.getL3({
|
||||
marketIndex,
|
||||
marketType,
|
||||
slot,
|
||||
oraclePriceData,
|
||||
});
|
||||
const state = {
|
||||
dlobSize: dlobProvider.size(),
|
||||
slot,
|
||||
markets: {
|
||||
perp: perpMarketInfos,
|
||||
spot: spotMarketInfos,
|
||||
},
|
||||
l2: l2WithBNToStrings(l2),
|
||||
l3,
|
||||
};
|
||||
|
||||
res.json(state);
|
||||
} catch (e) {
|
||||
res.status(500).json({ error: e.message });
|
||||
}
|
||||
};
|
||||
app.get('/debug', handleDebug);
|
||||
|
||||
app.get(
|
||||
'/health',
|
||||
handleHealthCheck(WS_FALLBACK_FETCH_INTERVAL, dlobProvider)
|
||||
|
||||
@@ -37,6 +37,21 @@ export const l2WithBNToStrings = (l2: L2OrderBook): any => {
|
||||
return l2;
|
||||
};
|
||||
|
||||
export const l3WithBNToStrings = (l3: L3OrderBook): any => {
|
||||
for (const key of Object.keys(l3)) {
|
||||
for (const idx in l3[key]) {
|
||||
const level = l3[key][idx];
|
||||
l3[key][idx] = {
|
||||
price: level.price.toString(),
|
||||
size: level.size.toString(),
|
||||
maker: level.maker.toBase58(),
|
||||
orderId: level.orderId.toString(),
|
||||
};
|
||||
}
|
||||
}
|
||||
return l3;
|
||||
};
|
||||
|
||||
export function sleep(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user