Skip to content

Instantly share code, notes, and snippets.

@Skeyelab
Last active January 16, 2018 15:31
Show Gist options
  • Save Skeyelab/53de74d820f5cd4fd67119f06818c367 to your computer and use it in GitHub Desktop.
Save Skeyelab/53de74d820f5cd4fd67119f06818c367 to your computer and use it in GitHub Desktop.
GDAX Spot Price - LTC

This pulls a LTC spot rate from GDAX.

#Usage

dashing install 53de74d820f5cd4fd67119f06818c367

Copy this into your dashboard

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
      <div data-id="ltcprice" data-view="Ltcprice" data-ltcprice="" data-prefix="$"></div>
</li>
require 'net/http'
require 'json'
require 'uri'
SCHEDULER.every '5s', allow_overlapping: false do
uri = URI.parse('https://api.coinbase.com/v2/prices/LTC-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)
ltc_price = json_response['data']['amount']
ltc_price = '%.2f' % ltc_price.delete(',').to_f
#puts btc_price
send_event('ltcprice', { value: ltc_price.to_f} )
end
class Dashing.Ltcprice extends Dashing.Widget
@accessor 'value', Dashing.AnimatedValue
@accessor 'ltcprice', ->
if @get('value')
price = parseFloat(@get('value'))
<img src="https://image.ibb.co/j4picb/ltc.png" class="ltc_logo" alt="" style="">
<h3 data-bind="ltcprice | 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-ltcprice {
background-color: $background-color;
.title {
color: $title-color;
}
.ltc_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 */
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment