Skip to content

Instantly share code, notes, and snippets.

@stephenyeargin
Created September 1, 2014 00:23
Show Gist options
  • Save stephenyeargin/a75d7dba0a09f7bd00af to your computer and use it in GitHub Desktop.
Save stephenyeargin/a75d7dba0a09f7bd00af to your computer and use it in GitHub Desktop.
Add the current price of Bitcoin to your Dashing Dashboard

Bitcoin Dashing Widget

Fairly straightforward. Uses BitcoinAverage.com to obtain the most recent price of Bitcoin across the exchanges. There are no setup instructions.

Installation

Copy the bitcoin.rb file into your ./jobs/ folder. Adjust the timing as needed. If you are not wanting the value in USD, you can swap out for another currency within there as well.

Template for your Dashboard

    <li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
      <div data-id="bitcoin" data-view="Number" data-title="Bitcoin Price" style="background-color:#96bf48;"></div>
      <i class="icon-bitcoin icon-background"></i>
    </li>
current_price = 0
SCHEDULER.every '5m' do
last_price = current_price
current_price = get_bitcoin('USD')
send_event('bitcoin', { current: current_price, last: last_price })
end
def get_bitcoin(market='USD')
uri = URI("https://api.bitcoinaverage.com/ticker/global/#{market}/")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
bitcoin_response = JSON.parse(response.body)
bitcoin_response['last']
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment