This commit is contained in:
tim
2025-02-21 23:37:29 -04:00
parent 366531c185
commit 2397ebfe45
7 changed files with 17 additions and 15 deletions

View File

@@ -144,7 +144,8 @@ export async function loadOHLC (symbol, contract, from, to, tvRes) {
let baseUrl
let latest = null // latest time, price
function fill(end, period) {
function fill(end) {
const period = res.seconds
if (latest===null) return
const [latestTime, price] = latest
end = ohlcStart(end, period)
@@ -206,6 +207,8 @@ export async function loadOHLC (symbol, contract, from, to, tvRes) {
const rows = responses[ri].split('\n')
for( let rj=0; rj<rows.length; rj++) {
const line = rows[rj];
if (line.trim().length === 0)
continue
const row = line.split(',')
let time, open, high, low, close=null
switch (row.length) {
@@ -262,18 +265,20 @@ export async function loadOHLC (symbol, contract, from, to, tvRes) {
finished = true
break
}
if (time >= from) {
fill(time, res.seconds)
if ( time >= from ) {
if ( latest !== null && time > latest[0] + res.seconds) {
fill(time)
}
const bar = {time: time * 1000, open, high, low, close};
bars.push(bar)
latest = [time, close]
}
}
}
console.log(`processed ${lineNum} lines`)
// console.log(`processed ${lineNum} lines`)
}
// console.log('loadOHLC prefill bars', bars)
fill(to, res.seconds)
fill(to)
// console.log('loadOHLC bars', bars)
return bars
}