Merge pull request #40 from drift-labs/server-fetch-from-redis
fetch from redis
This commit is contained in:
@@ -40,6 +40,8 @@ enum METRIC_TYPES {
|
|||||||
gpa_fetch_duration = 'gpa_fetch_duration',
|
gpa_fetch_duration = 'gpa_fetch_duration',
|
||||||
last_ws_message_received_ts = 'last_ws_message_received_ts',
|
last_ws_message_received_ts = 'last_ws_message_received_ts',
|
||||||
account_updates_count = 'account_updates_count',
|
account_updates_count = 'account_updates_count',
|
||||||
|
cache_hit_count = 'cache_hit_count',
|
||||||
|
cache_miss_count = 'cache_miss_count',
|
||||||
current_system_ts = 'current_system_ts',
|
current_system_ts = 'current_system_ts',
|
||||||
health_status = 'health_status',
|
health_status = 'health_status',
|
||||||
}
|
}
|
||||||
@@ -126,6 +128,14 @@ lastWsReceivedTsGauge.addCallback((obs: ObservableResult) => {
|
|||||||
obs.observe(lastWsMsgReceivedTs, {});
|
obs.observe(lastWsMsgReceivedTs, {});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const cacheHitCounter = meter.createCounter(METRIC_TYPES.cache_hit_count, {
|
||||||
|
description: 'Total redis cache hits',
|
||||||
|
});
|
||||||
|
|
||||||
|
const cacheMissCounter = meter.createCounter(METRIC_TYPES.cache_miss_count, {
|
||||||
|
description: 'Total redis cache misses',
|
||||||
|
});
|
||||||
|
|
||||||
const accountUpdatesCounter = meter.createCounter(
|
const accountUpdatesCounter = meter.createCounter(
|
||||||
METRIC_TYPES.account_updates_count,
|
METRIC_TYPES.account_updates_count,
|
||||||
{
|
{
|
||||||
@@ -238,4 +248,6 @@ export {
|
|||||||
handleHealthCheck,
|
handleHealthCheck,
|
||||||
setLastReceivedWsMsgTs,
|
setLastReceivedWsMsgTs,
|
||||||
accountUpdatesCounter,
|
accountUpdatesCounter,
|
||||||
|
cacheHitCounter,
|
||||||
|
cacheMissCounter,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -62,8 +62,8 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
marketType: MarketType.PERP,
|
marketType: MarketType.PERP,
|
||||||
marketName: market.symbol,
|
marketName: market.symbol,
|
||||||
depth: -1,
|
depth: -1,
|
||||||
includeVamm: true,
|
|
||||||
numVammOrders: 100,
|
numVammOrders: 100,
|
||||||
|
includeVamm: true,
|
||||||
updateOnChange: true,
|
updateOnChange: true,
|
||||||
fallbackL2Generators: [],
|
fallbackL2Generators: [],
|
||||||
});
|
});
|
||||||
@@ -124,13 +124,39 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
l2Args.marketType,
|
l2Args.marketType,
|
||||||
l2Args.marketIndex
|
l2Args.marketIndex
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const l2Formatted_depth100 = Object.assign({}, l2Formatted, {
|
||||||
|
bids: l2Formatted.bids.slice(0, 100),
|
||||||
|
asks: l2Formatted.asks.slice(0, 100),
|
||||||
|
});
|
||||||
|
const l2Formatted_depth20 = Object.assign({}, l2Formatted, {
|
||||||
|
bids: l2Formatted.bids.slice(0, 20),
|
||||||
|
asks: l2Formatted.asks.slice(0, 20),
|
||||||
|
});
|
||||||
|
const l2Formatted_depth5 = Object.assign({}, l2Formatted, {
|
||||||
|
bids: l2Formatted.bids.slice(0, 5),
|
||||||
|
asks: l2Formatted.asks.slice(0, 5),
|
||||||
|
});
|
||||||
|
|
||||||
this.redisClient.client.publish(
|
this.redisClient.client.publish(
|
||||||
`orderbook_${marketType}_${l2Args.marketIndex}`,
|
`orderbook_${marketType}_${l2Args.marketIndex}`,
|
||||||
JSON.stringify(l2Formatted)
|
JSON.stringify(l2Formatted)
|
||||||
);
|
);
|
||||||
this.redisClient.client.set(
|
this.redisClient.client.set(
|
||||||
`last_update_orderbook_${marketType}_${l2Args.marketIndex}`,
|
`last_update_orderbook_${marketType}_${l2Args.marketIndex}`,
|
||||||
JSON.stringify(l2Formatted)
|
JSON.stringify(l2Formatted_depth100)
|
||||||
|
);
|
||||||
|
this.redisClient.client.set(
|
||||||
|
`last_update_orderbook_${marketType}_${l2Args.marketIndex}_depth_100`,
|
||||||
|
JSON.stringify(l2Formatted_depth100)
|
||||||
|
);
|
||||||
|
this.redisClient.client.set(
|
||||||
|
`last_update_orderbook_${marketType}_${l2Args.marketIndex}_depth_20`,
|
||||||
|
JSON.stringify(l2Formatted_depth20)
|
||||||
|
);
|
||||||
|
this.redisClient.client.set(
|
||||||
|
`last_update_orderbook_${marketType}_${l2Args.marketIndex}_depth_5`,
|
||||||
|
JSON.stringify(l2Formatted_depth5)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
300
src/index.ts
300
src/index.ts
@@ -28,8 +28,6 @@ import {
|
|||||||
initialize,
|
initialize,
|
||||||
isVariant,
|
isVariant,
|
||||||
OrderSubscriber,
|
OrderSubscriber,
|
||||||
UserAccount,
|
|
||||||
Order,
|
|
||||||
} from '@drift-labs/sdk';
|
} from '@drift-labs/sdk';
|
||||||
|
|
||||||
import { logger, setLogLevel } from './utils/logger';
|
import { logger, setLogLevel } from './utils/logger';
|
||||||
@@ -39,7 +37,9 @@ import {
|
|||||||
gpaFetchDurationHistogram,
|
gpaFetchDurationHistogram,
|
||||||
handleHealthCheck,
|
handleHealthCheck,
|
||||||
accountUpdatesCounter,
|
accountUpdatesCounter,
|
||||||
|
cacheHitCounter,
|
||||||
setLastReceivedWsMsgTs,
|
setLastReceivedWsMsgTs,
|
||||||
|
cacheMissCounter,
|
||||||
} from './core/metrics';
|
} from './core/metrics';
|
||||||
import { handleResponseTime } from './core/middleware';
|
import { handleResponseTime } from './core/middleware';
|
||||||
import {
|
import {
|
||||||
@@ -59,8 +59,14 @@ import {
|
|||||||
getDLOBProviderFromOrderSubscriber,
|
getDLOBProviderFromOrderSubscriber,
|
||||||
getDLOBProviderFromUserMap,
|
getDLOBProviderFromUserMap,
|
||||||
} from './dlobProvider';
|
} from './dlobProvider';
|
||||||
|
import { RedisClient } from './utils/redisClient';
|
||||||
|
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
|
|
||||||
|
const REDIS_HOST = process.env.REDIS_HOST || 'localhost';
|
||||||
|
const REDIS_PORT = process.env.REDIS_PORT || '6379';
|
||||||
|
const REDIS_PASSWORD = process.env.REDIS_PASSWORD;
|
||||||
|
|
||||||
const driftEnv = (process.env.ENV || 'devnet') as DriftEnv;
|
const driftEnv = (process.env.ENV || 'devnet') as DriftEnv;
|
||||||
const commitHash = process.env.COMMIT;
|
const commitHash = process.env.COMMIT;
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
@@ -77,6 +83,7 @@ const rateLimitCallsPerSecond = process.env.RATE_LIMIT_CALLS_PER_SECOND
|
|||||||
? parseInt(process.env.RATE_LIMIT_CALLS_PER_SECOND)
|
? parseInt(process.env.RATE_LIMIT_CALLS_PER_SECOND)
|
||||||
: 1;
|
: 1;
|
||||||
const loadTestAllowed = process.env.ALLOW_LOAD_TEST?.toLowerCase() === 'true';
|
const loadTestAllowed = process.env.ALLOW_LOAD_TEST?.toLowerCase() === 'true';
|
||||||
|
const useRedis = process.env.USE_REDIS?.toLowerCase() === 'true';
|
||||||
|
|
||||||
const logFormat =
|
const logFormat =
|
||||||
':remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent" :req[x-forwarded-for]';
|
':remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent" :req[x-forwarded-for]';
|
||||||
@@ -264,6 +271,7 @@ const main = async () => {
|
|||||||
'updateReceived',
|
'updateReceived',
|
||||||
(_pubkey: PublicKey, _slot: number, _dataType: 'raw' | 'decoded') => {
|
(_pubkey: PublicKey, _slot: number, _dataType: 'raw' | 'decoded') => {
|
||||||
setLastReceivedWsMsgTs(Date.now());
|
setLastReceivedWsMsgTs(Date.now());
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
updatesReceivedTotal++;
|
updatesReceivedTotal++;
|
||||||
accountUpdatesCounter.add(1);
|
accountUpdatesCounter.add(1);
|
||||||
}
|
}
|
||||||
@@ -343,6 +351,13 @@ const main = async () => {
|
|||||||
`DLOBSubscriber initialized in ${Date.now() - initDlobSubscriberStart} ms`
|
`DLOBSubscriber initialized in ${Date.now() - initDlobSubscriberStart} ms`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let redisClient: RedisClient;
|
||||||
|
if (useRedis) {
|
||||||
|
logger.info('Connecting to redis');
|
||||||
|
redisClient = new RedisClient(REDIS_HOST, REDIS_PORT, REDIS_PASSWORD);
|
||||||
|
await redisClient.connect();
|
||||||
|
}
|
||||||
|
|
||||||
logger.info(`Initializing all market subscribers...`);
|
logger.info(`Initializing all market subscribers...`);
|
||||||
const initAllMarketSubscribersStart = Date.now();
|
const initAllMarketSubscribersStart = Date.now();
|
||||||
MARKET_SUBSCRIBERS = await initializeAllMarketSubscribers(driftClient);
|
MARKET_SUBSCRIBERS = await initializeAllMarketSubscribers(driftClient);
|
||||||
@@ -742,6 +757,69 @@ const main = async () => {
|
|||||||
adjustedDepth = '-1';
|
adjustedDepth = '-1';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let l2Formatted: any;
|
||||||
|
if (useRedis) {
|
||||||
|
if (
|
||||||
|
!isSpot &&
|
||||||
|
`${includeVamm}`.toLowerCase() === 'true' &&
|
||||||
|
`${includeOracle}`.toLowerCase().toLowerCase() === 'true' &&
|
||||||
|
!grouping
|
||||||
|
) {
|
||||||
|
let redisL2: string;
|
||||||
|
if (parseInt(adjustedDepth as string) === 5) {
|
||||||
|
redisL2 = await redisClient.client.get(
|
||||||
|
`last_update_orderbook_perp_${normedMarketIndex}_depth_5`
|
||||||
|
);
|
||||||
|
} else if (parseInt(adjustedDepth as string) === 20) {
|
||||||
|
redisL2 = await redisClient.client.get(
|
||||||
|
`last_update_orderbook_perp_${normedMarketIndex}_depth_20`
|
||||||
|
);
|
||||||
|
} else if (parseInt(adjustedDepth as string) === 100) {
|
||||||
|
redisL2 = await redisClient.client.get(
|
||||||
|
`last_update_orderbook_perp_${normedMarketIndex}_depth_100`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
redisL2 &&
|
||||||
|
slotSource.getSlot() - parseInt(JSON.parse(redisL2).slot) < 10
|
||||||
|
)
|
||||||
|
l2Formatted = redisL2;
|
||||||
|
} else if (
|
||||||
|
isSpot &&
|
||||||
|
`${includeSerum}`.toLowerCase() === 'true' &&
|
||||||
|
`${includePhoenix}`.toLowerCase() === 'true' &&
|
||||||
|
`${includeOracle}`.toLowerCase() === 'true' &&
|
||||||
|
!grouping
|
||||||
|
) {
|
||||||
|
let redisL2: string;
|
||||||
|
if (parseInt(adjustedDepth as string) === 5) {
|
||||||
|
redisL2 = await redisClient.client.get(
|
||||||
|
`last_update_orderbook_spot_${normedMarketIndex}_depth_5`
|
||||||
|
);
|
||||||
|
} else if (parseInt(adjustedDepth as string) === 20) {
|
||||||
|
redisL2 = await redisClient.client.get(
|
||||||
|
`last_update_orderbook_spot_${normedMarketIndex}_depth_20`
|
||||||
|
);
|
||||||
|
} else if (parseInt(adjustedDepth as string) === 100) {
|
||||||
|
redisL2 = await redisClient.client.get(
|
||||||
|
`last_update_orderbook_spot_${normedMarketIndex}_depth_100`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
redisL2 &&
|
||||||
|
slotSource.getSlot() - parseInt(JSON.parse(redisL2).slot) < 10
|
||||||
|
)
|
||||||
|
l2Formatted = redisL2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (l2Formatted) {
|
||||||
|
cacheHitCounter.add(1);
|
||||||
|
res.writeHead(200);
|
||||||
|
res.end(JSON.stringify(l2Formatted));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const l2 = dlobSubscriber.getL2({
|
const l2 = dlobSubscriber.getL2({
|
||||||
marketIndex: normedMarketIndex,
|
marketIndex: normedMarketIndex,
|
||||||
marketType: normedMarketType,
|
marketType: normedMarketType,
|
||||||
@@ -783,7 +861,7 @@ const main = async () => {
|
|||||||
res.end(JSON.stringify(l2Formatted));
|
res.end(JSON.stringify(l2Formatted));
|
||||||
} else {
|
} else {
|
||||||
// make the BNs into strings
|
// make the BNs into strings
|
||||||
const l2Formatted = l2WithBNToStrings(l2);
|
l2Formatted = l2WithBNToStrings(l2);
|
||||||
if (`${includeOracle}`.toLowerCase() === 'true') {
|
if (`${includeOracle}`.toLowerCase() === 'true') {
|
||||||
addOracletoResponse(
|
addOracletoResponse(
|
||||||
l2Formatted,
|
l2Formatted,
|
||||||
@@ -792,10 +870,10 @@ const main = async () => {
|
|||||||
normedMarketIndex
|
normedMarketIndex
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.writeHead(200);
|
|
||||||
res.end(JSON.stringify(l2Formatted));
|
|
||||||
}
|
}
|
||||||
|
cacheMissCounter.add(1);
|
||||||
|
res.writeHead(200);
|
||||||
|
res.end(JSON.stringify(l2Formatted));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
next(err);
|
next(err);
|
||||||
}
|
}
|
||||||
@@ -836,86 +914,148 @@ const main = async () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const l2s = normedParams.map((normedParam) => {
|
const l2s = await Promise.all(
|
||||||
const { normedMarketType, normedMarketIndex, error } =
|
normedParams.map(async (normedParam) => {
|
||||||
validateDlobQuery(
|
const { normedMarketType, normedMarketIndex, error } =
|
||||||
driftClient,
|
validateDlobQuery(
|
||||||
driftEnv,
|
driftClient,
|
||||||
normedParam['marketType'] as string,
|
driftEnv,
|
||||||
normedParam['marketIndex'] as string,
|
normedParam['marketType'] as string,
|
||||||
normedParam['marketName'] as string
|
normedParam['marketIndex'] as string,
|
||||||
);
|
normedParam['marketName'] as string
|
||||||
if (error) {
|
);
|
||||||
res.status(400).send(`Bad Request: ${error}`);
|
if (error) {
|
||||||
return;
|
res.status(400).send(`Bad Request: ${error}`);
|
||||||
}
|
|
||||||
|
|
||||||
const isSpot = isVariant(normedMarketType, 'spot');
|
|
||||||
|
|
||||||
let adjustedDepth = normedParam['depth'] ?? '10';
|
|
||||||
if (normedParam['grouping'] !== undefined) {
|
|
||||||
// If grouping is also supplied, we want the entire book depth.
|
|
||||||
// we will apply depth after grouping
|
|
||||||
adjustedDepth = '-1';
|
|
||||||
}
|
|
||||||
|
|
||||||
const l2 = dlobSubscriber.getL2({
|
|
||||||
marketIndex: normedMarketIndex,
|
|
||||||
marketType: normedMarketType,
|
|
||||||
depth: parseInt(adjustedDepth as string),
|
|
||||||
includeVamm: isSpot
|
|
||||||
? false
|
|
||||||
: `${normedParam['includeVamm']}`.toLowerCase() === 'true',
|
|
||||||
fallbackL2Generators: isSpot
|
|
||||||
? [
|
|
||||||
`${normedParam['includePhoenix']}`.toLowerCase() === 'true' &&
|
|
||||||
MARKET_SUBSCRIBERS[normedMarketIndex].phoenix,
|
|
||||||
`${normedParam['includeSerum']}`.toLowerCase() === 'true' &&
|
|
||||||
MARKET_SUBSCRIBERS[normedMarketIndex].serum,
|
|
||||||
].filter((a) => !!a)
|
|
||||||
: [],
|
|
||||||
});
|
|
||||||
|
|
||||||
if (normedParam['grouping']) {
|
|
||||||
const finalDepth = normedParam['depth']
|
|
||||||
? parseInt(normedParam['depth'] as string)
|
|
||||||
: 10;
|
|
||||||
if (isNaN(parseInt(normedParam['grouping'] as string))) {
|
|
||||||
res
|
|
||||||
.status(400)
|
|
||||||
.send('Bad Request: grouping must be a number if supplied');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const groupingBN = new BN(
|
|
||||||
parseInt(normedParam['grouping'] as string)
|
|
||||||
);
|
|
||||||
|
|
||||||
const l2Formatted = l2WithBNToStrings(
|
const isSpot = isVariant(normedMarketType, 'spot');
|
||||||
groupL2(l2, groupingBN, finalDepth)
|
|
||||||
);
|
let adjustedDepth = normedParam['depth'] ?? '10';
|
||||||
if (`${normedParam['includeOracle']}`.toLowerCase() === 'true') {
|
if (normedParam['grouping'] !== undefined) {
|
||||||
addOracletoResponse(
|
// If grouping is also supplied, we want the entire book depth.
|
||||||
l2Formatted,
|
// we will apply depth after grouping
|
||||||
driftClient,
|
adjustedDepth = '-1';
|
||||||
normedMarketType,
|
|
||||||
normedMarketIndex
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return l2Formatted;
|
|
||||||
} else {
|
let l2Formatted: any;
|
||||||
// make the BNs into strings
|
if (useRedis) {
|
||||||
const l2Formatted = l2WithBNToStrings(l2);
|
if (
|
||||||
if (`${normedParam['includeOracle']}`.toLowerCase() === 'true') {
|
marketType === 'perp' &&
|
||||||
addOracletoResponse(
|
normedParam['includeVamm'].toLowerCase() === 'true' &&
|
||||||
l2Formatted,
|
normedParam['includeOracle'].toLowerCase() === 'true' &&
|
||||||
driftClient,
|
!normedParam['grouping']
|
||||||
normedMarketType,
|
) {
|
||||||
normedMarketIndex
|
let redisL2: string;
|
||||||
);
|
if (parseInt(adjustedDepth as string) === 5) {
|
||||||
|
redisL2 = await redisClient.client.get(
|
||||||
|
`last_update_orderbook_perp_${normedMarketIndex}_depth_5`
|
||||||
|
);
|
||||||
|
} else if (parseInt(adjustedDepth as string) === 20) {
|
||||||
|
redisL2 = await redisClient.client.get(
|
||||||
|
`last_update_orderbook_perp_${normedMarketIndex}_depth_20`
|
||||||
|
);
|
||||||
|
} else if (parseInt(adjustedDepth as string) === 100) {
|
||||||
|
redisL2 = await redisClient.client.get(
|
||||||
|
`last_update_orderbook_perp_${normedMarketIndex}_depth_100`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
redisL2 &&
|
||||||
|
slotSource.getSlot() - parseInt(JSON.parse(redisL2).slot) < 10
|
||||||
|
)
|
||||||
|
l2Formatted = redisL2;
|
||||||
|
} else if (
|
||||||
|
marketType === 'spot' &&
|
||||||
|
normedParam['includePhoenix'].toLowerCase() === 'true' &&
|
||||||
|
normedParam['includeSerum'].toLowerCase() === 'true' &&
|
||||||
|
!normedParam['grouping']
|
||||||
|
) {
|
||||||
|
let redisL2: string;
|
||||||
|
if (parseInt(adjustedDepth as string) === 5) {
|
||||||
|
redisL2 = await redisClient.client.get(
|
||||||
|
`last_update_orderbook_spot_${normedMarketIndex}_depth_5`
|
||||||
|
);
|
||||||
|
} else if (parseInt(adjustedDepth as string) === 20) {
|
||||||
|
redisL2 = await redisClient.client.get(
|
||||||
|
`last_update_orderbook_spot_${normedMarketIndex}_depth_20`
|
||||||
|
);
|
||||||
|
} else if (parseInt(adjustedDepth as string) === 100) {
|
||||||
|
redisL2 = await redisClient.client.get(
|
||||||
|
`last_update_orderbook_spot_${normedMarketIndex}_depth_100`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
redisL2 &&
|
||||||
|
slotSource.getSlot() - parseInt(JSON.parse(redisL2).slot) < 10
|
||||||
|
)
|
||||||
|
l2Formatted = redisL2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (l2Formatted) {
|
||||||
|
cacheHitCounter.add(1);
|
||||||
|
return l2Formatted;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const l2 = dlobSubscriber.getL2({
|
||||||
|
marketIndex: normedMarketIndex,
|
||||||
|
marketType: normedMarketType,
|
||||||
|
depth: parseInt(adjustedDepth as string),
|
||||||
|
includeVamm: isSpot
|
||||||
|
? false
|
||||||
|
: `${normedParam['includeVamm']}`.toLowerCase() === 'true',
|
||||||
|
fallbackL2Generators: isSpot
|
||||||
|
? [
|
||||||
|
`${normedParam['includePhoenix']}`.toLowerCase() === 'true' &&
|
||||||
|
MARKET_SUBSCRIBERS[normedMarketIndex].phoenix,
|
||||||
|
`${normedParam['includeSerum']}`.toLowerCase() === 'true' &&
|
||||||
|
MARKET_SUBSCRIBERS[normedMarketIndex].serum,
|
||||||
|
].filter((a) => !!a)
|
||||||
|
: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (normedParam['grouping']) {
|
||||||
|
const finalDepth = normedParam['depth']
|
||||||
|
? parseInt(normedParam['depth'] as string)
|
||||||
|
: 10;
|
||||||
|
if (isNaN(parseInt(normedParam['grouping'] as string))) {
|
||||||
|
res
|
||||||
|
.status(400)
|
||||||
|
.send('Bad Request: grouping must be a number if supplied');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const groupingBN = new BN(
|
||||||
|
parseInt(normedParam['grouping'] as string)
|
||||||
|
);
|
||||||
|
|
||||||
|
l2Formatted = l2WithBNToStrings(
|
||||||
|
groupL2(l2, groupingBN, finalDepth)
|
||||||
|
);
|
||||||
|
if (`${normedParam['includeOracle']}`.toLowerCase() === 'true') {
|
||||||
|
addOracletoResponse(
|
||||||
|
l2Formatted,
|
||||||
|
driftClient,
|
||||||
|
normedMarketType,
|
||||||
|
normedMarketIndex
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// make the BNs into strings
|
||||||
|
l2Formatted = l2WithBNToStrings(l2);
|
||||||
|
if (`${normedParam['includeOracle']}`.toLowerCase() === 'true') {
|
||||||
|
addOracletoResponse(
|
||||||
|
l2Formatted,
|
||||||
|
driftClient,
|
||||||
|
normedMarketType,
|
||||||
|
normedMarketIndex
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cacheMissCounter.add(1);
|
||||||
return l2Formatted;
|
return l2Formatted;
|
||||||
}
|
})
|
||||||
});
|
);
|
||||||
|
|
||||||
res.writeHead(200);
|
res.writeHead(200);
|
||||||
res.end(JSON.stringify({ l2s }));
|
res.end(JSON.stringify({ l2s }));
|
||||||
|
|||||||
@@ -36,8 +36,6 @@ import { GeyserOrderSubscriber } from '../grpc/OrderSubscriberGRPC';
|
|||||||
|
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
const stateCommitment: Commitment = 'processed';
|
const stateCommitment: Commitment = 'processed';
|
||||||
const ORDERBOOK_UPDATE_INTERVAL = 400;
|
|
||||||
const WS_FALLBACK_FETCH_INTERVAL = ORDERBOOK_UPDATE_INTERVAL * 10;
|
|
||||||
const driftEnv = (process.env.ENV || 'devnet') as DriftEnv;
|
const driftEnv = (process.env.ENV || 'devnet') as DriftEnv;
|
||||||
const commitHash = process.env.COMMIT;
|
const commitHash = process.env.COMMIT;
|
||||||
const REDIS_HOST = process.env.REDIS_HOST || 'localhost';
|
const REDIS_HOST = process.env.REDIS_HOST || 'localhost';
|
||||||
@@ -62,6 +60,9 @@ const useOrderSubscriber =
|
|||||||
const useGrpc = process.env.USE_GRPC?.toLowerCase() === 'true';
|
const useGrpc = process.env.USE_GRPC?.toLowerCase() === 'true';
|
||||||
const useWebsocket = process.env.USE_WEBSOCKET?.toLowerCase() === 'true';
|
const useWebsocket = process.env.USE_WEBSOCKET?.toLowerCase() === 'true';
|
||||||
|
|
||||||
|
const ORDERBOOK_UPDATE_INTERVAL = useGrpc ? 500 : 1000;
|
||||||
|
const WS_FALLBACK_FETCH_INTERVAL = 10_000;
|
||||||
|
|
||||||
logger.info(`RPC endpoint: ${endpoint}`);
|
logger.info(`RPC endpoint: ${endpoint}`);
|
||||||
logger.info(`WS endpoint: ${wsEndpoint}`);
|
logger.info(`WS endpoint: ${wsEndpoint}`);
|
||||||
logger.info(`DriftEnv: ${driftEnv}`);
|
logger.info(`DriftEnv: ${driftEnv}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user