Created
March 24, 2023 01:46
-
-
Save microprediction/b99f512bce3e9e488bef83aa7703941e to your computer and use it in GitHub Desktop.
intrinio prices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
def intrinio_last_price(ticker, api_key=INTRINIO_KEY): | |
from getjson import getjson | |
template_url = 'https://api-v2.intrinio.com/securities/TICKER/prices/realtime?api_key=API_KEY' | |
url = template_url.replace('TICKER',ticker.upper()).replace('API_KEY',api_key) | |
try: | |
return getjson(url)['last_price'] | |
except: | |
time.sleep(0.2) | |
return getjson(url)['last_price'] | |
def intrinio_last_prices(tickers, verbose=False): | |
# Intrinio latest prices ... pretty slow unfortunately | |
prices = list() | |
for ticker in tickers: | |
try: | |
last_price = intrinio_last_price(ticker=ticker) | |
except Exception as e: | |
print('INTRINIO FAIL on '+ticker) | |
print(e) | |
last_price = 100.0 + 1e-1*np.random.randn() | |
prices.append(last_price) | |
return prices |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment