switched to IEX api
This commit is contained in:
parent
0cf368a527
commit
71d30146cf
@ -3,26 +3,32 @@ import time
|
||||
import csv
|
||||
import pytz
|
||||
from datetime import datetime
|
||||
|
||||
import pyEX
|
||||
import datetime as dt
|
||||
|
||||
def readCSV():
|
||||
def readCSV(max_stocks):
|
||||
|
||||
symbols = []
|
||||
stock_info = {}
|
||||
f = open('csv/tickers.csv', 'r')
|
||||
CSV = csv.reader(f)
|
||||
next(CSV)
|
||||
i = 0
|
||||
for row in CSV:
|
||||
print(row)
|
||||
try:
|
||||
symbol, current_price, opening_price = row
|
||||
symbols.append(symbol)
|
||||
stock_info[symbol] = [current_price, opening_price]
|
||||
except:
|
||||
symbol = row[0]
|
||||
symbols.append(symbol)
|
||||
stock_info[symbol] = []
|
||||
if i < max_stocks:
|
||||
i += 1
|
||||
|
||||
try:
|
||||
symbol, current_price, opening_price = row
|
||||
symbols.append(symbol)
|
||||
stock_info[symbol] = [current_price, opening_price]
|
||||
except:
|
||||
symbol = row[0]
|
||||
symbols.append(symbol)
|
||||
stock_info[symbol] = []
|
||||
else:
|
||||
print('max stocks exceeded')
|
||||
break
|
||||
|
||||
f.close()
|
||||
|
||||
@ -43,26 +49,21 @@ def updateUpdate(NY_time):
|
||||
|
||||
def updateStockPrices(symbols):
|
||||
|
||||
apiCalledError = False
|
||||
stock_info = []
|
||||
|
||||
symbols = []
|
||||
f = open('csv/tickers.csv', 'r')
|
||||
CSV = csv.reader(f)
|
||||
next(CSV) #read through headers
|
||||
for row in CSV:
|
||||
symbol = row[0]
|
||||
symbols.append(symbol)
|
||||
f.close()
|
||||
try:
|
||||
quotes = [finnhubClient.quote(symbol) for symbol in symbols]
|
||||
current_prices = [quote['c'] for quote in quotes]
|
||||
opening_prices = [quote['o'] for quote in quotes]
|
||||
#quotes = [finnhubClient.quote(symbol) for symbol in symbols]
|
||||
#current_prices = [quote['c'] for quote in quotes]
|
||||
#opening_prices = [quote['o'] for quote in quotes]
|
||||
quotes = [iexClient.quote(symbol=symbol) for symbol in symbols]
|
||||
|
||||
|
||||
current_prices = [quote['iexRealtimePrice'] for quote in quotes]
|
||||
opening_prices = [quote['iexOpen'] for quote in quotes]
|
||||
print(current_prices, opening_prices)
|
||||
CSV = open('csv/tickers.csv', 'w+')
|
||||
CSV.write('name,current,opening\n')
|
||||
for i, symbol in enumerate(symbols):
|
||||
symbol + ',' + str(current_prices[i]) + ',' + str(opening_prices[i]) + '\n'
|
||||
|
||||
CSV.write(symbol + ',' + str(current_prices[i]) + ',' + str(opening_prices[i]) + '\n')
|
||||
CSV.close()
|
||||
|
||||
@ -76,9 +77,17 @@ def updateStockPrices(symbols):
|
||||
apiCalledError = True
|
||||
|
||||
if __name__ == '__main__':
|
||||
APIkey = "c24qddqad3ickpckgg80"
|
||||
sandboxAPIkey = "sandbox_c24qddqad3ickpckgg8g"
|
||||
finnhubClient = finnhub.Client(api_key=APIkey)
|
||||
#finnhubAPIkey = "c24qddqad3ickpckgg80" #Finnhub
|
||||
#finnhubsandboxAPIkey = "sandbox_c24qddqad3ickpckgg8g" #Finnhub
|
||||
|
||||
iexAPIkey = 'pk_68ef6a15902c41f887f0b544a0ca17cf' #IEX
|
||||
iexSandboxAPIkey = 'Tpk_0078dff413ef4f979137f7111452dc4b'
|
||||
|
||||
iexClient = pyEX.Client(api_token = iexSandboxAPIkey, version = 'stable')
|
||||
|
||||
print(iexClient.quote(symbol='MSFT')['iexRealtimePrice'] )
|
||||
print(iexClient.quote(symbol='MSFT')['iexOpen'] )
|
||||
#finnhubClient = finnhub.Client(api_key=APIkey)
|
||||
|
||||
NY_zone = pytz.timezone('America/New_York')
|
||||
|
||||
@ -90,13 +99,14 @@ if __name__ == '__main__':
|
||||
|
||||
sleeptime = 2 #minutes
|
||||
|
||||
max_stocks = 200
|
||||
while True:
|
||||
NY_time = datetime.now(NY_zone)
|
||||
|
||||
symbols, stock_info = readCSV()
|
||||
print(type(NY_time))
|
||||
symbols, stock_info = readCSV(max_stocks)
|
||||
|
||||
if opening < NY_time < closing: # we need to do real time updating
|
||||
print('market open')
|
||||
updateStockPrices(symbols)
|
||||
updateUpdate(NY_time)
|
||||
|
||||
|
@ -1 +1 @@
|
||||
06/05/2021 15:58:05
|
||||
07/05/2021 14:25:26
|
||||
|
|
@ -1,21 +1,22 @@
|
||||
name,current,opening
|
||||
MSFT,249.35,246.45
|
||||
NFLX,498.645,495.99
|
||||
GOOG,2376.26,2350.64
|
||||
TSLA,663.1871,680.76
|
||||
AAPL,129.68,127.89
|
||||
INTC,57.095,56.615
|
||||
TXN,184.04,181.93
|
||||
HPQ,34.975,34.42
|
||||
HOG,48.895,49.36
|
||||
LUV,60.65,60.97
|
||||
WMT,140.925,140
|
||||
BJ,46.68,45.74
|
||||
ETSY,157.86,167.01
|
||||
G,47.115,47.17
|
||||
GDDY,81.28,80.11
|
||||
GNRC,317.81,315.29
|
||||
PEP,145.47,144.47
|
||||
STMYELP,0,0
|
||||
XRAY,67.36,66.6
|
||||
ZTS,167.11,167.25
|
||||
MSFT,252.64,252.64
|
||||
NFLX,502.76,502.76
|
||||
GOOG,2402.26,2402.26
|
||||
TSLA,669.66,669.66
|
||||
AAPL,130.175,130.175
|
||||
INTC,57.51,57.51
|
||||
TXN,187.09,187.09
|
||||
HPQ,35.49,35.49
|
||||
HOG,49.53,49.53
|
||||
LUV,61.89,61.89
|
||||
WMT,140.68,140.68
|
||||
BJ,45.675,45.675
|
||||
ETSY,164.27,164.27
|
||||
G,47.14,47.14
|
||||
GDDY,81.14,81.14
|
||||
GNRC,324.9,324.9
|
||||
PEP,145.53,145.53
|
||||
STM,37.26,37.26
|
||||
YELP,39.02,39.02
|
||||
XRAY,68.69,68.69
|
||||
ZTS,172.2,172.2
|
||||
|
|
Loading…
Reference in New Issue
Block a user