April 2019
Intermediate to advanced
426 pages
11h 13m
English
Add the following stream_prices() method in the OandaBroker class to start streaming prices from your broker:
def stream_prices(self, symbols=[]):
response = self.stream_api.pricing.stream(
self.accountid,
instruments=",".join(symbols),
snapshot=True
)
for msg_type, msg in response.parts():
if msg_type == "pricing.Heartbeat":
continue
elif msg_type == "pricing.ClientPrice":
self.process_price(msg)
Since the host connection expects a continuous stream, the response object has a parts() method that listens for incoming data. The msg object is essentially a price object, which we can reuse with the process_price() method to notify the listeners of an incoming price event.