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