+
+
+
+
+
+
+ getListings
+
+
+
+
+
+
+ Get all active cryptocurrency listings
+
+
+ getListings()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Example
+
+
+ const client = new CoinMarketCap()
+client.getListings().then(console.log).catch(console.error)
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/index.js b/index.js
index 9a3343a..78d1488 100644
--- a/index.js
+++ b/index.js
@@ -6,7 +6,7 @@ const qs = require('qs')
const BASE_URL = 'https://api.coinmarketcap.com'
class CoinMarketCap {
- constructor ({ version = 'v1' } = {}) {
+ constructor ({ version = 'v2' } = {}) {
this.headers = {
Accept: 'application/json',
'Accept-Charset': 'utf-8'
@@ -14,6 +14,20 @@ class CoinMarketCap {
this.url = `${BASE_URL}/${version}`
}
+ /**
+ * Get all active cryptocurrency listings
+ *
+ * @example
+ * const client = new CoinMarketCap()
+ * client.getListings().then(console.log).catch(console.error)
+ */
+ getListings () {
+ return createRequest({
+ url: `${this.url}/listings`,
+ headers: this.headers
+ })
+ }
+
/**
* Get ticker information
*
diff --git a/test.js b/test.js
index 8926278..4092eb5 100644
--- a/test.js
+++ b/test.js
@@ -8,6 +8,7 @@ test('should return new CoinMarketCap client', () => {
const client = new CoinMarketCap()
expect(client.getTicker).toBeDefined()
expect(client.getGlobal).toBeDefined()
+ expect(client.getListings).toBeDefined()
})
test('should get latest ticker', async () => {
@@ -17,7 +18,7 @@ test('should get latest ticker', async () => {
expect(typeof ticker1).toBe('object')
expect(typeof ticker2).toBe('object')
- expect(ticker2.length).toBe(10)
+ expect(Object.keys(ticker2.data).length).toBe(10)
})
test('should get latest global', async () => {
@@ -27,3 +28,10 @@ test('should get latest global', async () => {
expect(typeof global).toBe('object')
})
+test(`should get latest listings`, async () => {
+ const client = new CoinMarketCap()
+ const listings = await client.getListings()
+
+ expect(typeof listings).toBe('object')
+})
+