Switched batchL2 endpoint to just return array of results

This commit is contained in:
Luke Steyn
2023-06-02 14:27:09 +09:00
parent b096e782d7
commit ed53e78b8e

View File

@@ -1021,8 +1021,7 @@ const main = async () => {
return; return;
} }
const batchedL2s = {}; const l2s = normedParams.map((normedParam) => {
for (const normedParam of normedParams) {
const { normedMarketType, normedMarketIndex, error } = const { normedMarketType, normedMarketIndex, error } =
validateDlobQuery( validateDlobQuery(
normedParam['marketType'] as string, normedParam['marketType'] as string,
@@ -1035,7 +1034,6 @@ const main = async () => {
} }
const isSpot = isVariant(normedMarketType, 'spot'); const isSpot = isVariant(normedMarketType, 'spot');
const marketTypeStr = getVariant(normedMarketType);
let adjustedDepth = normedParam['depth'] ?? '10'; let adjustedDepth = normedParam['depth'] ?? '10';
if (normedParam['grouping'] !== undefined) { if (normedParam['grouping'] !== undefined) {
@@ -1072,23 +1070,16 @@ const main = async () => {
const groupingBN = new BN( const groupingBN = new BN(
parseInt(normedParam['grouping'] as string) parseInt(normedParam['grouping'] as string)
); );
if (batchedL2s[marketTypeStr] === undefined) {
batchedL2s[marketTypeStr] = {}; return l2WithBNToStrings(groupL2(l2, groupingBN, finalDepth));
}
batchedL2s[marketTypeStr][normedMarketIndex] = l2WithBNToStrings(
groupL2(l2, groupingBN, finalDepth)
);
} else { } else {
// make the BNs into strings // make the BNs into strings
if (batchedL2s[marketTypeStr] === undefined) { return l2WithBNToStrings(l2);
batchedL2s[marketTypeStr] = {};
}
batchedL2s[marketTypeStr][normedMarketIndex] = l2WithBNToStrings(l2);
} }
} });
res.writeHead(200); res.writeHead(200);
res.end(JSON.stringify(batchedL2s)); res.end(JSON.stringify({ l2s }));
} catch (err) { } catch (err) {
next(err); next(err);
} }