Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions src/publishers/tests/tradeMetricsProcessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,82 @@ describe('tradeMetricsProcessor', () => {
},
]);
});

it('does not emit maker_not_competitive for a fill maker without indicative quotes', async () => {
const metrics = createMetricSinks();
const quoteState = new Map<string, any>([
['market_mms_perp_0', ['quoted-maker']],
[
'mm_quotes_v2_perp_0_quoted-maker',
{
ts: 1710000000000,
quotes: [{ bid_price: 99900000, bid_size: 1000000000 }],
},
],
]);

const { processFillEvent } = createTradeMetricsProcessor({
redisClientPrefix: 'dlob:',
indicativeQuoteMaxAgeMs: 1000,
indicativeQuotesCacheTtlMs: 250,
spotMarketPrecisionResolver: () => undefined,
publisherRedisClient: {
publish: async () => 1,
},
indicativeQuotesRedisClient: {
smembers: async (key) => quoteState.get(key) ?? [],
get: async (key) => quoteState.get(key),
},
metrics,
});

const fillEvent: FillEvent = {
ts: 1710000000000,
marketIndex: 0,
marketType: 'perp',
filler: 'mock-filler',
takerFee: 0,
makerFee: 0,
quoteAssetAmountSurplus: 0,
baseAssetAmountFilled: 1,
quoteAssetAmountFilled: 100,
taker: 'mock-taker',
takerOrderId: 1,
takerOrderDirection: 'short',
takerOrderBaseAssetAmount: 1,
takerOrderCumulativeBaseAssetAmountFilled: 1,
takerOrderCumulativeQuoteAssetAmountFilled: 100,
maker: 'external-maker',
makerOrderId: 2,
makerOrderDirection: 'long',
makerOrderBaseAssetAmount: 1,
makerOrderCumulativeBaseAssetAmountFilled: 1,
makerOrderCumulativeQuoteAssetAmountFilled: 100,
oraclePrice: 100,
txSig: 'mock-2',
slot: 2,
fillRecordId: 2,
action: 'fill',
actionExplanation: 'none',
referrerReward: 0,
bitFlags: 0,
};

await processFillEvent(fillEvent);

expect(metrics.indicativeQuoteEvaluationCount.calls).not.toEqual(
expect.arrayContaining([
{
value: 1,
attributes: {
maker: 'external-maker',
market_index: 0,
market_type: 'perp',
side: 'long',
result: 'maker_not_competitive',
},
},
])
);
});
});
7 changes: 7 additions & 0 deletions src/publishers/tradeMetricsProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,15 @@ export const createTradeMetricsProcessor = ({
});
}

const fillMakerEvaluation = fillEvent.maker
? marketQuoteEvaluations.find(
(evaluation) => evaluation.maker === fillEvent.maker
)
: undefined;
if (
fillEvent.maker &&
fillMakerEvaluation &&
fillMakerEvaluation.totalQuoteValueOnBook > 0 &&
!marketQuotes.find((quote) => quote.maker === fillEvent.maker)
) {
metrics.indicativeQuoteEvaluationCount.add(1, {
Expand Down
Loading