data fixes, partial custom indicator support
This commit is contained in:
@@ -259,37 +259,17 @@ export class WebSocketDatafeed implements IBasicDataFeed {
|
||||
|
||||
const rawBars: any[] = response.history.bars || []
|
||||
|
||||
// Parse bars, preserving null OHLC for gap bars (no trades that period)
|
||||
const parsedBars: Bar[] = rawBars.map((bar: any) => {
|
||||
if (bar.open === null || bar.close === null) {
|
||||
return { time: bar.time * 1000, open: null, high: null, low: null, close: null }
|
||||
}
|
||||
return {
|
||||
time: bar.time * 1000,
|
||||
open: parseFloat(bar.open) / denoms.tick,
|
||||
high: parseFloat(bar.high) / denoms.tick,
|
||||
low: parseFloat(bar.low) / denoms.tick,
|
||||
close: parseFloat(bar.close) / denoms.tick,
|
||||
volume: parseFloat(bar.volume) / denoms.base
|
||||
}
|
||||
})
|
||||
// All bars have non-null prices — ingestor forward-fills interior gaps.
|
||||
const bars: Bar[] = rawBars.map((bar: any) => ({
|
||||
time: bar.time * 1000,
|
||||
open: parseFloat(bar.open) / denoms.tick,
|
||||
high: parseFloat(bar.high) / denoms.tick,
|
||||
low: parseFloat(bar.low) / denoms.tick,
|
||||
close: parseFloat(bar.close) / denoms.tick,
|
||||
volume: parseFloat(bar.volume) / denoms.base
|
||||
}))
|
||||
|
||||
parsedBars.sort((a, b) => a.time - b.time)
|
||||
|
||||
// Fill any gaps between returned bars with null bars so TradingView
|
||||
// receives a contiguous array of the correct length.
|
||||
const periodMs = intervalToSeconds(resolution) * 1000
|
||||
const bars: Bar[] = []
|
||||
for (let i = 0; i < parsedBars.length; i++) {
|
||||
if (i > 0) {
|
||||
const prev = parsedBars[i - 1].time
|
||||
const curr = parsedBars[i].time
|
||||
for (let t = prev + periodMs; t < curr; t += periodMs) {
|
||||
bars.push({ time: t, open: null, high: null, low: null, close: null })
|
||||
}
|
||||
}
|
||||
bars.push(parsedBars[i])
|
||||
}
|
||||
bars.sort((a, b) => a.time - b.time)
|
||||
|
||||
console.log('[TradingView Datafeed] Scaled bar sample:', bars[0])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user