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

Updating DataCube on real-time data #136

Closed
adsonvinicius opened this issue Sep 1, 2020 · 19 comments
Closed

Updating DataCube on real-time data #136

adsonvinicius opened this issue Sep 1, 2020 · 19 comments
Labels
question Further information is requested

Comments

@adsonvinicius
Copy link

adsonvinicius commented Sep 1, 2020

Checking docs I could see 3 possibilites of updating chart, using real-time data changes. The auto-timestamp idea behind price/volume updates considering open a new candle at moment of chart update call. However when retrieving previous (from now) candles sometimes the last candle isn't closed yet (depending of timeframe used). So is there a way to update the current candle when the now-timestamp still belongs to an opened candle?

@C451 C451 added the question Further information is requested label Sep 2, 2020
@adsonvinicius
Copy link
Author

adsonvinicius commented Sep 3, 2020

On the way to solve this, it could be a reasonable workaround ignore the last candle retrieved, creating a candle by myself using the ignored candle's data and updating it using the new values until finish the timestamp and then let the the library works as default?

@smcgovern
Copy link

From what it sounds like, you are trying to have the latest candle shown when it is not yet saved to your OHLC data? What I do -- since I collect all the ticks happening -- is when the page is loading I create a latestCandle that I push into the DataCube one page load with the component's beforeMounted() hook, then my live data feed continues to update the chart from there.

@adsonvinicius
Copy link
Author

adsonvinicius commented Sep 3, 2020

@smcgovern ok but when do you get the old candles, do you ignore the last one (which is not completed yet)?

On my chart, I make a XHR request to retrieve all candles of 5 minutes duration, and shows. Then start a WebSocket connection to handle price/volume data which by definition creates a new candle from the first chart update call, but the last candle of XHR request doesn't have closed yet and the first WebSocket data should be added on it (until the 5min time-step gets reached), which is not working

@smcgovern
Copy link

Correct me if I am wrong but the new websocket information should only create a new candle if its time is greater than the last candles + the timeframe interval you are watching.

I'd have to see the code to really get whats going on, some exchanges share OHLCV data with the currently drawn candle coming, others don't. I personally manage all the ticks and OHLC creation and fetch them from my local database, so when I'm fetching 5 minute data and the latest candle is 3 minutes away from being created, it gets appended as latestCandle and the websocket info pushes on top of it for the next 2 minutes.

@adsonvinicius
Copy link
Author

Correct me if I am wrong but the new websocket information should only create a new candle if its time is greater than the last candles + the timeframe interval you are watching.

Yes, you're right. If all candles have 5min difference between themselves and the WS data (price/volume) is fetched before the next timeframe (5min) the last candle should be updated before, instead of the library creates a new one automatically

I'd have to see the code to really get whats going on, some exchanges share OHLCV data with the currently drawn candle coming, others don't. I personally manage all the ticks and OHLC creation and fetch them from my local database, so when I'm fetching 5 minute data and the latest candle is 3 minutes away from being created, it gets appended as latestCandle and the websocket info pushes on top of it for the next 2 minutes.

I think you done similar what I asked: Fetch only the closed candles, retrieve the the information needed for create a new candle (latestCandle), updating this candle using WSS info until close and just after that let the library does its job.

If I'm correct I don't know how to stop updating the latestCandle and let the library creating new ones by itself.

The method I used was the fully-auto one:

// WSS onmessage method returning price-volume
...
this.chart.update({
price: stock.price,
volume: stock.volume,
})

@smcgovern
Copy link

Just append the latestCandle to the OHLC data, the system should automatically know it isn't closed yet. Insert the unclosed candle into the OHLCV array before even feeding it into tvjs.

@adsonvinicius
Copy link
Author

@smcgovern what the difference between doing that and fetch all 5min candles from XHR including last one which doesn't have closed yet, and just append WSS data (price/volume) through chart.update? This it should the correct behavior by system, shouldn't?

@smcgovern
Copy link

There should be no difference, if the OHLC data is coming with an unclosed candle and you use chart.update() it should just append to the unclosed candle.

@adsonvinicius
Copy link
Author

adsonvinicius commented Sep 3, 2020 via email

@smcgovern
Copy link

It is working for me, if you could recreate the problem using https://tvjs.io/play/ I'd def take a look at it.

@adsonvinicius
Copy link
Author

adsonvinicius commented Sep 4, 2020 via email

@smcgovern
Copy link

Yes I convert everything to UTC when I save OHLC data to my local db, its actually a preference I use before finding this project so I really think nothing of it. Timezones be cool though.

@adsonvinicius
Copy link
Author

adsonvinicius commented Sep 4, 2020 via email

@C451 C451 closed this as completed Sep 8, 2020
@adsonvinicius
Copy link
Author

This shouldn't be closed. I'm still facing this problem

@C451
Copy link
Collaborator

C451 commented Sep 8, 2020

@adsonvinicius I think @smcgovern did a great job of answering your question.

This part will likely be improved.
Alternatively you can rock your implementation. This will be fun, guaranteed.

@adsonvinicius
Copy link
Author

@C451, Sure he helped me, but I let the timestamps as UTC+0 on fetched candles and removed the "t += new Date(t).getTimezoneOffset() * MINUTE" from botbar.js functions and the system still creates a new candle when it shouldn't.

But if the auto-create candle checks whether the actual time still belongs to a created candle preventing create a new one, it's my bad then.

@C451
Copy link
Collaborator

C451 commented Sep 8, 2020

@adsonvinicius if you believe that there is a bug, create an issue using the template. That means I should be able to just copy paste the code/data and see the problem.

If you don't value my time, why should I value your problems?

@adsonvinicius
Copy link
Author

@C451 I think you misunderstood. You labelled as a question which it really was one. I could not reproduce because the data I fetch to simulate is real, and the market was closed on last 3 days, so I had to wait and see to provide what @smcgovern asked me to do.

I really don't get it why is this related to value time of anyone. I post here because someone can help me pointing what I couldn't see. just this.

Despite all of this, I really appreciate your job.

@adsonvinicius
Copy link
Author

A workaround i did for this: Just changed the now function on util.js

  now: function now() {
     return new Date().getTime() - new Date().getTimezoneOffset() * 60 * 1000;
  },

I guess if you consider all date on your current timezone, it should works. At least for my issue.

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

No branches or pull requests

3 participants