Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions btcticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ def getgecko(url):
geckojson={}
return geckojson, connectfail

def convertkraken(whichcoin,fiat):
# krakenpairs is only required if using kraken as the exchange, this comma seperated list must match the currency and fiatcurrency list
# A full list of support Kraken pairs can be found here: https://support.kraken.com/hc/en-us/articles/360000920306-Ticker-pairs
if (whichcoin == "bitcoin"):
krakenpair = "BTC" + fiat.upper()
else:
krakenpair = whichcoin[:3] + fiat.upper()

return krakenpair

def getData(config,other):
"""
The function to grab the data (TO DO: need to test properly)
Expand Down Expand Up @@ -140,6 +150,24 @@ def getData(config,other):
other['ATH']=True
else:
other['ATH']=False
elif config['ticker']['exchange']=='kraken':
krakenpair = convertkraken(whichcoin,fiat)
geckourl="https://api.kraken.com/0/public/Ticker?pair="+krakenpair;
logging.info(geckourl)
rawlivecoin , connectfail = getgecko(geckourl)
if connectfail==True:
pass
else:
logging.info(rawlivecoin['result'])
first_key = list(rawlivecoin['result'].keys())[0]
liveprice = rawlivecoin['result'][first_key]
pricenow= float(liveprice['c'][0])
alltimehigh = 1000000.0
config['display']['showrank']=False
other['market_cap_rank'] = 0
other['volume'] = float(liveprice['v'][1])*pricenow
timeseriesstack.append(pricenow)
other['ATH']=False
else:
geckourl= "https://api.coingecko.com/api/v3/exchanges/"+config['ticker']['exchange']+"/tickers?coin_ids="+whichcoin+"&include_exchange_logo=false"
logging.info(geckourl)
Expand Down Expand Up @@ -419,9 +447,9 @@ def main(loglevel=logging.WARNING):
# Time of start
lastcoinfetch = time.time()
# Quick Sanity check on update frequency, waveshare says no faster than 180 seconds
if float(config['ticker']['updatefrequency'])<180:
logging.info("Throttling update frequency to 180 seconds")
updatefrequency=180.0
if float(config['ticker']['updatefrequency'])<30:
logging.info("Throttling update frequency to 30 seconds")
updatefrequency=30.0
else:
updatefrequency=float(config['ticker']['updatefrequency'])
while internet() ==False:
Expand Down
1 change: 0 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ ticker:
fiatcurrency: usd,eur,gbp
sparklinedays: 1
updatefrequency: 300