Merge pull request #36 from drift-labs/gpa-catch

catch gpa error
This commit is contained in:
Nour Alharithi
2023-12-05 11:01:49 -08:00
committed by GitHub
2 changed files with 30 additions and 9 deletions

View File

@@ -289,8 +289,16 @@ const main = async () => {
const recursiveFetch = (delay = WS_FALLBACK_FETCH_INTERVAL) => {
setTimeout(() => {
const startFetch = Date.now();
dlobProvider.fetch().then(() => {
dlobProvider
.fetch()
.then(() => {
gpaFetchDurationHistogram.record(Date.now() - startFetch);
})
.catch((e) => {
logger.error('Failed to fetch GPA');
console.log(e);
})
.finally(() => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
recursiveFetch();
});

View File

@@ -30,6 +30,7 @@ import {
getDLOBProviderFromOrderSubscriber,
getDLOBProviderFromUserMap,
} from '../dlobProvider';
import FEATURE_FLAGS from '../utils/featureFlags';
require('dotenv').config();
const stateCommitment: Commitment = 'processed';
@@ -229,10 +230,22 @@ const main = async () => {
spotMarketSubscribers: MARKET_SUBSCRIBERS,
});
await dlobSubscriber.subscribe();
if (useWebsocket) {
setInterval(async () => {
await dlobProvider.fetch();
}, WS_FALLBACK_FETCH_INTERVAL);
if (useWebsocket && !FEATURE_FLAGS.DISABLE_GPA_REFRESH) {
const recursiveFetch = (delay = WS_FALLBACK_FETCH_INTERVAL) => {
setTimeout(() => {
dlobProvider
.fetch()
.catch((e) => {
logger.error('Failed to fetch GPA');
console.log(e);
})
.finally(() => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
recursiveFetch();
});
}, delay);
};
recursiveFetch();
}
console.log('DLOBSubscriber Publishing Messages');