From c485cc0a56062e512fcc95d460c81d8d73ad1be8 Mon Sep 17 00:00:00 2001 From: scoobybejesus Date: Fri, 4 Aug 2017 23:01:07 -0400 Subject: [PATCH] Add krak trigger. Added `if not trigger.group` line, and indented all below by 4 spaces. C&P'ed polo "else" section into krak, and modified as necessary. Commented out polo section unused. Added kraktrig string, to append coin ticker. Please check my kraktrig comments. Also, I'm not sure if the stringtosay .format will work the way I did it. Even if concatenating strings works, I think the volume might be in the coin, rather than BTC (XBT); and I don't know json one bit, so I don't know what to change. --- price.py | 81 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 59 insertions(+), 22 deletions(-) diff --git a/price.py b/price.py index 692d257..e2fcdb4 100644 --- a/price.py +++ b/price.py @@ -19,6 +19,7 @@ krakbtc = 'https://api.kraken.com/0/public/Ticker?pair=XMRXBT' krakbtceur = 'https://api.kraken.com/0/public/Ticker?pair=XBTEUR' krakusd = 'https://api.kraken.com/0/public/Ticker?pair=XMRUSD' krakeur = 'https://api.kraken.com/0/public/Ticker?pair=XMREUR' +kraktrig = 'https://api.kraken.com/0/public/Ticker?pair=XBT' #append coin/trigger in function below okcquar = 'https://www.okcoin.com/api/v1/future_ticker.do?symbol=btc_usd&contract_type=quarter' krakusdt = 'http://api.kraken.com/0/public/Ticker?pair=USDTUSD' bitflyerurl = 'https://api.bitflyer.jp/v1/ticker' @@ -69,28 +70,64 @@ def bfx(bot, trigger): @sopel.module.commands('krak', 'kraken') def krak(bot, trigger): stringtosay = '' - try: - r = requests.get(krakbtc) - j = r.json() - stringtosay += "Last XMR/BTC trade at {0:.6f} on {1:.2f} 24 h XMR volume. ".format(float(j['result']['XXMRXXBT']['c'][0]), float(j['result']['XXMRXXBT']['v'][1])) - except: - bot.say("Error getting XMR/BTC data") - try: - r = requests.get(krakusd) - j = r.json() - stringtosay += "Last XMR/USD trade at {0:.2f} on {1:.2f} 24 h XMR volume. ".format(float(j['result']['XXMRZUSD']['c'][0]), float(j['result']['XXMRZUSD']['v'][1])) - except: - bot.say("Error getting XMR/USD data") - try: - r = requests.get('https://api.kraken.com/0/public/Ticker?pair=XMREUR') - j = r.json() - stringtosay += "Last XMR/EUR trade at {0:.2f} on {1:.2f} 24 h XMR volume. ".format(float(j['result']['XXMRZEUR']['c'][0]), float(j['result']['XXMRZEUR']['v'][1])) - except: - bot.say("Error getting XMR/EUR data") - try: - bot.say(stringtosay) - except: - bot.say("Error getting data") + if not trigger.group(2): + try: + r = requests.get(krakbtc) + j = r.json() + stringtosay += "Last XMR/BTC trade at {0:.6f} on {1:.2f} 24 h XMR volume. ".format(float(j['result']['XXMRXXBT']['c'][0]), float(j['result']['XXMRXXBT']['v'][1])) + except: + bot.say("Error getting XMR/BTC data") + try: + r = requests.get(krakusd) + j = r.json() + stringtosay += "Last XMR/USD trade at {0:.2f} on {1:.2f} 24 h XMR volume. ".format(float(j['result']['XXMRZUSD']['c'][0]), float(j['result']['XXMRZUSD']['v'][1])) + except: + bot.say("Error getting XMR/USD data") + try: + r = requests.get('https://api.kraken.com/0/public/Ticker?pair=XMREUR') #shouldn't this be krakeur? + j = r.json() + stringtosay += "Last XMR/EUR trade at {0:.2f} on {1:.2f} 24 h XMR volume. ".format(float(j['result']['XXMRZEUR']['c'][0]), float(j['result']['XXMRZEUR']['v'][1])) + except: + bot.say("Error getting XMR/EUR data") + try: + bot.say(stringtosay) + except: + bot.say("Error getting data") + else: + coin = trigger.group(2).upper() + try: + kraktrig = kraktrig[-1] #Didn't test. It's meant to delete the "'". Delete this line if unneeded. + kraktrig = kraktrig.append(coin)+"'" #Again, delete the "+" and after if unneeded. + r=requests.get(kraktrig) + j=r.json() + stringtosay += coin + " at {0:.2f} on {1:.2f} 24 h BTC volume. ".format(float(j['result']['X'+str(coin)+'XXBT']['c'][0]), float(j['result']['X'+str(coin)+'XXBT']['v'][1])) + except: + bot.say("Error connecting to Kraken") +# if len(coin) > 5 or len(coin) < 2: +# bot.say("Coin ticker is too long or short") +# elif coin == "PIVX": +# bot.say("Masternodes + PoS...what could possibly go wrong?") +# else: + try: + bot.say(stringtosay) + except: + bot.say("Error getting data") + +# THIS WAS COPIED FROM THE POLO FUNCTION, AND IS UNUSED, AT LEAST FOR NOW +# label="BTC_" + coin +# try: +# ticker=j[label] +# last=float(ticker['last']) +# change=float(ticker['percentChange']) +# vol=float(ticker['baseVolume']) +# if change >= 0: +# sign = '+' +# else: +# sign = '' +# bot.say("{0} at {1:.8f} BTC; {2}{3:.2f}% over 24 hours on {4:.3f} BTC volume".format(coin, last, sign, change*100, vol)) +# except: +# bot.say("ERROR!") + @sopel.module.commands('usdt') def usdt(bot, trigger):