historical bars fill fix

This commit is contained in:
tim
2024-10-26 19:58:54 -04:00
parent ffdb60afa2
commit cf7eb637bc
3 changed files with 13 additions and 10 deletions

View File

@@ -121,10 +121,10 @@ export async function loadOHLC (symbol, contract, from, to, tvRes) {
function fill(end, period) {
if (latest===null) return
const [start, price] = latest
const periodSecs = period * 60
end = ohlcStart(end, periodSecs)
for (let now=ohlcStart(start+periodSecs, periodSecs); now < end; now += periodSecs ) {
const [latestTime, price] = latest
end = ohlcStart(end, period)
const start = ohlcStart(latestTime+period, period);
for (let now= start; now < end; now += period ) {
bars.push({time:now * 1000, open:price, high:price, low:price, close:price})
latest = [now, price]
}

View File

@@ -226,11 +226,14 @@ export function linspace(a, b, n) {
export function intervalToSeconds(interval) {
if (interval.endsWith('T'))
throw Error('Tick intervals not supported')
return interval.endsWith('M') ? 30 * 24 * 60 * 60
: interval.endsWith('W') ? 7 * 24 * 60 * 60
: interval.endsWith('D') ? 24 * 60 * 60
: interval.endsWith('S') ? 1
: 60 // if no unit char, then it's minutes
const unit = interval.endsWith('M') ? 30 * 24 * 60 * 60
: interval.endsWith('W') ? 7 * 24 * 60 * 60
: interval.endsWith('D') ? 24 * 60 * 60
: interval.endsWith('S') ? 1
: 60 // if no unit char, then it's minutes
const result = parseInt(/\d+/.exec(interval)[0]) * unit
console.log('intervalToSeconds', interval, result)
return result
}

View File

@@ -5,7 +5,7 @@ import Color from "color";
// export const red = '#DD1A10';
// export const green = '#009f49'
// export const red = '#BD0D26'
export const green = '#1e9a57'
export const green = '#20A55D'
export const red = '#B22235'
export const yellow = '#FFDE00'
export const orange = '#F58A00'