Skip to content

stream() appends plot values on every live update #263

Description

@jentzheng

When using PineTS.stream() in live mode, the output series (ctx.plots[*].data) continues to grow on every polling interval, even when no new market bar has been added.

Reproduction

import { PineTS, Provider } from "pinets";

const pineTS = new PineTS(Provider.Binance, "ETHUSDT", "15m", 1000);

const code = `
//@version=5
indicator("Test", timeframe="15", overlay=false)

[TF_close] = request.security("ETHUSDT", "60", [close])

plot(close, title="close")
plot(TF_close, title="TF_close")
`;

const evt = pineTS.stream(code, {
  pageSize: 100,
  live: true,
  interval: 5000,
});

evt.on("data", (ctx) => {
  const lastCandle = ctx.marketData[ctx.idx];
  const isHistory = lastCandle.closeTime < Date.now();

  if (!isHistory) {
    console.log(
      "marketData",
      ctx.marketData.length,
      lastCandle.close
    );

    console.log(
      "close",
      ctx.plots["close"].data.length,
      ctx.plots["close"].data.at(-1)?.value
    );

    console.log(
      "TF_close",
      ctx.plots["TF_close"].data.length,
      ctx.plots["TF_close"].data.at(-1)?.value
    );
  }
});

It seems the live streaming engine appends new plot values on every polling cycle instead of updating the current bar until a new candle is confirmed and the value is also not consistence.

Image
index, D_close data
3000: {title: 'D_close', time: 1784446200000, value: 1869.39, options: {…}}
3001: {title: 'D_close', time: 1784446200000, value: 1868.56, options: {…}}
3002: {title: 'D_close', time: 1784446200000, value: 1867.33, options: {…}}
3003: {title: 'D_close', time: 1784446200000, value: 1867.08, options: {…}}
3004: {title: 'D_close', time: 1784446200000, value: 1871.44, options: {…}}
3005: {title: 'D_close', time: 1784446200000, value: 1859.18, options: {…}}
3006: {title: 'D_close', time: 1784446200000, value: 1861.45, options: {…}}
3007: {title: 'D_close', time: 1784446200000, value: 1862.61, options: {…}}

https://codesandbox.io/p/devbox/peaceful-pond-7xtrlm

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions