Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Exchange Quotes
#7
(May-26-2019, 07:58 AM)OstermanA Wrote: It looks like the data you are receiving is in json form. Using import json gives you access to a number of useful features, including several methods of pretty-printing them to console.
There is no need to use import json as Requests that @heiner55 use has a build in json parser/encoder.

@heiner55 could you a little description about code,don't need to long like not all now what Requests is.
I can also add a example of using the data which is json,i know if just need Quotes text output then it's okay.
But often when using these API want to do stuff with the json data.
import requests
from pprint import pprint

key = "xxxxxxx" # key is free (5 requests per minute, 500 requests per day)
tic = "ibm"
url = f"https://www.alphavantage.co/query?apikey={key}&function=TIME_SERIES_DAILY&symbol={tic}"

rsp = requests.get(url)
if rsp.status_code == 200:
    json_data = rsp.json()
    pprint(json_data)
else:
    print(f"ERROR: {rsp.status_code}")
    print(rsp.text)
Now the output the same,but it's json that can used.
# Meta Data index
>>> json_data['Meta Data']
{'1. Information': 'Daily Prices (open, high, low, close) and Volumes',
 '2. Symbol': 'ibm',
 '3. Last Refreshed': '2019-05-24',
 '4. Output Size': 'Compact',
 '5. Time Zone': 'US/Eastern'}

>>> # Get data for a single day
>>> json_data['Time Series (Daily)']['2019-01-02']
{'1. open': '112.0100',
 '2. high': '115.9800',
 '3. low': '111.6900',
 '4. close': '115.2100',
 '5. volume': '4239924'}

>>> # Get data for a single day
>>> json_data['Time Series (Daily)']['2019-05-22']
{'1. open': '136.0000',
 '2. high': '136.7500',
 '3. low': '135.7116',
 '4. close': '136.3500',
 '5. volume': '1849821'}
Reply


Messages In This Thread
Exchange Quotes - by heiner55 - May-24-2019, 06:34 AM
RE: Exchange Quotes - by heiner55 - May-24-2019, 11:14 AM
RE: Exchange Quotes - by heiner55 - May-24-2019, 12:41 PM
RE: Exchange Quotes - by heiner55 - May-26-2019, 04:27 AM
RE: Exchange Quotes - by OstermanA - May-26-2019, 07:58 AM
RE: Exchange Quotes - by heiner55 - May-26-2019, 08:10 AM
RE: Exchange Quotes - by snippsat - May-26-2019, 05:04 PM
RE: Exchange Quotes - by heiner55 - May-26-2019, 05:13 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020