Submodule drift-common updated: 1458a9b2c1...99805fd4a5
85
src/index.ts
85
src/index.ts
@@ -546,29 +546,48 @@ const main = async (): Promise<void> => {
|
|||||||
selectMostRecentBySlot
|
selectMostRecentBySlot
|
||||||
);
|
);
|
||||||
const depthToUse = Math.min(parseInt(adjustedDepth as string) ?? 1, 100);
|
const depthToUse = Math.min(parseInt(adjustedDepth as string) ?? 1, 100);
|
||||||
|
let cacheMiss = true;
|
||||||
|
if (redisL2) {
|
||||||
|
cacheMiss = false;
|
||||||
redisL2['bids'] = redisL2['bids']?.slice(0, depthToUse);
|
redisL2['bids'] = redisL2['bids']?.slice(0, depthToUse);
|
||||||
redisL2['asks'] = redisL2['asks']?.slice(0, depthToUse);
|
redisL2['asks'] = redisL2['asks']?.slice(0, depthToUse);
|
||||||
if (redisL2) {
|
l2Formatted = redisL2;
|
||||||
l2Formatted = JSON.stringify(redisL2);
|
} else {
|
||||||
|
console.log(
|
||||||
|
`No L2 found for ${getVariant(
|
||||||
|
normedMarketType
|
||||||
|
)} market ${normedMarketIndex}`
|
||||||
|
);
|
||||||
|
const oracleData = isSpot
|
||||||
|
? driftClient.getOracleDataForSpotMarket(normedMarketIndex)
|
||||||
|
: driftClient.getOracleDataForPerpMarket(normedMarketIndex);
|
||||||
|
l2Formatted = {
|
||||||
|
bids: [],
|
||||||
|
asks: [],
|
||||||
|
marketType: normedMarketType,
|
||||||
|
marketIndex: normedMarketIndex,
|
||||||
|
marketName: undefined,
|
||||||
|
slot: dlobProvider.getSlot(),
|
||||||
|
oracle: oracleData.price.toNumber(),
|
||||||
|
oracleData: {
|
||||||
|
price: oracleData.price.toNumber(),
|
||||||
|
slot: oracleData.slot.toNumber(),
|
||||||
|
confidence: oracleData.confidence.toNumber(),
|
||||||
|
hasSufficientNumberOfDataPoints: true,
|
||||||
|
twap: oracleData.twap.toNumber(),
|
||||||
|
twapConfidence: oracleData.twapConfidence.toNumber(),
|
||||||
|
},
|
||||||
|
ts: Date.now(),
|
||||||
|
marketSlot: dlobProvider.getSlot(),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (l2Formatted) {
|
|
||||||
cacheHitCounter.add(1, {
|
cacheHitCounter.add(1, {
|
||||||
miss: false,
|
miss: cacheMiss,
|
||||||
path: req.baseUrl + req.path,
|
path: req.baseUrl + req.path,
|
||||||
});
|
});
|
||||||
res.writeHead(200);
|
res.writeHead(200);
|
||||||
res.end(l2Formatted);
|
res.end(JSON.stringify(l2Formatted));
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
cacheHitCounter.add(1, {
|
|
||||||
miss: true,
|
|
||||||
path: req.baseUrl + req.path,
|
|
||||||
});
|
|
||||||
res.writeHead(500);
|
|
||||||
res.end('No dlob data found');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
next(err);
|
next(err);
|
||||||
}
|
}
|
||||||
@@ -636,20 +655,50 @@ const main = async (): Promise<void> => {
|
|||||||
selectMostRecentBySlot
|
selectMostRecentBySlot
|
||||||
);
|
);
|
||||||
const depth = Math.min(parseInt(adjustedDepth as string) ?? 1, 100);
|
const depth = Math.min(parseInt(adjustedDepth as string) ?? 1, 100);
|
||||||
|
let cacheMiss = true;
|
||||||
|
if (redisL2) {
|
||||||
|
cacheMiss = false;
|
||||||
redisL2['bids'] = redisL2['bids']?.slice(0, depth);
|
redisL2['bids'] = redisL2['bids']?.slice(0, depth);
|
||||||
redisL2['asks'] = redisL2['asks']?.slice(0, depth);
|
redisL2['asks'] = redisL2['asks']?.slice(0, depth);
|
||||||
if (redisL2) {
|
|
||||||
l2Formatted = redisL2;
|
l2Formatted = redisL2;
|
||||||
|
} else {
|
||||||
|
console.log(
|
||||||
|
`No L2 found for ${getVariant(
|
||||||
|
normedMarketType
|
||||||
|
)} market ${normedMarketIndex}`
|
||||||
|
);
|
||||||
|
const oracleData = isSpot
|
||||||
|
? driftClient.getOracleDataForSpotMarket(normedMarketIndex)
|
||||||
|
: driftClient.getOracleDataForPerpMarket(normedMarketIndex);
|
||||||
|
l2Formatted = {
|
||||||
|
bids: [],
|
||||||
|
asks: [],
|
||||||
|
marketType: normedMarketType,
|
||||||
|
marketIndex: normedMarketIndex,
|
||||||
|
marketName: undefined,
|
||||||
|
slot: dlobProvider.getSlot(),
|
||||||
|
oracle: oracleData.price.toNumber(),
|
||||||
|
oracleData: {
|
||||||
|
price: oracleData.price.toNumber(),
|
||||||
|
slot: oracleData.slot.toNumber(),
|
||||||
|
confidence: oracleData.confidence.toNumber(),
|
||||||
|
hasSufficientNumberOfDataPoints: true,
|
||||||
|
twap: oracleData.twap.toNumber(),
|
||||||
|
twapConfidence: oracleData.twapConfidence.toNumber(),
|
||||||
|
},
|
||||||
|
ts: Date.now(),
|
||||||
|
marketSlot: dlobProvider.getSlot(),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (l2Formatted) {
|
if (l2Formatted) {
|
||||||
cacheHitCounter.add(1, {
|
cacheHitCounter.add(1, {
|
||||||
miss: false,
|
miss: cacheMiss,
|
||||||
path: req.baseUrl + req.path,
|
path: req.baseUrl + req.path,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
cacheHitCounter.add(1, {
|
cacheHitCounter.add(1, {
|
||||||
miss: true,
|
miss: cacheMiss,
|
||||||
path: req.baseUrl + req.path,
|
path: req.baseUrl + req.path,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user