Intelligence, Advanced Charting & Trading Platform
test(integration): specify REST history contract consumed by chart renderer
davoodmehraban89 committed
Oct 12, 2026 at 00:31 UTC
8c5cd3e8d0683995240a2c1c4bd5be9a7cd70d4c
1 file changed
+32
packages/market-feed/test/history-to-chart-integration.test.mjs
new
+32
@@ -0,0 +1,32 @@
1
+import test from "node:test";
2
+import assert from "node:assert/strict";
3
+import {serveHistoryV2} from "../src/history-api.mjs";
4
+import {normalizeHistoryResponse} from "../src/chart-adapter.mjs";
5
+// Synthetic isolated fixtures, not real prices nor redistributable vendor data.
6
+const request=(params)=>new Request("https://staging.invalid/api/v2/history?"+new URLSearchParams(params));
7
+const params={
8
+ symbol:"BTC_USD",dataKind:"source_ohlc",timeframe:"1h",
9
+ from:"2026-10-08",to:"2026-10-10",limit:"10",
10
+};
11
+test("provider-neutral licensed REST response can be consumed by Lightweight Charts candle adapter",async()=>{
12
+ const res=await serveHistoryV2(request(params),{lookup:async()=>({
13
+ source:"fixture_provider",rights:"approved_public",dataKind:"source_ohlc",attribution:"Test fixture",unit:"USD_PER_BTC",
14
+ rows:[{symbol:"BTC_USD",unit:"USD_PER_BTC",timeframe:"1h",openTime:"2026-10-09T10:00:00Z",closeTime:"2026-10-09T11:00:00Z",
15
+ open:"101",high:"106",low:"99",close:"104",volume:"0",quality:"GOOD"}]
16
+ })});
17
+ assert.equal(res.status,200);
18
+ const data=await res.json(),normalized=normalizeHistoryResponse(data,"BTC_USD");
19
+ assert.equal(normalized.kind,"candle");
20
+ assert.equal(normalized.data[0].time,Date.parse("2026-10-09T10:00:00Z")/1000);
21
+ assert.equal(normalized.data[0].close,104);
22
+});
23
+test("provider-neutral daily reference time/price cannot become OHLC",async()=>{
24
+ const res=await serveHistoryV2(request({...params,symbol:"EUR_USD_ECB",dataKind:"reference_point",timeframe:"1d"}),{lookup:async()=>({
25
+ source:"fixture_reference",rights:"approved_public",dataKind:"reference_point",attribution:"Test fixture",unit:"USD_PER_EUR",
26
+ rows:[{symbol:"EUR_USD_ECB",unit:"USD_PER_EUR",sourceTimestamp:"2026-10-09T14:00:00Z",price:"1.16",quality:"GOOD"}]
27
+ })});
28
+ assert.equal(res.status,200);
29
+ const out=normalizeHistoryResponse(await res.json(),"EUR_USD_ECB");
30
+ assert.equal(out.kind,"reference");
31
+ assert.deepEqual(out.data,[{time:"2026-10-09",value:1.16}]);
32
+});