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()); } }