Skip to content

Instantly share code, notes, and snippets.

@leoschweizer
Forked from Skeyelab/btcprice.coffee
Last active January 16, 2018 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leoschweizer/bf768da4e56721f5003cf8d5448a9ea6 to your computer and use it in GitHub Desktop.
Save leoschweizer/bf768da4e56721f5003cf8d5448a9ea6 to your computer and use it in GitHub Desktop.

This pulls a BTC spot rate from GDAX.

#Usage

dashing install bf768da4e56721f5003cf8d5448a9ea6

Copy this into your dashboard

    <li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
      <div data-id="btcprice" data-view="Btcprice" data-btcprice="" data-prefix="€"></div>
    </li>
class Dashing.Btcprice extends Dashing.Widget
@accessor 'value', Dashing.AnimatedValue
@accessor 'btcprice', ->
if @get('value')
price = parseFloat(@get('value'))
<img src="http://logok.org/wp-content/uploads/2016/10/Bitcoin-Logo-640x480.png" class="btc_logo" alt="" style="">
<h3 data-bind="btcprice | prepend prefix" class="price value"></h3>
<p class="updated-at" data-bind="updatedAtMessage"></p>
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #3498db;
$title-color: rgba(255, 255, 255, 0.7);
$moreinfo-color: rgba(255, 255, 255, 0.7);
// ----------------------------------------------------------------------------
// Widget-text styles
// ----------------------------------------------------------------------------
.widget-btcprice {
background-color: $background-color;
.title {
color: $title-color;
}
.btc_logo {
position: relative; /* Declared position allows for location changes */
top: -20px; /* Moves the image 2px closer to the top of the page */
}
.more-info {
color: $moreinfo-color;
}
.updated-at {
color: rgba(255, 255, 255, 0.7);
}
.price {
font-size: 3em;
position: relative; /* Declared position allows for location changes */
bottom: 38px; /* Moves the image 2px closer to the top of the page */
}
}
require 'net/http'
require 'json'
require 'uri'
SCHEDULER.every '5s', allow_overlapping: false do
uri = URI.parse('https://api.coinbase.com/v2/prices/BTC-EUR/spot')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
json_response = JSON.parse(response.body)
btc_price = json_response['data']['amount']
btc_price = '%.2f' % btc_price.delete(',').to_f
#puts btc_price
send_event('btcprice', { value: btc_price.to_f} )
end
<img src="http://logok.org/wp-content/uploads/2016/10/Bitcoin-Logo-640x480.png" class="btc_logo" alt="" style="">
<h3 data-bind="btcprice | prepend prefix" class="price value"></h3>
<p class="updated-at" data-bind="updatedAtMessage"></p>
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #3498db;
$title-color: rgba(255, 255, 255, 0.7);
$moreinfo-color: rgba(255, 255, 255, 0.7);
// ----------------------------------------------------------------------------
// Widget-text styles
// ----------------------------------------------------------------------------
.widget-btcprice {
background-color: $background-color;
.title {
color: $title-color;
}
.btc_logo {
position: relative; /* Declared position allows for location changes */
top: -20px; /* Moves the image 2px closer to the top of the page */
}
.more-info {
color: $moreinfo-color;
}
.updated-at {
color: rgba(255, 255, 255, 0.7);
}
.price {
font-size: 3em;
position: relative; /* Declared position allows for location changes */
bottom: 38px; /* Moves the image 2px closer to the top of the page */
}
}
class Dashing.Btcprice extends Dashing.Widget
@accessor 'value', Dashing.AnimatedValue
@accessor 'btcprice', ->
if @get('value')
price = parseFloat(@get('value'))
This pulls a BTC spot rate from GDAX.
#Usage
`dashing install 19880011b1a9f9912b5823fc3e281cb0`
Copy this into your dashboard
```
<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="btcprice" data-view="Btcprice" data-btcprice="" data-prefix="$"></div>
</li>
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment