fix includeUserStats
This commit is contained in:
34
src/index.ts
34
src/index.ts
@@ -396,6 +396,7 @@ const main = async () => {
|
|||||||
driftClient,
|
driftClient,
|
||||||
driftClient.userStatsAccountSubscriptionConfig
|
driftClient.userStatsAccountSubscriptionConfig
|
||||||
);
|
);
|
||||||
|
await userStatsMap.subscribe();
|
||||||
|
|
||||||
const dlobSubscriber = new DLOBSubscriber({
|
const dlobSubscriber = new DLOBSubscriber({
|
||||||
driftClient,
|
driftClient,
|
||||||
@@ -488,8 +489,23 @@ const main = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleStartup = async (_req, res, _next) => {
|
||||||
|
if (
|
||||||
|
driftClient.isSubscribed &&
|
||||||
|
userMap.size() > 0 &&
|
||||||
|
userStatsMap.size() > 0
|
||||||
|
) {
|
||||||
|
res.writeHead(200);
|
||||||
|
res.end('OK');
|
||||||
|
} else {
|
||||||
|
res.writeHead(500);
|
||||||
|
res.end('Not ready');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// start http server listening to /health endpoint using http package
|
// start http server listening to /health endpoint using http package
|
||||||
app.get('/health', handleHealthCheck);
|
app.get('/health', handleHealthCheck);
|
||||||
|
app.get('/startup', handleStartup);
|
||||||
app.get('/', handleHealthCheck);
|
app.get('/', handleHealthCheck);
|
||||||
|
|
||||||
app.get('/orders/json/raw', async (_req, res, next) => {
|
app.get('/orders/json/raw', async (_req, res, next) => {
|
||||||
@@ -825,7 +841,7 @@ const main = async () => {
|
|||||||
|
|
||||||
const topMakers = new Set();
|
const topMakers = new Set();
|
||||||
let foundMakers = 0;
|
let foundMakers = 0;
|
||||||
const findMakers = (sideGenerator: Generator<DLOBNode>) => {
|
const findMakers = async (sideGenerator: Generator<DLOBNode>) => {
|
||||||
for (const side of sideGenerator) {
|
for (const side of sideGenerator) {
|
||||||
if (limit && foundMakers >= normedLimit) {
|
if (limit && foundMakers >= normedLimit) {
|
||||||
break;
|
break;
|
||||||
@@ -837,10 +853,14 @@ const main = async () => {
|
|||||||
} else {
|
} else {
|
||||||
if (`${includeUserStats}`.toLowerCase() === 'true') {
|
if (`${includeUserStats}`.toLowerCase() === 'true') {
|
||||||
const userAccount = side.userAccount.toBase58();
|
const userAccount = side.userAccount.toBase58();
|
||||||
const userStats = userStatsMap
|
await userMap.mustGet(userAccount);
|
||||||
.get(userAccount)
|
const userStats = await userStatsMap.mustGet(
|
||||||
.userStatsAccountPublicKey.toBase58();
|
userMap.getUserAuthority(userAccount)!.toBase58()
|
||||||
topMakers.add([userAccount, userStats]);
|
);
|
||||||
|
topMakers.add([
|
||||||
|
userAccount,
|
||||||
|
userStats.userStatsAccountPublicKey.toBase58(),
|
||||||
|
]);
|
||||||
} else {
|
} else {
|
||||||
topMakers.add(side.userAccount.toBase58());
|
topMakers.add(side.userAccount.toBase58());
|
||||||
}
|
}
|
||||||
@@ -853,7 +873,7 @@ const main = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (normedSide === 'bid') {
|
if (normedSide === 'bid') {
|
||||||
findMakers(
|
await findMakers(
|
||||||
dlobSubscriber
|
dlobSubscriber
|
||||||
.getDLOB()
|
.getDLOB()
|
||||||
.getRestingLimitBids(
|
.getRestingLimitBids(
|
||||||
@@ -864,7 +884,7 @@ const main = async () => {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
findMakers(
|
await findMakers(
|
||||||
dlobSubscriber
|
dlobSubscriber
|
||||||
.getDLOB()
|
.getDLOB()
|
||||||
.getRestingLimitAsks(
|
.getRestingLimitAsks(
|
||||||
|
|||||||
Reference in New Issue
Block a user