I ask how to calculate the json data provided by api in python after processing.

Asked 2 years ago, Updated 2 years ago, 47 views

I'd like to make a trading bot. We use JSON data to get the average price I'd like to calculate the margin of error of the price.

I'm still studying. More than anything else, First of all, the part where there' I'd like to convert JSON data into a list form and make it calculate with other variables. Then I wonder how to organize it.

Ezero, From the

python api json

2022-09-22 08:12

1 Answers

import requests # It is not a standard module, so it needs to be installed separately 

response = requests.get('http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22USDKRW%22)&format=json&env=store://datatables.org/alltableswithkeys&callback=')
financeData = response.json()

financeData
{'query': {'count': 1,
  'created': '2017-05-12T01:40:27Z',
  'lang': 'en-US',
  'results': {'rate': {'Ask': '1128.7700',
    'Bid': '1127.7700',
    'Date': '5/11/2017',
    'Name': 'USD/KRW',
    'Rate': '1127.7700',
    'Time': '4:28pm',
    'id': 'USDKRW'}}}}

financeData['query']['results']['rate']['Bid']
Out[19]: '1127.7700'


2022-09-22 08:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.