coinranking-oss-sdk
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "coinranking-oss-sdk", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "An unofficial SDK for the coinranking REST API.", | ||
@@ -5,0 +5,0 @@ "main": "src/coinranking-oss-sdk-index.js", |
242
readme.md
@@ -6,2 +6,7 @@ | ||
## What is Coinranking? | ||
Coinranking is a database that stores information about cryptocurrencies, NFTs, DAPPs, crypto markets and crypto exchanges. They provide two API's for fetching their data: REST, and Websockets. This package is built on the REST API with tentative hopes to build a Websocket version in the future. | ||
You can visit Coinranking by going here: https://coinranking.com/ | ||
Otherwise, check out the documentation for the SDK below. | ||
@@ -11,129 +16,200 @@ | ||
# How to use these docs | ||
To get an API Key, go to | ||
Each method in these docs will include: | ||
https://coinranking.com/page/key-generator | ||
- Name of method | ||
- High-level description: What the method does. | ||
- Low-level description: How it does what it does. | ||
- List of parameters. | ||
- Description of what it returns. | ||
- Example code | ||
# Method Reference | ||
## Method Reference | ||
### *async* init() | ||
All methods are async. Many methods take an optional queryParams object, which | ||
contains your query parameters. The API request the SDK makes will include the | ||
params you specify. | ||
**High level**: | ||
Example: | ||
Initializes the SDK with a list of coins and currencies pulled from the API, then | ||
sets up caching based on the optional config object you pass into it. | ||
`await coinRankingSDK.getExchanges({referenceCurrencyUuid: '5k-_VTxqtCEI'})` | ||
**Low Level**: | ||
Will make this request: | ||
Executes a fetch request to https://api.coinranking.com/v2/indexes/coins, then maps | ||
the resulting array to a new array that the sdk stores. Configures caching based on | ||
the optional config object you pass to it. | ||
`https://api.coinranking.com/v2/exchanges?referenceCurrencyUuid=5k-_VTxqtCEI` | ||
- Takes: | ||
- config: Object | optional config object (Described below this entry) | ||
--- | ||
- Returns: Void | Nothing is returned. | ||
#### Init your sdk object. | ||
Example: | ||
This optional method takes a config object which contains the options you want | ||
to change in the SDK. The only two implemented properties that can be changed | ||
are showDeepResults and apiKey. | ||
``` | ||
const coinrankingSDK = require('coinranking-oss-sdk') | ||
coinrankingSDK.init({ | ||
apiKey: '5030820852jds', | ||
limit: 50, | ||
showDeepResults: true, | ||
}) | ||
const coinRankingSDK = require('coinranking-oss-sdk') | ||
coinRankingSDK.init({apiKey: '501030249'}) | ||
``` | ||
#### config: Object | ||
The config object is optional. You do not need an apiKey to use this sdk. By | ||
default, all methods return shallow results. Below is an example of what | ||
showDeepResults does. | ||
**High Level**: An optional object to be passed to the init() method. The config object sets the default options for queries. In future versions of the SDK, you will be able to modify the config after init is called. For now, you can pass your optional parameters into the queryParameters objects of the methods you call, as will be explained later in the documentation. Below is the list of functioning config properties: | ||
`console.log(await coinRankingSDK.getCoinsByQuery('bitcoin'))` | ||
- config properties: | ||
- **apiKey**: String | your api auth key from | ||
https://coinranking.com/page/key-generator | ||
Will show: | ||
``` | ||
{ | ||
"uuid": "Qwsogvtv82FCd", | ||
"iconUrl": "https://cdn.coinranking.com/bOabBYkcX/bitcoin_btc.svg", | ||
"name": "Bitcoin", | ||
"symbol": "BTC" | ||
}, | ||
``` | ||
- **showDeepResults**: Boolean | tells the sdk whether you want results of your queries to have all possible details or not. Default false. | ||
But with the showDeepResults config property set to true, it will show: | ||
### *async* getCoins(queryParams | Object, optional) | ||
``` | ||
{ | ||
"uuid": "Qwsogvtv82FCd", | ||
"symbol": "BTC", | ||
"name": "Bitcoin", | ||
"color": "#f7931A", | ||
"iconUrl": "https://cdn.coinranking.com/bOabBYkcX/bitcoin_btc.svg", | ||
"marketCap": "675363653114.2232812265917263135", | ||
"price": "36073.2892889105884555198", | ||
"listedAt": 1330214400, | ||
"tier": 1, | ||
"change": "3.0583802753754554", | ||
"rank": 1, | ||
"sparkline": [ | ||
"35010.5303218600111478953", | ||
"34909.00443207421422149077", | ||
"34629.66751175945689709165", | ||
"34728.41741641907404637792", | ||
"34291.25523852246856575276", | ||
"34462.29287247915263939462", | ||
"34305.2374929037934768079", | ||
"33928.95279376258192902647", | ||
"33967.04068787229485731744", | ||
"34126.79887708277684087609", | ||
"34277.4787737251132607257", | ||
"34495.13486506954909369016", | ||
"34572.61722302962304720503", | ||
"34246.64339532343773653377", | ||
"33771.50226346070129677326", | ||
"34060.4826867892839909812", | ||
"34565.58717491097922026174", | ||
"34722.9331091426479865895", | ||
"34977.32128009553819540104", | ||
"35383.90346857155540177202", | ||
"35691.34605993936237027942", | ||
"35912.69880854507392433813", | ||
"35778.63137739629327635604", | ||
"35877.71584279866411893909", | ||
"35841.93357317088269181255", | ||
"36013.29536621204563364777", | ||
"36073.2892889105884555198" | ||
], | ||
"lowVolume": false, | ||
"coinrankingUrl": "https://coinranking.com/coin/Qwsogvtv82FCd+bitcoin-btc", | ||
"24hVolume": "38516156547.74537036819457201655", | ||
"btcPrice": "1" | ||
} | ||
``` | ||
*For a list of all params, check out the API documentation: https://developers.coinranking.com/api/documentation* | ||
| Parameter | Type | Description | | ||
| :-------- | :------- | :-------------------------------- | | ||
| `config` | `object` | **Optional**. Set the config options for the sdk to use | | ||
**High Level**: Return a list of all existing coins in the coinranking API. | ||
*Config object:* | ||
### *async* getExchanges(queryParams | Object, optional) | ||
| Property | Type | Description | | ||
| :-------- | :------- | :-------------------------------- | | ||
| `apiKey` | `string` | **Optional**. Your API key string | | ||
| `showDeepResults` | `boolean` | **Optional**. Tell the SDK how detailed results should be | | ||
*For a list of all params, check out the API documentation: https://developers.coinranking.com/api/documentation* | ||
--- | ||
**High Level**: Return a list of all existing exchanges in the coinranking API. | ||
### Return an array of all coins, markets, exchanges, etc | ||
### *async* getMarkets(queryParams | Object, optional) | ||
``` | ||
const coinRankingSDK = require('coinranking-oss-sdk') | ||
coinRankingSDK.init({apiKey: '501030249'}) | ||
*For a list of all params, check out the API documentation: https://developers.coinranking.com/api/documentation* | ||
await coinRankingSDK.getCoins() | ||
await coinRankingSDK.getExchanges() | ||
await coinRankingSDK.getMarkets() | ||
await coinRankingSDK.getDapps() | ||
await coinRankingSDK.getNFTs() | ||
``` | ||
**High Level**: Return a list of all existing markets in the coinranking API. | ||
You can also add a queryParams object with the params you'd like to add. | ||
### *async* getDapps(queryParams | Object, optional) | ||
*For a list of all params, check out the API documentation: https://developers.coinranking.com/api/documentation* | ||
**High Level**: Return a list of all existing dapps in the coinranking API. | ||
``` | ||
await coinRankingSDK.getCoins({limit: 1}) | ||
await coinRankingSDK.getMarkets({ | ||
limit: 10, | ||
referenceCurrencyUuid: 'yhjMzLPhuIDl' | ||
}) | ||
``` | ||
### *async* getNFTs(queryParams | Object, optional) | ||
| Parameter | Type | Description | | ||
| :-------- | :------- | :------------------------- | | ||
| `queryParams` | `object` | **Optional**. An object containing your params. | | ||
*For a list of all params, check out the API documentation: https://developers.coinranking.com/api/documentation* | ||
#### Return an array of items that match a query string you provide. | ||
**High Level**: Return a list of all existing NFTs in the coinranking API. | ||
``` | ||
const coinRankingSDK = require('coinranking-oss-sdk') | ||
coinRankingSDK.init({apiKey: '501030249'}) | ||
### *async* getCoinByQuery(query | required String, options | optional Object) | ||
const customHeaders = {'x-access-token': '53a0b0a7e4f2fa59519e4'} | ||
await coinRankingSDK.getCoinsByQuery('bitcoin') | ||
await coinRankingSDK.getExchangesByQuery('DOGE', {headers: customHeaders}) | ||
await coinRankingSDK.getMarketsByQuery('etherium') | ||
await coinRankingSDK.getAllByQuery('eth') | ||
``` | ||
*For a list of all params, check out the API documentation: https://developers.coinranking.com/api/documentation* | ||
| Parameter | Type | Description | | ||
| :-------- | :------- | :-------------------------------- | | ||
| `query` | `string` | **Required**. Text to search for | | ||
| `options` | `object` | **Optional**. Override headers for the fetch request| | ||
**High Level**: Find a coin or set of coins that match your query string. | ||
#### Return a coin, exchange, or market whose uuid matches the string you provide. | ||
### *async* getExchangesByQuery(query | required String, options | optional Object) | ||
``` | ||
const coinRankingSDK = require('coinranking-oss-sdk') | ||
coinRankingSDK.init({apiKey: '501030249'}) | ||
*For a list of all params, check out the API documentation: https://developers.coinranking.com/api/documentation* | ||
await coinRankingSDK.getCoinByUuid('Qwsogvtv82FCd') | ||
await coinRankingSDK.getExchangeByUuid('-zdvbieRdZ', {}) | ||
await coinRankingSDK.getMarketByUuid('MP77r-vKf4') | ||
``` | ||
**High Level**: Find an exchange or set of exchanges that match your query string. | ||
| Parameter | Type | Description | | ||
| :-------- | :------- | :-------------------------------- | | ||
| `uuid` | `string` | **Required**. Uuid to search for | | ||
| `queryParams` | `object` | **Optional**. An object containing your params | | ||
### *async* getMarketByQuery(query | required String, options | optional Object) | ||
*For a list of all params, check out the API documentation: https://developers.coinranking.com/api/documentation* | ||
#### Return a dapp whose name matches the string you provide. | ||
**High Level**: Find a market or set of markets that match your query string. | ||
``` | ||
await coinRankingSDK.getDapp('cryptokitties') | ||
``` | ||
### *async* getAllByQuery(query | required String, options | optional Object) | ||
| Parameter | Type | Description | | ||
| :-------- | :------- | :-------------------------------- | | ||
| `dappName` | `string` | **Required**. Dapp to search for | | ||
| `queryParams` | `object` | **Optional**. An object containing your params| | ||
*For a list of all params, check out the API documentation: https://developers.coinranking.com/api/documentation* | ||
#### Return an NFT whose id matches the string you provide. | ||
**High Level**: Return all items of all data types which match your query string. | ||
``` | ||
await coinRankingSDK.getNFT( | ||
'16443c43d6a1ba33c85a49c7c6c36f7ac7150e478a405d05c4bedcc200b9610a' | ||
) | ||
``` | ||
### *async* getCoinByUuid(uuid | required String, queryParams | Object, optional) | ||
*For a list of all params, check out the API documentation: https://developers.coinranking.com/api/documentation* | ||
**High Level**: Return a coin that matches the provided uuid. | ||
### *async* getExchangeByUuid(uuid | required String, queryParams | Object, optional) | ||
*For a list of all params, check out the API documentation: https://developers.coinranking.com/api/documentation* | ||
**High Level**: Return an exchange that matches the provided uuid. | ||
### *async* getDapp(dappName | required String, queryParams | Object, optional) | ||
*For a list of all params, check out the API documentation: https://developers.coinranking.com/api/documentation* | ||
**High Level**: Return a Dapp that matches the provided name. | ||
### *async* getNFT(id | required String, queryParams | Object, optional) | ||
*For a list of all params, check out the API documentation: https://developers.coinranking.com/api/documentation* | ||
**High Level**: Return an NFT that matches the provided id. | ||
| Parameter | Type | Description | | ||
| :-------- | :------- | :-------------------------------- | | ||
| `id` | `string` | **Required**. NFT id to search for | | ||
| `queryParams` | `object` | **Optional**. An object containing your params| |
@@ -28,4 +28,8 @@ const fetch = require('node-fetch') | ||
defaults.defaultLimit = config.params.limit || defaults.defaultLimit | ||
defaults.defaultOffset = config.params.offset || defaults.defaultOffset | ||
if(config.params){ | ||
defaults.defaultLimit = config.params.limit || defaults.defaultLimit | ||
defaults.defaultOffset = config.params.offset || defaults.defaultOffset | ||
if(config.params.types) | ||
defaults.defaultTypes = reduceTypesToString(config.params.types) | ||
} | ||
@@ -35,6 +39,4 @@ if(config.showDeepResults && typeof config.showDeepResults === 'boolean') | ||
if(config.params.types) | ||
defaults.defaultTypes = reduceTypesToString(config.params.types) | ||
defaults.fetchOptions.headers = {'x-access-token': config.apiKey} | ||
if(config.apiKey) | ||
defaults.fetchOptions.headers = {'x-access-token': config.apiKey} | ||
@@ -58,3 +60,2 @@ }//if(config) | ||
fetchOptions : { | ||
method: 'GET', | ||
headers: '', | ||
@@ -61,0 +62,0 @@ }, |
const fetch = require('node-fetch') | ||
const fetchList = async (endpoint, options)=>{ | ||
const fetchResult = await fetch(endpoint, options) | ||
const fetchOptions = {method: 'GET'} | ||
if(options){ | ||
fetchOptions.headers = options.headers ?? {} | ||
} | ||
const fetchResult = await fetch(endpoint, fetchOptions) | ||
const resultJSON = await fetchResult.json() | ||
@@ -6,0 +10,0 @@ if(resultJSON.status === 'fail') |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21045
275
213