unrip/test/market-data.test.mjs
philipp 0f33a53fa9
Some checks failed
deploy / deploy (push) Failing after 54s
Add BTC USDC price route
Proof: npm test passed 184/184; npm run operator-dashboard:build; focused route tests cover BTC/USDC route seeding, inventory tracking, Kraken/CoinGecko parsing, route-specific price selection, fresh BTC/USDC strategy approval, stale route blocking, and missing USDC reference fields.

Assumptions: BTC/USDC uses Kraken XBTUSDC as primary reference and CoinGecko bitcoin/USD as fallback with USDC ~= USD; operator-enabled maker pairs may mark their assets inventory-tracked, but imported assets remain non-trading by default.

Still fake: BTC/USDC taker request creation is not generalized; USDC/USD parity is an explicit assumption; solver liquidity and fee-complete PnL are not proven by this route.
2026-05-13 15:18:38 +02:00

37 lines
961 B
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {
fetchCoinGeckoBtcUsd,
fetchKrakenBtcUsdc,
} from '../src/lib/market-data.mjs';
test('market data helpers parse Kraken BTC/USDC and CoinGecko BTC/USD prices', async () => {
const previousFetch = globalThis.fetch;
try {
globalThis.fetch = async (url) => ({
ok: true,
async text() {
if (String(url).includes('kraken')) {
return JSON.stringify({
result: {
XBTUSDC: {
c: ['80266.54000', '0.00019173'],
},
},
});
}
return JSON.stringify({
bitcoin: {
usd: 80250.12,
},
});
},
});
assert.equal(await fetchKrakenBtcUsdc('https://kraken.test'), 80266.54);
assert.equal(await fetchCoinGeckoBtcUsd('https://coingecko.test'), 80250.12);
} finally {
globalThis.fetch = previousFetch;
}
});