Skip to content

Instantly share code, notes, and snippets.

@Skeyelab
Last active August 13, 2018 21:00
Show Gist options
  • Save Skeyelab/19880011b1a9f9912b5823fc3e281cb0 to your computer and use it in GitHub Desktop.
Save Skeyelab/19880011b1a9f9912b5823fc3e281cb0 to your computer and use it in GitHub Desktop.

This pulls a ETH 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="ethprice" data-view="Ethprice" data-ethprice="" data-prefix="$"></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 | 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-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 '5s', allow_overlapping: false do
uri = URI.parse('https://api.coinbase.com/v2/prices/ETH-USD/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
#puts btc_price
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