chore: update channel prefixes for pubsub
This commit is contained in:
@@ -137,6 +137,7 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getL2AndSendMsg(marketArgs: wsMarketArgs): void {
|
getL2AndSendMsg(marketArgs: wsMarketArgs): void {
|
||||||
|
const clientPrefix = this.redisClient.forceGetClient().options.keyPrefix;
|
||||||
const grouping = marketArgs.grouping;
|
const grouping = marketArgs.grouping;
|
||||||
const { marketName, ...l2FuncArgs } = marketArgs;
|
const { marketName, ...l2FuncArgs } = marketArgs;
|
||||||
const l2 = this.getL2(l2FuncArgs);
|
const l2 = this.getL2(l2FuncArgs);
|
||||||
@@ -263,7 +264,7 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.redisClient.publish(
|
this.redisClient.publish(
|
||||||
`orderbook_${marketType}_${marketArgs.marketIndex}`,
|
`${clientPrefix}orderbook_${marketType}_${marketArgs.marketIndex}`,
|
||||||
l2Formatted
|
l2Formatted
|
||||||
);
|
);
|
||||||
this.redisClient.set(
|
this.redisClient.set(
|
||||||
|
|||||||
17
src/index.ts
17
src/index.ts
@@ -51,10 +51,7 @@ import { getDLOBProviderFromOrderSubscriber } from './dlobProvider';
|
|||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
|
|
||||||
// Reading in Redis env vars
|
// Reading in Redis env vars
|
||||||
const REDIS_CLIENTS = process.env.REDIS_CLIENTS?.replace(/^\[|\]$/g, '')
|
const REDIS_CLIENTS = [RedisClientPrefix.DLOB, RedisClientPrefix.DLOB_HELIUS];
|
||||||
.split(',')
|
|
||||||
.map((clients) => clients.trim()) || ['DLOB'];
|
|
||||||
|
|
||||||
console.log('Redis Clients:', REDIS_CLIENTS);
|
console.log('Redis Clients:', REDIS_CLIENTS);
|
||||||
|
|
||||||
const driftEnv = (process.env.ENV || 'devnet') as DriftEnv;
|
const driftEnv = (process.env.ENV || 'devnet') as DriftEnv;
|
||||||
@@ -294,8 +291,7 @@ const main = async (): Promise<void> => {
|
|||||||
if (useRedis) {
|
if (useRedis) {
|
||||||
logger.info('Connecting to redis');
|
logger.info('Connecting to redis');
|
||||||
for (let i = 0; i < REDIS_CLIENTS.length; i++) {
|
for (let i = 0; i < REDIS_CLIENTS.length; i++) {
|
||||||
const prefix = RedisClientPrefix[REDIS_CLIENTS[i]];
|
redisClients.push(new RedisClient({ prefix: REDIS_CLIENTS[i] }));
|
||||||
redisClients.push(new RedisClient({ prefix }));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < sdkConfig.SPOT_MARKETS.length; i++) {
|
for (let i = 0; i < sdkConfig.SPOT_MARKETS.length; i++) {
|
||||||
@@ -402,11 +398,12 @@ const main = async (): Promise<void> => {
|
|||||||
const { marketIndex, marketType } = req.query;
|
const { marketIndex, marketType } = req.query;
|
||||||
|
|
||||||
const fees = await redisClients
|
const fees = await redisClients
|
||||||
.find(
|
.find((client) => {
|
||||||
(client) =>
|
return (
|
||||||
client.forceGetClient().options.keyPrefix ===
|
client.forceGetClient().options.keyPrefix ===
|
||||||
RedisClientPrefix.DLOB_HELIUS
|
RedisClientPrefix.DLOB_HELIUS
|
||||||
)
|
);
|
||||||
|
})
|
||||||
.getRaw(`priorityFees_${marketType}_${marketIndex}`);
|
.getRaw(`priorityFees_${marketType}_${marketIndex}`);
|
||||||
|
|
||||||
if (fees) {
|
if (fees) {
|
||||||
@@ -521,7 +518,7 @@ const main = async (): Promise<void> => {
|
|||||||
|
|
||||||
let accountFlag = false;
|
let accountFlag = false;
|
||||||
if (includeAccounts) {
|
if (includeAccounts) {
|
||||||
accountFlag = includeAccounts === 'true';
|
accountFlag = (includeAccounts as string).toLowerCase() === 'true';
|
||||||
}
|
}
|
||||||
|
|
||||||
let topMakers: string[];
|
let topMakers: string[];
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ require('dotenv').config();
|
|||||||
const stateCommitment: Commitment = 'confirmed';
|
const stateCommitment: Commitment = 'confirmed';
|
||||||
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 redisClientPrefix = RedisClientPrefix.DLOB_HELIUS;
|
||||||
// Set up express for health checks
|
// Set up express for health checks
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ class PriorityFeeSubscriber {
|
|||||||
dataPerp.forEach((result: any) => {
|
dataPerp.forEach((result: any) => {
|
||||||
const marketIndex = parseInt(result['id']);
|
const marketIndex = parseInt(result['id']);
|
||||||
this.redisClient.publish(
|
this.redisClient.publish(
|
||||||
`priorityFees_perp_${marketIndex}`,
|
`${redisClientPrefix}priorityFees_perp_${marketIndex}`,
|
||||||
result.result['priorityFeeLevels']
|
result.result['priorityFeeLevels']
|
||||||
);
|
);
|
||||||
this.redisClient.set(
|
this.redisClient.set(
|
||||||
@@ -147,7 +147,7 @@ class PriorityFeeSubscriber {
|
|||||||
dataSpot.forEach((result: any) => {
|
dataSpot.forEach((result: any) => {
|
||||||
const marketIndex = parseInt(result['id']) - 100;
|
const marketIndex = parseInt(result['id']) - 100;
|
||||||
this.redisClient.publish(
|
this.redisClient.publish(
|
||||||
`priorityFees_spot_${marketIndex}`,
|
`${redisClientPrefix}priorityFees_spot_${marketIndex}`,
|
||||||
result.result['priorityFeeLevels']
|
result.result['priorityFeeLevels']
|
||||||
);
|
);
|
||||||
this.redisClient.set(
|
this.redisClient.set(
|
||||||
@@ -165,7 +165,7 @@ const main = async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const redisClient = new RedisClient({
|
const redisClient = new RedisClient({
|
||||||
prefix: RedisClientPrefix.DLOB_HELIUS,
|
prefix: redisClientPrefix,
|
||||||
});
|
});
|
||||||
await redisClient.connect();
|
await redisClient.connect();
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import { fromEvent, filter, map } from 'rxjs';
|
|||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
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 redisClientPrefix = RedisClientPrefix.DLOB;
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
const sdkConfig = initialize({ env: process.env.ENV });
|
const sdkConfig = initialize({ env: process.env.ENV });
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ const main = async () => {
|
|||||||
env: driftEnv,
|
env: driftEnv,
|
||||||
});
|
});
|
||||||
|
|
||||||
const redisClient = new RedisClient({ prefix: RedisClientPrefix.DLOB });
|
const redisClient = new RedisClient({ prefix: redisClientPrefix });
|
||||||
await redisClient.connect();
|
await redisClient.connect();
|
||||||
|
|
||||||
const slotSubscriber = new SlotSubscriber(connection, {});
|
const slotSubscriber = new SlotSubscriber(connection, {});
|
||||||
@@ -180,7 +180,7 @@ const main = async () => {
|
|||||||
)
|
)
|
||||||
.subscribe((fillEvent) => {
|
.subscribe((fillEvent) => {
|
||||||
redisClient.publish(
|
redisClient.publish(
|
||||||
`trades_${fillEvent.marketType}_${fillEvent.marketIndex}`,
|
`${redisClientPrefix}trades_${fillEvent.marketType}_${fillEvent.marketIndex}`,
|
||||||
fillEvent
|
fillEvent
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -30,10 +30,7 @@ import { RedisClient, RedisClientPrefix } from '@drift/common';
|
|||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
|
|
||||||
// Reading in Redis env vars
|
// Reading in Redis env vars
|
||||||
const REDIS_CLIENTS = process.env.REDIS_CLIENTS?.replace(/^\[|\]$/g, '')
|
const REDIS_CLIENTS = [RedisClientPrefix.DLOB, RedisClientPrefix.DLOB_HELIUS];
|
||||||
.split(',')
|
|
||||||
.map((clients) => clients.trim()) || ['DLOB'];
|
|
||||||
|
|
||||||
console.log('Redis Clients:', REDIS_CLIENTS);
|
console.log('Redis Clients:', REDIS_CLIENTS);
|
||||||
|
|
||||||
const driftEnv = (process.env.ENV || 'devnet') as DriftEnv;
|
const driftEnv = (process.env.ENV || 'devnet') as DriftEnv;
|
||||||
|
|||||||
@@ -347,11 +347,13 @@ export const getAccountFromId = async (
|
|||||||
) => {
|
) => {
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
topMakers.map(async (accountId) => {
|
topMakers.map(async (accountId) => {
|
||||||
const userMap = await userMapClient.getRaw(accountId);
|
const userAccountEncoded = await userMapClient.getRaw(accountId);
|
||||||
if (userMap) {
|
if (userAccountEncoded) {
|
||||||
return {
|
return {
|
||||||
accountId,
|
accountId,
|
||||||
account: decodeUser(Buffer.from(userMap.split('::')[1], 'base64')),
|
account: decodeUser(
|
||||||
|
Buffer.from(userAccountEncoded.split('::')[1], 'base64')
|
||||||
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { WebSocket, WebSocketServer } from 'ws';
|
|||||||
import { sleep } from './utils/utils';
|
import { sleep } from './utils/utils';
|
||||||
import { register, Gauge } from 'prom-client';
|
import { register, Gauge } from 'prom-client';
|
||||||
import { DriftEnv, PerpMarkets, SpotMarkets } from '@drift-labs/sdk';
|
import { DriftEnv, PerpMarkets, SpotMarkets } from '@drift-labs/sdk';
|
||||||
import { RedisClient } from '@drift/common';
|
import { RedisClient, RedisClientPrefix } from '@drift/common';
|
||||||
|
|
||||||
// Set up env constants
|
// Set up env constants
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
@@ -34,6 +34,7 @@ const WS_PORT = process.env.WS_PORT || '3000';
|
|||||||
console.log(`WS LISTENER PORT : ${WS_PORT}`);
|
console.log(`WS LISTENER PORT : ${WS_PORT}`);
|
||||||
|
|
||||||
const MAX_BUFFERED_AMOUNT = 300000;
|
const MAX_BUFFERED_AMOUNT = 300000;
|
||||||
|
const CHANNEL_PREFIX = RedisClientPrefix.DLOB;
|
||||||
|
|
||||||
const safeGetRawChannelFromMessage = (message: any): string => {
|
const safeGetRawChannelFromMessage = (message: any): string => {
|
||||||
return message?.channel;
|
return message?.channel;
|
||||||
@@ -64,11 +65,11 @@ const getRedisChannelFromMessage = (message: any): string => {
|
|||||||
|
|
||||||
switch (channel.toLowerCase()) {
|
switch (channel.toLowerCase()) {
|
||||||
case 'trades':
|
case 'trades':
|
||||||
return `trades_${marketType}_${marketIndex}`;
|
return `${CHANNEL_PREFIX}trades_${marketType}_${marketIndex}`;
|
||||||
case 'orderbook':
|
case 'orderbook':
|
||||||
return `orderbook_${marketType}_${marketIndex}`;
|
return `${CHANNEL_PREFIX}orderbook_${marketType}_${marketIndex}`;
|
||||||
case 'priorityfees':
|
case 'priorityfees':
|
||||||
return `priorityFees_${marketType}_${marketIndex}`;
|
return `${CHANNEL_PREFIX}priorityFees_${marketType}_${marketIndex}`;
|
||||||
case undefined:
|
case undefined:
|
||||||
default:
|
default:
|
||||||
throw new Error('Bad channel specified');
|
throw new Error('Bad channel specified');
|
||||||
@@ -77,7 +78,7 @@ const getRedisChannelFromMessage = (message: any): string => {
|
|||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const redisClient = new RedisClient({});
|
const redisClient = new RedisClient({});
|
||||||
const lastMessageRetriever = new RedisClient({});
|
const lastMessageRetriever = new RedisClient({ prefix: CHANNEL_PREFIX });
|
||||||
|
|
||||||
await redisClient.connect();
|
await redisClient.connect();
|
||||||
await lastMessageRetriever.connect();
|
await lastMessageRetriever.connect();
|
||||||
@@ -183,11 +184,13 @@ async function main() {
|
|||||||
);
|
);
|
||||||
// Fetch and send last message
|
// Fetch and send last message
|
||||||
if (redisChannel.includes('orderbook')) {
|
if (redisChannel.includes('orderbook')) {
|
||||||
const lastUpdateChannel = `last_update_${redisChannel}`;
|
const lastUpdateChannel = `last_update_${redisChannel}`.replace(
|
||||||
const lastMessage = await lastMessageRetriever.get(
|
CHANNEL_PREFIX,
|
||||||
|
''
|
||||||
|
);
|
||||||
|
const lastMessage = await lastMessageRetriever.getRaw(
|
||||||
lastUpdateChannel
|
lastUpdateChannel
|
||||||
);
|
);
|
||||||
|
|
||||||
if (lastMessage) {
|
if (lastMessage) {
|
||||||
ws.send(
|
ws.send(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
|||||||
Reference in New Issue
Block a user