From 7157a8c88825148be5533eacd32b9c4d3e5b9317 Mon Sep 17 00:00:00 2001 From: Caoyuan Deng Date: Thu, 5 Mar 2026 21:08:37 -0800 Subject: [PATCH] Fix data length in barstate. #150 --- src/namespaces/Barstate.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/namespaces/Barstate.ts b/src/namespaces/Barstate.ts index 2512f7f..6ebd179 100644 --- a/src/namespaces/Barstate.ts +++ b/src/namespaces/Barstate.ts @@ -3,7 +3,7 @@ import { Series } from '../Series'; export class Barstate { private _live: boolean = false; - constructor(private context: any) {} + constructor(private context: any) { } public setLive() { this._live = true; } @@ -20,20 +20,24 @@ export class Barstate { } public get ishistory() { - return this.context.idx < this.context.data.close.data.length - 1; + return this.context.idx < this.context.length - 1; } public get isrealtime() { - return this.context.idx === this.context.data.close.data.length - 1; + return this.context.idx === this.context.length - 1; } public get isconfirmed() { - return this.context.data.closeTime[this.context.data.closeTime.length - 1] <= new Date().getTime(); + return this.context.data.closeTime.data[this.context.idx] <= new Date().getTime(); } public get islastconfirmedhistory() { //FIXME : this is a temporary solution to get the islastconfirmedhistory value, //we need to implement a better way to handle it based on market data - return this.context.data.closeTime[this.context.data.closeTime.length - 1] <= new Date().getTime(); + return ( + // this is the last and isconfirmed + this.context.idx === this.context.length - 1 && this.isconfirmed || + // this is the second to last and the last is not confirmed + this.context.idx === this.context.length - 2 && this.context.data.closeTime.data[this.context.length - 1] > new Date().getTime()); } }