add includeUserStats to /topMakers

This commit is contained in:
wphan
2023-10-11 08:56:09 -07:00
parent 8ae9cb4fd2
commit d8b12305e9

View File

@@ -33,6 +33,7 @@ import {
groupL2,
L2OrderBook,
Wallet,
UserStatsMap,
} from '@drift-labs/sdk';
import { Mutex } from 'async-mutex';
@@ -391,6 +392,10 @@ const main = async () => {
false
);
await userMap.subscribe();
const userStatsMap = new UserStatsMap(
driftClient,
driftClient.userStatsAccountSubscriptionConfig
);
const dlobSubscriber = new DLOBSubscriber({
driftClient,
@@ -787,6 +792,7 @@ const main = async () => {
marketType,
side, // bid or ask
limit, // number of unique makers to return, if undefined will return all
includeUserStats,
} = req.query;
const { normedMarketType, normedMarketIndex, error } = validateDlobQuery(
@@ -817,7 +823,7 @@ const main = async () => {
normedLimit = parseInt(limit as string);
}
const topMakers: Set<string> = new Set();
const topMakers = new Set();
let foundMakers = 0;
const findMakers = (sideGenerator: Generator<DLOBNode>) => {
for (const side of sideGenerator) {
@@ -828,8 +834,16 @@ const main = async () => {
const maker = side.userAccount.toBase58();
if (topMakers.has(maker)) {
continue;
} else {
if (`${includeUserStats}`.toLowerCase() === 'true') {
const userAccount = side.userAccount.toBase58();
const userStats = userStatsMap
.get(userAccount)
.userStatsAccountPublicKey.toBase58();
topMakers.add([userAccount, userStats]);
} else {
topMakers.add(side.userAccount.toBase58());
}
foundMakers++;
}
} else {