add idlWithSlot market filter

This commit is contained in:
wphan
2023-05-23 09:55:14 -07:00
parent 74554249e4
commit 3589467d17

View File

@@ -24,6 +24,7 @@ import {
PerpMarkets,
DLOBSubscriber,
MarketType,
isVariant,
} from "@drift-labs/sdk";
import { Mutex } from "async-mutex";
@@ -549,11 +550,30 @@ const main = async () => {
}
});
app.get(
"/orders/idlWithSlot",
handleResponseTime,
async (_req, res, next) => {
app.get("/orders/idlWithSlot", handleResponseTime, async (req, res, next) => {
try {
const { marketName, marketIndex, marketType } = req.query;
const { normedMarketType, normedMarketIndex, error } = validateDlobQuery(
marketType as string,
marketIndex as string,
marketName as string
);
const useFilter =
marketName !== undefined ||
marketIndex !== undefined ||
marketType !== undefined;
if (useFilter) {
if (
error ||
normedMarketType === undefined ||
normedMarketIndex === undefined
) {
res.status(400).send(error);
return;
}
}
const dlobOrders: DLOBOrders = [];
for (const user of userMap.values()) {
@@ -564,6 +584,15 @@ const main = async () => {
continue;
}
if (useFilter) {
if (
getVariant(order.marketType) !== getVariant(normedMarketType) ||
order.marketIndex !== normedMarketIndex
) {
continue;
}
}
dlobOrders.push({
user: user.getUserAccountPublicKey(),
order,
@@ -571,7 +600,6 @@ const main = async () => {
}
}
res.writeHead(200);
res.end(
JSON.stringify({
slot: bulkAccountLoader.mostRecentSlot,
@@ -581,8 +609,7 @@ const main = async () => {
} catch (err) {
next(err);
}
}
);
});
const validateDlobQuery = (
marketType?: string,