Intelligence, Advanced Charting & Trading Platform
fix(chart-ui): consume normalized REST history time/price fields without inventing candles
davoodmehraban89 committed
Oct 12, 2026 at 00:22 UTC
fd6cfdd16eb19b412a634932ba722e059b7e0707
1 file changed
+9
-8
packages/chart-ui/src/LightweightMarketChart.tsx
+9
-8
@@ -6,8 +6,8 @@ import {
6
} from "lightweight-charts";
7
8
type Quality="GOOD"|"DEGRADED"|"STALE"|"INVALID";
9
-type Point={date:string;close:number;quality:Quality};
10
-type Candle={openTime:string;sessionDate?:string;open:string|number;high:string|number;low:string|number;close:string|number;quality:Quality};
9
+type Point={date?:string;time?:string;close?:number;price?:number;quality:Quality};
10
+type Candle={openTime?:string;time?:string;sessionDate?:string;open:string|number;high:string|number;low:string|number;close:string|number;volume?:number|null;quality:Quality};
11
type History={
12
ok:boolean;symbol:string;source:string;storage:string;
13
dataKind:"source_ohlc"|"daily_reference_point_not_ohlc"|"reference_point";
@@ -33,8 +33,9 @@ function safeTime(t:string,day:boolean):Time{
33
return Math.floor(value/1000) as UTCTimestamp;
34
}
35
function pointValue(p:Point):number{
36
- if(!Number.isFinite(p.close)||p.close<=0)throw Error("Invalid reference rate");
37
- return p.close;
36
+ const value=Number(p.price??p.close);
37
+ if(!Number.isFinite(value)||value<=0)throw Error("Invalid reference rate");
38
+ return value;
39
}
40
function candleValue(c:Candle){
41
const [open,high,low,close]=[c.open,c.high,c.low,c.close].map(Number);
@@ -83,11 +84,11 @@ export function LightweightMarketChart({symbol,from,to,timeframe,historyEndpoint
84
const isCandle=data.dataKind==="source_ohlc";
85
if(isCandle&&data.timeframe&&data.timeframe!==timeframe)throw Error("بازه زمانی کندل ناسازگار است");
86
const mapped=isCandle?data.series.map(p=>{
86
- if(!("openTime" in p))throw Error("Missing source candle");
87
- return {time:safeTime(timeframe==="1d"?(p.sessionDate??p.openTime):p.openTime,timeframe==="1d"),...candleValue(p)};
87
+ if(!("open" in p))throw Error("Missing source candle");
88
+ return {time:safeTime(timeframe==="1d"?(p.sessionDate??p.openTime??p.time??""):(p.openTime??p.time??""),timeframe==="1d"),...candleValue(p)};
89
}):data.series.map(p=>{
89
- if(!("date" in p))throw Error("Missing point timestamp");
90
- return {time:safeTime(p.date,true),value:pointValue(p)};
90
+ if(!("date" in p)&&!("time" in p))throw Error("Missing point timestamp");
91
+ return {time:safeTime(p.date??p.time??"",timeframe==="1d"),value:pointValue(p)};
92
});
93
for(let i=1;i<mapped.length;i++){
94
// Data must already be sorted and deduplicated by the provider adapter.