Im trying to pull financial data from the polygon.io API to organize it and later inject it into an Azure database. In order to accomplish this I have been using the "petl" python package but I am having issues starting with an example table because of an invalid source argument that I believe to be caused by how I am retrieving and writing the JSON result.
import petl as etl
import websocket
import json
import requests
r =requests.get("https://api.polygon.io/v1/historic/forex/AUD/USD/2018-2-2?limit=1&apiKey=*********")
#gets data includes plenty of responses that arnt text
data = json.loads(r.text)
table1 = etl.fromjson(data, header=['day','map','msLatency','pair','status','ticks','type'])
print(table1)
I expected a table with the column headers being the ones listed with their values underneath but instead received this error message: "AssertionError: invalid source argument, expected None or a string or an object implementing open()"
When printing the data from the API it looks like this:
{'day': '2018-2-2', 'map': {'a': 'ask', 'b': 'bid', 't': 'timestamp'}, 'msLatency': 1, 'pair': 'AUD/USD', 'status': 'success', 'ticks': [{'b': 0.80392, 'a': 0.80392, 'x': 0, 't': 1517529600225}], 'type': 'forex'}
I have tried converting the data or using the api call line as the data argument but have had little success