How to create live data feed?
-
I wish to integrate with custom broker, do we have some sort of documentation to tell how can we easily achieve that?
-
See Docs - Binary Datafeed Development
There is only one thing which is needed missing in the document (tba):
- Method
live
which should returnTrue
if the fee is in live mode (such a feed can be for example used to download historical data from the online source and could returnFalse
in that case)
The rest is specific to the actual on-line source which may need:
- One or more background threads to manage connections to the online source
- Event-listening or polling
- Rate-limiting intelligence
- Time/Timezone management (to put the times in UTC format in to backtrader)
The recommendation would be to look at the latest developed data feed which was probably the cleanest implementtion:
Oanda
and see if the patterns match the ones of your online data feed. - Method
-
@backtrader Thanks, I'll read the tutorial.
May I know how does Cerebro know if there is new tick?
And how does Cerebro know when to stop? I wish to let it run forever by default, is it possible? -
May I know how does Cerebro know if there is new tick?
Because as shown in the document your
_load
method returnsTrue
if it can load something.In order to support resampling, the convention for data feeds is to return
None
if the data is not finished but has nothing to load.And how does Cerebro know when to stop? I wish to let it run forever by default, is it possible?
Cerebro won't stop if any data feed keeps on providing data.
-
@backtrader Thanks for the tip.
Can I know how OandaData expose the underlying data to Cerebro?
Can you point me to the relevant code in Cerebro?
-
It's obviously not in cerebro. Go to the sources and see
feeds/oanda.py
-
I guess I found it, so anyone implementing custom data feed should update
self.lines
in data feed. -
Out of curiosity. Isn't that in the documentation page linked above?
-
It wasn't clear to me at first. I only get it on hindsight.
I guess part of the reason is that I am not familiar with Python, and was expecting some method to be exposed rather than internal variables.
Thanks for your help !
-
They are not internal variables. The entire concept of backtrader revolves around the definition of lines and accessing/manipulating them.
-
@backtrader sorry I've missed them, now everything makes more sense.