tv DataFeed rework

This commit is contained in:
tim
2024-08-28 18:57:58 -04:00
parent 55397c2b1c
commit 79a6822fd5
7 changed files with 468 additions and 403 deletions

View File

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