Jan-10-2021, 01:29 AM
Pulling from polygon.io API.
(JSON Object Response example at bottom)
green text is where im stuck
red text is from documentation
this response object from the api has no top-level key for the json.
Read https://medium.com/swlh/converting-neste...106c59976e
2/3 down they have a json_normalize example
it uses a top-level key and the response object I am getting does not have one.
what do i put in my highlighted line below?
from documentation:
(JSON Object Response example at bottom)
green text is where im stuck
red text is from documentation
this response object from the api has no top-level key for the json.
Read https://medium.com/swlh/converting-neste...106c59976e
2/3 down they have a json_normalize example
it uses a top-level key and the response object I am getting does not have one.
what do i put in my highlighted line below?
from documentation:
pandas.json_normalize(data, record_path=None, meta=None, meta_prefix=None, record_prefix=None, errors='raise', sep='.', max_level=None)See my work right below minus API information etc(results is the information from the API's GET request:
results = requests.get(url).json() df = pd.DataFrame.from_records(results,columns=['symbol','isUTC','day','open','close','openTrades','closingTrades']) FIELDS = ["symbol", "isUTC", "day", "open", "openTrades.s",'openTrades.p','openTrades.x','openTrades.t','openTrades.c','closingTrades.s','closingTrades.p','closingTrades.x','closingTrades.t','closingTrades.c'] df = pd.json_normalize(results) df[FIELDS]
Output:{
"symbol": "BTC-USD",
"isUTC": true,
"day": "2020-10-14",
"open": 11442.72553612,
"close": 11417.8,
"openTrades": [
{
"s": 0.00942955,
"p": 11442.72553612,
"x": 2,
"t": 1602633600081,
"c": [
2
]
},
{
"s": 0.00118,
"p": 11443,
"x": 2,
"t": 1602633600338,
"c": [
2
]
},
{
"s": 0.00145141,
"p": 11428.22,
"x": 1,
"t": 1602633600593,
"c": [
1
]
},
{
"s": 0.01813,
"p": 11420.57,
"x": 4,
"t": 1602633600777,
"c": [
1
]
},
{
"s": 0.002402,
"p": 11420.97,
"x": 4,
"t": 1602633601102,
"c": [
1
]
}
],
"closingTrades": [
{
"s": 0.00200489,
"p": 11417.8,
"x": 17,
"t": 1602719999943,
"c": [
2
]
},
{
"s": 0.329184,
"p": 11417.89,
"x": 4,
"t": 1602719999802,
"c": [
2
]
},
{
"s": 0.002726,
"p": 11417.89,
"x": 4,
"t": 1602719999549,
"c": [
2
]
},
{
"s": 0.2,
"p": 11417.89,
"x": 4,
"t": 1602719999512,
"c": [
2
]
},
{
"s": 0.00278713,
"p": 11427.7,
"x": 1,
"t": 1602719999498,
"c": [
1
]
}
]
}