![]() |
Exchange Quotes - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: General (https://python-forum.io/forum-1.html) +--- Forum: Code sharing (https://python-forum.io/forum-5.html) +--- Thread: Exchange Quotes (/thread-18607.html) |
Exchange Quotes - heiner55 - May-24-2019 Quotes from iextrading.com: #!/usr/bin/python3 import requests tic = "ibm" url = "https://api.iextrading.com/1.0/stock/" + tic + "/quote" rsp = requests.get(url) if rsp.status_code in (200,): ustr = rsp.text.strip() print(ustr) else: print("ERROR:", rsp.status_code) print(rsp.text)
RE: Exchange Quotes - heiner55 - May-24-2019 Quotes from stooq.com: #!/usr/bin/python3 import requests tic = "ibm.us" url = "https://stooq.com/q/l/?f=sd2t2ohlcv&h&e=csv&s=" + tic rsp = requests.get(url) if rsp.status_code in (200,): ustr = rsp.text.strip() print(ustr) else: print("ERROR:", rsp.status_code) print(rsp.text)
RE: Exchange Quotes - heiner55 - May-24-2019 Quotes from alphavantage.co: #!/usr/bin/python3 import requests key = "xxxxxxxxx" # key is free (5 requests per minute, 500 requests per day) tic = "ibm" url = "https://www.alphavantage.co/query?apikey="+key+"&function=TIME_SERIES_DAILY&symbol="+ tic rsp = requests.get(url) if rsp.status_code in (200,): ustr = rsp.text.strip() print(ustr) else: print("ERROR:", rsp.status_code) print(rsp.text)
RE: Exchange Quotes - heiner55 - May-26-2019 Quotes from quandl.com: #!/usr/bin/python3 import requests key = "xxxxxxxxx" # key is free tic = "euronext/ibma" url = "https://www.quandl.com/api/v3/datasets/"+tic+"?rows=1&api_key="+key rsp = requests.get(url) if rsp.status_code in (200,): ustr = rsp.text.strip() print(ustr) else: print("ERROR:", rsp.status_code) print(rsp.text)
RE: Exchange Quotes - OstermanA - May-26-2019 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.
RE: Exchange Quotes - heiner55 - May-26-2019 We are in forum "Scripts/Snippets". If you know where to get free quotes, let me know, because it gets more and more difficult to get free quotes since Yahoo API or Google API have been down. RE: Exchange Quotes - snippsat - May-26-2019 (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'} RE: Exchange Quotes - heiner55 - May-26-2019 Yes, you are right. I was a little bit lazy. My goal was only to show where you can get quotes with a tiny code example. |