Socket
Socket
Sign inDemoInstall

cryptocompare

Package Overview
Dependencies
0
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.7.2 to 1.0.0

8

CHANGELOG.md

@@ -0,1 +1,9 @@

1.0.0 / 2019-02-05
------------------
- added: `constituentExchangeList()` method ([#36](https://github.com/exodusmovement/cryptocompare/pull/36))
- added: `latestSocial()` method ([#36](https://github.com/exodusmovement/cryptocompare/pull/36))
- added: `histoSocial()` method ([#36](https://github.com/exodusmovement/cryptocompare/pull/36))
- fixed: docs for `toTs` option ([#36](https://github.com/exodusmovement/cryptocompare/pull/36))
0.7.2 / 2019-01-25

@@ -2,0 +10,0 @@ ------------------

31

index.js

@@ -43,2 +43,9 @@ 'use strict'

function constituentExchangeList (options) {
options = options || {}
let url = `${baseUrl}all/includedexchanges`
if (options.instrument) url += `?instrument=${options.instrument}`
return fetchJSON(url).then(result => result.Data)
}
function newsFeedsAndCategories () {

@@ -170,5 +177,25 @@ const url = `${baseUrl}news/feedsandcategories`

function latestSocial (options) {
options = options || {}
let url = `${baseUrl}social/coin/latest`
if (options.coinId) url += `?coinId=${options.coinId}`
return fetchJSON(url).then(result => result.Data)
}
function histoSocial (timePeriod, options) {
options = options || {}
let url = `${baseUrl}social/coin/histo/${timePeriod === 'hour' ? 'hour' : 'day'}`
let query = []
if (options.coinId) query.push(`coinId=${options.coinId}`)
if (options.aggregate >= 1 && options.aggregate <= 30) query.push(`aggregate=${options.aggregate}`)
if (options.aggregate && typeof options.aggregatePredictableTimePeriods === 'boolean') query.push(`&aggregatePredictableTimePeriods=${options.aggregatePredictableTimePeriods}`)
if (options.limit >= 1 && options.limit <= 2000) query.push(`limit=${options.limit}`)
if (options.toTs) query.push(`toTs=${options.toTs}`)
return fetchJSON(`${url}${query.length > 0 ? '?' + query.join('&') : ''}`).then(result => result.Data)
}
module.exports = {
setApiKey,
coinList,
constituentExchangeList,
exchangeList,

@@ -187,3 +214,5 @@ newsFeedsAndCategories,

histoHour,
histoMinute
histoMinute,
latestSocial,
histoSocial
}

4

package.json
{
"name": "cryptocompare",
"description": "CryptoCompare JavaScript API",
"version": "0.7.2",
"version": "1.0.0",
"author": "JP Richardson <jprichardson@gmail.com>",

@@ -12,3 +12,3 @@ "bugs": {

"standard": "9.x",
"tap-spec": "^4.0.2",
"tap-spec": "^5.0.0",
"tape": "^4.0.0"

@@ -15,0 +15,0 @@ },

@@ -401,3 +401,3 @@ cryptocompare

- `allData` (Boolean) Returns all data.
- `toTs` (Boolean) Last unix timestamp to return data for.
- `toTs` (Number) Last unix timestamp to return data for.
- `limit` (Number | `'none'`) Limit the number of days to lookup. Default is 30. If you set it to the string `'none'`, you will get all available data.

@@ -435,3 +435,3 @@ - `tryConversion` (Boolean) By default, if the crypto does not trade directly into the toSymbol requested, BTC will be used for conversion. Set `tryConversion` to `false` to disable using BTC for conversion.

- `aggregatePredictableTimePeriods` (Boolean) Generate predictable time periods.
- `toTs` (Boolean) Last unix timestamp to return data for
- `toTs` (Number) Last unix timestamp to return data for
- `limit` (Number) Limit the number of hours to lookup. Default is 168.

@@ -469,3 +469,3 @@ - `tryConversion` (Boolean) By default, if the crypto does not trade directly into the toSymbol requested, BTC will be used for conversion. Set `tryConversion` to `false` to disable using BTC for conversion.

- `aggregatePredictableTimePeriods` (Boolean) Generate predictable time periods.
- `toTs` (Boolean) Last unix timestamp to return data for
- `toTs` (Number) Last unix timestamp to return data for
- `limit` (Number) Limit the number of minutes to lookup. Default is 1440.

@@ -581,4 +581,156 @@ - `tryConversion` (Boolean) By default, if the crypto does not trade directly into the toSymbol requested, BTC will be used for conversion. Set `tryConversion` to `false` to disable using BTC for conversion.

### `constituentExchangeList()`
Returns all the constituent exchanges in the request instrument.
`constituentExchangeList([options])`
- `options` (Object)
- `instrument` (String) The type of average instrument.
- `Returns` (Object)
```js
const cc = require('cryptocompare')
cc.setApiKey('<your-api-key>')
// Usage:
cc.constituentExchangeList()
.then(exchanges => {
console.log(exchanges)
// {
// "ABCC": {
// "includeAll": false,
// "onlyPairs": {
// "CNN~BTC": true,
// "TNS~BTC": true,
// "TTU~USDT": true,
// "XMX~BTC": true,
// "GUSD~USDT": true
// }
// },
// "ACX": {
// "includeAll": true,
// "onlyPairs": {}
// },
// ...
// }
})
.catch(console.error)
```
### `latestSocial()`
Returns latest social stats data for the coin requested.
_Note_: **Requires a valid API key.**
`latestSocial([options])`
- `options` (Object)
- `coinId` (Number) The id of the coin.
- `Returns` (Object)
```js
const cc = require('cryptocompare')
cc.setApiKey('<your-api-key>')
// Usage:
cc.latestSocial()
.then(social => {
console.log(social)
// {
// "General": {
// "Points": 7431355,
// "Name": "BTC",
// "CoinName": "Bitcoin",
// "Type": "Webpagecoinp"
// },
// "CryptoCompare": {
// ...
// },
// "Twitter": {
// ...
// },
// "Reddit": {
// ...
// },
// "Facebook": {
// ...
// },
// "CodeRepository": {
// ...
// }
// }
})
.catch(console.error)
```
### `histoSocial()`
Returns social stats data for the coin requested.
_Note_: **Requires a valid API key.**
`histoSocial(timePeriod[, options])`
- `timePeriod` (String) Time period - 'day' or 'hour'
- `options` (Object)
- `coinId` (Number) The id of the coin.
- `aggregate` (Number) Time period to aggregate the data over.
- `aggregatePredictableTimePeriods` (Boolean) Only used if `aggregate` param included. If false, then it will create time slots based on when the call is made.
- `limit` (Number) Number of data points to return.
- `toTs` (Number) Last unix timestamp to return data for
- `Returns` (Array of Objects)
```js
const cc = require('cryptocompare')
cc.setApiKey('<your-api-key>')
// Usage:
cc.histoSocial('hour')
.then(socialStats => {
console.log(socialStats)
// [
// {
// "time": 1548640800,
// "comments": 229133,
// "posts": 89997,
// "followers": 64128,
// "points": 6144455,
// "overview_page_views": 22335644,
// "analysis_page_views": 955496,
// "markets_page_views": 1402190,
// "charts_page_views": 7527086,
// "trades_page_views": 673204,
// "forum_page_views": 6585840,
// "influence_page_views": 55903,
// "total_page_views": 39535363,
// "fb_likes": 40054,
// "fb_talking_about": 92,
// "twitter_followers": 844049,
// "twitter_following": 165,
// "twitter_lists": 6631,
// "twitter_favourites": 1000,
// "twitter_statuses": 20316,
// "reddit_subscribers": 1013891,
// "reddit_active_users": 4365,
// "reddit_posts_per_hour": 3.77,
// "reddit_posts_per_day": 90.46,
// "reddit_comments_per_hour": 68.39,
// "reddit_comments_per_day": 1641.34,
// "code_repo_stars": 44353,
// "code_repo_forks": 25367,
// "code_repo_subscribers": 4179,
// "code_repo_open_pull_issues": 330,
// "code_repo_closed_pull_issues": 11847,
// "code_repo_open_issues": 903,
// "code_repo_closed_issues": 5187
// }
// ]
})
.catch(console.error)
```
## License
[MIT](LICENSE.md)

@@ -7,3 +7,11 @@ 'use strict'

const helpers = require('./helpers')
const API_KEY = process.env.API_KEY
if (API_KEY) {
test('setup', t => {
cc.setApiKey(process.env.API_KEY)
t.end()
})
}
test('coinList()', t => {

@@ -261,1 +269,55 @@ t.plan(4)

})
test('constituentExchangeList()', t => {
t.plan(2)
cc.constituentExchangeList().then(exchanges => {
t.strictEqual(typeof exchanges.Coinbase.includeAll, 'boolean', 'exchanges.Coinbase.includeAll is a boolean')
t.strictEqual(typeof exchanges.Coinbase.onlyPairs, 'object', 'exchanges.Coinbase.onlyPairs is an object')
t.end()
}).catch(t.end)
})
if (API_KEY) {
test('latestSocial()', t => {
t.plan(6)
cc.latestSocial().then(social => {
t.strictEqual(typeof social.General, 'object', 'social.General is an object')
t.strictEqual(typeof social.CryptoCompare, 'object', 'social.CryptoCompare is an object')
t.strictEqual(typeof social.Twitter, 'object', 'social.Twitter is an object')
t.strictEqual(typeof social.Reddit, 'object', 'social.Reddit is an object')
t.strictEqual(typeof social.Facebook, 'object', 'social.Facebook is an object')
t.strictEqual(typeof social.CodeRepository, 'object', 'social.CodeRepository is an object')
t.end()
}).catch(t.end)
})
test('latestSocial() coinId option works', t => {
t.plan(7)
cc.latestSocial({ coinId: 7605 }).then(social => {
t.strictEqual(typeof social.General, 'object', 'social.General is an object')
t.strictEqual(social.General.Name, 'ETH', 'social.General.Name is \'ETH\'')
t.strictEqual(typeof social.CryptoCompare, 'object', 'social.CryptoCompare is an object')
t.strictEqual(typeof social.Twitter, 'object', 'social.Twitter is an object')
t.strictEqual(typeof social.Reddit, 'object', 'social.Reddit is an object')
t.strictEqual(typeof social.Facebook, 'object', 'social.Facebook is an object')
t.strictEqual(typeof social.CodeRepository, 'object', 'social.CodeRepository is an object')
t.end()
}).catch(t.end)
})
test("histoSocial()'s timePeriod='day' works", t => {
t.plan(1)
cc.histoSocial('day').then(socialStats => {
t.strictEqual(typeof socialStats.length, 'number', 'socialStats.length returned is an array')
t.end()
}).catch(t.end)
})
test("histoSocial()'s timePeriod='hour' works", t => {
t.plan(1)
cc.histoSocial('hour').then(socialStats => {
t.strictEqual(typeof socialStats.length, 'number', 'socialStats.length returned is an array')
t.end()
}).catch(t.end)
})
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc