Skip to content

Instantly share code, notes, and snippets.

@mehdicopter
Forked from Skeyelab/ethprice.coffee
Last active August 13, 2018 21:18
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 mehdicopter/7d5962d06c16f8dda16d017bf07f20bb to your computer and use it in GitHub Desktop.
Save mehdicopter/7d5962d06c16f8dda16d017bf07f20bb to your computer and use it in GitHub Desktop.

This pulls a ETH spot rate from GDAX.

#Usage

smashing install 7d5962d06c16f8dda16d017bf07f20bb

Copy this into your dashboard

    <li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
      <div data-id="ethprice" data-view="Ethprice" data-ethprice="" data-suffix="€"></div>
    </li>
class Dashing.Ethprice extends Dashing.Widget
@accessor 'value', Dashing.AnimatedValue
@accessor 'ethprice', ->
if @get('value')
price = parseFloat(@get('value'))
<img src="https://image.ibb.co/ewwUHb/eth.png" class="eth_logo" alt="" style="">
<h3 data-bind="ethprice | append suffix" 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-ethprice {
background-color: $background-color;
.title {
color: $title-color;
}
.eth_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 '1m', allow_overlapping: false do
uri = URI.parse('https://api.coinbase.com/v2/prices/ETH-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)
eth_price = json_response['data']['amount']
eth_price = '%.2f' % eth_price.delete(',').to_f
send_event('ethprice', { value: eth_price.to_f} )
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment