From 8480bd6c59dae23b316cde92e00422ef6e614875 Mon Sep 17 00:00:00 2001 From: Joshua Seigler Date: Sun, 8 May 2016 16:24:32 -0400 Subject: [PATCH] use new coinmarket API --- .gitignore | 1 + index.html | 235 +++++++++++++++++++++++++++++++---------------------- 2 files changed, 139 insertions(+), 97 deletions(-) diff --git a/.gitignore b/.gitignore index 2ccbe46..100a0cd 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /node_modules/ +/.brackets.json diff --git a/index.html b/index.html index 63c7ec1..4c59218 100644 --- a/index.html +++ b/index.html @@ -15,114 +15,155 @@

Dash Price Widget

- -
-
Dash Price
-
- - -
-
- + function updatePrices() { + // this requests the Dash price JSON and executes a callback with the parsed result once it is available + fetchJSONFile('https://coinmarketcap-nexuist.rhcloud.com/api/dash/', function (data) { + var markup = '
Dash Price
!price_usd
!percent_change_24h
!price_btc
'; + +/* +{ + "symbol":"dash", + "position":"5", + "name":"Dash", + "market_cap":{ + "usd":42443061.2936, + "eur":37214670.34508659, + "cny":275818610.627892, + "gbp":29413847.89462938, + "cad":54771497.307551995, + "rub":2800409354.958081, + "hkd":329415538.6572049, + "jpy":4545448180.293412, + "aud":57612508.5013617, + "btc":92474.6576981 + }, + "price":{ + "usd":6.59801, + "eur":5.78522754014, + "cny":42.87753747356, + "gbp":4.572546292190001, + "cad":8.5145339647, + "rub":435.33921364181, + "hkd":51.20947810952, + "jpy":706.6152071500101, + "aud":8.95618496007, + "btc":0.0143757 + }, + "supply":"6432706", + "volume":{ + "usd":300399, + "eur":263394.048786, + "cny":1952159.723844, + "gbp":208182.21458100004, + "cad":387655.89753, + "rub":19820440.472018998, + "hkd":2331502.379448, + "jpy":32171291.285198998, + "aud":407763.70539300004, + "btc":654.506 + }, + "change":"-3.01", + "timestamp":"1462626382.036" +} +*/ + + console.log(data); + if (data) { + markup = markup.replace(/!price_usd/g, makeCurrencyString(data.price.usd) + " USD"); + markup = markup.replace(/!percent_change_24h/g, data.change + "%"); + markup = markup.replace(/!price_btc/g, makeCurrencyString(data.price.btc) + " BTC"); + document.querySelector('[data-dash-price-widget]').innerHTML = markup; + } + }); + } + + updatePrices(); // update prices now + setInterval(updatePrices, 5 * 60 * 1000); // ...and every five minutes after this +}()); +