2011-11-20 22:23:31 +13:00
from util import http , hook
2013-11-29 00:36:54 +13:00
@hook.command ( " btc " , autohelp = False )
2011-11-20 22:23:31 +13:00
@hook.command ( autohelp = False )
2013-11-29 00:36:54 +13:00
def bitcoin ( inp ) :
" bitcoin <exchange> -- Gets current exchange rate for bitcoins from several exchanges, default is MtGox. Supports MtGox, Bitpay, and BitStamp. "
exchanges = {
" mtgox " : {
" api_url " : " https://mtgox.com/api/1/BTCUSD/ticker " ,
2013-11-29 11:55:07 +13:00
" func " : lambda data : u " MtGox // Current: \x03 07 {} \x0f - High: \x03 07 {} \x0f - Low: \x03 07 {} \x0f - Best Ask: \x03 07 {} \x0f - Volume: {} " . format ( data [ ' return ' ] [ ' last ' ] [ ' display ' ] , \
2013-11-29 00:36:54 +13:00
data [ ' return ' ] [ ' high ' ] [ ' display ' ] , data [ ' return ' ] [ ' low ' ] [ ' display ' ] , data [ ' return ' ] [ ' buy ' ] [ ' display ' ] , \
data [ ' return ' ] [ ' vol ' ] [ ' display ' ] )
} ,
" bitpay " : {
" api_url " : " https://bitpay.com/api/rates " ,
2013-11-29 01:06:12 +13:00
" func " : lambda data : u " Bitpay // Current: \x03 07$ {:.2f} \x0f " . format ( data [ 0 ] [ ' rate ' ] )
2013-11-29 00:36:54 +13:00
} ,
" bitstamp " : {
" api_url " : " https://www.bitstamp.net/api/ticker/ " ,
2013-11-29 01:06:12 +13:00
" func " : lambda data : u " BitStamp // Current: \x03 07$ {} \x0f - High: \x03 07$ {} \x0f - Low: \x03 07$ {} \x0f - Volume: {:.2f} BTC " . format ( data [ ' last ' ] , data [ ' high ' ] , data [ ' low ' ] , \
2013-11-29 00:36:54 +13:00
float ( data [ ' volume ' ] ) )
}
2013-04-17 21:32:24 -07:00
}
2013-11-29 00:36:54 +13:00
inp = inp . lower ( )
if inp :
if inp in exchanges :
exchange = exchanges [ inp ]
else :
return " Invalid Exchange "
else :
exchange = exchanges [ " mtgox " ]
data = http . get_json ( exchange [ " api_url " ] )
func = exchange [ " func " ]
return func ( data )
2013-11-29 00:04:28 +13:00
2013-11-28 18:48:11 +08:00
@hook.command ( autohelp = False )
def litecoin ( inp , message = None ) :
""" litecoin -- gets current exchange rate for litecoins from BTC-E """
data = http . get_json ( " https://btc-e.com/api/2/ltc_usd/ticker " )
ticker = data [ ' ticker ' ]
2013-11-29 00:04:28 +13:00
message ( " Current: \x03 07$ {:.2f} \x0f - High: \x03 07$ {:.2f} \x0f "
" - Low: \x03 07$ {:.2f} \x0f - Volume: {:.2f} LTC " . format ( ticker [ ' buy ' ] , ticker [ ' high ' ] , ticker [ ' low ' ] , ticker [ ' vol_cur ' ] ) )