Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repaired: name, symbol, volume, supply; numbers not as strings anymore #23

Merged
merged 9 commits into from
Feb 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules/*

npm-debug.log
/.project
/package-lock.json
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ JSON API for coinmarketcap.com hosted on OpenShift. The documentation for this s

The service itself is hosted by me at https://coinmarketcap-nexuist.rhcloud.com/. You can use that site or, if you want, host it yourself.

To run, `npm install && npm start`.
To run,

```
npm install
npm start
```

### Version 2.0.9 (altsheets)
* CMC had changed separator from " " to "\n" - fixed
* several previous updates, see [commit history](https://github.com/altsheets/CoinMarketCapAPI/commits/master)

### New in 2.0

Expand Down
4 changes: 4 additions & 0 deletions history.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
history

v2.0.7 repaired 'symbol' and 'name'; CMC had probably changed layout (altsheets)
v2.0.8 repaired: 'volume', 'supply'; all numbers now are not strings anymore (altsheets)
25 changes: 17 additions & 8 deletions lib/CoinFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,34 @@ module.exports = class CoinFactory {
Object.keys(self.exchangeRates).forEach(function (currency) {
dict[currency] = usd / self.exchangeRates[currency]
})
dict["btc"] = btc
dict["btc"] = btc / 1 // was = btc but then returned as string not as number
return dict
}

produce(tr) {
var self = this
var tds = tr.find("td") // Array of tds in this tr
var td = function (index) {
return tds.eq(index).text().trim()
}

var col2 = tds.eq(1).text().trim().split("\n");
// console.log(col2);
// console.log();
// console.log(col2[0].trim());
// console.log(col2[col2.length-1].trim());
// a[42]

var coin = {
"symbol": tds.eq(4).text().match(/\s([a-z]|[0-9]|@)+\s/i)[0].trim().toLowerCase(),
"position": td(0),
"name": tds.eq(1).find("img").attr("alt"),
"symbol": col2[0].trim().toLowerCase(), // tds.eq(5).text().match(/\s([a-z]|[0-9]|@)+\s/i)[0].trim().toLowerCase(),
"position": td(0) / 1,
"name": col2[col2.length-1].trim(), // tds.eq(1).find("img").attr("alt"),
"market_cap": self.currencyDictionary(tds.eq(2)),
"price": self.currencyDictionary(tds.eq(3).find("a").eq(0)),
"supply": td(4).replace(/\D/g, "").trim(), // Remove all non-numeric characters
"volume": self.currencyDictionary(tds.eq(5).find("a").eq(0)),
"change": td(6).replace("%", "").trim(),
"timestamp": (Date.now() / 1000).toString()
"supply": td(5).replace(/\D/g, "").trim() / 1, // td(4).replace(/\D/g, "").trim(), // Remove all non-numeric characters
"volume": self.currencyDictionary(tds.eq(4).find("a").eq(0)), // self.currencyDictionary(tds.eq(5).find("a").eq(0)),
"change": td(6).replace("%", "").trim() / 1,
"timestamp": (Date.now() / 1000).toString() / 1
}
return coin
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "coinmarketcap",
"version": "2.0.6",
"version": "2.0.9",
"description": "JSON API for coinmarketcap.com.",
"main": "main.js",
"devDependencies": {},
Expand Down