@davoodmehraban89 / VELYQOR / commits / fdaadeb
Fork 0

Intelligence, Advanced Charting & Trading Platform

Fix Alpha Vantage live gold response shape

Fix Alpha Vantage live gold response shape

Davood Mehraban committed Oct 10, 2026 at 15:56 UTC fdaadeba7c6111296ea3bfeee3763326cc44224a
2 files changed +7 -1
packages/market-domain/src/adapters/alpha-vantage.mjs
+3 -1
@@ -44,7 +44,9 @@ export function parseAlphaVantageGoldSpot({ payload, receivedAt }) {
44 throw new TypeError('payload must be an object');
45 }
46
47 - const unit = String(payload.unit ?? '').trim().toLowerCase();
47 + // GOLD_SILVER_SPOT currently returns nominal, timestamp, and price without a unit field.
48 + // The requested endpoint and GOLD symbol define USD per troy ounce; reject explicit conflicting units.
49 + const unit = String(payload.unit ?? 'usd per troy ounce').trim().toLowerCase();
50 if (!ACCEPTED_UNITS.has(unit)) {
51 throw new RangeError(`unsupported Alpha Vantage gold unit: ${payload.unit ?? '<missing>'}`);
52 }
packages/market-domain/test/alpha-vantage-live-shape.test.mjs new
+4
@@ -0,0 +1,4 @@
1 +import test from 'node:test';
2 +import assert from 'node:assert/strict';
3 +import {parseAlphaVantageGoldSpot} from '../src/adapters/alpha-vantage.mjs';
4 +test('accepts observed GOLD_SILVER_SPOT response without explicit unit',()=>{const result=parseAlphaVantageGoldSpot({payload:{nominal:'1',timestamp:'2026-10-05T12:00:00Z',price:'4001.25'},receivedAt:new Date('2026-10-05T12:00:02Z')});assert.equal(result.canonicalSymbol,'XAU_USD');assert.equal(result.price,4001.25);assert.equal(result.canonicalUnit,'USD_PER_TROY_OUNCE')});