From b5fcf7d2e447e09c9d9703d1663a64e0f79d45c7 Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Fri, 5 Apr 2024 10:42:13 -0700 Subject: [PATCH] batchPriorityFes --- src/index.ts | 41 ++++++++++++++++++++++++++++++++++++++ src/wsConnectionManager.ts | 11 ++++------ 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index a1bbb41..3ee92bc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -475,6 +475,47 @@ const main = async (): Promise => { } }); + app.get('/batchPriorityFees', async (req, res, next) => { + try { + const { marketIndex, marketType } = req.query; + + const normedParams = normalizeBatchQueryParams({ + marketIndex: marketIndex as string | undefined, + marketType: marketType as string | undefined, + }); + + if (normedParams === undefined) { + res + .status(400) + .send( + 'Bad Request: all params for batch request must be the same length' + ); + return; + } + + const fees = await Promise.all( + normedParams.map(async (normedParam) => { + const fees = await redisClients[ + parseInt(process.env.HELIUS_REDIS_HOST_INDEX) ?? 0 + ].client.get( + `priorityFees_${normedParam['marketType']}_${normedParam['marketIndex']}` + ); + return JSON.parse(fees); + }) + ); + + if (fees && fees.length > 0) { + res.status(200).json(fees); + return; + } else { + res.writeHead(404); + res.end('Not found'); + } + } catch (err) { + next(err); + } + }); + app.get('/topMakers', async (req, res, next) => { try { const { diff --git a/src/wsConnectionManager.ts b/src/wsConnectionManager.ts index 3f37f7c..76fe7c5 100644 --- a/src/wsConnectionManager.ts +++ b/src/wsConnectionManager.ts @@ -146,15 +146,14 @@ async function main() { ws.send( JSON.stringify({ channel: requestChannel, - error: - 'Error subscribing to channel' + error: 'Error subscribing to channel', }) ); } else { ws.close( 1003, JSON.stringify({ - error: 'Error subscribing to channel' + error: 'Error subscribing to channel', }) ); } @@ -219,16 +218,14 @@ async function main() { ws.send( JSON.stringify({ channel: requestChannel, - error: - 'Error unsubscribing from channel' + error: 'Error unsubscribing from channel', }) ); } else { ws.close( 1003, JSON.stringify({ - error: - 'Error unsubscribing from channel' + error: 'Error unsubscribing from channel', }) ); }