Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streaming Issue in Intraday #359

Open
hiran-iouring opened this issue Oct 12, 2023 · 1 comment
Open

Streaming Issue in Intraday #359

hiran-iouring opened this issue Oct 12, 2023 · 1 comment

Comments

@hiran-iouring
Copy link

I Have implemented streaming using web socket data based on the
[https://www.tradingview.com/charting-library-docs/latest/tutorials/implement_datafeed_tutorial/Streaming-Implementation/] but it suits only historical data, not working for Intraday.

Actual Scenario: Assume have refresh the charts at 12:48pm, with 30m interval, got data upto 12:45pm from getBars and streaming subscribed then upto 12:59:59pm data updates on 12:45 candle.

when time reaches to 01:00 pm new candle plots here instead of 01:15pm. Observed it happens only at when Heikin Ashi selects.

** Expected**
How to implement streaming for Intraday(Minute data) and Historical data?

Note: We are not found any relevant example from official documentation. So, we are taken reference as [https://medium.com/@jonchurch/tv-part-2-b8c2d4211f90]

The below code is core logic for candle update

`function updateBar(streamResponse, sub) {
var lastBar = sub.lastBar;
let resolution = sub.resolution;
if (resolution.includes('D')) {
// 1 day in minutes === 1440
resolution = 1440
} else if (resolution.includes('W')) {
// 1 week in minutes === 10080
resolution = 10080
}
var coeff = resolution * 60 * 1000;
// console.log({coeff})
var rounded = Math.floor(streamResponse.tradeTime / coeff) * coeff;
var lastBarSec = lastBar.time;
var _lastBar;

if (rounded > lastBarSec) {
    // create a new candle, use last close as open **PERSONAL CHOICE**
    _lastBar = {
        time: rounded,
        open: lastBar.close,
        high: lastBar.close,
        low: lastBar.close,
        close: streamResponse.tradePricel
    }

} else {
    // update lastBar candle!
    if (streamResponse.tradePrice < lastBar.low) {
        lastBar.low = streamResponse.tradePrice
    } else if (streamResponse.tradePrice > lastBar.high) {
        lastBar.high = streamResponse.tradePrice
    }

    lastBar.close = streamResponse.tradePrice
    _lastBar = lastBar
}
return _lastBar;

}`

@buzzsubash
Copy link

following

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants