From 5db785d6623b1a492810126e2c5ef3ede2b2fe71 Mon Sep 17 00:00:00 2001 From: Neythen Date: Tue, 6 Jul 2021 20:32:34 +0100 Subject: [PATCH] IEX API working --- api_caller.py | 24 +++++++++++++++++------- csv/tickers.csv | 6 +++--- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/api_caller.py b/api_caller.py index 10622c3..62f9b77 100644 --- a/api_caller.py +++ b/api_caller.py @@ -100,7 +100,7 @@ def updateUpdate(NY_time): f.write(NY_str + '\n') f.close() -def updateStockPrices(): +def updateStockPricesFinhubb(): max_stocks = 200 finnhubsandboxAPIkey = "sandbox_c24qddqad3ickpckgg8g" #Finnhub finnhubAPIkey = "c24qddqad3ickpckgg80" #Finnhub @@ -136,7 +136,7 @@ def updateStockPrices(): print(e) -def updateStockPricesIEX(): +def updateStockPrices(): iexAPIkey = 'pk_68ef6a15902c41f887f0b544a0ca17cf' #IEX iexSandboxAPIkey = 'Tpk_0078dff413ef4f979137f7111452dc4b' @@ -188,14 +188,22 @@ def updateStockPricesIEX(): print('Response code: \n',intraday_response) - print(intraday_response.text) - - opn = intraday_response.json()[0]['open'] - current = intraday_response.json()[-1]['close'] + #print(intraday_response.text) + for i in range(len(intraday_response.json())): + opn = intraday_response.json()[i]['open'] + print(opn) + if opn is not None: + break + for i in range(len(intraday_response.json())-1, 0, -1): + + current = intraday_response.json()[i]['close'] + if current is not None: + break + opening_prices.append(opn) current_prices.append(current) - + print(opn, current) ''' for time_point in intraday_response.json(): print(time_point['date']) @@ -608,6 +616,8 @@ if __name__ == '__main__': #update_times = {'stocks':NY_str, 'crypto':NY_str, 'news':NY_str, 'weather': NY_str, 'forex': CET_str} # all in NY time apart from forex in CET #json.dump(update_times, f) #f.close() + + try: f = open('csv/last_updates.json', 'r') diff --git a/csv/tickers.csv b/csv/tickers.csv index 7c7cda3..64a00f4 100644 --- a/csv/tickers.csv +++ b/csv/tickers.csv @@ -1,4 +1,4 @@ name,current,opening -MSFT,276.845,278.03 -NFLX,541.92,533 -GOOG,2589.7622,2588.99 +MSFT,277.355,278.02 +NFLX,542.15,532.56 +GOOG,2595.72,2588.01