2017-03-21 03:59:50 +00:00
#romerito -*- coding: UTF-8 -*-
import sopel . module
import requests
import time
2017-04-26 04:29:09 +00:00
import random
2018-04-21 16:51:59 +00:00
import datetime
2017-06-01 01:10:54 +00:00
# from apikey import commodity_key
2017-03-21 03:59:50 +00:00
polourl = " https://poloniex.com/public?command=returnTicker "
poloxmrlendurl = " https://poloniex.com/public?command=returnLoanOrders¤cy=XMR&limit=999999 "
2017-05-07 18:00:44 +00:00
polobtclendurl = " https://poloniex.com/public?command=returnLoanOrders¤cy=BTC&limit=999999 "
2017-03-21 03:59:50 +00:00
prevamnt , prevtime = 0 , 0
trexurl = " https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc- "
2017-04-26 04:29:09 +00:00
cryptopiaurl = " https://www.cryptopia.co.nz/api/GetMarkets "
2017-03-21 03:59:50 +00:00
bitsquareurl = " https://market.bitsquare.io/api/ticker/?market=xmr_btc "
finexbtc = ' https://api.bitfinex.com/v1/pubticker/XMRBTC '
finexusd = ' https://api.bitfinex.com/v1/pubticker/XMRUSD '
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 '
2017-08-09 00:06:59 +00:00
kraktrig = ' https://api.kraken.com/0/public/Ticker?pair= ' #append coin/trigger in function below
2017-03-21 03:59:50 +00:00
okcquar = ' https://www.okcoin.com/api/v1/future_ticker.do?symbol=btc_usd&contract_type=quarter '
2017-04-26 04:29:09 +00:00
krakusdt = ' http://api.kraken.com/0/public/Ticker?pair=USDTUSD '
2017-06-01 01:10:54 +00:00
bitflyerurl = ' https://api.bitflyer.jp/v1/ticker '
2017-09-07 20:40:29 +00:00
thumbxmrurl = ' https://api.bithumb.com/public/ticker/xmr ' # measured natively in KRW
thumbbtcurl = ' https://api.bithumb.com/public/ticker/btc ' # measured natively in KRW
2018-01-24 04:49:36 +00:00
binanceurl = ' https://api.binance.com/api/v1/ticker/24hr '
2018-07-18 09:35:39 +00:00
localmonerousd = ' https://localmonero.co/api/ticker?currencyCode=USD '
2018-07-28 19:56:30 +00:00
ogreurl = ' https://tradeogre.com/api/v1/markets '
2017-09-07 20:40:29 +00:00
2018-11-27 01:16:19 +00:00
@sopel.module.commands ( ' stock ' )
def stock ( bot , trigger ) :
if trigger . group ( 2 ) :
ticker = trigger . group ( 2 ) . upper ( )
else : ticker = ' WOW '
try :
r = requests . get ( ' https://api.iextrading.com/1.0/stock/ {} /batch?types=quote,news,chart&range=1m&last=10 ' . format ( ticker ) )
j = r . json ( )
name = j [ ' quote ' ] [ ' companyName ' ]
exchange = j [ ' quote ' ] [ ' primaryExchange ' ]
date = j [ ' quote ' ] [ ' latestTime ' ]
high = j [ ' quote ' ] [ ' high ' ]
low = j [ ' quote ' ] [ ' low ' ]
last = j [ ' quote ' ] [ ' latestPrice ' ]
bot . say ( " {} ( {} ) trading at {} on {} had a high of {:.2f} , a low of {:.2f} , and last price of {:.2f} " . format ( name , ticker , exchange , date , high , low , last ) )
except :
bot . say ( " Can ' t find {} " . format ( ticker ) )
2018-01-02 05:18:11 +00:00
@sopel.module.commands ( ' forksum ' )
def forksum ( bot , trigger ) :
2017-11-17 22:11:48 +00:00
url = ' https://api.coinmarketcap.com/v1/ticker/?bch '
2017-07-28 04:01:49 +00:00
try :
r = requests . get ( url )
j = r . json ( )
for i in j :
try :
2018-01-02 05:18:11 +00:00
if i [ ' id ' ] == ' bitcoin ' :
btcprice = float ( i [ ' price_usd ' ] )
2017-07-28 04:01:49 +00:00
if i [ ' id ' ] == ' bitcoin-cash ' :
2018-01-02 05:18:11 +00:00
bcashprice = float ( i [ ' price_usd ' ] )
if i [ ' id ' ] == ' bitcoin-gold ' :
bgoldprice = float ( i [ ' price_usd ' ] )
2017-07-28 04:01:49 +00:00
except : pass
2018-07-28 14:43:56 +00:00
bot . say ( " The sum of USD price of BTC, BCH, and BTG is $ {:.2f} " . format ( btcprice + bcashprice + bgoldprice ) )
2017-07-28 04:01:49 +00:00
except :
bot . say ( " Error parsing ticker " )
2018-07-28 14:43:56 +00:00
2018-04-21 16:51:59 +00:00
@sopel.module.commands ( ' ath ' )
def ath ( bot , trigger ) :
with open ( ' /root/.sopel/modules/ath.log ' , ' r ' ) as f :
text = f . read ( )
btcath = float ( text . split ( ' ' ) [ 0 ] )
btcathdate = text . split ( ' ' ) [ 1 ]
usdath = float ( text . split ( ' ' ) [ 2 ] )
usdathdate = text . split ( ' ' ) [ 3 ]
update = False
url = ' https://api.coinmarketcap.com/v1/ticker/monero '
r = requests . get ( url )
j = r . json ( )
price_btc = float ( j [ 0 ] [ ' price_btc ' ] )
price_usd = float ( j [ 0 ] [ ' price_usd ' ] )
if price_btc > btcath :
btcath = price_btc
update = True
btcathdate = datetime . datetime . fromtimestamp ( int ( coin [ ' last_updated ' ] ) ) . strftime ( ' % Y- % m- %d ' )
if price_usd > usdath :
usdath = price_usd
update = True
usdathdate = datetime . datetime . fromtimestamp ( int ( coin [ ' last_updated ' ] ) ) . strftime ( ' % Y- % m- %d ' )
if update == True :
with open ( ' /root/.sopel/modules/ath.log ' , ' w ' ) as f :
f . write ( " {} {} {} {} " . format ( btcath , btcathdate , usdath , usdathdate ) )
bot . say ( " BTC ath = {} on {} . USD ath = $ {} on {} " . format ( btcath , btcathdate , usdath , usdathdate ) )
2017-07-28 04:01:49 +00:00
2017-03-21 03:59:50 +00:00
@sopel.module.commands ( ' bfx ' , ' bitfinex ' )
def bfx ( bot , trigger ) :
stringtosay = ' '
try :
r = requests . get ( finexbtc )
j = r . json ( )
stringtosay + = " Last XMR/BTC trade at {0:.6f} on {1:.2f} 24 h XMR volume. " . format ( float ( j [ ' last_price ' ] ) , float ( j [ ' volume ' ] ) )
except :
bot . say ( " Error getting XMR/BTC data " )
try :
r = requests . get ( finexusd )
j = r . json ( )
stringtosay + = " Last XMR/USD trade at {0:.2f} on {1:.2f} 24 h XMR volume. " . format ( float ( j [ ' last_price ' ] ) , float ( j [ ' volume ' ] ) )
except :
bot . say ( " Error getting XMR/USD data " )
try :
bot . say ( stringtosay )
except :
bot . say ( " Error getting data " )
2018-11-27 01:16:19 +00:00
@sopel.module.commands ( ' gecko ' , ' cg ' , ' gec ' )
def gecko ( bot , trigger ) :
if not trigger . group ( 2 ) :
coin = " monero "
else :
coin = trigger . group ( 2 )
try :
r = requests . get ( ' https://api.coingecko.com/api/v3/coins/ ' + coin )
j = r . json ( )
coinid = j [ ' id ' ]
mcaprank = j [ ' market_cap_rank ' ]
geckorank = j [ ' coingecko_rank ' ]
btcprice = j [ ' market_data ' ] [ ' current_price ' ] [ ' btc ' ]
usdprice = j [ ' market_data ' ] [ ' current_price ' ] [ ' usd ' ]
athbtc = j [ ' market_data ' ] [ ' ath ' ] [ ' btc ' ]
athusd = j [ ' market_data ' ] [ ' ath ' ] [ ' usd ' ]
bot . say ( " {} ( {} ) is # {:.0f} by mcap and # {:.0f} by coingecko rank. Current price is {:.8f} BTC / $ {:.3f} . ATH price is {:.8f} BTC / $ {:.3f} . " . format ( coin , coinid , mcaprank , geckorank , btcprice , usdprice , athbtc , athusd ) )
except :
bot . say ( " Couldn ' t find {} on le gecko " . format ( coin ) )
2017-03-21 03:59:50 +00:00
@sopel.module.commands ( ' krak ' , ' kraken ' )
def krak ( bot , trigger ) :
stringtosay = ' '
2017-08-05 03:01:07 +00:00
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 :
2018-07-28 14:43:56 +00:00
bot . say ( " Error getting data " )
2017-08-05 03:01:07 +00:00
else :
coin = trigger . group ( 2 ) . upper ( )
try :
2017-08-09 00:06:59 +00:00
r = requests . get ( kraktrig + coin + ' XBT ' )
2017-08-05 03:01:07 +00:00
j = r . json ( )
2017-08-09 00:09:21 +00:00
stringtosay + = " {0} at {1:.8f} on {2:.2f} 24 h {0} volume. " . format ( coin , float ( j [ ' result ' ] [ ' X ' + str ( coin ) + ' XXBT ' ] [ ' c ' ] [ 0 ] ) , float ( j [ ' result ' ] [ ' X ' + str ( coin ) + ' XXBT ' ] [ ' v ' ] [ 1 ] ) )
2017-08-05 03:01:07 +00:00
except :
bot . say ( " Error connecting to Kraken " )
try :
bot . say ( stringtosay )
except :
bot . say ( " Error getting data " )
2017-03-21 03:59:50 +00:00
2017-04-26 04:29:09 +00:00
@sopel.module.commands ( ' usdt ' )
def usdt ( bot , trigger ) :
try :
r = requests . get ( krakusdt )
j = r . json ( )
stringtosay = " Last USDT/USD trade at $ {0:.4f} on {1:.2f} USD 24 h volume. Highest bid at $ {2:.4f} " . format ( float ( j [ ' result ' ] [ ' USDTZUSD ' ] [ ' c ' ] [ 0 ] ) , float ( j [ ' result ' ] [ ' USDTZUSD ' ] [ ' v ' ] [ 0 ] ) , float ( j [ ' result ' ] [ ' USDTZUSD ' ] [ ' b ' ] [ 0 ] ) )
bot . say ( stringtosay )
except :
bot . say ( " Error getting USDT/USD data " )
2017-03-21 03:59:50 +00:00
@sopel.module.commands ( ' btckrak ' , ' btckraken ' , ' btceur ' )
def krakeur ( bot , trigger ) :
stringtosay = ' '
try :
r = requests . get ( krakbtceur )
j = r . json ( )
stringtosay + = " Last BTC/EUR trade at € {0:.2f} on {1:.2f} BTC 24 h volume. " . format ( float ( j [ ' result ' ] [ ' XXBTZEUR ' ] [ ' c ' ] [ 0 ] ) , float ( j [ ' result ' ] [ ' XXBTZEUR ' ] [ ' v ' ] [ 0 ] ) )
except :
bot . say ( " Error getting BTC/EUR data " )
try :
bot . say ( stringtosay )
except :
bot . say ( " Error getting data " )
@sopel.module.commands ( ' chart ' )
def chart ( bot , trigger ) :
bot . say ( ' https://cryptowat.ch/poloniex/xmrbtc ' )
@sopel.module.commands ( ' polo ' , ' poloniex ' , ' marco ' )
@sopel.module.interval ( 3600 )
def polo ( bot , trigger ) :
2018-07-28 14:43:56 +00:00
if not trigger . group ( 2 ) :
2017-03-21 03:59:50 +00:00
try :
r = requests . get ( polourl )
j = r . json ( )
xmr = j [ " BTC_XMR " ]
last = float ( xmr [ ' last ' ] )
change = float ( xmr [ ' percentChange ' ] )
vol = float ( xmr [ ' baseVolume ' ] )
2018-07-28 14:43:56 +00:00
if change > = 0 :
2017-03-21 03:59:50 +00:00
sign = ' + '
else :
sign = ' '
face = ' '
if change > 0.10 :
face = u ' \u263d ' . encode ( ' utf8 ' )
if 0.10 > = change > 0.05 :
face = u ' \u2661 ' . encode ( ' utf8 ' )
if 0.05 > = change > 0.02 :
face = u ' \u263a ' . encode ( ' utf8 ' )
if 0.02 > = change > - 0.02 :
face = u ' \u2694 ' . encode ( ' utf8 ' )
if - 0.02 > = change > - 0.05 :
face = u ' \u2639 ' . encode ( ' utf8 ' )
if - 0.05 > = change > - 0.1 :
face = u ' \u2620 ' . encode ( ' utf8 ' )
2018-07-28 14:43:56 +00:00
if change < - 0.1 :
2017-03-21 03:59:50 +00:00
face = u ' \u262d ' . encode ( ' utf8 ' )
bot . say ( " Poloniex at {0:.8f} BTC; {1} {2:.2f} % o ver 24 hours on {3:.3f} BTC volume {4} " . format ( last , sign , change * 100 , vol , face ) )
except :
bot . say ( " Error retrieving data from Poloniex " )
else :
coin = trigger . group ( 2 ) . upper ( )
try :
r = requests . get ( polourl )
j = r . json ( )
except :
bot . say ( " Error connecting to Poloniex " )
if len ( coin ) > 5 or len ( coin ) < 2 :
bot . say ( " Coin ticker is too long or short " )
# elif coin == "PASC":
# bot.say("COBOL only in #monero-markets")
# elif coin == "NAUT":
# bot.say("That ship has sailed...")
2017-04-26 04:29:09 +00:00
elif coin == " PIVX " :
bot . say ( " Masternodes + PoS...what could possibly go wrong? " )
2017-03-21 03:59:50 +00:00
else :
label = " BTC_ " + coin
try :
ticker = j [ label ]
last = float ( ticker [ ' last ' ] )
change = float ( ticker [ ' percentChange ' ] )
vol = float ( ticker [ ' baseVolume ' ] )
2018-07-28 14:43:56 +00:00
if change > = 0 :
2017-03-21 03:59:50 +00:00
sign = ' + '
else :
sign = ' '
bot . say ( " {0} at {1:.8f} BTC; {2} {3:.2f} % o ver 24 hours on {4:.3f} BTC volume " . format ( coin , last , sign , change * 100 , vol ) )
except :
bot . say ( " ERROR! " )
@sopel.module.commands ( ' lending ' )
def lending ( bot , trigger ) :
try :
2018-07-28 14:43:56 +00:00
r = requests . get ( poloxmrlendurl )
2017-03-21 03:59:50 +00:00
j = r . json ( )
amnt = 0
currenttime = time . time ( )
for i in j [ ' offers ' ] :
amnt + = float ( i [ ' amount ' ] )
bot . say ( " Total amount of XMR available {0:,.2f} . Changed by {1:.2f} in the last {2:.2f} hours " . format ( amnt , amnt - prevamnt , ( currenttime - prevtime ) / 3600 ) )
global prevamnt
prevamnt = amnt
global prevtime
prevtime = currenttime
except :
bot . say ( " Something bad happened :o " )
2018-07-28 14:43:56 +00:00
2017-06-01 01:10:54 +00:00
@sopel.module.commands ( ' btclending ' )
def btclending ( bot , trigger ) :
try :
2018-07-28 14:43:56 +00:00
r = requests . get ( polobtclendurl )
2017-06-01 01:10:54 +00:00
j = r . json ( )
amnt = 0
amnt10 = 0
rate10 = 0
amnt100 = 0
rate100 = 0
for i in j [ ' offers ' ] :
if amnt < 10 :
amnt10 = amnt
rate10 = float ( i [ ' rate ' ] )
if amnt < 100 :
amnt100 = amnt
rate100 = float ( i [ ' rate ' ] )
amnt + = float ( i [ ' amount ' ] )
bot . say ( " Minimum rate is {0:.3f} % . To borrow {1:,.2f} BTC need up to rate {2:.3f} % . To borrow {3:,.2f} BTC need up to rate {4:.3f} % . Total amount is {5:,.2f} BTC at max rate {6:.3f} % " . format ( float ( j [ ' offers ' ] [ 0 ] [ ' rate ' ] ) * 100 , amnt10 , rate10 * 100 , amnt100 , rate100 * 100 , amnt , float ( j [ ' offers ' ] [ - 1 ] [ ' rate ' ] ) * 100 ) )
except :
bot . say ( " Something bad happened :o " )
2018-07-28 14:43:56 +00:00
2017-03-21 03:59:50 +00:00
@sopel.module.commands ( ' trex ' , ' bittrex ' )
def trex ( bot , trigger ) :
if not trigger . group ( 2 ) :
geturl = trexurl + ' xmr '
2018-07-28 14:43:56 +00:00
else :
2017-03-21 03:59:50 +00:00
geturl = trexurl + trigger . group ( 2 )
try :
r = requests . get ( geturl )
j = r . json ( )
xmr = j [ ' result ' ] [ 0 ]
last = float ( xmr [ ' Last ' ] )
change = ( ( last / float ( xmr [ ' PrevDay ' ] ) ) - 1 )
vol = float ( xmr [ ' BaseVolume ' ] )
bot . say ( " Bittrex at {0:.8f} BTC; {1:.2f} % o ver 24 hours on {2:.3f} BTC volume " . format ( last , change * 100 , vol ) )
except :
bot . say ( " Error retrieving data from Bittrex " )
2018-07-28 19:56:30 +00:00
@sopel.module.commands ( ' tradeogre ' , ' ogre ' )
def ogre ( bot , trigger ) :
if not trigger . group ( 2 ) :
2018-07-28 20:14:37 +00:00
pair = ' BTC-XMR '
2018-07-28 19:56:30 +00:00
else :
2018-07-28 20:14:37 +00:00
pair = ' BTC- ' + trigger . group ( 2 ) . upper ( )
2018-07-28 19:56:30 +00:00
try :
r = requests . get ( ogreurl )
j = r . json ( )
for i in j :
2018-07-28 20:14:37 +00:00
if pair == i . keys ( ) [ 0 ] :
2018-07-28 20:08:20 +00:00
last = float ( i [ pair ] [ ' price ' ] )
vol = float ( i [ pair ] [ ' volume ' ] )
2018-07-28 20:14:37 +00:00
bot . say ( " {0} on Tradeogre at {1:.8f} BTC on {2:.3f} BTC volume " . format ( pair , last , vol ) )
2018-07-28 19:56:30 +00:00
except :
bot . say ( " Error retrieving data from Ogre " )
2017-03-21 03:59:50 +00:00
@sopel.module.commands ( ' bsq ' , ' bitsquare ' )
def bsq ( bot , trigger ) :
try :
r = requests . get ( bitsquareurl )
j = r . json ( )
xmr = j [ ' xmr_btc ' ]
last = float ( xmr [ ' last ' ] )
vol = float ( xmr [ ' volume_right ' ] )
bot . say ( " Bitsquare at {0:.8f} BTC on {1:.3f} BTC volume " . format ( last , vol ) )
except :
bot . say ( " Error retrieving data from Bitsquare " )
2018-01-24 04:49:36 +00:00
@sopel.module.commands ( ' binance ' )
def binance ( bot , trigger ) :
try :
if not trigger . group ( 2 ) :
coin = ' XMR '
pair = ' BTC '
2018-07-28 14:43:56 +00:00
else :
2018-01-24 04:49:36 +00:00
coin = trigger . group ( 2 ) . split ( ' ' ) [ 0 ] . upper ( )
try :
if len ( trigger . group ( 2 ) . split ( ' ' ) [ 1 ] ) > 1 :
pair = trigger . group ( 2 ) . split ( ' ' ) [ 1 ] . upper ( )
else :
pair = " BTC "
except :
pair = " BTC "
r = requests . get ( binanceurl )
j = r . json ( )
found = False
for i in j :
if i [ " symbol " ] == coin + pair :
last = float ( i [ ' lastPrice ' ] )
change = float ( i [ ' priceChangePercent ' ] )
vol = float ( i [ ' volume ' ] )
bot . say ( " {0} on Binance at {1:.8f} {2} ; {3:.2f} % o ver 24 hours on {4:.3f} {2} volume " . format ( coin , last , pair , change , vol * last ) )
found = True
if found == False :
bot . say ( " Too scammy even for Binance " )
except :
bot . say ( " Error retrieving data from Binance " )
2017-07-15 00:57:04 +00:00
@sopel.module.commands ( ' cryptopia ' , ' shitopia ' , ' topia ' , ' ctop ' )
2017-03-21 03:59:50 +00:00
def cryptopia ( bot , trigger ) :
try :
2017-04-26 04:29:09 +00:00
if not trigger . group ( 2 ) :
coin = ' XMR '
pair = ' BTC '
2018-07-28 14:43:56 +00:00
else :
2017-04-26 04:29:09 +00:00
coin = trigger . group ( 2 ) . split ( ' ' ) [ 0 ] . upper ( )
try :
if len ( trigger . group ( 2 ) . split ( ' ' ) [ 1 ] ) > 1 :
pair = trigger . group ( 2 ) . split ( ' ' ) [ 1 ] . upper ( )
else :
pair = " BTC "
except :
pair = " BTC "
2017-03-21 03:59:50 +00:00
r = requests . get ( cryptopiaurl )
j = r . json ( )
2017-04-26 04:29:09 +00:00
found = False
for i in j [ " Data " ] :
if i [ " Label " ] == coin + " / " + pair :
last = float ( i [ ' LastPrice ' ] )
change = float ( i [ ' Change ' ] )
vol = float ( i [ ' Volume ' ] )
bot . say ( " {0} on Cryptopia at {1:.8f} {2} ; {3:.2f} % o ver 24 hours on {4:.3f} {2} volume " . format ( coin , last , pair , change , vol * last ) )
found = True
if found == False :
bot . say ( " This shit is too shitty even for shitopia " )
2017-03-21 03:59:50 +00:00
except :
bot . say ( " Error retrieving data from Cryptopia " )
@sopel.module.commands ( ' cmc ' , ' coinmarketcap ' )
def cmc ( bot , trigger ) :
2018-01-24 04:49:36 +00:00
# try:
# if trigger.group(2).lower() == 'trx':
# bot.say("Fuck off with your scams scammer")
# return
2018-07-28 14:43:56 +00:00
# except:
2018-01-24 04:49:36 +00:00
# pass
2017-03-21 03:59:50 +00:00
try :
2018-04-21 16:51:59 +00:00
r = requests . get ( ' https://api.coinmarketcap.com/v1/ticker?limit=1500 ' )
2017-03-21 03:59:50 +00:00
j = r . json ( )
except :
bot . say ( " Can ' t connect to API " )
if not trigger . group ( 2 ) :
2018-04-21 16:51:59 +00:00
c1 = ' XMR '
2017-03-21 03:59:50 +00:00
else :
2018-04-21 16:51:59 +00:00
if ' ' in trigger . group ( 2 ) :
c1 = trigger . group ( 2 ) . split ( ' ' ) [ 0 ] . upper ( )
c2 = trigger . group ( 2 ) . split ( ' ' ) [ 1 ] . upper ( )
2017-04-26 04:29:09 +00:00
else :
2018-04-21 16:51:59 +00:00
if trigger . group ( 2 ) . isdigit ( ) :
rank = trigger . group ( 2 )
elif trigger . group ( 2 ) == ' random ' :
rank = random . randint ( 1 , 1500 )
else :
c1 = trigger . group ( 2 ) . upper ( )
2017-03-21 03:59:50 +00:00
try :
2018-04-21 16:51:59 +00:00
if not ' c2 ' in locals ( ) :
for i in j :
try :
if i [ ' symbol ' ] == c1 :
coin = i
except : pass
try :
if i [ ' rank ' ] == str ( rank ) :
coin = i
except : pass
2018-07-28 14:43:56 +00:00
symbol = coin [ ' symbol ' ]
2018-04-21 16:51:59 +00:00
name = coin [ ' name ' ]
rank = coin [ ' rank ' ]
price_usd = float ( coin [ ' price_usd ' ] )
price_btc = float ( coin [ ' price_btc ' ] )
volume_usd = float ( coin [ ' 24h_volume_usd ' ] )
market_cap_usd = float ( coin [ ' market_cap_usd ' ] )
available_supply = float ( coin [ ' available_supply ' ] )
total_supply = float ( coin [ ' total_supply ' ] )
percent_change_24h = float ( coin [ ' percent_change_24h ' ] )
2018-07-28 14:43:56 +00:00
bot . say ( " {0} ( {1} ) is # {2} . Last price $ {3:.2f} / ฿ {4:.8f} . 24h volume $ {5:,.0f} changed {6} % . Market cap $ {7:,.0f} . Available / total coin supply {8:,.0f} / {9:,.0f} . " . format ( name , symbol , rank , price_usd , price_btc , volume_usd , percent_change_24h , market_cap_usd , available_supply , total_supply ) )
2018-04-21 16:51:59 +00:00
else :
for i in j :
try :
if i [ ' symbol ' ] == c1 :
coin = i
if i [ ' symbol ' ] == c2 :
c2coin = i
except : pass
2018-07-28 14:43:56 +00:00
symbol = coin [ ' symbol ' ]
c2symbol = c2coin [ ' symbol ' ]
2018-04-21 16:51:59 +00:00
name = coin [ ' name ' ]
rank = coin [ ' rank ' ]
price_usd = float ( coin [ ' price_usd ' ] )
price_btc = float ( coin [ ' price_btc ' ] )
c2price_btc = float ( c2coin [ ' price_btc ' ] )
volume_usd = float ( coin [ ' 24h_volume_usd ' ] )
market_cap_usd = float ( coin [ ' market_cap_usd ' ] )
available_supply = float ( coin [ ' available_supply ' ] )
total_supply = float ( coin [ ' total_supply ' ] )
percent_change_24h = float ( coin [ ' percent_change_24h ' ] )
2018-07-28 14:43:56 +00:00
bot . say ( " {0} ( {1} ) is # {2} . Last price $ {3:.2f} / {4:.8f} {1} / {5} . 24h volume $ {6:,.0f} . Market cap $ {7:,.0f} . Available / total coin supply {8:,.0f} / {9:,.0f} . " . format ( name , symbol , rank , price_usd , price_btc / c2price_btc , c2symbol , volume_usd , market_cap_usd , available_supply , total_supply ) )
2017-03-21 03:59:50 +00:00
except :
bot . say ( " Error parsing ticker " )
2018-07-28 14:43:56 +00:00
try :
2018-04-21 16:51:59 +00:00
if c1 == ' XMR ' :
with open ( ' /root/.sopel/modules/ath.log ' , ' r ' ) as f :
text = f . read ( )
btcath = float ( text . split ( ' ' ) [ 0 ] )
btcathdate = text . split ( ' ' ) [ 1 ]
usdath = float ( text . split ( ' ' ) [ 2 ] )
usdathdate = text . split ( ' ' ) [ 3 ]
update = False
if price_btc > btcath :
btcath = price_btc
update = True
btcathdate = datetime . datetime . fromtimestamp ( int ( coin [ ' last_updated ' ] ) ) . strftime ( ' % Y- % m- %d ' )
if price_usd > usdath :
usdath = price_usd
update = True
usdathdate = datetime . datetime . fromtimestamp ( int ( coin [ ' last_updated ' ] ) ) . strftime ( ' % Y- % m- %d ' )
if update == True :
with open ( ' /root/.sopel/modules/ath.log ' , ' w ' ) as f :
f . write ( " {} {} {} {} " . format ( btcath , btcathdate , usdath , usdathdate ) )
except :
pass
2017-03-21 03:59:50 +00:00
2018-01-02 03:59:15 +00:00
@sopel.module.commands ( ' top ' )
2018-01-02 05:07:47 +00:00
def top ( bot , trigger ) :
2018-01-27 15:22:42 +00:00
topXstring = " "
try :
2018-01-03 15:58:02 +00:00
try :
2018-01-27 15:22:42 +00:00
r = requests . get ( ' https://api.coinmarketcap.com/v1/global/ ' )
j = r . json ( )
usd_total_mkt_cap = float ( j [ ' total_market_cap_usd ' ] )
total_mcap_short = int ( int ( round ( usd_total_mkt_cap , - 9 ) ) / int ( 1e9 ) )
rounded_total_mcap = str ( total_mcap_short ) + " B "
topXstring + = " Total market cap $ " + rounded_total_mcap + " | "
except :
bot . say ( " Can ' t connect to coinmarketcap API " )
if not trigger . group ( 2 ) :
limit = 20
else :
2018-01-03 15:58:02 +00:00
limit = int ( trigger . group ( 2 ) )
2018-01-03 16:01:13 +00:00
if limit > 20 :
bot . say ( " Too high! Max is 20! " )
2018-01-03 15:58:02 +00:00
elif limit < 1 :
bot . say ( " Dude... " )
2018-01-27 15:22:42 +00:00
r = requests . get ( ' https://api.coinmarketcap.com/v1/ticker?limit= {} ' . format ( limit ) )
j = r . json ( )
for i in j :
2018-07-28 14:43:56 +00:00
symbol = i [ ' symbol ' ]
2018-01-27 15:22:42 +00:00
name = i [ ' name ' ]
rank = i [ ' rank ' ]
price_usd = float ( i [ ' price_usd ' ] )
price_btc = float ( i [ ' price_btc ' ] )
market_cap_usd = float ( i [ ' market_cap_usd ' ] )
if market_cap_usd > = 1e9 :
if market_cap_usd > = 1e10 :
market_cap_short = int ( int ( round ( market_cap_usd , - 9 ) ) / int ( 1e9 ) )
else :
market_cap_short = float ( round ( market_cap_usd , - 8 ) / 1e9 )
rounded_mcap = str ( market_cap_short ) + " B "
2018-01-03 15:58:02 +00:00
else :
2019-07-27 07:34:46 +00:00
#rounded_mcap = "tiny"
market_cap_short = float ( round ( market_cap_usd , - 5 ) / 1e6 )
rounded_mcap = str ( market_cap_short ) + " M "
2018-01-27 15:22:42 +00:00
topXstring + = " {0} . {1} $ {2} | " . format ( rank , symbol , rounded_mcap ) #TODO: add price_usd, rounded
2018-07-28 14:43:56 +00:00
bot . say ( topXstring [ : - 2 ] )
2018-01-27 15:22:42 +00:00
except :
bot . say ( " The use is ' top ' and then a digit 1 - 20 " )
2018-01-02 03:59:15 +00:00
2017-03-21 03:59:50 +00:00
@sopel.module.commands ( ' okc ' , ' okcoin ' )
def okc ( bot , trigger ) :
try :
r = requests . get ( okcquar )
j = r . json ( )
xmr = j [ ' ticker ' ]
last = float ( xmr [ ' last ' ] )
vol = float ( xmr [ ' vol ' ] )
bot . say ( " OKcoin quarterly futures at $ {0:.2f} on {1:.0f} volume " . format ( last , vol ) )
except :
bot . say ( " Error retrieving data from OKCoin " )
2017-05-14 19:21:07 +00:00
@sopel.module.commands ( ' tux ' )
def tux ( bot , trigger ) :
try :
r = requests . get ( ' https://tuxexchange.com/api?method=getticker ' )
j = r . json ( )
if not trigger . group ( 2 ) :
ticker = ' XMR '
else :
ticker = trigger . group ( 2 ) . upper ( )
coin = j [ ' BTC_ {} ' . format ( ticker ) ]
last = float ( coin [ ' last ' ] )
vol = float ( coin [ ' baseVolume ' ] )
change = float ( coin [ ' percentChange ' ] )
bot . say ( " {0} at {1:.8f} BTC on {2:.3f} BTC volume, changed {3:.2f} % o ver last 24 hr " . format ( ticker , last , vol , change ) )
except :
bot . say ( " Error retrieving data from Tuxexchange " )
2017-03-21 03:59:50 +00:00
@sopel.module.commands ( ' pepe ' , ' pepecash ' )
def pepe ( bot , trigger ) :
try :
r = requests . get ( ' https://tuxexchange.com/api?method=getticker ' )
j = r . json ( )
pepe = j [ ' BTC_PEPECASH ' ]
last = float ( pepe [ ' last ' ] )
vol = float ( pepe [ ' baseVolume ' ] )
change = float ( pepe [ ' percentChange ' ] )
bot . say ( " Pepecash at {0:.8f} BTC on {1:.3f} BTC volume, changed {2:.2f} % o ver last 24 hr " . format ( last , vol , change ) )
except :
bot . say ( " Error retrieving data from Tuxexchange " )
@sopel.module.commands ( ' pepexmr ' )
def pepexmr ( bot , trigger ) :
try :
r = requests . get ( ' https://tuxexchange.com/api?method=getticker ' )
j = r . json ( )
pepe = j [ ' BTC_PEPECASH ' ]
pepelast = float ( pepe [ ' last ' ] )
r = requests . get ( polourl )
j = r . json ( )
xmr = j [ " BTC_XMR " ]
xmrlast = float ( xmr [ ' last ' ] )
bot . say ( " Pepe/XMR ratio is : {0:.8f} " . format ( pepelast / xmrlast ) )
except :
bot . say ( " FAILURE! " )
@sopel.module.commands ( ' tall ' )
def tall ( bot , trigger ) :
stringtosend = ' '
stampurl = ' https://www.bitstamp.net/api/ticker/ '
finexurl = ' https://api.bitfinex.com/v1/pubticker/BTCUSD '
btccurl = ' https://data.btcchina.com/data/ticker?market=btccny '
gemiurl = ' https://api.gemini.com/v1/pubticker/btcusd '
2017-06-01 01:10:54 +00:00
gdaxurl = ' https://api.gdax.com/products/BTC-USD/ticker '
2017-03-21 03:59:50 +00:00
# Bitstamp
2018-07-28 14:43:56 +00:00
try :
2017-03-21 03:59:50 +00:00
stampresult = requests . get ( stampurl )
stampjson = stampresult . json ( )
except :
stampjson = False
if stampjson :
2018-07-28 14:43:56 +00:00
stringtosend + = " Bitstamp last: $ {0:,.2f} , vol: {1:,.1f} | " . format ( float ( stampjson [ ' last ' ] ) , float ( stampjson [ ' volume ' ] ) )
2017-03-21 03:59:50 +00:00
# Gemini
2018-07-28 14:43:56 +00:00
try :
2017-03-21 03:59:50 +00:00
gemiresult = requests . get ( gemiurl )
gemijson = gemiresult . json ( )
except :
gemijson = False
if gemijson :
try :
2018-07-28 14:43:56 +00:00
stringtosend + = " Gemini last: $ {0:,.2f} , vol: {1:,.1f} | " . format ( float ( gemijson [ ' last ' ] ) , float ( gemijson [ ' volume ' ] [ ' BTC ' ] ) )
2017-03-21 03:59:50 +00:00
except :
pass
# Gdax
2018-07-28 14:43:56 +00:00
try :
2017-03-21 03:59:50 +00:00
gdaxresult = requests . get ( gdaxurl )
gdaxjson = gdaxresult . json ( )
2018-01-02 05:18:11 +00:00
gdaxprice = float ( gdaxjson [ ' price ' ] )
gdaxvolume = float ( gdaxjson [ ' volume ' ] )
2017-03-21 03:59:50 +00:00
except :
gdaxjson = False
if gdaxjson :
2018-10-18 23:49:23 +00:00
stringtosend + = " CBP last: $ {0:,.2f} , vol: {1:,.1f} | " . format ( gdaxprice , gdaxvolume )
# Binance
try :
binanceresult = requests . get ( binanceurl )
binancejson = binanceresult . json ( )
for i in binancejson :
if i [ " symbol " ] == " BTCUSDT " :
binanceprice = float ( i [ ' lastPrice ' ] )
binancevolume = float ( i [ ' volume ' ] )
except :
binancejson = False
if binancejson :
stringtosend + = " Binance last: $ {0:,.2f} , vol: {1:,.1f} | " . format ( binanceprice , binancevolume )
2017-03-21 03:59:50 +00:00
# Bitfinex
2018-07-28 14:43:56 +00:00
try :
2017-03-21 03:59:50 +00:00
finexresult = requests . get ( finexurl )
finexjson = finexresult . json ( )
except :
finexjson = False
2018-07-28 14:00:43 +00:00
try :
if finexjson :
2018-07-28 14:43:56 +00:00
stringtosend + = " Bitfinex last: $ {0:,.2f} , vol: {1:,.1f} | " . format ( float ( finexjson [ ' last_price ' ] ) , float ( finexjson [ ' volume ' ] ) )
2018-07-28 14:00:43 +00:00
except :
stringtosend + = " Finex sucks | "
2017-10-05 13:46:29 +00:00
# Bitthumb
2018-07-28 14:43:56 +00:00
try :
2017-10-05 13:46:29 +00:00
thumbresult = requests . get ( thumbbtcurl )
thumbjson = thumbresult . json ( )
2017-11-25 21:43:51 +00:00
if thumbjson [ ' data ' ] :
pass
2017-03-21 03:59:50 +00:00
except :
2017-10-05 13:46:29 +00:00
thumbjson = False
if thumbjson :
2018-07-28 14:43:56 +00:00
stringtosend + = " Bithumb last: ₩ {0:,.2f} , vol: {1:,.1f} | " . format ( float ( thumbjson [ ' data ' ] [ ' buy_price ' ] ) , float ( thumbjson [ ' data ' ] [ ' volume_1day ' ] ) )
2017-06-01 01:10:54 +00:00
# Bitflyer
2018-07-28 14:43:56 +00:00
try :
2017-06-01 01:10:54 +00:00
bitflyerresult = requests . get ( bitflyerurl )
bitflyerjson = bitflyerresult . json ( )
except :
bitflyerjson = False
if bitflyerjson :
2018-07-28 14:43:56 +00:00
stringtosend + = " Bitflyer last: ¥ {0:,.2f} , vol: {1:,.1f} | " . format ( float ( bitflyerjson [ ' ltp ' ] ) , float ( bitflyerjson [ ' volume_by_product ' ] ) )
2017-03-21 03:59:50 +00:00
# Send the tickers to IRC
2018-01-24 04:49:36 +00:00
bot . say ( stringtosend [ : - 2 ] )
2018-07-28 14:43:56 +00:00
2017-09-06 00:47:31 +00:00
2018-01-02 05:18:11 +00:00
@sopel.module.commands ( ' xmrtall ' , ' xmr ' )
2017-09-06 00:47:31 +00:00
def xmrtall ( bot , trigger ) :
stringtosend = ' '
2017-09-07 20:40:29 +00:00
2017-09-06 00:47:31 +00:00
# Polo
try :
r = requests . get ( polourl )
j = r . json ( )
xmr = j [ " BTC_XMR " ]
last = float ( xmr [ ' last ' ] )
2018-07-28 14:43:56 +00:00
# change=float(xmr['percentChange'])
vol = float ( xmr [ ' baseVolume ' ] )
2017-09-06 03:40:37 +00:00
stringtosend + = " Poloniex last: {0:.6f} BTC on {1:.2f} BTC volume | " . format ( last , vol )
2017-09-06 00:47:31 +00:00
except :
2018-07-28 14:43:56 +00:00
bot . say ( " Something borked ¯ \ (º_o)/¯ " )
2017-09-06 00:47:31 +00:00
# bfx
try :
r = requests . get ( finexbtc )
j = r . json ( )
2017-09-06 03:40:37 +00:00
stringtosend + = " Bitfinex last: {0:.6f} on {1:.2f} XMR volume | " . format ( float ( j [ ' last_price ' ] ) , float ( j [ ' volume ' ] ) )
2017-09-06 00:47:31 +00:00
except :
bot . say ( " Something borked ʕノ•ᴥ•ʔノ ︵ ┻━┻ " )
# Kraken
try :
r = requests . get ( krakbtc )
j = r . json ( )
2017-09-06 03:40:37 +00:00
stringtosend + = " Kraken last: {0:.6f} on {1:.2f} XMR volume | " . format ( float ( j [ ' result ' ] [ ' XXMRXXBT ' ] [ ' c ' ] [ 0 ] ) , float ( j [ ' result ' ] [ ' XXMRXXBT ' ] [ ' v ' ] [ 1 ] ) )
2017-09-06 00:47:31 +00:00
except :
bot . say ( " Something borked ¤ \ ( `⌂´ )/¤ " )
2018-07-28 14:43:56 +00:00
2018-01-27 15:22:42 +00:00
# Binance
try :
2018-01-27 06:17:14 +00:00
r = requests . get ( binanceurl )
j = r . json ( )
found = False
for i in j :
2018-01-27 15:22:42 +00:00
if i [ " symbol " ] == " XMRBTC " :
2018-01-27 06:17:14 +00:00
last = float ( i [ ' lastPrice ' ] )
vol = float ( i [ ' volume ' ] )
2018-02-15 17:30:38 +00:00
stringtosend + = ( " Binance last: {0:.6f} on {1:.2f} BTC volume | " . format ( last , vol * last ) )
2018-01-27 06:17:14 +00:00
found = True
except :
bot . say ( " Borka borka ┌∩┐(◣_◢)┌∩┐ " )
2018-07-28 14:43:56 +00:00
2017-09-06 00:47:31 +00:00
# Trex
geturl = trexurl + ' xmr '
try :
r = requests . get ( geturl )
j = r . json ( )
xmr = j [ ' result ' ] [ 0 ]
last = float ( xmr [ ' Last ' ] )
# change=((last/float(xmr['PrevDay']))-1)
vol = float ( xmr [ ' BaseVolume ' ] )
2017-09-06 03:40:37 +00:00
stringtosend + = " Bittrex last: {0:.6f} BTC on {1:.2f} BTC volume | " . format ( last , vol )
2017-09-06 00:47:31 +00:00
except :
bot . say ( " Something borked -_- " )
2018-07-28 14:43:56 +00:00
2019-07-27 07:34:46 +00:00
# # Cryptopia
# try:
# coin = 'XMR'
# pair = 'BTC'
# r = requests.get(cryptopiaurl)
# j = r.json()
# found = False
# for i in j["Data"]:
# if i["Label"] == coin+"/"+pair:
# last=float(i['LastPrice'])
# change=float(i['Change'])
# vol=float(i['Volume'])
# stringtosend += "Cryptopia last: {0:.6f} {1} on {2:.2f} {1} volume | ".format(last, pair, vol*last)
# found = True
# if found == False:
# bot.say("WTF?!?")
# except:
# bot.say("Something borked ( -.-) ノ -=≡≡卍 (<-- this is a ninja star, nothing naziish)")
2018-07-28 14:43:56 +00:00
2019-07-26 19:59:07 +00:00
# Bithumb (Note: Must calculate BTCXMR price from BTCKRW and XMRKRW)
try :
xmr_r = requests . get ( thumbxmrurl )
btc_r = requests . get ( thumbbtcurl )
xmrjson = xmr_r . json ( )
btcjson = btc_r . json ( )
# No last price in api. Must average buy and sell price.
thumbXMRbuy = float ( xmrjson [ ' data ' ] [ ' buy_price ' ] )
thumbXMRsell = float ( xmrjson [ ' data ' ] [ ' sell_price ' ] )
thumbXMRkrw = ( thumbXMRbuy + thumbXMRsell ) / 2
# Same for BTC
thumbBTCbuy = float ( btcjson [ ' data ' ] [ ' buy_price ' ] )
thumbBTCsell = float ( btcjson [ ' data ' ] [ ' sell_price ' ] )
thumbBTCkrw = ( thumbBTCbuy + thumbBTCsell ) / 2
# Finally, price in BTC, and volume in XMR
thumbBTCxmr = thumbXMRkrw / thumbBTCkrw
thumbXMRVol = float ( xmrjson [ ' data ' ] [ ' volume_1day ' ] )
2019-08-14 23:41:04 +00:00
stringtosend + = " Bithumb last: {0:.6f} BTC on {1:.2f} XMR volume | " . format ( thumbBTCxmr , thumbXMRVol )
2019-07-26 19:59:07 +00:00
except :
bot . say ( " Error - bithumb korea is worst korea. " )
2017-09-06 00:47:31 +00:00
# Tux
2018-04-21 16:51:59 +00:00
# try:
# r = requests.get('https://tuxexchange.com/api?method=getticker')
# j = r.json()
# if not trigger.group(2):
# ticker='XMR'
# else:
# ticker=trigger.group(2).upper()
# coin=j['BTC_{}'.format(ticker)]
# last=float(coin['last'])
# vol=float(coin['baseVolume'])
# change=float(coin['percentChange'])
# stringtosend += "Tux last: {0:.6f} BTC on {1:.2f} BTC volume. ".format(last, vol)
# except:
# bot.say("Something borked ( ︶︿︶)_╭∩╮")
2017-09-06 00:47:31 +00:00
#Finally... print to IRC
2018-04-21 16:51:59 +00:00
bot . say ( stringtosend [ : - 2 ] )
2017-03-21 03:59:50 +00:00
@sopel.module.commands ( ' usd ' )
def usd ( bot , trigger ) :
try :
r = requests . get ( ' https://api.coinmarketcap.com/v1/ticker/monero/ ' )
j = r . json ( )
price = float ( j [ 0 ] [ ' price_usd ' ] )
bot . say ( " Monero price in USD = $ {0:,.2f} " . format ( price ) )
except :
bot . say ( " Failed to retrieve price. " )
2017-04-26 04:29:09 +00:00
@sopel.module.commands ( ' price ' )
def price ( bot , trigger ) :
try :
2018-01-02 05:18:11 +00:00
bot . say ( " 1 XMR = $12,345 USD (Offer valid in participating locations) " )
2017-04-26 04:29:09 +00:00
except :
bot . say ( " C-cex sucks " )
2017-06-01 01:10:54 +00:00
2018-07-28 19:56:30 +00:00
@sopel.module.commands ( ' comm ' )
def comm ( bot , trigger ) :
2018-07-28 20:43:44 +00:00
commurl = ' https://api.commoprices.com/v1/wrb/ '
apitoken = ' ?api_token=9gdRSeoek4N0AnZHUvP0TSIR74jmyQpsjz5HuGRjfDmsCDxppYiG76GuxaF1 '
try :
r = requests . get ( commurl + apitoken )
data = r . json ( ) [ ' data ' ]
for i in data :
if trigger . group ( 2 ) . lower ( ) in i [ ' name ' ] . lower ( ) :
print ( i )
code = i [ ' code ' ]
except :
bot . say ( " Error getting data or commodity not priced " )
2018-10-18 23:49:23 +00:00
return
2018-07-28 20:43:44 +00:00
try :
r2 = requests . get ( commurl + code + ' /data/ ' + apitoken )
j = r2 . json ( )
bot . say ( " {0} last price at {1:.2f} {2} on {3} " . format ( j [ ' data ' ] [ ' info ' ] [ ' name ' ] , j [ ' data ' ] [ ' request ' ] [ ' dataseries ' ] [ - 1 ] [ 1 ] , j [ ' data ' ] [ ' info ' ] [ ' original_price_unit ' ] [ ' name ' ] , j [ ' data ' ] [ ' request ' ] [ ' dataseries ' ] [ - 1 ] [ 0 ] ) )
except :
bot . say ( " Error parsing some shit " )
2018-07-28 19:56:30 +00:00
2018-01-02 05:18:11 +00:00
@sopel.module.commands ( ' xmy ' )
def xmy ( bot , trigger ) :
try :
r = requests . get ( ' https://api.coinmarketcap.com/v1/ticker?limit=500 ' )
j = r . json ( )
except :
bot . say ( " Can ' t connect to API " )
symbol = ' XMY '
try :
for i in j :
try :
if i [ ' symbol ' ] == symbol :
coin = i
except : pass
try :
if i [ ' rank ' ] == str ( rank ) :
coin = i
except : pass
2018-07-28 14:43:56 +00:00
symbol = coin [ ' symbol ' ]
2018-01-02 05:18:11 +00:00
name = coin [ ' name ' ]
rank = coin [ ' rank ' ]
price_usd = float ( coin [ ' price_usd ' ] )
price_btc = float ( coin [ ' price_btc ' ] )
volume_usd = float ( coin [ ' 24h_volume_usd ' ] )
market_cap_usd = float ( coin [ ' market_cap_usd ' ] )
available_supply = float ( coin [ ' available_supply ' ] )
total_supply = float ( coin [ ' total_supply ' ] )
percent_change_24h = float ( coin [ ' percent_change_24h ' ] )
2018-07-28 14:43:56 +00:00
bot . say ( " {0} ( {1} ) is # {2} . Last price $ {3:.2f} / ฿ {4:.8f} . 24h volume $ {5:,.0f} changed {6} % . Market cap $ {7:,.0f} . Available / total coin supply {8:,.0f} / {9:,.0f} . " . format ( name , symbol , rank , price_usd , price_btc , volume_usd , percent_change_24h , market_cap_usd , available_supply , total_supply ) )
2018-01-02 05:18:11 +00:00
except :
bot . say ( " Error parsing ticker " )
2018-07-18 09:35:39 +00:00
@sopel.module.commands ( ' localmonero ' , ' localxmr ' , ' lxmr ' , ' lm ' , ' street ' )
def localmonero ( bot , trigger ) :
try :
r = requests . get ( localmonerousd )
j = r . json ( )
2018-07-28 14:50:05 +00:00
stringtosay = " LocalMonero XMR/USD 12h-avg: $ {0:.2f} , 24h-avg: $ {0:.2f} . " . format ( float ( j [ ' USD ' ] [ ' avg_12h ' ] ) , float ( j [ ' USD ' ] [ ' avg_24h ' ] ) )
2018-07-18 09:35:39 +00:00
bot . say ( stringtosay )
except :
bot . say ( " Error getting data " )