I am trying to access the streaming API using Python and queries.
What the API says: "Weve turned on the streaming endpoint to request both quotation data and trade data using a permanent HTTP socket connection. Streaming data from the API is to execute an authenticated HTTP request and leave the HTTP open connection to constantly receive data. "
How I tried to access the data:
s = requests.Session() def streaming(symbols): url = 'https://stream.tradeking.com/v1/market/quotes.json' payload = {'symbols': ','.join(symbols)} return s.get(url, params=payload, stream=True) r = streaming(['AAPL', 'GOOG'])
The docs requests here show two things of interest: use a generator / iterator for use with interleaved data passed into the data field. It is proposed to use code for streaming data, for example:
for line in r.iter_lines(): print(line)
Nothing works, although I have no idea what to turn on the generator function, as the example is unclear. Using r.iter_lines (), I get the output: "b" {"status": "connected"} {"status": disconnected "} '"
I can access the headers and the response is HTTP 200, but cannot get valid data or find clear examples of how to access HTTP streaming data in python. Any help would be greatly appreciated. The API recommends using Jetty for Java to keep the stream open, but I'm not sure how to do this in Python.
Headers: {'connection': 'keep-alive', 'content-type': 'application / json', 'x-powered-by': 'Express', 'transfer-encoding': 'chunked'}