@@ -6,7 +6,7 @@
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@coral-xyz/anchor": "^0.29.0",
|
||||
"@drift-labs/sdk": "2.78.0-beta.0",
|
||||
"@drift-labs/sdk": "2.79.0-beta.2",
|
||||
"@opentelemetry/api": "^1.1.0",
|
||||
"@opentelemetry/auto-instrumentations-node": "^0.31.1",
|
||||
"@opentelemetry/exporter-prometheus": "^0.31.0",
|
||||
|
||||
71
src/index.ts
71
src/index.ts
@@ -7,11 +7,9 @@ import morgan from 'morgan';
|
||||
import { Commitment, Connection, Keypair, PublicKey } from '@solana/web3.js';
|
||||
|
||||
import {
|
||||
BulkAccountLoader,
|
||||
DLOBNode,
|
||||
DLOBSubscriber,
|
||||
DriftClient,
|
||||
DriftClientSubscriptionConfig,
|
||||
DriftEnv,
|
||||
SlotSubscriber,
|
||||
Wallet,
|
||||
@@ -92,7 +90,7 @@ const serverPort = process.env.PORT || 6969;
|
||||
export const ORDERBOOK_UPDATE_INTERVAL = 1000;
|
||||
const WS_FALLBACK_FETCH_INTERVAL = ORDERBOOK_UPDATE_INTERVAL * 10;
|
||||
const SLOT_STALENESS_TOLERANCE =
|
||||
parseInt(process.env.SLOT_STALENESS_TOLERANCE) || 20;
|
||||
parseInt(process.env.SLOT_STALENESS_TOLERANCE) || 35;
|
||||
const ROTATION_COOLDOWN = parseInt(process.env.ROTATION_COOLDOWN) || 5000;
|
||||
const useWebsocket = process.env.USE_WEBSOCKET?.toLowerCase() === 'true';
|
||||
const useRedis = process.env.USE_REDIS?.toLowerCase() === 'true';
|
||||
@@ -226,63 +224,32 @@ const main = async (): Promise<void> => {
|
||||
commitment: stateCommitment,
|
||||
});
|
||||
|
||||
// only set when polling
|
||||
let bulkAccountLoader: BulkAccountLoader | undefined;
|
||||
|
||||
// only set when using websockets
|
||||
let slotSubscriber: SlotSubscriber | undefined;
|
||||
|
||||
let accountSubscription: DriftClientSubscriptionConfig;
|
||||
|
||||
if (!useWebsocket) {
|
||||
bulkAccountLoader = new BulkAccountLoader(
|
||||
connection,
|
||||
stateCommitment,
|
||||
ORDERBOOK_UPDATE_INTERVAL
|
||||
);
|
||||
|
||||
accountSubscription = {
|
||||
type: 'polling',
|
||||
accountLoader: bulkAccountLoader,
|
||||
};
|
||||
} else {
|
||||
accountSubscription = {
|
||||
type: 'websocket',
|
||||
commitment: stateCommitment,
|
||||
};
|
||||
slotSubscriber = new SlotSubscriber(connection, {
|
||||
const slotSubscriber = new SlotSubscriber(connection, {
|
||||
resubTimeoutMs: 5000,
|
||||
});
|
||||
await slotSubscriber.subscribe();
|
||||
}
|
||||
|
||||
driftClient = new DriftClient({
|
||||
connection,
|
||||
wallet,
|
||||
programID: clearingHousePublicKey,
|
||||
accountSubscription,
|
||||
env: driftEnv,
|
||||
});
|
||||
|
||||
let subscriptionConfig;
|
||||
if (useWebsocket) {
|
||||
subscriptionConfig = {
|
||||
accountSubscription: {
|
||||
type: 'websocket',
|
||||
commitment: stateCommitment,
|
||||
resyncIntervalMs: WS_FALLBACK_FETCH_INTERVAL,
|
||||
};
|
||||
} else {
|
||||
subscriptionConfig = {
|
||||
type: 'polling',
|
||||
frequency: ORDERBOOK_UPDATE_INTERVAL,
|
||||
commitment: stateCommitment,
|
||||
};
|
||||
}
|
||||
resubTimeoutMs: 60_000,
|
||||
},
|
||||
env: driftEnv,
|
||||
});
|
||||
|
||||
let updatesReceivedTotal = 0;
|
||||
const orderSubscriber = new OrderSubscriber({
|
||||
driftClient,
|
||||
subscriptionConfig,
|
||||
subscriptionConfig: {
|
||||
type: 'websocket',
|
||||
commitment: stateCommitment,
|
||||
resubTimeoutMs: 10_000,
|
||||
resyncIntervalMs: WS_FALLBACK_FETCH_INTERVAL,
|
||||
},
|
||||
});
|
||||
orderSubscriber.eventEmitter.on(
|
||||
'updateReceived',
|
||||
@@ -690,11 +657,7 @@ const main = async (): Promise<void> => {
|
||||
|
||||
let l2Formatted: any;
|
||||
if (useRedis) {
|
||||
if (
|
||||
!isSpot &&
|
||||
`${includeVamm}`?.toLowerCase() === 'true' &&
|
||||
`${includeOracle}`?.toLowerCase() === 'true'
|
||||
) {
|
||||
if (!isSpot && `${includeVamm}`?.toLowerCase() === 'true') {
|
||||
let redisL2: string;
|
||||
const redisClient = perpMarketRedisMap.get(normedMarketIndex).client;
|
||||
if (parseInt(adjustedDepth as string) === 5) {
|
||||
@@ -726,8 +689,7 @@ const main = async (): Promise<void> => {
|
||||
} else if (
|
||||
isSpot &&
|
||||
`${includeSerum}`?.toLowerCase() === 'true' &&
|
||||
`${includePhoenix}`?.toLowerCase() === 'true' &&
|
||||
`${includeOracle}`?.toLowerCase() === 'true'
|
||||
`${includePhoenix}`?.toLowerCase() === 'true'
|
||||
) {
|
||||
let redisL2: string;
|
||||
const redisClient = spotMarketRedisMap.get(normedMarketIndex).client;
|
||||
@@ -866,8 +828,7 @@ const main = async (): Promise<void> => {
|
||||
if (useRedis) {
|
||||
if (
|
||||
!isSpot &&
|
||||
normedParam['includeVamm']?.toLowerCase() === 'true' &&
|
||||
normedParam['includeOracle']?.toLowerCase() === 'true'
|
||||
normedParam['includeVamm']?.toLowerCase() === 'true'
|
||||
) {
|
||||
let redisL2: string;
|
||||
const redisClient =
|
||||
|
||||
@@ -115,10 +115,10 @@
|
||||
enabled "2.0.x"
|
||||
kuler "^2.0.0"
|
||||
|
||||
"@drift-labs/sdk@2.78.0-beta.0":
|
||||
version "2.78.0-beta.0"
|
||||
resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.78.0-beta.0.tgz#5b33c41c561825ebef8849fdc71a76194715d5be"
|
||||
integrity sha512-Z/+NY15Du9zRjA9ExIZFsNhxwE0OY5JGdfiu5wPk2mjRmOneEu71sltu5Z+yA89z8nGw/s0oZKdAsQnUZLzX6A==
|
||||
"@drift-labs/sdk@2.79.0-beta.2":
|
||||
version "2.79.0-beta.2"
|
||||
resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.79.0-beta.2.tgz#0b339759ceabd16334744db371843a9af3d6de36"
|
||||
integrity sha512-gXgLiw60KK+fBHA78oVy/ydZKDJe9vyJva8ab1rTQEtSpHA2rGGTKQRcpmfV0qOkRM4O4e54FwNg6SOSPAUZoQ==
|
||||
dependencies:
|
||||
"@coral-xyz/anchor" "0.28.1-beta.2"
|
||||
"@ellipsis-labs/phoenix-sdk" "^1.4.2"
|
||||
|
||||
Reference in New Issue
Block a user