OHLC rework

This commit is contained in:
tim
2024-08-06 20:59:37 -04:00
parent d47d90e432
commit f9f154f495
4 changed files with 258 additions and 212 deletions

View File

@@ -1,13 +1,17 @@
import {useChartOrderStore} from "@/orderbuild.js";
export function nearestOhlcStart(time) {
// todo subtract OHLC root time
const period = useChartOrderStore().intervalSecs
return Math.round(time / period) * period
const OHLC_START = new Date(1231027200*1000) // Sunday January 4th, 2009 just before Bitcoin Genesis
export function nearestOhlcStart(time, periodSeconds=null) {
if (periodSeconds===null)
periodSeconds = useChartOrderStore().intervalSecs
return Math.round((time-OHLC_START) / periodSeconds) * periodSeconds + OHLC_START
}
export function pointsToOhlcStart(points) {
return points === null ? null : points.map((p) => {
return {time: nearestOhlcStart(p.time), price: p.price}
})
}
}