Commit 24926372 authored by Cool Fire's avatar Cool Fire

Move dogecoin plugin away from discontinued API

parent f5cd78d9
Pipeline #561 passed with stages
in 3 minutes and 29 seconds
...@@ -14,37 +14,31 @@ class Dogecoin ...@@ -14,37 +14,31 @@ class Dogecoin
@irc = irc @irc = irc
@timer = timer @timer = timer
@api_host = 'pubapi.cryptsy.com' @api_uri = 'https://api.cryptonator.com/api/ticker/doge-btc'
@api_path = '/api.php?method=singlemarketdata&marketid=132' @last = BigDecimal( "0.0" )
@last = BigDecimal.new( "0.0" )
end end
# Alias for last # Alias for last
def main( _nick, _user, _host, from, _msg, _arguments, con ) def main( _nick, _user, _host, from, _msg, _arguments, con )
uri = URI.parse( "http://#{@api_host}#{@api_path}" ) uri = URI(@api_uri)
response = Net::HTTP.get( uri )
http = Net::HTTP.new( uri.host, uri.port ) puts response
result = JSON.parse( response )
request = Net::HTTP::Get.new( uri.request_uri )
response = http.request( request )
result = JSON.parse( response.body )
# Calculate delta from last !btc puts result.inspect
ldiff = BigDecimal.new( result[ 'return' ][ 'markets' ][ 'DOGE' ][ 'lasttradeprice' ] ) - @last # Calculate delta from last !doge
ldiff = BigDecimal( result[ 'ticker' ][ 'price' ] ) - @last
if( ldiff > 0 ) if( ldiff > 0 )
ldiff = "+#{ldiff}" ldiff = "+#{ldiff}"
else else
ldiff = "#{ldiff}" ldiff = "#{ldiff}"
end end
@last = BigDecimal.new( result[ 'return' ][ 'markets' ][ 'DOGE' ][ 'lasttradeprice' ] ) @last = BigDecimal( result[ 'ticker' ][ 'price' ] )
rounded = "#{( BigDecimal.new( result[ 'return' ][ 'markets' ][ 'DOGE' ][ 'lasttradeprice' ] ) * 100 ).round / 100.0}" rounded = "#{( BigDecimal( result[ 'ticker' ][ 'price' ] ) * 100 ).round / 100.0}"
line = "Cryptsy DOGE/BTC rate: #{rounded} (#{result[ 'return' ][ 'markets' ][ 'DOGE' ][ 'lasttradeprice' ]}) (#{ldiff} since last !doge)" line = "Cryptonator DOGE/BTC rate: #{rounded} (#{result[ 'ticker' ][ 'price' ]}) (#{ldiff} since last !doge)"
if( con ) if( con )
@output.c( line + "\n" ) @output.c( line + "\n" )
...@@ -56,10 +50,10 @@ class Dogecoin ...@@ -56,10 +50,10 @@ class Dogecoin
# Function to send help about this plugin (Can also be called by the help plugin.) # Function to send help about this plugin (Can also be called by the help plugin.)
def help( nick, _user, _host, _from, _msg, _arguments, con ) def help( nick, _user, _host, _from, _msg, _arguments, con )
help = [ help = [
"Gets current litecoin values from Btc-e", "Gets current litecoin values from cryptonator",
" dogecoin - Get DOGE/BTC exchange rate" " dogecoin - Get DOGE/BTC exchange rate"
] ]
# Print out help # Print out help
help.each do |line| help.each do |line|
if( con ) if( con )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment