Skip to content
Open
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
17 changes: 12 additions & 5 deletions core/src/exchanges/myriad/normalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ const MYRIAD_PROMOTED_EVENT_KEYS = [
'id', 'title', 'markets',
] as const;

const WEI_SCALE = BigInt('1000000000000000000');
const PRECISION_SCALE = BigInt('1000000000000');

function weiStringToNumber(value: string): number {
const scaled = (BigInt(value) * PRECISION_SCALE) / WEI_SCALE;
return Number(scaled) / Number(PRECISION_SCALE);
}

function selectTimeframe(interval: CandleInterval): string {
switch (interval) {
case '1m':
Expand Down Expand Up @@ -213,15 +221,14 @@ export class MyriadNormalizer implements IExchangeNormalizer<MyriadRawMarket, My
}

normalizeClobOrderBook(raw: { bids: [string, string][]; asks: [string, string][] }): OrderBook {
const WEI = 1e18;
return {
bids: raw.bids.map(([priceWei, sizeWei]) => ({
price: Number(priceWei) / WEI,
size: Number(sizeWei) / WEI,
price: weiStringToNumber(priceWei),
size: weiStringToNumber(sizeWei),
})),
asks: raw.asks.map(([priceWei, sizeWei]) => ({
price: Number(priceWei) / WEI,
size: Number(sizeWei) / WEI,
price: weiStringToNumber(priceWei),
size: weiStringToNumber(sizeWei),
})),
timestamp: Date.now(),
};
Expand Down
11 changes: 11 additions & 0 deletions core/test/normalizers/exchange-normalizers-2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,17 @@ describe('MyriadNormalizer', () => {
const result = normalizer.normalizeMarket(noExpiry)!;
expect(result.resolutionDate.getTime()).toBe(0);
});

it('preserves sub-1 wei prices without rounding to 1', () => {
const result = normalizer.normalizeClobOrderBook({
bids: [['999999999999999999', '250000000000000000'], ['100000000000000000', '1']],
asks: [['500000000000000000', '1000000000000000000']],
});

expect(result.bids[0].price).toBeLessThan(1);
expect(result.bids[0].price).toBeCloseTo(0.999999999999);
expect(result.bids[0].size).toBeCloseTo(0.25);
});
});

// -----------------------------------------------------------------------
Expand Down
Loading