How to implement HeartBeat, UpdateQuote and UpdateMiniBar methods correctly in Streaming Providers?
Author: yzolotarev
Creation Date: 10/10/2016 7:54 PM
profile picture

yzolotarev

#1
I have been struggling with my streaming provider and although reading through the API a few thousand times and examining the Google Provider did help a lot I'm still stuck.

I subscribe to ticks data from my server, start a new thread just like in the google provider and inside a while loop start to create instances of the Quote object just like below, the same way as demonstrated in the Google Provider. The ticks come in perfect but what next...

CODE:
Please log in to see this code.


I don't understand what am I supposed to do next in order to:

- use the UpdateQuote(q) correctly

So far I have figured out, UpdateQuote(q); in this case will only update the quotes shown in the quotes window and it has to be called everytime I get a new tick from my server so I get all the h/l/c/o values into WL correctly. Does it do anything else? I have tried so many ways already that I think it sometimes updates the chart as well in some mystical manner that I don't completely understand. Does it add to the Quote collection that can be accessed by user at a required timestamp in order to form a new bar correctly with the appropriate h/l values that appeared in the tick data? Is that what the HeartBeat does?

- get bars to close in sync with the server and update on the chart

I have just as many Quote objects as I have ticks coming in and I want to close the bar at the moment when the tick changes the timeframe increment, 1 minute for example. What I'm worried about is if I use local time it might become out of sync with server time and eventually WL will put ticks that server_time are on the current bar, on the previous bar for example. What is the best workaround for this? Is this what the Heartbeat(DateTime timestamp) method is used for? From what I have figured out so far, the local time is somehow important but I can't figure out why. I thought I can make the provider independant from the local time, because it always differs depending on the connection so I wanted to close the bar as soon as I get a tick which is timestamped with a different server minute, is that even possible? What is the parameter that is passed with the Heartbeat, I have tried pasing various DateTime objects and could not figure out what it really affects.

- where do the bars go

The only method that I figured out that saves the actual bars to drive is the SaveBarsObject(bars); from the Static Part. What about the Streaming Provider, will the bars be saved on the drive if one of the above mentioned methods will be implemented correctly? What I'm worried about is runing the provider for a long time in streaming mode. Are there any guidelines or suggestions on this, if I keep it on for a long time I will eventually get an out of memory if the bars are not saved or should the static part be called from time to time or is it neccesary to form Bars objects from Quotes as well and add them to existing bars. The RequestData method seems to be called in the start when going into streaming mode but after that WL Streaming Provider seems to deal with the bars elsewhere.

- alternative method with collecting the quotes and passing them onto the minibar

I have the same issue with the UpdateMiniBar (Quote q, double open, double high, double low) as I have with the UpdateQute and HeartBeat. When is it suppposed to be called? Does it update the chart or save the bars to disk?

Any info on above problems will be very usefull and helpfull. Thank you.

profile picture

Eugene

#2
Yuri, you've raised really a lot of questions but sometimes an example is worth a thousand words. Here's a link to a Github repo referred in the Wiki FAQ with more examples of streaming providers like AlfaDirect and QUIK. I hope that helps.

QUOTE:
Is that what the HeartBeat does?
...
Is this what the Heartbeat(DateTime timestamp) method is used for?

What it does is documented in the API guide (see below), precisely.

QUOTE:
I thought I can make the provider independant from the local time,

It might be possible to sync your PC clock in your provider using NTP or SNMP. Your provider would have to run long enough for the clock to get out of sync... but isn't this (time synchronization) what Windows itself does effectively? If your server and client are both in sync, what's the issue?

QUOTE:
So far I have figured out, UpdateQuote(q); in this case will only update the quotes shown in the quotes window and it has to be called everytime I get a new tick from my server so I get all the h/l/c/o values into WL correctly.

That's right, with the exception that this applies not just to Quote windows but streaming chart windows.

QUOTE:
Does it add to the Quote collection that can be accessed by user

The only collection accessible to you is the one you build. There's no accessible collection in Wealth-Lab and it's not required.

QUOTE:
From what I have figured out so far, the local time is somehow important but I can't figure out why.

This was the point of my reply to your ticket 27465.

QUOTE:
I have the same issue with the UpdateMiniBar ...When is it suppposed to be called?

UpdateMiniBar should be called just as UpdateQuote method which it replaces. So as not to duplicate the API guide please follow the link for more detail.

QUOTE:
will the bars be saved on the drive if one of the above mentioned methods will be implemented correctly?
...
Does it update the chart or save the bars to disk?

You don't have to worry about this part. Wealth-Lab does that under the hood.
profile picture

yzolotarev

#3
Thank you! This should help.
profile picture

Eugene

#4
Glad to help.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).