Permalink
Browse files

[bc_*] Added Bitcoin-Central.net

  • Loading branch information...
xHire committed Mar 6, 2013
1 parent 3dbc180 commit 88367a48a94d20432c7278f099acf5a82154e466
Showing with 42 additions and 3 deletions.
  1. +21 −1 plugins/bc_market.rb
  2. +21 −2 plugins/bc_rate.rb
View
@@ -123,6 +123,25 @@ def run channel, params = ''
sell[:b24] ||= 0.0
end
+ threads << Thread.start do
+ begin
+ # obtain bitcoin-central info
+ ticker = open('https://bitcoin-central.net/api/v1/ticker').readline.strip
+ buy[:bc] = ActiveSupport::JSON.decode(ticker)['bid'].to_f
+ sell[:bc] = ActiveSupport::JSON.decode(ticker)['ask'].to_f
+ rescue Errno::ETIMEDOUT
+ $bot.put "PRIVMSG #{channel} :Sorry, bitcoin-central doesn't respond."
+ rescue OpenURI::HTTPError => err
+ $bot.put "PRIVMSG #{channel} :Sorry, bitcoin-central shouts HTTP error: #{err}"
+ rescue Errno::ECONNRESET
+ $bot.put "PRIVMSG #{channel} :Sorry, bitcoin-central reset the connection"
+ rescue OpenSSL::SSL::SSLError
+ $bot.put "PRIVMSG #{channel} :Sorry, bitcoin-central has some SSL difficulties"
+ end
+ buy[:bc] ||= 0.0
+ sell[:bc] ||= 0.0
+ end
+
# wait for all threads
threads.each do |t|
t.join
@@ -132,7 +151,8 @@ def run channel, params = ''
$bot.put "PRIVMSG #{channel} :buy/sell: " +
"[MtGox] #{round(buy[:mtgox])}/#{round(sell[:mtgox])} | " +
"[Bitstamp] #{round(buy[:bs])}/#{round(sell[:bs])} | " +
- "[BTC24] #{round(buy[:b24])}/#{round(sell[:b24])}"
+ "[BTC24] #{round(buy[:b24])}/#{round(sell[:b24])} | " +
+ "[B-C] #{round(buy[:bc])}/#{round(sell[:bc])}"
rescue Timeout::Error
$bot.put "PRIVMSG #{channel} :Sorry, timeout :c("
puts "[TRH] Exception was raised: #{e.inspect}"
View
@@ -116,6 +116,23 @@ def run channel, params = ''
btc[:b24_eur] ||= 0.0
end
+ threads << Thread.start do
+ begin
+ # obtain EUR/BTC rate -- bitcoin-central
+ ticker = open('https://bitcoin-central.net/api/v1/ticker')
+ btc[:bc_eur] = ActiveSupport::JSON.decode(ticker.readline.strip)['price'].to_f
+ rescue Errno::ETIMEDOUT
+ $bot.put "PRIVMSG #{channel} :Sorry, bitcoin-central doesn't respond."
+ rescue OpenURI::HTTPError => err
+ $bot.put "PRIVMSG #{channel} :Sorry, bitcoin-central shouts HTTP error: #{err}"
+ rescue Errno::ECONNRESET
+ $bot.put "PRIVMSG #{channel} :Sorry, bitcoin-central reset the connection"
+ rescue OpenSSL::SSL::SSLError
+ $bot.put "PRIVMSG #{channel} :Sorry, bitcoin-central has some SSL difficulties"
+ end
+ btc[:bc_eur] ||= 0.0
+ end
+
# wait for all threads
threads.each do |t|
t.join
@@ -128,13 +145,15 @@ def run channel, params = ''
$bot.put "PRIVMSG #{channel} :#{c.to_s.upcase}: " +
"[MtGox] #{round(btc[:mtgox_usd] * rate[:usd] / rate[c])} | " +
"[Bitstamp] #{round(btc[:bs_usd] * rate[:usd] / rate[c])} | " +
- "[BTC24] #{round(btc[:b24_eur] * rate[:eur] / rate[c])}"
+ "[BTC24] #{round(btc[:b24_eur] * rate[:eur] / rate[c])} | " +
+ "[B-C] #{round(btc[:bc_eur] * rate[:eur] / rate[c])}"
end
unless any
$bot.put "PRIVMSG #{channel} :USD/CZK: " +
"[MtGox] #{round(btc[:mtgox_usd])}/#{round(btc[:mtgox_usd] * rate[:usd])} | " +
"[Bitstamp] #{round(btc[:bs_usd])}/#{round(btc[:bs_usd] * rate[:usd])} | " +
- "[BTC24] #{round(btc[:b24_eur] * rate[:eur] / rate[:usd])}/#{round(btc[:b24_eur] * rate[:eur])}"
+ "[BTC24] #{round(btc[:b24_eur] * rate[:eur] / rate[:usd])}/#{round(btc[:b24_eur] * rate[:eur])} | " +
+ "[B-C] #{round(btc[:bc_eur] * rate[:eur] / rate[:usd])}/#{round(btc[:bc_eur] * rate[:eur])}"
end
rescue Timeout::Error => e
$bot.put "PRIVMSG #{channel} :Sorry, timeout :c("

0 comments on commit 88367a4

Please sign in to comment.