frist section done

This commit is contained in:
Neythen 2021-05-08 12:10:05 +01:00
parent 079c95f559
commit 4374934237
5 changed files with 251 additions and 41 deletions

View File

@ -5,6 +5,8 @@ import pytz
from datetime import datetime from datetime import datetime
import pyEX import pyEX
import datetime as dt import datetime as dt
import sys, os, base64, hashlib, hmac
import requests
def readCSV(max_stocks): def readCSV(max_stocks):
@ -51,14 +53,16 @@ def updateStockPrices(symbols):
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] print(current_prices)
print(opening_prices)
current_prices = [quote['iexRealtimePrice'] for quote in quotes]
opening_prices = [quote['iexOpen'] for quote in quotes]
print(current_prices, opening_prices) 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')
@ -76,18 +80,80 @@ def updateStockPrices(symbols):
print(e) print(e)
apiCalledError = True apiCalledError = True
def updateStockPricesIEX(symbols):
symbols_str = ','.join(symbols)
method = 'GET'
host = 'https://cloud.iexapis.com/stable'
lastEndpoint = '/tops/last'
querystring = '?symbols=' + symbols_str +'&token='+iexAPIkey
last_request_url = host + lastEndpoint + querystring
print('\nBEGIN REQUEST++++++++++++++++++++++++++++++++++++')
print('Request URL = ' + last_request_url)
last_response = requests.get(last_request_url)
if last_response.status_code == 200:
print('last success')
current_prices = []
for stock in last_response.json():
current_prices.append(stock['price'])
for symbol in symbols:
symbol = 'MSFT'
method = 'GET'
host = 'https://cloud.iexapis.com/stable'
lastEndpoint = '/tops/last'
intradayEndpoint = '/stock/'+ symbol+ '/intraday-prices'
querystring = '?chartIEXOnly=true&token='+iexAPIkey
intraday_request_url = host + intradayEndpoint + querystring
print('\nBEGIN REQUEST++++++++++++++++++++++++++++++++++++')
print('Request URL = ' + intraday_request_url)
intraday_response = requests.get(intraday_request_url)
print('\nRESPONSE++++++++++++++++++++++++++++++++++++')
print('Response code: %d\n' % intraday_response.status_code)
print(intraday_response.text)
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()
print(lasts)
if __name__ == '__main__': if __name__ == '__main__':
#finnhubAPIkey = "c24qddqad3ickpckgg80" #Finnhub finnhubAPIkey = "c24qddqad3ickpckgg80" #Finnhub
#finnhubsandboxAPIkey = "sandbox_c24qddqad3ickpckgg8g" #Finnhub finnhubsandboxAPIkey = "sandbox_c24qddqad3ickpckgg8g" #Finnhub
sleeptime = 2 #minutes
finnhubClient = finnhub.Client(api_key=finnhubAPIkey)
max_stocks = 200
iexAPIkey = 'pk_68ef6a15902c41f887f0b544a0ca17cf' #IEX iexAPIkey = 'pk_68ef6a15902c41f887f0b544a0ca17cf' #IEX
iexSandboxAPIkey = 'Tpk_0078dff413ef4f979137f7111452dc4b' iexSandboxAPIkey = 'Tpk_0078dff413ef4f979137f7111452dc4b'
iexClient = pyEX.Client(api_token = iexSandboxAPIkey, version = 'stable') #updateStockPricesIEX(symbols)
print(iexClient.quote(symbol='MSFT')['iexRealtimePrice'] )
print(iexClient.quote(symbol='MSFT')['iexOpen'] )
#finnhubClient = finnhub.Client(api_key=APIkey) finnhubClient = finnhub.Client(api_key=finnhubAPIkey)
NY_zone = pytz.timezone('America/New_York') NY_zone = pytz.timezone('America/New_York')
@ -97,24 +163,31 @@ if __name__ == '__main__':
NY_time = datetime.now(NY_zone) NY_time = datetime.now(NY_zone)
sleeptime = 2 #minutes print(NY_time)
max_stocks = 200
while True: while True:
NY_time = datetime.now(NY_zone) NY_time = datetime.now(NY_zone)
symbols, stock_info = readCSV(max_stocks) symbols, stock_info = readCSV(max_stocks)
if opening < NY_time < closing and datetime.today().weekday() < 5: # we need to do real time updating
if opening < NY_time < closing: # we need to do real time updating
print('market open') print('market open')
updateStockPrices(symbols) updateStockPrices(symbols)
updateUpdate(NY_time) updateUpdate(NY_time)
elif emptyInfo(symbols, stock_info): # if theres any empty stocks elif emptyInfo(symbols, stock_info): # if theres any empty stocks
updateStockPrices(symbols) updateStockPrices(symbols)
updateUpdate(NY_time) updateUpdate(NY_time)
else: else:
# update if last update was before the previous days closing # update if last update was before the previous days closing
f = open('csv/last_update.csv', 'r') f = open('csv/last_update.csv', 'r')
CSV = csv.reader(f) CSV = csv.reader(f)
last_update_str = next(CSV)[0] last_update_str = next(CSV)[0]
@ -128,6 +201,7 @@ if __name__ == '__main__':
print(last_update < yday_closing) print(last_update < yday_closing)
if last_update < yday_closing: if last_update < yday_closing:
updateStockPrices(symbols) updateStockPrices(symbols)
updateUpdate(NY_time) updateUpdate(NY_time)

View File

@ -1 +1 @@
07/05/2021 14:25:26 08/05/2021 07:09:36

1 07/05/2021 14:25:26 08/05/2021 07:09:36

View File

@ -1,22 +1,22 @@
name,current,opening name,current,opening
MSFT,252.64,252.64 MSFT,252.46,252.15
NFLX,502.76,502.76 NFLX,503.84,504.62
GOOG,2402.26,2402.26 GOOG,2398.69,2400
TSLA,669.66,669.66 TSLA,672.08,665.8
AAPL,130.175,130.175 AAPL,130.21,130.85
INTC,57.51,57.51 INTC,57.67,57.7
TXN,187.09,187.09 TXN,187.76,186.7
HPQ,35.49,35.49 HPQ,35.57,34.99
HOG,49.53,49.53 HOG,49.71,48.96
LUV,61.89,61.89 LUV,61.66,60.68
WMT,140.68,140.68 WMT,140.2,141.63
BJ,45.675,45.675 BJ,45.86,46.59
ETSY,164.27,164.27 ETSY,165.51,163.93
G,47.14,47.14 G,47.13,47.11
GDDY,81.14,81.14 GDDY,81.06,81.78
GNRC,324.9,324.9 GNRC,327.38,319.52
PEP,145.53,145.53 PEP,145.56,145.23
STM,37.26,37.26 STM,37.33,37.31
YELP,39.02,39.02 YELP,39.46,38.86
XRAY,68.69,68.69 XRAY,68.47,67.39
ZTS,172.2,172.2 ZTS,171.55,169.19

1 name current opening
2 MSFT 252.64 252.46 252.64 252.15
3 NFLX 502.76 503.84 502.76 504.62
4 GOOG 2402.26 2398.69 2402.26 2400
5 TSLA 669.66 672.08 669.66 665.8
6 AAPL 130.175 130.21 130.175 130.85
7 INTC 57.51 57.67 57.51 57.7
8 TXN 187.09 187.76 187.09 186.7
9 HPQ 35.49 35.57 35.49 34.99
10 HOG 49.53 49.71 49.53 48.96
11 LUV 61.89 61.66 61.89 60.68
12 WMT 140.68 140.2 140.68 141.63
13 BJ 45.675 45.86 45.675 46.59
14 ETSY 164.27 165.51 164.27 163.93
15 G 47.14 47.13 47.14 47.11
16 GDDY 81.14 81.06 81.14 81.78
17 GNRC 324.9 327.38 324.9 319.52
18 PEP 145.53 145.56 145.53 145.23
19 STM 37.26 37.33 37.26 37.31
20 YELP 39.02 39.46 39.02 38.86
21 XRAY 68.69 68.47 68.69 67.39
22 ZTS 172.2 171.55 172.2 169.19

BIN
final.ppm

Binary file not shown.

136
resetmatrix.py Normal file
View File

@ -0,0 +1,136 @@
#!/usr/bin/python3
from __future__ import print_function
from gpiozero import LED
from time import sleep
# 0123456789012345
b12a="0111111111111111"
b12b="0111100000111111"
b12c="0111111111111111"
b12d="0111100000111111"
b12a="0111111111111111"
b12b="0111111111111111"
b12c="0111111111111111"
b12d="0111111111111111"
b13a="0000000001000000"
b13b="0000000001000000"
b13c="0000000001000000"
b13d="0000000001000000"
# b12 - 1 adds red tinge
# b12 - 9/8/7/6/5 = 4 bit brightness
# b13 - 9 =1 screen on
# b13 - 6 =1 screen off
xr1=LED(5)
xr2=LED(12)
xg1=LED(13)
xg2=LED(16)
xb1=LED(6)
xb2=LED(23)
xA=LED(22)
xB=LED(26)
xC=LED(27)
xD=LED(20)
xLAT=LED(21)
xCLK=LED(17)
xOE=LED(4)
xCLK.off()
xOE.off()
xA.on()
xB.off()
xC.off()
xD.off()
xr1.off()
xr2.off()
xg1.off()
xg2.off()
xb1.off()
xb2.off()
b12=b12a
b13=b13a
for x in range(128):
y=x%16
if(y==0):
print(' ',end='')
if (b12[y:y+1] is "0"):
print('0',end='')
xr1.off()
xr2.off()
xg1.off()
xg2.off()
xb1.off()
xb2.off()
else:
print('1',end='')
xr1.on()
xr2.on()
xg1.on()
xg2.on()
xb1.on()
xb2.on()
xCLK.on()
sleep(0.001)
xCLK.off()
sleep(0.001)
if(x>31):
b12=b12b
if(x>63):
b12=b12c
if(x>95):
b12=b12d
if(x==(128-12)):
print('*',end='')
xLAT.on()
xLAT.off();
print('')
for x in range(128):
y=x%16
if(y==0):
print(' ',end='')
if (b13[y:y+1] is "0"):
print('0',end='')
xr1.off()
xr2.off()
xg1.off()
xg2.off()
xb1.off()
xb2.off()
else:
print('1',end='')
xr1.on()
xr2.on()
xg1.on()
xg2.on()
xb1.on()
xb2.on()
xCLK.on()
sleep(0.001)
xCLK.off()
sleep(0.001)
if(x>31):
b13=b13b
if(x>63):
b13=b13c
if(x>95):
b13=b13d
if(x==(128-13)):
print('*',end='')
xLAT.on()
xLAT.off();
print('')
xOE.on();