data fixes; indicator=>workspace sync

This commit is contained in:
2026-03-31 20:29:12 -04:00
parent 998f69fa1a
commit cd28e18e52
45 changed files with 1324 additions and 1239 deletions

View File

@@ -9,6 +9,7 @@
*/
import { wsManager, type MessageHandler } from './useWebSocket'
import { intervalToSeconds } from '../utils'
import type {
IBasicDataFeed,
DatafeedConfiguration,
@@ -241,14 +242,39 @@ export class WebSocketDatafeed implements IBasicDataFeed {
console.log('[TradingView Datafeed] Raw bar sample:', response.history.bars?.[0])
console.log('[TradingView Datafeed] Denominators:', denoms)
const bars: Bar[] = (response.history.bars || []).map((bar: any) => ({
time: bar.time * 1000, // Convert to milliseconds
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
}))
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
}
})
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])
}
console.log('[TradingView Datafeed] Scaled bar sample:', bars[0])