api and transition updates

This commit is contained in:
Neythen
2021-06-29 21:17:52 +01:00
parent a23b0f849c
commit afe4f583bf
11 changed files with 162 additions and 45 deletions

View File

@@ -100,6 +100,7 @@ def updateUpdate(NY_time):
f.close()
def updateStockPrices():
max_stocks = 200
finnhubsandboxAPIkey = "sandbox_c24qddqad3ickpckgg8g" #Finnhub
finnhubAPIkey = "c24qddqad3ickpckgg80" #Finnhub
finnhubClient = finnhub.Client(api_key=finnhubAPIkey)
@@ -141,7 +142,10 @@ def updateStockPricesIEX():
max_stocks = 200
symbols, stock_info = readCSV('csv/tickers.csv', max_stocks)
try:
'''
symbols_str = ','.join(symbols)
print(symbols)
print(symbols_str)
method = 'GET'
host = 'https://cloud.iexapis.com/stable'
lastEndpoint = '/tops/last'
@@ -153,20 +157,23 @@ def updateStockPricesIEX():
print('\nBEGIN REQUEST++++++++++++++++++++++++++++++++++++')
print('Request URL = ' + last_request_url)
last_response = requests.get(last_request_url)
print('done')
if last_response.status_code == 200:
print('last success')
current_prices = []
for stock in last_response.json():
current_prices.append(stock['price'])
'''
current_prices = []
opening_prices = []
for symbol in symbols:
symbol = 'MSFT'
print(symbol)
method = 'GET'
host = 'https://cloud.iexapis.com/stable'
lastEndpoint = '/tops/last'
intradayEndpoint = '/stock/'+ symbol+ '/intraday-prices'
querystring = '?chartIEXOnly=true&token='+iexAPIkey
@@ -177,23 +184,32 @@ def updateStockPricesIEX():
intraday_response = requests.get(intraday_request_url)
print('\nRESPONSE++++++++++++++++++++++++++++++++++++')
print('Response code: %d\n' % intraday_response.status_code)
print('Response code: \n',intraday_response)
print(intraday_response.text)
opn = intraday_response.json()[0]['open']
current = intraday_response.json()[-1]['close']
opening_prices.append(opn)
current_prices.append(current)
'''
for time_point in intraday_response.json():
print(time_point['date'])
print(time_point['open'])
'''
CSV = open('csv/tickers.csv', 'w+')
CSV.write('name,current,opening\n')
for i, symbol in enumerate(symbols):
CSV.write(symbol + ',' + str(current_prices[i]) + ',' + str(opening_prices[i]) + '\n')
CSV.close()
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
@@ -202,7 +218,8 @@ def updateStockPricesIEX():
logf.write('. line: ' + str(exc_tb.tb_lineno))
logf.write('. type: ' + str(exc_type))
logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
print(e)
raise e
sys.exit()
def updateCrypto():
@@ -360,10 +377,6 @@ def updateForex():
c_dict = {}
for curr in currencies:
current = all_data['rates'][str_tod][curr]
@@ -558,7 +571,16 @@ def checkStocks(last_update, update_frequency):
if __name__ == '__main__':
updateWeather()
logf = open("log.txt", "w")
t = time.time()
updateStockPrices()
print('finnhub:',time.time() -t)
t = time.time()
updateStockPricesIEX()
print('iex:', time.time() -t)
sys.exit()
max_stocks = 200
max_crypto = 100
@@ -587,7 +609,7 @@ if __name__ == '__main__':
t = time.time()
logf = open("log.txt", "w")
try:
while True: