base currencies and point change added for cryptos

This commit is contained in:
Neythen
2021-05-25 19:57:34 +01:00
parent 8295ca593e
commit 87fe5a67d6
135 changed files with 76 additions and 74 deletions

View File

@@ -48,29 +48,33 @@ def readCryptoCSV(file_path, max_stocks):
CSV = csv.reader(f)
next(CSV)
i = 0
unique_bases = []
for row in CSV:
print(row)
if i < max_stocks:
i += 1
try:
symbol, name, current_price, opening_price = row
symbol, name, base, current_price, opening_price = row
symbols.append(symbol)
names.append(name)
stock_info[name] = [symbol, current_price, opening_price]
stock_info[name] = [symbol, base, current_price, opening_price]
if base not in unique_bases:
unique_bases.append(base)
except:
symbol = row[0]
name = row[1]
symbol, name, base = row
if base not in unique_bases:
unique_bases.append(base)
symbols.append(symbol)
names.append(name)
stock_info[name] = [symbol]
stock_info[name] = [symbol, base]
else:
print('max stocks exceeded')
break
f.close()
return names, stock_info
return names, stock_info, unique_bases
def emptyInfo(symbols, stock_info):
update = False
@@ -91,10 +95,9 @@ def updateStockPrices(symbols):
quotes = [finnhubClient.quote(symbol) for symbol in symbols]
current_prices = [quote['c'] for quote in quotes]
opening_prices = [quote['o'] for quote in quotes]
print(current_prices)
print(opening_prices)
print(current_prices, opening_prices)
CSV = open('csv/tickers.csv', 'w+')
CSV.write('name,current,opening\n')
for i, symbol in enumerate(symbols):
@@ -166,18 +169,21 @@ def updateStockPricesIEX(symbols):
CSV.write(symbol + ',' + str(current_prices[i]) + ',' + str(opening_prices[i]) + '\n')
CSV.close()
print(lasts)
def updateCrypto(coins, coin_info):
response = coingecko_client.get_price(ids=','.join(coins), vs_currencies = 'usd', include_24hr_change=True)
def updateCrypto(coins, coin_info, unique_bases):
response = coingecko_client.get_price(ids=','.join(coins), vs_currencies = unique_bases, include_24hr_change=True)
CSV = open('csv/crypto.csv', 'w+')
CSV.write('symbol,name,current,24hr change\n')
CSV.write('symbol,name,base,current,24hr change\n')
for coin in coins:
CSV.write(coin_info[coin][0] + ',' + coin+ ',' + str(response[coin]['usd']) + ',' + str(response[coin]['usd_24h_change']) + '\n')
info = coin_info[coin]
print(info)
CSV.write(info[0] + ',' + coin + ',' + info[1] + ',' +str(response[coin][info[1]]) + ',' + str(response[coin]['usd_24h_change']) + '\n')
CSV.close()
@@ -223,17 +229,15 @@ if __name__ == '__main__':
closing = NY_time.replace(hour=16, minute=0, second=0, microsecond=0)
NY_time = datetime.now(NY_zone)
print(NY_time)
symbols, stock_info = readCSV('csv/tickers.csv', max_stocks)
updateStockPrices(symbols)
updateUpdate(NY_time)
while True:
coins, coin_info = readCryptoCSV('csv/crypto.csv', max_stocks)
print(coins)
print(coin_info)
updateCrypto(coins, coin_info)
coins, coin_info, unique_bases = readCryptoCSV('csv/crypto.csv', max_stocks)
updateCrypto(coins, coin_info, unique_bases)
updateNews()
@@ -256,7 +260,7 @@ if __name__ == '__main__':
f = open('csv/last_update.csv', 'r')
CSV = csv.reader(f)
last_update_str = next(CSV)[0]
print(last_update_str)
last_update = datetime.strptime(last_update_str, "%d/%m/%Y %H:%M:%S")
yday_closing = closing - dt.timedelta(days=1)
@@ -264,7 +268,7 @@ if __name__ == '__main__':
yday_closing = datetime.strptime(yday_str, "%d/%m/%Y %H:%M:%S")
print(last_update < yday_closing)
if last_update < yday_closing:
updateStockPrices(symbols)