Versie 0.3.2

This commit is contained in:
Atreides Assets committed 2026-10-29 15:24:06 +01:00
1 parent e77d8fd373
commit 1cf6eeed29
16 files changed
+551 -44

No files matched your search

+9 -4
View File
@@ -1,4 +1,4 @@
// Generated, do not edit. sha256:31a0448818ec43a013271278ccfca034b12a6cd78e023ce301c87ce6d267b944
// Generated, do not edit. sha256:30f785c6890a03397971aad68496979bd9657deab8cb4a7a61fd0569a7cf87a8
import { randomUUID, createHash } from 'node:crypto';
import { readFileSync } from 'node:fs';
import { readFile, writeFile, mkdir } from 'node:fs/promises';
@@ -342,18 +342,23 @@ export function createMarketClient({
const { json, requestId } = await exchange('/v1/series', { instrument, quote, kind: 'history', from: cursor, to });
rid = requestId;
const cols = Array.isArray(json.columns) ? json.columns : [];
const [ti, pi, ri] = ['t', 'price', 'resolution'].map(c => cols.indexOf(c));
const [ti, pi, ri, si] = ['t', 'price', 'resolution', 'source'].map(c => cols.indexOf(c));
if (ti < 0 || pi < 0 || ri < 0 || !Array.isArray(json.rows) || typeof json.currency !== 'string' || !json.currency) {
fail('marketService.badAnswer', { url: (await config()).url }, 'The history in the answer has no time, price, resolution or currency.');
}
if (meta && json.currency !== meta.currency) {
fail('marketService.badAnswer', { url: (await config()).url }, 'The currency changed between two pages of one series.');
}
meta ??= { instrument, currency: json.currency, source: json.source || null };
meta ??= { instrument, currency: json.currency, source: json.source || null, sourceLabels: {} };
if (json.sourceLabels && typeof json.sourceLabels === 'object') {
for (const [key, label] of Object.entries(json.sourceLabels)) if (typeof label === 'string' && label) meta.sourceLabels[key] = label;
}
for (const r of json.rows) {
const t = Number(r?.[ti]);
const p = Number(r?.[pi]);
if (Number.isFinite(t) && t > 0 && Number.isFinite(p) && p > 0) points.push([t, p, r[ri]]);
if (!(Number.isFinite(t) && t > 0 && Number.isFinite(p) && p > 0)) continue;
const src = si >= 0 && typeof r[si] === 'string' && r[si] ? r[si] : null;
points.push(src ? [t, p, r[ri], src] : [t, p, r[ri]]);
}
if (json.next == null || !(Number(json.next) > cursor)) break;
cursor = Number(json.next);