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.
This commit is contained in:
scoobybejesus 2017-08-04 23:01:07 -04:00 committed by GitHub
parent 0d829bd63e
commit c485cc0a56
1 changed files with 59 additions and 22 deletions

View File

@ -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,6 +70,7 @@ def bfx(bot, trigger):
@sopel.module.commands('krak', 'kraken')
def krak(bot, trigger):
stringtosay = ''
if not trigger.group(2):
try:
r = requests.get(krakbtc)
j = r.json()
@ -82,7 +84,7 @@ def krak(bot, trigger):
except:
bot.say("Error getting XMR/USD data")
try:
r = requests.get('https://api.kraken.com/0/public/Ticker?pair=XMREUR')
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:
@ -91,6 +93,41 @@ def krak(bot, trigger):
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):