diff --git a/GradDemo.Api/Controllers/AuthController.cs b/GradDemo.Api/Controllers/AuthController.cs index 1738499..a8ef28a 100644 --- a/GradDemo.Api/Controllers/AuthController.cs +++ b/GradDemo.Api/Controllers/AuthController.cs @@ -1,5 +1,6 @@ using GradDemo.Api.Entities; using GradDemo.Api.Helpers; +using GradDemo.Api.Models; using GradDemo.Api.Models.Auth; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; @@ -22,6 +23,7 @@ public AuthController(UserManager userManager, AuthTokenHelper authhelpe { _userManager = userManager; _authHelper = authhelper; + } /// @@ -89,5 +91,13 @@ private string GenerateRandomClientSecret() return converted; } } + + /*[HttpGet("preferences")] + /*public async Task> GetPreference() + { + var preference = new Device(); + + //var pref = await _userManager.GetPreferences(); + }*/ } } diff --git a/GradDemo.Api/Controllers/CryptoController.cs b/GradDemo.Api/Controllers/CryptoController.cs index cdbca2f..6e83b1a 100644 --- a/GradDemo.Api/Controllers/CryptoController.cs +++ b/GradDemo.Api/Controllers/CryptoController.cs @@ -44,5 +44,17 @@ public async Task> GetCoin(string coinId, string cu return Response.Error("Something went wrong"); } + + [HttpGet("value/for/currencies")] + public async Task> GetCurrencyPrice() + { + string[] currencyResults; //will return an array of strings, in this case, a string of the different currencies + currencyResults = await _coinGeckoProvider.GetCurrency(); // awaits the class written in the GeckoProvider + if (currencyResults != null) //if currencyResults are not empty, then return a string array of all currencies else state that there is an error message + { + return Response.Successful(currencyResults); + } + return Response.Error("Something went wrong"); + } } } diff --git a/GradDemo.Api/Controllers/DemoController.cs b/GradDemo.Api/Controllers/DemoController.cs deleted file mode 100644 index 5de18d8..0000000 --- a/GradDemo.Api/Controllers/DemoController.cs +++ /dev/null @@ -1,88 +0,0 @@ -using GradDemo.Api.Entities; -using GradDemo.Api.Models; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace GradDemo.Api.Controllers -{ - [ApiController] - [Route("[controller]")] - public class DemoController : ControllerBase - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - private readonly ILogger _logger; - private readonly ApplicationDbContext _context; - - public DemoController(ILogger logger, ApplicationDbContext context) - { - _logger = logger; - _context = context; - } - - [HttpGet] - public IEnumerable Get() - { - var rng = new Random(); - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateTime.Now.AddDays(index), - TemperatureC = rng.Next(-20, 55), - Summary = Summaries[rng.Next(Summaries.Length)] - }) - .ToArray(); - } - - [HttpPost("say-hello")] - public Response SayHello([FromBody] string name) - { - var reallyOld = "Hello " + name; - var lessOld = string.Format("Hello {0}", name); - - return Response.Successful($"Hello, {name}!"); - } - - [HttpGet("should-fail")] - public Response ShouldFail() - { - return Response.Error("Fails for test purposes"); - } - - [HttpPost("say-hello-to-more-people/{number}")] - public Response SayHelloToLotsOfPeople(int number, [FromBody] HelloRequest name) - { - return Response.Successful($"[{number}] Hello {name.Name} and {name.OtherName} and especially you {name.LastName}"); - } - - [HttpPost("add-contact")] - public async Task> AddContactAsync(ContactRequest contact) - { - _context.Contacts.Add(new Contact() - { - ContactNumber = contact.ContactNumber, - LastName = contact.LastName, - Name = contact.Name - }); - - await _context.SaveChangesAsync(); - - return Response.Successful(""); - } - - [HttpGet("contacts")] - public async Task>> GetContacts() - { - var contacts = await _context.Contacts.ToListAsync(); - - return Response>.Successful(contacts); - } - } -} diff --git a/GradDemo.Api/Entities/Device.cs b/GradDemo.Api/Entities/Device.cs index ea06add..e205d10 100644 --- a/GradDemo.Api/Entities/Device.cs +++ b/GradDemo.Api/Entities/Device.cs @@ -9,5 +9,6 @@ namespace GradDemo.Api.Entities public class Device : IdentityUser { public string ShirtSize { get; set; } + public string Preference { get; set; } } } diff --git a/GradDemo.Api/Models/Crypto.cs b/GradDemo.Api/Models/Crypto.cs new file mode 100644 index 0000000..b726875 --- /dev/null +++ b/GradDemo.Api/Models/Crypto.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace GradDemo.Api.Models +{ + public class Crypto + { + + public class CryptoCurrency + { + public int Id { set; get; } + public int Name { set; get; } + public int Current_price { set; get; } + + } + } +} diff --git a/GradDemo.Api/Providers/CoinGeckoProvider.cs b/GradDemo.Api/Providers/CoinGeckoProvider.cs index 7885a9b..23cb87d 100644 --- a/GradDemo.Api/Providers/CoinGeckoProvider.cs +++ b/GradDemo.Api/Providers/CoinGeckoProvider.cs @@ -43,5 +43,21 @@ public CoinGeckoProvider(string baseUrl) return null; } + public async Task GetCurrency() + { + string[] currencyResults = null; + string path = $"/api/v3/simple/supported_vs_currencies"; + + HttpResponseMessage currencyResponse = await client.GetAsync(path); + + if (currencyResponse.IsSuccessStatusCode) + { + var result = await currencyResponse.Content.ReadAsStringAsync(); + var currencyResult = JsonConvert.DeserializeObject(result); + currencyResults = currencyResult; + return currencyResults; + } + return null; + } } } diff --git a/GradDemo.Api/node_modules/coingecko-api/.DS_Store b/GradDemo.Api/node_modules/coingecko-api/.DS_Store new file mode 100644 index 0000000..f3a6a85 Binary files /dev/null and b/GradDemo.Api/node_modules/coingecko-api/.DS_Store differ diff --git a/GradDemo.Api/node_modules/coingecko-api/.travis.yml b/GradDemo.Api/node_modules/coingecko-api/.travis.yml new file mode 100644 index 0000000..efb0983 --- /dev/null +++ b/GradDemo.Api/node_modules/coingecko-api/.travis.yml @@ -0,0 +1,3 @@ +language: node_js +node_js: + - "8" diff --git a/GradDemo.Api/node_modules/coingecko-api/LICENSE b/GradDemo.Api/node_modules/coingecko-api/LICENSE new file mode 100644 index 0000000..125882c --- /dev/null +++ b/GradDemo.Api/node_modules/coingecko-api/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Mark Miscavage + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/GradDemo.Api/node_modules/coingecko-api/README.md b/GradDemo.Api/node_modules/coingecko-api/README.md new file mode 100644 index 0000000..f959553 --- /dev/null +++ b/GradDemo.Api/node_modules/coingecko-api/README.md @@ -0,0 +1,805 @@ +# CoinGecko API Client for Node.js + +Travis CI Build Status +NPM version +NPM downloads +Dependency Status +Dev Dependency Status + +A Node.js wrapper for the CoinGecko API with no dependencies. + +## • Installation + +Latest version: 1.0.10 + +`npm install coingecko-api` + +## • CoinGecko API Documentation + +For complete API documentation, up-to-date parameters, responses and errors, please refer to https://www.coingecko.com/api/docs/v3. + +## • Quick Start Example + +```javascript +//1. Import coingecko-api +const CoinGecko = require('coingecko-api'); + +//2. Initiate the CoinGecko API Client +const CoinGeckoClient = new CoinGecko(); + +//3. Make calls +var func = async() => { + let data = await CoinGeckoClient.ping(); +}; +``` + +## • Constants + +This module provides helper constants for use in calls. + +___ +#### • `CoinGecko.ORDER` +Order results in specific calls by using one of the following values. + +| Key | Usage | Description | +| --- | --- | --- | +`GECKO_ASC` | `CoinGecko.ORDER.GECKO_ASC` | Order results by CoinGecko's scoring system (ascending) +`GECKO_DESC` | `CoinGecko.ORDER.GECKO_DESC` | Order results by CoinGecko's scoring system (descending) +`MARKET_CAP_ASC` | `CoinGecko.ORDER.MARKET_CAP_ASC` | Order results by market cap (ascending) +`MARKET_CAP_DESC` | `CoinGecko.ORDER.MARKET_CAP_DESC` | Order results by market cap (descending) +`VOLUME_ASC` | `CoinGecko.ORDER.VOLUME_ASC` | Order results by volume (ascending) +`VOLUME_DESC` | `CoinGecko.ORDER.VOLUME_DESC` | Order results by volume (descending) +`COIN_NAME_ASC` | `CoinGecko.ORDER.COIN_NAME_ASC` | Order results by coin name (ascending) +`COIN_NAME_DESC` | `CoinGecko.ORDER.COIN_NAME_DESC` | Order results by coin name (descending) +`PRICE_ASC` | `CoinGecko.ORDER.PRICE_ASC` | Order results by price (ascending) +`PRICE_DESC` | `CoinGecko.ORDER.PRICE_DESC` | Order results by price (descending) +`HOUR_24_ASC` | `CoinGecko.ORDER.HOUR_24_ASC` | Order results by 24 hour change (ascending) +`HOUR_24_DESC` | `CoinGecko.ORDER.HOUR_24_DESC` | Order results by 24 hour change (descending) +`TRUST_SCORE_DESC` | `CoinGecko.ORDER.TRUST_SCORE_DESC` | Order results by CoinGecko's trust scoring system (descending) + +___ +#### • `CoinGecko.STATUS_UPDATE_CATEGORY` +Available status update categories to filter by. + +| Key | Usage | Description | +| --- | --- | --- | +`GENERAL` | `CoinGecko.STATUS_UPDATE_CATEGORY.GENERAL` | Filter status update results by general news +`MILESTONE` | `CoinGecko.STATUS_UPDATE_CATEGORY.MILESTONE` | Filter status update results by milestones +`PARTNERSHIP` | `CoinGecko.STATUS_UPDATE_CATEGORY.PARTNERSHIP` | Filter status update results by partnerships +`EXCHANGE_LISTING` | `CoinGecko.STATUS_UPDATE_CATEGORY.EXCHANGE_LISTING` | Filter status update results by exchange listings +`SOFTWARE_RELEASE` | `CoinGecko.STATUS_UPDATE_CATEGORY.SOFTWARE_RELEASE` | Filter status update results by software releases +`FUND_MOVEMENT` | `CoinGecko.STATUS_UPDATE_CATEGORY.FUND_MOVEMENT` | Filter status update results by fund movements +`NEW_LISTINGS` | `CoinGecko.STATUS_UPDATE_CATEGORY.NEW_LISTINGS` | Filter status update results by new listings +`EVENT` | `CoinGecko.STATUS_UPDATE_CATEGORY.EVENT` | Filter status update results by events + +___ +#### • `CoinGecko.STATUS_UPDATE_PROJECT_TYPE` +Available status update project types to filter by. + +| Key | Usage | Description | +| --- | --- | --- | +`COIN` | `CoinGecko.STATUS_UPDATE_PROJECT_TYPE.COIN` | Filter status update results by coins only +`MARKET` | `CoinGecko.STATUS_UPDATE_PROJECT_TYPE.MARKET` | Filter status update results by markets only + +___ +#### • `CoinGecko.EVENT_TYPE` +List of event types (most recent from `CoinGeckoClient.events.fetchTypes()`) + +| Key | Usage | Description | +| --- | --- | --- | +`EVENT` | `CoinGecko.EVENT_TYPE.EVENT` | Filter events by _events_ only +`CONFERENCE` | `CoinGecko.EVENT_TYPE.CONFERENCE` | Filter events by conferences only +`MEETUP` | `CoinGecko.EVENT_TYPE.MEETUP` | Filter events by meetups only + +___ +## • Making Calls +All calls using the CoinGeckoClient are asynchronous. + +All calls are returned in the following format: +```javascript +{ + success: Boolean, + message: String, + code: Number, + data: Object +} +``` + +The CoinGeckoClient splits up the currently available calls outline in the official CoinGecko API documentation into nine (9) parts. (Aside from the `ping` and `global` calls.) + +| Namespace | Usage | Description | +| --- | --- | --- | +`coins` | `CoinGeckoClient.coins[...]` | Calls related to coins +`exchanges` | `CoinGeckoClient.exchanges[...]` | Calls related to exchanges +`statusUpdates` | `CoinGeckoClient.statusUpdates[...]` | Calls related to status updates +`events` | `CoinGeckoClient.events[...]` | Calls related to events +`exchangeRates` | `CoinGeckoClient.exchangeRates[...]` | Calls related to exchange rates +`simple` | `CoinGeckoClient.simple[...]` | Calls related to "simple" endpoints +`finance` | `CoinGeckoClient.finance[...]` | Calls related to finance endpoints +`indexes` | `CoinGeckoClient.indexes[...]` | Calls related to index endpoints +`derivatives` | `CoinGeckoClient.derivatives[...]` | Calls related to derivative endpoints + +___ +### • Ping +Check API server status. + +#### `ping()` +Check API server status. + +Usage Example: +```javascript +let data = await CoinGeckoClient.ping(); +``` + +___ +### • Global +Get cryptocurrency global data. + +#### `global()` +Get cryptocurrency global data. + +Usage Example: +```javascript +let data = await CoinGeckoClient.global(); +``` + +___ +### • Coins +Calls related to coins. + + +#### `coins.all()` +List all coins with data (name, price, market, developer, community, etc) - paginated by 50. + +Official documentation: https://www.coingecko.com/api/docs/v3#/coins/get_coins + +Params: + +- `params`: `Object` - Parameters to pass through to the request +- `params.order`: `String` - Order results by `CoinGecko.ORDER[*]` +- `params.per_page`: `Number` - Total results per page +- `params.page`: `Number` - Page through results +- `params.localization`: `Boolean` [default: `true`] - Set to false to exclude localized languages in response +- `params.sparkline`: `Boolean` [default: `false`] - Include sparkline 7 days data + +Usage Example: +```javascript +let data = await CoinGeckoClient.coins.all(); +``` + +___ +#### `coins.list()` +Use this to obtain all the coins’ id in order to make API calls + +Official documentation: https://www.coingecko.com/api/docs/v3#/coins/get_coins_list + +Usage Example: +```javascript +let data = await CoinGeckoClient.coins.list(); +``` + +___ +#### `coins.markets()` +Use this to obtain all the coins market data (price, market cap, volume). + +Official documentation: https://www.coingecko.com/api/docs/v3#/coins/get_coins_markets + +Params: + +- `params`: `Object` - Parameters to pass through to the request +- `params.order`: `String` - Order results by `CoinGecko.ORDER[*]` +- `params.per_page`: `Number` - Total results per page +- `params.page`: `Number` - Page through results +- `params.localization`: `Boolean` [default: `true`] - Set to false to exclude localized languages in response +- `params.sparkline`: `Boolean` [default: `false`] - Include sparkline 7 days data +- `params.vs_currency`: `String` [default: `usd`] - The target currency of market data (`usd`, `eur`, `jpy`, etc.) +- `params.ids`: `Array|String` - List of coin id to filter if you want specific results + +Usage Example: +```javascript +let data = await CoinGeckoClient.coins.markets(); +``` + +___ +#### `coins.fetch()` +Get current data (name, price, market, … including exchange tickers) for a coin. + +Official documentation: https://www.coingecko.com/api/docs/v3#/coins/get_coins__id_ + +Params: + +- `coinId`: `String` - (Required) The coin id (can be obtained from `coins.list()`) eg. `bitcoin` +- `params`: `Object` - Parameters to pass through to the request +- `params.tickers`: `Boolean` - [default: `true`] - Include ticker data +- `params.market_data`: `Boolean` - [default: `true`] - Include market data +- `params.community_data`: `Boolean` - [default: `true`] - Include community data +- `params.developer_data`: `Boolean` - [default: `true`] - Include developer data +- `params.localization`: `Boolean` [default: `true`] - Set to false to exclude localized languages in response +- `params.sparkline`: `Boolean` [default: `false`] - Include sparkline 7 days data + +Usage Example: +```javascript +let data = await CoinGeckoClient.coins.fetch('bitcoin', {}); +``` + +___ +#### `coins.fetchTickers()` +Get coin tickers (paginated to 100 items). + +Official documentation: https://www.coingecko.com/api/docs/v3#/coins/get_coins__id__tickers + +Params: + +- `coinId`: `String` - (Required) The coin id (can be obtained from `coins.list()`) eg. `bitcoin` +- `params`: `Object` - Parameters to pass through to the request +- `params.page`: `Number` - Page through results +- `params.exchange_ids`: `Array|String` - Filter tickers by exchange_ids (can be obtained from `exchanges.list()`) eg. `binance` +- `params.order`: `String` - [default: `trust_score_desc`] - Order results by `CoinGecko.ORDER.TRUST_SCORE_DESC` or `CoinGecko.ORDER.VOLUME_DESC` + +Usage Example: +```javascript +let data = await CoinGeckoClient.coins.fetchTickers('bitcoin'); +``` + +___ +#### `coins.fetchHistory()` +Get historical data (name, price, market, stats) at a given date for a coin. + +Official documentation: https://www.coingecko.com/api/docs/v3#/coins/get_coins__id__history + +Params: + +- `coinId`: `String` - (Required) The coin id (can be obtained from `coins.list()`) eg. `bitcoin` +- `params`: `Object` - Parameters to pass through to the request +- `params.date`: `String` - (Required) The date of data snapshot in dd-mm-yyyy eg. `30-12-2017` +- `params.localization`: `Boolean` [default: `true`] - Set to false to exclude localized languages in response + +Usage Example: +```javascript +let data = await CoinGeckoClient.coins.fetchHistory('bitcoin', { + date: '30-12-2017' +}); +``` + +___ +#### `coins.fetchMarketChart()` +Get historical market data include price, market cap, and 24h volume (granularity auto). + +Official documentation: https://www.coingecko.com/api/docs/v3#/coins/get_coins__id__market_chart + +Params: + +- `coinId`: `String` - (Required) The coin id (can be obtained from `coins.list()`) eg. `bitcoin` +- `params`: `Object` - Parameters to pass through to the request +- `params.days`: `String` [default: `1`] - (Required )Data up to number of days ago (eg. `1`, `14`, `30`, `max`) +- `params.vs_currency`: `String` [default: `usd`] - (Required) The target currency of market data (`usd`, `eur`, `jpy`, etc.) + +Usage Example: +```javascript +let data = await CoinGeckoClient.coins.fetchMarketChart('bitcoin'); +``` + +___ +#### `coins.fetchMarketChartRange()` +Get historical market data include price, market cap, and 24h volume within a range of timestamp (granularity auto). Minutely data will be used for duration within 1 day. Hourly data will be used for duration between 1 day and 90 days. Daily data will be used for duration above 90 days. + +Official documentation: https://www.coingecko.com/api/documentations/v3#/coins/get_coins__id__market_chart_range + +Params: + +- `coinId`: `String` - (Required) The coin id (can be obtained from `coins.list()`) eg. `bitcoin` +- `params`: `Object` - Parameters to pass through to the request +- `params.vs_currency`: `String` [default: `usd`] - The target currency of market data (`usd`, `eur`, `jpy`, etc.) +- `params.from`: `Number` - (Required) From date in UNIX Timestamp (eg. 1392577232) +- `params.to`: `Number` - (Required) To date in UNIX Timestamp (eg. 1422577232) + +Usage Example: +```javascript +let data = await CoinGeckoClient.coins.fetchMarketChartRange('bitcoin', { + from: 1392577232, + to: 1422577232, +}); +``` + +___ +#### `coins.fetchStatusUpdates()` +Get status updates for a given coin. + +Official documentation: https://www.coingecko.com/api/docs/v3#/coins/get_coins__id__status_updates + +Params: + +- `coinId`: `String` - (Required) The coin id (can be obtained from `coins.list()`) eg. `bitcoin` +- `params`: `Object` - Parameters to pass through to the request +- `params.per_page`: `Number` - Total results per page +- `params.page`: `Number` - Page through results + +Usage Example: +```javascript +let data = await CoinGeckoClient.coins.fetchStatusUpdates('bitcoin'); +``` + +___ +#### `coins.fetchCoinContractInfo()` +Get coin info from contract address. + +Official documentation: https://www.coingecko.com/api/docs/v3#/coins/get_coins__id__contract__contract_address_ + +Params: + +- `contractAddress`: `String` - (Required) Token’s contract address +- `assetPlatform`: `String` [default: `ethereum`] - Asset platform (only `ethereum` is supported at this moment). + +Usage Example: +```javascript +// 0x contract address (as a test) +let zrx = '0xe41d2489571d322189246dafa5ebde1f4699f498'; +let data = await CoinGeckoClient.coins.fetchCoinContractInfo(zrx); +``` + +___ +#### `coins.fetchCoinContractMarketChart()` +Get historical market data include price, market cap, and 24h volume (granularity auto) from a contract address. + +Official documentation: https://www.coingecko.com/api/documentations/v3#/contract/get_coins__id__contract__contract_address__market_chart_ + +Params: + +- `contractAddress`: `String` - (Required) Token’s contract address +- `assetPlatform`: `String` [default: `ethereum`] - Asset platform (only `ethereum` is supported at this moment). +- `params`: `Object` - Parameters to pass through to the request +- `params.vs_currency`: `String` [default: `usd`] - (Required) The target currency of market data (usd, eur, jpy, etc.) +- `params.days`: `String` [default: `1`] - (Required) Data up to number of days ago (eg. 1,14,30,max) + +Usage Example: +```javascript +// 0x contract address (as a test) +let zrx = '0xe41d2489571d322189246dafa5ebde1f4699f498'; +let data = await CoinGeckoClient.coins.fetchCoinContractMarketChart(zrx); +``` + +___ +#### `coins.fetchCoinContractMarketChartRange()` +Get historical market data include price, market cap, and 24h volume within a range of timestamp (granularity auto). + +Official documentation: https://www.coingecko.com/api/documentations/v3#/contract/get_coins__id__contract__contract_address__market_chart_range +Params: + +- `contractAddress`: `String` - (Required) Token’s contract address +- `assetPlatform`: `String` [default: `ethereum`] - Asset platform (only `ethereum` is supported at this moment). +- `params`: `Object` - Parameters to pass through to the request +- `params.vs_currency`: `String` [default: `usd`] - (Required) The target currency of market data (usd, eur, jpy, etc.) +- `params.from`: `Number` - (Required) From date in UNIX Timestamp (eg. 1392577232) +- `params.to`: `Number` - (Required) To date in UNIX Timestamp (eg. 1422577232) + +Usage Example: +```javascript +// 0x contract address (as a test) +let zrx = '0xe41d2489571d322189246dafa5ebde1f4699f498'; +let data = await CoinGeckoClient.coins.fetchCoinContractMarketChartRange(zrx, 'ethereum', { + from: 1392577232, + to: 1422577232, +}); +``` + +___ +### • Exchanges +Calls related to exchanges. + + +#### `exchanges.all()` +List all exchanges. + +Official documentation: https://www.coingecko.com/api/docs/v3#/exchanges_(beta)/get_exchanges + +Usage Example: +```javascript +let data = await CoinGeckoClient.exchanges.all(); +``` + +___ +#### `exchanges.list()` +List all supported markets id and name (no pagination required). + +Official documentation: https://www.coingecko.com/api/docs/v3#/exchanges_(beta)/get_exchanges_list + +Usage Example: +```javascript +let data = await CoinGeckoClient.exchanges.list(); +``` + +___ +#### `exchanges.fetch()` +Get exchange volume in BTC and top 100 tickers only for a given exchange. + +Official documentation: https://www.coingecko.com/api/docs/v3#/exchanges_(beta)/get_exchanges__id_ + +Params: + +- `exchangeId`: `String` - (Required) The exchange id (can be obtained from `exchanges.all()`) eg. `binance` + +Usage Example: +```javascript +let data = await CoinGeckoClient.exchanges.fetch('binance'); +``` + +___ +#### `exchanges.fetchTickers()` +Get tickers for a given exchange. + +Official documentation: https://www.coingecko.com/api/docs/v3#/exchanges_(beta)/get_exchanges__id__tickers + +Params: + +- `exchangeId`: `String` - (Required) The exchange id (can be obtained from `exchanges.all()`) eg. `binance` +- `params`: `Object` - Parameters to pass through to the request +- `params.page`: `Number` - Page through results +- `params.coin_ids`: `Array|String` - Filter tickers by coin_ids (can be obtained from `coins.list()`) eg. `bitcoin` +- `params.order`: `String` - [default: `trust_score_desc`] - Order results by `CoinGecko.ORDER.TRUST_SCORE_DESC` or `CoinGecko.ORDER.VOLUME_DESC` + +Usage Example: +```javascript +let data = await CoinGeckoClient.exchanges.fetchTickers('binance'); +``` + +___ +#### `exchanges.fetchStatusUpdates()` +Get status updates for a given exchange. + +Official documentation: https://www.coingecko.com/api/docs/v3#/exchanges_(beta)/get_exchanges__id__status_updates + +Params: + +- `exchangeId`: `String` - (Required) The exchange id (can be obtained from `exchanges.all()`) eg. `binance` +- `params`: `Object` - Parameters to pass through to the request +- `params.page`: `Number` - Page through results +- `params.per_page`: `Number` - Total results per page + +Usage Example: +```javascript +let data = await CoinGeckoClient.exchanges.fetchStatusUpdates('binance'); +``` + +___ +#### `exchanges.fetchVolumeChart()` +Get volume chart data for a given exchange, returned in BTC + +Official documentation: https://www.coingecko.com/en/api#operations-exchanges%20(beta)-get_exchanges__id__volume_chart + +Params: + +- `exchangeId`: `String` - (Required) The exchange id (can be obtained from `exchanges.all()`) eg. `binance` +- `params`: `Object` - Parameters to pass through to the request +- `params.days`: `Number` - Data up to number of days ago (eg. 1, 14, 30) + +Usage Example: +```javascript +let data = await CoinGeckoClient.exchanges.fetchVolumeChart('binance', { + days: 1, +}); +``` + +___ +### • Status Updates +Calls related to status updates. + + +#### `statusUpdates.all()` +List all status_updates with data (description, category, created_at, user, user_title and pin). + +Official documentation: https://www.coingecko.com/api/docs/v3#/status_updates_(beta)/get_status_updates + +Params: + +- `params`: `Object` - Parameters to pass through to the request +- `params.category`: `Number` - Filter results by `CoinGecko.STATUS_UPDATE_CATEGORY[*]` +- `params.project_type`: `Number` - Filter results by `CoinGecko.STATUS_UPDATE_PROJECT_TYPE[*]` (If left empty returns both status from `coins` and `markets`) +- `params.page`: `Number` - Page through results +- `params.per_page`: `Number` - Total results per page + +Usage Example: +```javascript +let data = await CoinGeckoClient.statusUpdates.all(); +``` + +___ +### • Events +Calls related to events. + + +#### `events.all()` +Get events, paginated by 100. + +Official documentation: https://www.coingecko.com/api/docs/v3#/events/get_events + +Params: + +- `params`: `Object` - Parameters to pass through to the request +- `params.country_code`: `Number` - country_code of event (eg. `US`). Use `events.fetchHistory()` for list of `country_codes` +- `params.type`: `String` - Type of event (eg. `Conference`). Use `events.fetchTypes()` for list of types. Or use `CoinGecko.EVENT_TYPE[*]` +- `params.page`: `Number` - Page through results +- `params.upcoming_events_only`: `Boolean` - [default: `true`] - Lists only upcoming events +- `params.from_date`: `String` - Lists events after this date yyyy-mm-dd +- `params.to_date`: `String` - Lists events before this date yyyy-mm-dd (set `upcoming_events_only` to false if fetching past events) + +Usage Example: +```javascript +let data = await CoinGeckoClient.events.all(); +``` + +___ +#### `events.fetchCountries()` +Get list of event countries. + +Official documentation: https://www.coingecko.com/api/docs/v3#/events/get_events_countries + +Usage Example: +```javascript +let data = await CoinGeckoClient.events.fetchCountries(); +``` + +___ +#### `events.fetchTypes()` +Get list of event types. + +Official documentation: https://www.coingecko.com/api/docs/v3#/events/get_events_types + +Usage Example: +```javascript +let data = await CoinGeckoClient.events.fetchTypes(); +``` + +___ +### • Exchange Rates +Calls related to exchange rates. + + +#### `exchangeRates.all()` +Get BTC-to-Currency exchange rates. + +Official documentation: https://www.coingecko.com/api/docs/v3#/exchange_rates/get_exchange_rates + +Usage Example: +```javascript +let data = await CoinGeckoClient.exchangeRates.all(); +``` + +___ +### • Simple +Calls related to simple endpoints. + + +#### `simple.price()` +Get the current price of any cryptocurrencies in any other supported currencies that you need. + +Official documentation: https://www.coingecko.com/api/docs/v3#/simple/get_simple_price + +Params: + +- `params`: `Object` - Parameters to pass through to the request +- `params.ids`: `Array|String` - (Required) A single id or a list of coin ids to filter if you want specific results. Use `coins.list()` for a list of coin ids. +- `params.vs_currencies`: `Array|String` - [default: `usd`] - A single id or a list of ids. Use `simple.supportedVsCurrencies()` for a list of vsCurrency ids. +- `params.include_24hr_vol`: `Boolean` - [default: `false`] - To include 24hr volume. +- `params.include_last_updated_at`: `Boolean` - [default: `false`] - To include last_updated_at of price. + +Usage Example: +```javascript +let data = await CoinGeckoClient.simple.price({ + ids: ['bitcoin', 'ethereum'], + vs_currencies: ['eur', 'usd'], +}); +``` + +___ +#### `simple.supportedVsCurrencies()` +Get list of supported vs/comparisons currencies. + +Official documentation: https://www.coingecko.com/api/docs/v3#/simple/get_simple_supported_vs_currencies + +Usage Example: +```javascript +let data = await CoinGeckoClient.simple.supportedVsCurrencies(); +``` + +___ +#### `simple.fetchTokenPrice()` +Get current price of tokens (using contract addresses) for a given platform in any other currency that you need. + +Official documentation: https://www.coingecko.com/en/api#operations-simple-get_simple_token_price__id_ + +Params: + +- `params`: `Object` - Parameters to pass through to the request +- `assetPlatform`: `String` - [default: `ethereum`] - (Required) Asset platform (only ethereum is supported at this moment) +- `params.contract_addresses`: `String|Array` - (Required) Token’s contract address +- `params.vs_currencies`: `String|Array` - (Required) vs_currency of coins. Use `simple.supportedVsCurrencies()` for a list of vsCurrency ids. +- `params.include_market_cap`: `Boolean` - [default: `false`] - Include market cap in results or not +- `params.include_24hr_vol`: `Boolean` - [default: `false`] - Include 24hr volume in results or not +- `params.include_24hr_change`: `Boolean` - [default: `false`] - Include 24hr change in results or not +- `params.include_last_updated_at`: `Boolean` - [default: `false`] - Include last updated date in results or not + + +Usage Example: +```javascript +// 0x contract address (as a test) +var zrx = '0xe41d2489571d322189246dafa5ebde1f4699f498'; +let data = await CoinGeckoClient.simple.fetchTokenPrice({ + contract_addresses: zrx, + vs_currencies: 'usd', +}); +``` + +___ +### • Finance +Calls related to finance endpoints. + + +#### `finance.fetchPlatforms()` +List all finance platforms + +Official documentation: https://www.coingecko.com/api/documentations/v3#/finance_(beta)/get_finance_platforms + +Params: + +- `params`: `Object` - Parameters to pass through to the request +- `params.per_page`: `Number` - Total results per page +- `params.page`: `Number` - Page of results (paginated to 100 by default) + +Usage Example: +```javascript +let data = await CoinGeckoClient.finance.fetchPlatforms(); +``` + +___ +#### `finance.fetchProducts()` +List all finance products + +Official documentation: https://www.coingecko.com/api/documentations/v3#/finance_(beta)/get_finance_products + +Params: + +- `params`: `Object` - Parameters to pass through to the request +- `params.per_page`: `Number` - Total results per page +- `params.page`: `Number` - Page of results (paginated to 100 by default) +- `params.start_at`: `String` - Start date of the financial products +- `params.end_at`: `String` - End date of the financial products + +Usage Example: +```javascript +let data = await CoinGeckoClient.finance.fetchProducts(); +``` + +___ +### • Indexes +Calls related to index endpoints. + + +#### `indexes.all()` +List all market indexes + +Official documentation: https://www.coingecko.com/en/api#operations-tag-indexes_(beta) + +Params: + +- `params`: `Object` - Parameters to pass through to the request +- `params.per_page`: `Number` - Total results per page +- `params.page`: `Number` - Page of results (paginated to 100 by default) + +Usage Example: +```javascript +let data = await CoinGeckoClient.indexes.all(); +``` + +#### `indexes.fetch()` +List all market indexes + +Official documentation: https://www.coingecko.com/en/api#operations-indexes%20(beta)-get_indexes__id_ + +Params: + +- `indexId`: `String` - (Required) The index id (can be obtained from `indexes.list()`) + +Usage Example: +```javascript +let testIndexId = 'BTC'; // as a test +let data = await CoinGeckoClient.indexes.fetch(testIndexId); +``` + +#### `indexes.list()` +List market indexes id and name + +Official documentation: https://www.coingecko.com/en/api#operations-indexes%20(beta)-get_indexes_list + +Usage Example: +```javascript +let data = await CoinGeckoClient.indexes.list(); +``` + +___ +### • Derivatives +Calls related to derivative endpoints. + + +#### `derivatives.fetchTickers()` +List all derivative tickers + +Official documentation: https://www.coingecko.com/api/documentations/v3#/operations-tag-derivatives_(beta) + +Usage Example: +```javascript +let data = await CoinGeckoClient.derivatives.fetchTickers(); +``` + +#### `derivatives.allExchanges()` +List all derivative exchanges + +Official documentation: https://www.coingecko.com/en/api#operations-derivatives%20(beta)-get_derivatives_exchanges + +Params: + +- `params`: `Object` - Parameters to pass through to the request +- `params.order`: `String` - Order results by `CoinGecko.ORDER[*]` +- `params.per_page`: `Number` - Total results per page +- `params.page`: `Number` - Page of results + +Usage Example: +```javascript +let data = await CoinGeckoClient.derivatives.allExchanges(); +``` + +#### `derivatives.fetchExchange()` +Show derivative exchange data + +Official documentation: https://www.coingecko.com/en/api#operations-derivatives%20(beta)-get_derivatives_exchanges__id_ + +Params: + +- `exchangeId`: `String` - (Required) The exchange id (can be obtained from `derivatives.listExchanges()`) +- `params`: `Object` - Parameters to pass through to the request +- `params.include_tickers`: `boolean` - [default: `false`] - Include the tickers information + +Usage Example: +```javascript +let testExchangeId = 'bitmex'; // as a test +let data = await CoinGeckoClient.derivatives.fetchExchange(testExchangeId); +``` + +#### `derivatives.listExchanges()` +List all derivative exchanges name and identifier + +Official documentation: https://www.coingecko.com/en/api#operations-derivatives%20(beta)-get_derivatives_exchanges_list + +Usage Example: +```javascript +let data = await CoinGeckoClient.derivatives.listExchanges(); +``` + +## • Say Hi + +Find me on Gab: [@markmiscavage](https://gab.com/markmiscavage). + +Tweet at me: [@markmiscavage](https://twitter.com/markmiscavage). + +## • License + +MIT License + +Copyright (c) 2020 Mark Miscavage + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/GradDemo.Api/node_modules/coingecko-api/index.js b/GradDemo.Api/node_modules/coingecko-api/index.js new file mode 100644 index 0000000..20b0fed --- /dev/null +++ b/GradDemo.Api/node_modules/coingecko-api/index.js @@ -0,0 +1 @@ +module.exports = exports = require('./lib/CoinGecko'); diff --git a/GradDemo.Api/node_modules/coingecko-api/lib/CoinGecko.js b/GradDemo.Api/node_modules/coingecko-api/lib/CoinGecko.js new file mode 100644 index 0000000..9c5708f --- /dev/null +++ b/GradDemo.Api/node_modules/coingecko-api/lib/CoinGecko.js @@ -0,0 +1,908 @@ +'use strict'; + +//Modules +const https = require('https'); +const querystring = require('querystring'); + +//Helpers +const Utils = require('./helpers/utilities'); +const Constants = require('./helpers/constants'); +const ReturnObject = require('./helpers/ReturnObject'); + +/** + * @class CoinGecko + * @author Mark Miscavage + * @description A Node.js wrapper for the CoinGecko API with no dependencies. For more information, visit: https://www.coingecko.com/api/docs/v3 + * @example + * const CoinGecko = require('coingecko-api'); + * const CoinGeckoClient = new CoinGecko(); + * @public + * @version 1.0.10 + * @license MIT + * @kind class + */ +class CoinGecko { + + /** + * @description Check API server status + * @function ping + * @returns {ReturnObject} + */ + ping() { + const path = `/ping`; + + return this._request(path); + }; + + /** + * @description Get cryptocurrency global data + * @function global + * @returns {ReturnObject} + */ + global() { + const path = `/global`; + + return this._request(path); + }; + + /** + * @description Calls related to coins + */ + get coins() { + const pathPrefix = 'coins'; + + return { + + /** + * @description List all coins with data (name, price, market, developer, community, etc) - paginated by 50 + * @function coins.all() + * @param {object} params - Parameters to pass through to the request + * @param {string} params.order - Order results by CoinGecko.ORDER[*] + * @param {number} params.per_page - Total results per page + * @param {number} params.page - Page through results + * @param {boolean} params.localization [default: true] - Set to false to exclude localized languages in response + * @param {boolean} params.sparkline [default: false] - Include sparkline 7 days data + * @returns {ReturnObject} + */ + all: (params = {}) => { + const path = `/${pathPrefix}`; + + return this._request(path, params); + }, + + /** + * @description Use this to obtain all the coins’ id in order to make API calls + * @function coins.list() + * @returns {ReturnObject} + */ + list: () => { + const path = `/${pathPrefix}/list`; + + return this._request(path); + }, + + /** + * @description Use this to obtain all the coins market data (price, market cap, volume) + * @function coins.markets() + * @param {object} params - Parameters to pass through to the request + * @param {string} params.vs_currency [default: usd] - The target currency of market data (usd, eur, jpy, etc.) + * @param {array|string} params.ids - List of coin id to filter if you want specific results + * @param {string} params.order - Order results by CoinGecko.ORDER[*] + * @param {number} params.per_page - Total results per page + * @param {number} params.page - Page through results + * @param {boolean} params.sparkline [default: false] - Include sparkline 7 days data (true/false) + * @returns {ReturnObject} + */ + markets: (params = {}) => { + const path = `/${pathPrefix}/markets`; + + //Must be object + if (!Utils.isObject(params)) Utils._WARN_('Invalid parameter', 'params must be of type: Object'); + + //If no params.vs_currency, set to default: 'usd' + if (!Utils.isString(params['vs_currency']) || Utils.isStringEmpty(params['vs_currency'])) { + params.vs_currency = 'usd'; + } + + //Check the params.ids + //If is string, ok. If is array, convert to string + if (Utils.isArray(params['ids'])) { + params.ids = params.ids.join(','); + } + + return this._request(path, params); + }, + + /** + * @description Get current data (name, price, market, … including exchange tickers) for a coin. + * @function coins.fetch() + * @param {string} coinId - (Required) The coin id (can be obtained from coins.list()) eg. bitcoin + * @param {object} params - Parameters to pass through to the request + * @param {boolean} params.tickers [default: true] - Include ticker data + * @param {boolean} params.market_data [default: true] - Include market data + * @param {boolean} params.community_data [default: true] - Include community data + * @param {boolean} params.developer_data [default: true] - Include developer data + * @param {boolean} params.localization [default: true] - Set to false to exclude localized languages in response + * @param {boolean} params.sparkline [default: false] - Include sparkline 7 days data (true/false) + * @returns {ReturnObject} + */ + fetch: (coinId, params = {}) => { + //Must have coinId + if (!Utils.isString(coinId) || Utils.isStringEmpty(coinId)) Utils._WARN_('Invalid parameter', 'coinId must be of type: String and greater than 0 characters.'); + + const path = `/${pathPrefix}/${coinId}`; + + return this._request(path, params); + }, + + /** + * @description Get coin tickers (paginated to 100 items). + * @function coins.fetchTickers() + * @param {string} coinId - (Required) The coin id (can be obtained from coins.list()) eg. bitcoin + * @param {object} params - Parameters to pass through to the request + * @param {string} params.page - Page through results + * @param {number} params.exchange_ids - Filter tickers by exchange_ids + * @param {string} params.order [default: trust_score_desc] - Order results by CoinGecko.ORDER.TRUST_SCORE_DESC or CoinGecko.ORDER.VOLUME_DESC + * @returns {ReturnObject} + */ + fetchTickers: (coinId, params = {}) => { + //Must have coinId + if (!Utils.isString(coinId) || Utils.isStringEmpty(coinId)) Utils._WARN_('Invalid parameter', 'coinId must be of type: String and greater than 0 characters.'); + + //Convert array to string + if (Utils.isArray(params['exchange_ids'])) { + params.exchange_ids = params.exchange_ids.join(','); + } + + const path = `/${pathPrefix}/${coinId}/tickers`; + + return this._request(path, params); + }, + + /** + * @description Get historical data (name, price, market, stats) at a given date for a coin + * @function coins.fetchHistory() + * @param {string} coinId - (Required) The coin id (can be obtained from coins.list()) eg. bitcoin + * @param {object} params - Parameters to pass through to the request + * @param {string} params.date - (Required) The date of data snapshot in dd-mm-yyyy eg. 30-12-2017 + * @param {boolean} params.localization [default: true] - Set to false to exclude localized languages in response + * @returns {ReturnObject} + */ + fetchHistory: (coinId, params = {}) => { + //Must have coinId + if (!Utils.isString(coinId) || Utils.isStringEmpty(coinId)) Utils._WARN_('Invalid parameter', 'coinId must be of type: String and greater than 0 characters.'); + + //Must be object + if (!Utils.isObject(params)) Utils._WARN_('Invalid parameter', 'params must be of type: Object'); + + //If no params.date, set to default today/now + if (!Utils.isString(params['date']) || Utils.isStringEmpty(params['date'])) Utils._WARN_('Missing parameter', 'params must include `date` and be a string in format: `dd-mm-yyyy`'); + + const path = `/${pathPrefix}/${coinId}/history`; + + return this._request(path, params); + }, + + /** + * @description Get historical market data include price, market cap, and 24h volume (granularity auto) + * @function coins.fetchMarketChart() + * @param {string} coinId - (Required) The coin id (can be obtained from coins.list()) eg. bitcoin + * @param {object} params - Parameters to pass through to the request + * @param {string} params.vs_currency [default: usd] - (Required) The target currency of market data (usd, eur, jpy, etc.) + * @param {string} params.days [default: 1] - (Required) Data up to number of days ago (eg. 1,14,30,max) + * @returns {ReturnObject} + */ + fetchMarketChart: (coinId, params = {}) => { + //Must have coinId + if (!Utils.isString(coinId) || Utils.isStringEmpty(coinId)) Utils._WARN_('Invalid parameter', 'coinId must be of type: String and greater than 0 characters.'); + + //Must be object + if (!Utils.isObject(params)) Utils._WARN_('Invalid parameter', 'params must be of type: Object'); + + //If no params.vs_currency, set to default: 'usd' + if (!Utils.isString(params['vs_currency']) || Utils.isStringEmpty(params['vs_currency'])) { + params.vs_currency = 'usd'; + } + + //If no params.days, set to default: 1 + if (params['days'] == undefined) { + params.days = 1; + } + + const path = `/${pathPrefix}/${coinId}/market_chart`; + + return this._request(path, params); + }, + + /** + * @description Get historical market data include price, market cap, and 24h volume within a range of timestamp (granularity auto). + * Minutely data will be used for duration within 1 day. + * Hourly data will be used for duration between 1 day and 90 days. + * Daily data will be used for duration above 90 days. + * @function coins.fetchMarketChartRange() + * @param {string} coinId - (Required) The coin id (can be obtained from coins.list()) eg. bitcoin + * @param {object} params - Parameters to pass through to the request + * @param {string} params.vs_currency [default: usd] - (Required) The target currency of market data (usd, eur, jpy, etc.) + * @param {number} params.from - (Required) From date in UNIX Timestamp (eg. 1392577232) + * @param {number} params.to - (Required) To date in UNIX Timestamp (eg. 1422577232) + * @returns {ReturnObject} + */ + fetchMarketChartRange: (coinId, params = {}) => { + //Must have coinId + if (!Utils.isString(coinId) || Utils.isStringEmpty(coinId)) Utils._WARN_('Invalid parameter', 'coinId must be of type: String and greater than 0 characters.'); + + //Must be object + if (!Utils.isObject(params)) Utils._WARN_('Invalid parameter', 'params must be of type: Object'); + + //If no params.vs_currency, set to default: 'usd' + if (!Utils.isString(params['vs_currency']) || Utils.isStringEmpty(params['vs_currency'])) { + params.vs_currency = 'usd'; + } + + if (!Utils.isNumber(params['from'])) Utils._WARN_('Missing parameter', 'params must include `from` and be a UNIX timestamp.'); + if (!Utils.isNumber(params['to'])) Utils._WARN_('Missing parameter', 'params must include `to` and be a UNIX timestamp.'); + + const path = `/${pathPrefix}/${coinId}/market_chart/range`; + + return this._request(path, params); + }, + + /** + * @description Get status updates for a given coin + * @function coins.fetchStatusUpdates() + * @param {string} coinId - (Required) The coin id (can be obtained from coins.list()) eg. bitcoin + * @param {object} params - Parameters to pass through to the request + * @param {number} params.per_page - Total results per page + * @param {number} params.page - Page through results + * @returns {ReturnObject} + */ + fetchStatusUpdates: (coinId, params = {}) => { + //Must have coinId + if (!Utils.isString(coinId) || Utils.isStringEmpty(coinId)) Utils._WARN_('Invalid parameter', 'coinId must be of type: String and greater than 0 characters.'); + + const path = `/${pathPrefix}/${coinId}/status_updates`; + + return this._request(path, params); + }, + + /** + * @description Get coin info from contract address + * @function coins.fetchCoinContractInfo() + * @param {object} contractAddress - (Required) Token’s contract address + * @param {string} assetPlatform [default: ethereum] - (Required) Asset platform (only ethereum is supported at this moment) + * @returns {ReturnObject} + */ + fetchCoinContractInfo: (contractAddress, assetPlatform = 'ethereum') => { + //Must have contractAddress, assetPlatform + if (!Utils.isString(contractAddress) || Utils.isStringEmpty(contractAddress)) Utils._WARN_('Invalid parameter', 'contractAddress must be of type: String and greater than 0 characters.'); + if (!Utils.isString(assetPlatform) || Utils.isStringEmpty(assetPlatform)) Utils._WARN_('Invalid parameter', 'assetPlatform must be of type: String and greater than 0 characters.'); + + const path = `/${pathPrefix}/${assetPlatform}/contract/${contractAddress}`; + + return this._request(path); + }, + + /** + * @description Get historical market data include price, market cap, and 24h volume (granularity auto) from a contract address + * @function coins.fetchCoinContractMarketChart() + * @param {object} contractAddress - (Required) Token’s contract address + * @param {string} assetPlatform [default: ethereum] - (Required) Asset platform (only ethereum is supported at this moment) + * @param {object} params - Parameters to pass through to the request + * @param {string} params.vs_currency [default: usd] - (Required) The target currency of market data (usd, eur, jpy, etc.) + * @param {string} params.days [default: 1] - (Required) Data up to number of days ago (eg. 1,14,30,max) + * @returns {ReturnObject} + */ + fetchCoinContractMarketChart: (contractAddress, assetPlatform = 'ethereum', params = {}) => { + //Must have contractAddress, assetPlatform + if (!Utils.isString(contractAddress) || Utils.isStringEmpty(contractAddress)) Utils._WARN_('Invalid parameter', 'contractAddress must be of type: String and greater than 0 characters.'); + if (!Utils.isString(assetPlatform) || Utils.isStringEmpty(assetPlatform)) Utils._WARN_('Invalid parameter', 'assetPlatform must be of type: String and greater than 0 characters.'); + + //Must be object + if (!Utils.isObject(params)) Utils._WARN_('Invalid parameter', 'params must be of type: Object'); + + //If no params.vs_currency, set to default: 'usd' + if (!Utils.isString(params['vs_currency']) || Utils.isStringEmpty(params['vs_currency'])) { + params.vs_currency = 'usd'; + } + + //If no params.days, set to default: 1 + if (params['days'] == undefined) { + params.days = 1; + } + + const path = `/${pathPrefix}/${assetPlatform}/contract/${contractAddress}/market_chart`; + + return this._request(path, params); + }, + + /** + * @description Get historical market data include price, market cap, and 24h volume within a range of timestamp (granularity auto) + * @function coins.fetchCoinContractMarketChartRange() + * @param {object} contractAddress - (Required) Token’s contract address + * @param {string} assetPlatform [default: ethereum] - (Required) Asset platform (only ethereum is supported at this moment) + * @param {object} params - Parameters to pass through to the request + * @param {string} params.vs_currency [default: usd] - (Required) The target currency of market data (usd, eur, jpy, etc.) + * @param {number} params.from - (Required) From date in UNIX Timestamp (eg. 1392577232) + * @param {number} params.to - (Required) To date in UNIX Timestamp (eg. 1422577232) + * @returns {ReturnObject} + */ + fetchCoinContractMarketChartRange: (contractAddress, assetPlatform = 'ethereum', params = {}) => { + //Must have contractAddress, assetPlatform + if (!Utils.isString(contractAddress) || Utils.isStringEmpty(contractAddress)) Utils._WARN_('Invalid parameter', 'contractAddress must be of type: String and greater than 0 characters.'); + if (!Utils.isString(assetPlatform) || Utils.isStringEmpty(assetPlatform)) Utils._WARN_('Invalid parameter', 'assetPlatform must be of type: String and greater than 0 characters.'); + + //Must be object + if (!Utils.isObject(params)) Utils._WARN_('Invalid parameter', 'params must be of type: Object'); + + //If no params.vs_currency, set to default: 'usd' + if (!Utils.isString(params['vs_currency']) || Utils.isStringEmpty(params['vs_currency'])) { + params.vs_currency = 'usd'; + } + + //If no params.days, set to default: 1 + if (params['days'] == undefined) { + params.days = 1; + } + + const path = `/${pathPrefix}/${assetPlatform}/contract/${contractAddress}/market_chart/range`; + + return this._request(path, params); + }, + }; + }; + + /** + * @description Calls related to exchanges + */ + get exchanges() { + const pathPrefix = 'exchanges'; + + return { + + /** + * @description List all exchanges + * @function exchanges.all() + * @returns {ReturnObject} + */ + all: () => { + const path = `/${pathPrefix}`; + + return this._request(path); + }, + + /** + * @description List all supported markets id and name + * @function exchanges.list() + * @returns {ReturnObject} + */ + list: () => { + const path = `/${pathPrefix}/list`; + + return this._request(path); + }, + + /** + * @description Get exchange volume in BTC and top 100 tickers only for a given exchange + * @function exchanges.fetch() + * @param {string} exchangeId - (Required) The exchange id (can be obtained from exchanges.all()) eg. binance + * @returns {ReturnObject} + */ + fetch: (exchangeId) => { + //Must have exchangeId + if (!Utils.isString(exchangeId) || Utils.isStringEmpty(exchangeId)) Utils._WARN_('Invalid parameter', 'exchangeId must be of type: String and greater than 0 characters.'); + + const path = `/${pathPrefix}/${exchangeId}`; + + return this._request(path); + }, + + /** + * @description Get tickers for a given exchange + * @function exchanges.fetchTickers() + * @param {string} exchangeId - (Required) The exchange id (can be obtained from exchanges.all()) eg. binance + * @param {object} params - Parameters to pass through to the request + * @param {number} params.page - Page through results + * @param {number} params.coin_ids - Filter tickers by coin_ids + * @param {string} params.order [default: trust_score_desc] - Order results by CoinGecko.ORDER.TRUST_SCORE_DESC or CoinGecko.ORDER.VOLUME_DESC + * @returns {ReturnObject} + */ + fetchTickers: (exchangeId, params = {}) => { + //Must have exchangeId + if (!Utils.isString(exchangeId) || Utils.isStringEmpty(exchangeId)) Utils._WARN_('Invalid parameter', 'exchangeId must be of type: String and greater than 0 characters.'); + + //Convert array to string + if (Utils.isArray(params['coin_ids'])) { + params.coin_ids = params.coin_ids.join(','); + } + + const path = `/${pathPrefix}/${exchangeId}/tickers`; + + return this._request(path, params); + }, + + /** + * @description Get status updates for a given exchange + * @function exchanges.fetchStatusUpdates() + * @param {string} exchangeId - (Required) The exchange id (can be obtained from exchanges.all()) eg. binance + * @param {object} params - Parameters to pass through to the request + * @param {number} params.per_page - Total results per page + * @param {number} params.page - Page through results + * @returns {ReturnObject} + */ + fetchStatusUpdates: (exchangeId, params = {}) => { + //Must have exchangeId + if (!Utils.isString(exchangeId) || Utils.isStringEmpty(exchangeId)) Utils._WARN_('Invalid parameter', 'exchangeId must be of type: String and greater than 0 characters.'); + + const path = `/${pathPrefix}/${exchangeId}/status_updates`; + + return this._request(path, params); + }, + + /** + * @description Get volume chart data for a given exchange, returned in BTC + * @function exchanges.fetchVolumeChart() + * @param {string} exchangeId - (Required) The exchange id (can be obtained from exchanges.all()) eg. binance + * @param {object} params - Parameters to pass through to the request + * @param {number} params.days - Data up to number of days ago (eg. 1, 14, 30) + * @returns {ReturnObject} + */ + fetchVolumeChart: (exchangeId, params = {}) => { + //Must have exchangeId + if (!Utils.isString(exchangeId) || Utils.isStringEmpty(exchangeId)) Utils._WARN_('Invalid parameter', 'exchangeId must be of type: String and greater than 0 characters.'); + + const path = `/${pathPrefix}/${exchangeId}/volume_chart`; + + return this._request(path, params); + }, + }; + }; + + /** + * @description Calls related to status updates + */ + get statusUpdates() { + return { + + /** + * @description List all status_updates with data (description, category, created_at, user, user_title and pin) + * @function statusUpdates.all() + * @param {object} params - Parameters to pass through to the request + * @param {number} params.category - Filter results by CoinGecko.STATUS_UPDATE_CATEGORY[*] + * @param {number} params.project_type - Filter results by CoinGecko.STATUS_UPDATE_PROJECT_TYPE[*] (If left empty returns both status from coins and markets) + * @param {number} params.per_page - Total results per page + * @param {number} params.page - Page through results + * @returns {ReturnObject} + */ + all: (params = {}) => { + const path = `/status_updates`; + + return this._request(path, params); + }, + }; + }; + + /** + * @description Calls related to events + */ + get events() { + const pathPrefix = 'events'; + + return { + + /** + * @description Get events, paginated by 100 + * @function events.all() + * @param {object} params - Parameters to pass through to the request + * @param {number} params.country_code - country_code of event (eg. ‘US’). Use events.fetchHistory() for list of country_codes + * @param {string} params.type - Type of event (eg.‘Conference’). Use events.fetchTypes() for list of types. Or use CoinGecko.EVENT_TYPE[*] + * @param {number} params.page - Page of results (paginated by 100) + * @param {boolean} params.upcoming_events_only [default: true] - Lists only upcoming events + * @param {string} params.from_date - Lists events after this date yyyy-mm-dd + * @param {string} params.to_date - Lists events before this date yyyy-mm-dd (set upcoming_events_only to false if fetching past events) + * @returns {ReturnObject} + */ + all: (params = {}) => { + const path = `/${pathPrefix}`; + + return this._request(path, params); + }, + + /** + * @description Get list of event countries + * @function events.fetchCountries() + * @returns {ReturnObject} + */ + fetchCountries: () => { + const path = `/${pathPrefix}/countries`; + + return this._request(path); + }, + + /** + * @description Get list of event types + * @function events.fetchTypes() + * @returns {ReturnObject} + */ + fetchTypes: () => { + const path = `/${pathPrefix}/types`; + + return this._request(path); + }, + }; + }; + + /** + * @description Calls related to exchange rates + */ + get exchangeRates() { + return { + + /** + * @description Get BTC-to-Currency exchange rates + * @function exchangeRates.all() + * @returns {ReturnObject} + */ + all: () => { + const path = `/exchange_rates`; + + return this._request(path); + } + }; + }; + + /** + * @description Calls related to "simple" endpoints + */ + get simple() { + return { + + /** + * @description Get the current price of any cryptocurrencies in any other supported currencies that you need + * @function simple.price() + * @param {object} params - Parameters to pass through to the request + * @param {array|string} params.ids - (Required) A single id or a list of coin ids to filter if you want specific results. Use coins.list() for a list of coin ids. + * @param {array|string} params.vs_currencies [default: usd] - A single id or a list of ids. Use simple.supportedVsCurrencies() for a list of vsCurrency ids. + * @param {boolean} params.include_24hr_vol [default: false] - To include 24hr_vol (true/false) + * @param {boolean} params.include_last_updated_at [default: false] - To include last_updated_at of price (true/false) + * @returns {ReturnObject} + */ + price: (params = {}) => { + //Must be object + if (!Utils.isObject(params)) Utils._WARN_('Invalid parameter', 'params must be of type: Object'); + + //Check the params.vs_currencies + //If is string, ok. If is array, convert to string + if (Utils.isArray(params['vs_currencies'])) { + params.vs_currencies = params.vs_currencies.join(','); + } + + //If no params.vs_currency, set to default: 'usd' + if (!Utils.isString(params['vs_currencies']) || Utils.isStringEmpty(params['vs_currencies'])) { + params.vs_currencies = 'usd'; + } + + //Check the params.ids + //If is string, ok. If is array, convert to string + if (Utils.isArray(params['ids'])) { + params.ids = params.ids.join(','); + } + + //Must have params.ids + if (!Utils.isString(params['ids']) || Utils.isStringEmpty(params['ids'])) Utils._WARN_('Invalid parameter', 'params.ids must be of type: String or Array and greater than 0 characters.'); + + // + + const path = `/simple/price`; + + return this._request(path, params); + }, + + /** + * @description Get list of supported vs/comparisons currencies + * @function simple.supportedVsCurrencies() + * @returns {ReturnObject} + */ + supportedVsCurrencies: () => { + const path = `/simple/supported_vs_currencies`; + + return this._request(path); + }, + + /** + * @description Get current price of tokens (using contract addresses) for a given platform in any other currency that you need + * @function simple.fetchTokenPrice() + * @param {object} params - Parameters to pass through to the request + * @param {string} assetPlatform [default: ethereum] - (Required) Asset platform (only ethereum is supported at this moment) + * @param {string|array} params.contract_addresses - (Required) Token’s contract address + * @param {string|array} params.vs_currencies - (Required) vs_currency of coins. Use simple.supportedVsCurrencies() for a list of vsCurrency ids. + * @param {boolean} params.include_market_cap [default: false] - Include market cap in results or not + * @param {boolean} params.include_24hr_vol [default: false] - Include 24hr volume in results or not + * @param {boolean} params.include_24hr_change [default: false] - Include 24hr change in results or not + * @param {boolean} params.include_last_updated_at [default: false] - Include last updated date in results or not + * @returns {ReturnObject} + */ + fetchTokenPrice: (params = {}, assetPlatform = 'ethereum') => { + //Must be object + if (!Utils.isObject(params)) Utils._WARN_('Invalid parameter', 'params must be of type: Object'); + + //Must have assetPlatform + if (!Utils.isString(assetPlatform) || Utils.isStringEmpty(assetPlatform)) Utils._WARN_('Invalid parameter', 'assetPlatform must be of type: String and greater than 0 characters.'); + + //Must have contract_addresses, vs_currencies + if (!params['contract_addresses']) Utils._WARN_('Missing parameter', 'params must include `contract_addresses` and be a of type: String or Object'); + if (!params['vs_currencies']) Utils._WARN_('Missing parameter', 'params must include `vs_currencies` and be a of type: String or Object'); + + //If are arrays, convert to string + if (Utils.isArray(params['contract_addresses'])) { + params.contract_addresses = params.contract_addresses.join(','); + } + + if (Utils.isArray(params['vs_currencies'])) { + params.vs_currencies = params.vs_currencies.join(','); + } + + const path = `/simple/token_price/${assetPlatform}`; + + return this._request(path, params); + }, + }; + }; + + /** + * @description Calls related to finance endpoints + */ + get finance() { + return { + /** + * @description List all finance platforms + * @function finance.fetchPlatforms() + * @param {object} params - Parameters to pass through to the request + * @param {number} params.per_page - Total results per page + * @param {number} params.page - Page of results (paginated to 100 by default) + * @returns {ReturnObject} + */ + fetchPlatforms: (params = {}) => { + const path = `/finance_platforms`; + + return this._request(path, params); + }, + + /** + * @description List all finance products + * @function finance.fetchProducts() + * @param {object} params - Parameters to pass through to the request + * @param {number} params.per_page - Total results per page + * @param {number} params.page - Page of results (paginated to 100 by default) + * @param {string} params.start_at - Start date of the financial products + * @param {string} params.end_at - End date of the financial products + * @returns {ReturnObject} + */ + fetchProducts: (params = {}) => { + const path = `/finance_products`; + + return this._request(path, params); + }, + }; + }; + + /** + * @description Calls related to index endpoints + */ + get indexes() { + const pathPrefix = 'indexes'; + + return { + /** + * @description List all market indexes + * @function indexes.all() + * @param {object} params - Parameters to pass through to the request + * @param {number} params.per_page - Total results per page + * @param {number} params.page - Page of results + * @returns {ReturnObject} + */ + all: (params = {}) => { + const path = `/${pathPrefix}`; + + return this._request(path, params); + }, + + /** + * @description Fetch market index by id + * @function indexes.fetch() + * @param {string} indexId - (Required) The index id (can be obtained from indexes.list()) + * @returns {ReturnObject} + */ + fetch: (indexId) => { + //Must have indexId + if (!Utils.isString(indexId) || Utils.isStringEmpty(indexId)) Utils._WARN_('Invalid parameter', 'indexId must be of type: String and greater than 0 characters.'); + + const path = `/${pathPrefix}/${indexId}`; + + return this._request(path); + }, + + /** + * @description List market indexes id and name + * @function indexes.list() + * @returns {ReturnObject} + */ + list: () => { + const path = `/${pathPrefix}/list`; + + return this._request(path); + }, + + }; + }; + + /** + * @description Calls related to derivative endpoints + */ + get derivatives() { + const pathPrefix = 'derivatives'; + + return { + /** + * @description List all derivative tickers + * @function derivatives.fetchTickers() + * @returns {ReturnObject} + */ + fetchTickers: () => { + const path = `/${pathPrefix}`; + + return this._request(path); + }, + + /** + * @description List all derivative exchanges + * @function derivatives.allExchanges() + * @param {object} params - Parameters to pass through to the request + * @param {string} params.order - Order results by CoinGecko.ORDER[*] + * @param {number} params.per_page - Total results per page + * @param {number} params.page - Page of results + * @returns {ReturnObject} + */ + allExchanges: (params = {}) => { + const path = `/${pathPrefix}/exchanges`; + + return this._request(path, params); + }, + + /** + * @description Show derivative exchange data + * @function derivatives.fetchExchange() + * @param {string} exchangeId - (Required) The exchange id (can be obtained from derivatives.listExchanges()) e.g. bitmex + * @param {object} params - Parameters to pass through to the request + * @param {boolean} params.include_tickers [default: false] - Include the tickers information + * @returns {ReturnObject} + */ + fetchExchange: (exchangeId, params = {}) => { + //Must have exchangeId + if (!Utils.isString(exchangeId) || Utils.isStringEmpty(exchangeId)) Utils._WARN_('Invalid parameter', 'exchangeId must be of type: String and greater than 0 characters.'); + + const path = `/${pathPrefix}/exchanges/${exchangeId}`; + + return this._request(path, params); + }, + + /** + * @description List all derivative exchanges name and identifier + * @function derivatives.listExchanges() + * @returns {ReturnObject} + */ + listExchanges: () => { + const path = `/${pathPrefix}/exchanges/list`; + + return this._request(path); + }, + }; + }; + + /** + * @description Build options for https.request + * @function _buildRequestOptions + * @protected + * @param {string} path - Relative path for API + * @param {object} params - Object representing query strings for url parameters + * @returns {Object} - {path, method, host, port} Options for request + */ + _buildRequestOptions(path, params) { + //Stringify object params if exist + if (Utils.isObject(params)) params = querystring.stringify(params); + else params = undefined; + + //Make relative path + //Check if has params, append accordingly + if (params == undefined) path = `/api/v${Constants.API_VERSION}${path}`; + else path = `/api/v${Constants.API_VERSION}${path}?${params}`; + + //Return options + return { + path, + method: 'GET', + host: Constants.HOST, + port: 443, + timeout: CoinGecko.TIMEOUT, + }; + }; + + /** + * @description Perform https request + * @function _request + * @protected + * @param {string} path - Relative path for API + * @param {object} params - Object representing query strings for url parameters + * @returns {Promise} Body of https request data results + */ + _request(path, params) { + let options = this._buildRequestOptions(path, params); + + return new Promise((resolve, reject) => { + //Perform request + let req = https.request(options, (res) => { + let body = []; + + //Set body on data + res.on('data', (chunk) => { + body.push(chunk); + }); + + //On end, end the Promise + res.on('end', () => { + try { + body = Buffer.concat(body); + body = body.toString(); + + //Check if page is returned instead of JSON + if (body.startsWith('')) { + Utils._WARN_('Invalid request', 'There was a problem with your request. The parameter(s) you gave are missing or incorrect.'); + } else if (body.startsWith('Throttled')) { + Utils._WARN_('Throttled request', 'There was a problem with request limit.'); + } + + //Attempt to parse + body = JSON.parse(body); + } + catch (error) { + reject(error); + }; + + //Create return object + resolve( + ReturnObject( + !(res.statusCode < 200 || res.statusCode >= 300), + res.statusMessage, + res.statusCode, + body + ) + ); + }); + }); + + //On error, reject the Promise + req.on('error', (error) => reject(error)); + + //On timeout, reject the Promise + req.on('timeout', () => { + req.abort(); + reject(new Error(`CoinGecko API request timed out. Current timeout is: ${CoinGecko.TIMEOUT} milliseconds`)); + }); + + //End request + req.end(); + }); + }; +}; + +//Set Constants +CoinGecko.API_VERSION = Constants.API_VERSION; +CoinGecko.REQUESTS_PER_SECOND = Constants.REQUESTS_PER_SECOND; +CoinGecko.ORDER = Constants.ORDER; +CoinGecko.STATUS_UPDATE_CATEGORY = Constants.STATUS_UPDATE_CATEGORY; +CoinGecko.STATUS_UPDATE_PROJECT_TYPE = Constants.STATUS_UPDATE_PROJECT_TYPE; +CoinGecko.EVENT_TYPE = Constants.EVENT_TYPE; +CoinGecko.TIMEOUT = Constants.TIMEOUT; + +// + +module.exports = exports = CoinGecko; \ No newline at end of file diff --git a/GradDemo.Api/node_modules/coingecko-api/lib/helpers/ReturnObject.js b/GradDemo.Api/node_modules/coingecko-api/lib/helpers/ReturnObject.js new file mode 100644 index 0000000..59d73b3 --- /dev/null +++ b/GradDemo.Api/node_modules/coingecko-api/lib/helpers/ReturnObject.js @@ -0,0 +1,19 @@ +/** + * @typedef {Object} ReturnObject + * @description - Return object for requests in the class. Helper for reference. + * @param {boolean} success - Whether the response status code returned a successful code (>200 && <300) + * @param {string} message - The response status message + * @param {number} code - The response status code + * @param {object|*} data - The body data in json format from the request + * @property {boolean} success - Whether the response status code returned a successful code (>200 && <300) + * @property {string} message - The response status message + * @property {number} code - The response status code + * @property {object|*} data - The body data in json format from the request + */ +const ReturnObject = (success, message, code, data) => { + return { success, message, code, data }; +}; + +// + +module.exports = ReturnObject; \ No newline at end of file diff --git a/GradDemo.Api/node_modules/coingecko-api/lib/helpers/constants.js b/GradDemo.Api/node_modules/coingecko-api/lib/helpers/constants.js new file mode 100644 index 0000000..726ef8f --- /dev/null +++ b/GradDemo.Api/node_modules/coingecko-api/lib/helpers/constants.js @@ -0,0 +1,110 @@ +/** + * @description The base url for the CoinGecko API + * @kind constant + */ +const BASE = 'https://api.coingecko.com/api/'; + +/** + * @description The host of the CoinGecko API + * @kind constant + */ +const HOST = 'api.coingecko.com'; + +/** + * @description The current version for the CoinGecko API + * @kind constant + */ +const API_VERSION = '3'; + +/** + * @description The CoinGecko URI according to base and current version + * @kind constant + */ +const URI = `${BASE}v${API_VERSION}`; + +/** + * @description The maximum number of requests per second for the CoinGecko API + * @kind constant + */ +const REQUESTS_PER_SECOND = 10; + +/** + * @description Timeout for connecton to CoinGecko API in milliseconds (default: 30 seconds) + * @kind constant + */ +const TIMEOUT = 30000; + +/** + * @description Available options to order results by + * @kind constant + */ +const ORDER = { + GECKO_ASC: 'gecko_asc', + GECKO_DESC: 'gecko_desc', + MARKET_CAP_ASC: 'market_cap_asc', + MARKET_CAP_DESC: 'market_cap_desc', + VOLUME_ASC: 'volume_asc', + VOLUME_DESC: 'volume_desc', + COIN_NAME_ASC: 'coin_name_asc', + COIN_NAME_DESC: 'coin_name_desc', + PRICE_ASC: 'price_asc', + PRICE_DESC: 'price_desc', + HOUR_24_ASC: 'h24_change_asc', + HOUR_24_DESC: 'h24_change_desc', + TRUST_SCORE_DESC: 'trust_score_desc', + NAME_ASC: 'name_asc', + NAME_DESC: 'name_desc', + OPEN_INTEREST_BTC_ASC: 'open_interest_btc_asc', + OPEN_INTEREST_BTC_DESC: 'open_interest_btc_desc', + TRADE_VOLUME_24H_BTC_ASC: 'trade_volume_24h_btc_asc', + TRADE_VOLUME_24H_BTC_DESC: 'trade_volume_24h_btc_desc', +}; + +/** + * @description Available status update category types to filter by + * @kind constant + */ +const STATUS_UPDATE_CATEGORY = { + GENERAL: 'general', + MILESTONE: 'milestone', + PARTNERSHIP: 'partnership', + EXCHANGE_LISTING: 'exchange_listing', + SOFTWARE_RELEASE: 'software_release', + FUND_MOVEMENT: 'fund_movement', + NEW_LISTINGS: 'new_listings', + EVENT: 'event', +}; + +/** + * @description Available project type options to filter by + * @kind constant + */ +const STATUS_UPDATE_PROJECT_TYPE = { + COIN: 'coin', + MARKET: 'market', +} + +/** + * @description List of event types (most recent from /events/type) + * @kind constant + */ +const EVENT_TYPE = { + EVENT: 'Event', + CONFERENCE: 'Conference', + MEETUP: 'Meetup', +}; + +// + +module.exports = { + BASE, + HOST, + API_VERSION, + URI, + REQUESTS_PER_SECOND, + ORDER, + STATUS_UPDATE_CATEGORY, + STATUS_UPDATE_PROJECT_TYPE, + EVENT_TYPE, + TIMEOUT, +}; \ No newline at end of file diff --git a/GradDemo.Api/node_modules/coingecko-api/lib/helpers/utilities.js b/GradDemo.Api/node_modules/coingecko-api/lib/helpers/utilities.js new file mode 100644 index 0000000..289f474 --- /dev/null +++ b/GradDemo.Api/node_modules/coingecko-api/lib/helpers/utilities.js @@ -0,0 +1,90 @@ +/** + * @description Internal helper to check if parameter is a string + * @function isString + * @param {*} str + * @returns {boolean} + */ +const isString = (str) => { + return (typeof str === 'string' || str instanceof String); +}; + +/** + * @description Internal helper to check if string is empty + * @function isStringEmpty + * @param {*} str + * @returns {boolean} + */ +const isStringEmpty = (str) => { + if (!isString(str)) return false; + return (str.length == 0); +}; + +/** + * @description Internal helper to check if parameter is a date + * @function isDate + * @param {*} date + * @returns {boolean} + */ +const isDate = (date) => { + if (isString(date) || isArray(date) || date == undefined || date == null) return false; + return (date && Object.prototype.toString.call(date) === "[object Date]" && !isNaN(date)); +}; + +/** + * @description Internal helper to check if parameter is an object + * @function isObject + * @param {*} obj + * @returns {boolean} + */ +const isObject = (obj) => { + if (isArray(obj) || isDate(obj)) return false; + return (obj !== null && typeof obj === 'object'); +}; + +/** + * @description Internal helper to check if parameter is a number + * @function isNumber + * @param {*} num + * @returns {boolean} + */ +const isNumber = (num) => { + return (!isNaN(num) && !isNaN(parseInt(num))); +}; + +/** + * @description Internal helper to check if parameter is an array + * @function isArray + * @param {*} arr + * @returns {boolean} + */ +const isArray = (arr) => { + return Array.isArray(arr); +}; + +/** + * @description Internal helper to emit a warning to the console + * @function _WARN_ + * @param {string} title + * @param {string} detail + * @returns {boolean} + */ +const _WARN_ = (title = '', detail = '') => { + process.emitWarning(title, { + detail, + code: 'CoinGecko', + }); + + return true; +}; + +// + +module.exports = { + isString, + isStringEmpty, + isDate, + isObject, + isNumber, + isArray, + _WARN_, +}; \ No newline at end of file diff --git a/GradDemo.Api/node_modules/coingecko-api/package.json b/GradDemo.Api/node_modules/coingecko-api/package.json new file mode 100644 index 0000000..0ca21fd --- /dev/null +++ b/GradDemo.Api/node_modules/coingecko-api/package.json @@ -0,0 +1,63 @@ +{ + "_from": "coingecko-api", + "_id": "coingecko-api@1.0.10", + "_inBundle": false, + "_integrity": "sha512-7YLLC85+daxAw5QlBWoHVBVpJRwoPr4HtwanCr8V/WRjoyHTa1Lb9DQAvv4MDJZHiz4no6HGnDQnddtjV35oRA==", + "_location": "/coingecko-api", + "_phantomChildren": {}, + "_requested": { + "type": "tag", + "registry": true, + "raw": "coingecko-api", + "name": "coingecko-api", + "escapedName": "coingecko-api", + "rawSpec": "", + "saveSpec": null, + "fetchSpec": "latest" + }, + "_requiredBy": [ + "#USER", + "/" + ], + "_resolved": "https://registry.npmjs.org/coingecko-api/-/coingecko-api-1.0.10.tgz", + "_shasum": "ac8694d5999f00727fe55f0078ce2917603076b2", + "_spec": "coingecko-api", + "_where": "C:\\Users\\FWilson\\GradsDemoDotNet\\GradDemo.Api", + "author": { + "name": "Mark Miscavage" + }, + "bugs": { + "url": "https://github.com/miscavage/CoinGecko-API/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "A Node.js wrapper for the CoinGecko API with no dependencies.", + "devDependencies": { + "chai": "^4.2.0", + "mocha": "^6.2.2" + }, + "homepage": "https://github.com/miscavage/CoinGecko-API#readme", + "keywords": [ + "coingecko", + "cryptocurrency", + "api", + "api-wrapper", + "dependency-less", + "no-dependencies", + "nodejs", + "npm", + "javascript", + "api-client" + ], + "license": "MIT", + "main": "index.js", + "name": "coingecko-api", + "repository": { + "type": "git", + "url": "git+https://github.com/miscavage/CoinGecko-API.git" + }, + "scripts": { + "test": "mocha --no-timeouts --reporter spec \"./tests/lib/*.js\" \"./tests/lib/**/*.js\"" + }, + "version": "1.0.10" +} diff --git a/GradDemo.Api/node_modules/coingecko-api/tests/lib/CoinGecko.spec.js b/GradDemo.Api/node_modules/coingecko-api/tests/lib/CoinGecko.spec.js new file mode 100644 index 0000000..e4e84ec --- /dev/null +++ b/GradDemo.Api/node_modules/coingecko-api/tests/lib/CoinGecko.spec.js @@ -0,0 +1,512 @@ +//Modules +const fs = require('fs'); +const mocha = require('mocha'); +const chai = require('chai'); +var should = chai.should(); + +//Helpers +const CoinGecko = require('../../lib/CoinGecko'); + +const shared = require('../shared'); + +describe('CoinGecko', function () { + before(function (done) { + this.CoinGeckoClient = new CoinGecko(); + + done(); + }); + + describe('ping', function () { + before(function (done) { + this.CoinGeckoClient.ping().then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('global', function () { + before(function (done) { + this.CoinGeckoClient.global().then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('coins', function () { + + describe('list', function () { + before(function (done) { + this.CoinGeckoClient.coins.list().then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('all', function () { + before(function (done) { + this.CoinGeckoClient.coins.all({ + order: CoinGecko.ORDER.COIN_NAME_ASC, + per_page: 100, + page: 1, + localization: false, + sparkline: true, + }).then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('markets', function () { + before(function (done) { + this.CoinGeckoClient.coins.markets({ + vs_currency: 'usd', + ids: ['bitcoin', 'ethereum', 'ripple'], + order: CoinGecko.ORDER.COIN_NAME_ASC, + per_page: 100, + page: 1, + sparkline: true, + }).then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('fetch', function () { + before(function (done) { + this.CoinGeckoClient.coins.fetch('bitcoin', { + tickers: true, + market_data: true, + community_data: true, + developer_data: true, + localization: true, + sparkline: true, + }).then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('fetchTickers', function () { + before(function (done) { + this.CoinGeckoClient.coins.fetchTickers('bitcoin').then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('fetchHistory', function () { + before(function (done) { + this.CoinGeckoClient.coins.fetchHistory('bitcoin', { + date: '30-12-2017', + localization: true, + }).then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('fetchMarketChart', function () { + before(function (done) { + this.CoinGeckoClient.coins.fetchMarketChart('bitcoin', { + vs_currency: 'usd', + days: 1, + }).then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('fetchMarketChartRange', function () { + before(function (done) { + this.CoinGeckoClient.coins.fetchMarketChartRange('bitcoin', { + vs_currency: 'usd', + from: 1392577232, + to: 1422577232, + }).then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('fetchStatusUpdates', function () { + before(function (done) { + this.CoinGeckoClient.coins.fetchStatusUpdates('bitcoin', { + per_page: 100, + page: 1, + }).then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('fetchCoinContractInfo', function () { + before(function (done) { + var zrx = '0xe41d2489571d322189246dafa5ebde1f4699f498'; + this.CoinGeckoClient.coins.fetchCoinContractInfo(zrx).then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('fetchCoinContractMarketChart', function () { + before(function (done) { + var zrx = '0xe41d2489571d322189246dafa5ebde1f4699f498'; + this.CoinGeckoClient.coins.fetchCoinContractMarketChart(zrx).then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('fetchCoinContractMarketChartRange', function () { + before(function (done) { + var zrx = '0xe41d2489571d322189246dafa5ebde1f4699f498'; + this.CoinGeckoClient.coins.fetchCoinContractMarketChartRange(zrx, 'ethereum', { + from: 1392577232, + to: 1422577232, + }).then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + }); + + describe('exchanges', function () { + describe('all', function () { + before(function (done) { + this.CoinGeckoClient.exchanges.all().then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('list', function () { + before(function (done) { + this.CoinGeckoClient.exchanges.list().then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('fetch', function () { + before(function (done) { + this.CoinGeckoClient.exchanges.fetch('binance').then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('fetchTickers', function () { + before(function (done) { + this.CoinGeckoClient.exchanges.fetchTickers('binance', { + page: 1, + }).then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('fetchStatusUpdates', function () { + before(function (done) { + this.CoinGeckoClient.exchanges.fetchStatusUpdates('binance', { + per_page: 100, + page: 1, + }).then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('fetchVolumeChart', function () { + before(function (done) { + this.CoinGeckoClient.exchanges.fetchVolumeChart('binance', { + days: 1, + }).then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + }); + + describe('statusUpdates', function () { + describe('all', function () { + before(function (done) { + this.CoinGeckoClient.statusUpdates.all({ + category: CoinGecko.STATUS_UPDATE_CATEGORY.EVENT, + project_type: CoinGecko.STATUS_UPDATE_PROJECT_TYPE.COIN, + per_page: 100, + page: 1, + }).then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + }); + + describe('events', function () { + describe('all', function () { + before(function (done) { + this.CoinGeckoClient.events.all({ + country_code: 'US', + type: CoinGecko.EVENT_TYPE.CONFERENCE, + page: 1, + upcoming_events_only: false, + from_date: '2018-06-01', + to_date: '2018-07-01' + }).then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('fetchCountries', function () { + before(function (done) { + this.CoinGeckoClient.events.fetchCountries().then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('fetchTypes', function () { + before(function (done) { + this.CoinGeckoClient.events.fetchTypes().then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + }); + + describe('exchangeRates', function () { + describe('all', function () { + before(function (done) { + this.CoinGeckoClient.exchangeRates.all().then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + }); + + describe('simple', function () { + describe('price', function () { + before(function (done) { + this.CoinGeckoClient.simple.price({ + vs_currencies: 'usd', + ids: ['bitcoin', 'ethereum', 'ripple'], + }).then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('supportedVsCurrencies', function () { + before(function (done) { + this.CoinGeckoClient.simple.supportedVsCurrencies().then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('fetchTokenPrice', function () { + before(function (done) { + var zrx = '0xe41d2489571d322189246dafa5ebde1f4699f498'; + this.CoinGeckoClient.simple.fetchTokenPrice({ + contract_addresses: zrx, + vs_currencies: 'usd', + }).then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + }); + + describe('finance', function () { + describe('fetchPlatforms', function () { + before(function (done) { + this.CoinGeckoClient.finance.fetchPlatforms().then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('fetchProducts', function () { + before(function (done) { + this.CoinGeckoClient.finance.fetchProducts().then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + }); + + describe('indexes', function () { + describe('all', function () { + before(function (done) { + this.CoinGeckoClient.indexes.all().then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('fetch', function () { + before(function (done) { + this.CoinGeckoClient.indexes.fetch('BTC').then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('list', function () { + before(function (done) { + this.CoinGeckoClient.indexes.list().then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + }); + + describe('derivatives', function () { + describe('fetchTickers', function () { + before(function (done) { + this.CoinGeckoClient.derivatives.fetchTickers().then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('allExchanges', function () { + before(function (done) { + this.CoinGeckoClient.derivatives.allExchanges().then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('fetchExchange', function () { + before(function (done) { + this.CoinGeckoClient.derivatives.fetchExchange('bitmex').then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + describe('listExchanges', function () { + before(function (done) { + this.CoinGeckoClient.derivatives.listExchanges().then((data) => { + this.data = data; + done(); + }); + }); + + shared.shouldBeAValidRequest(); + }); + + }); + +}); \ No newline at end of file diff --git a/GradDemo.Api/node_modules/coingecko-api/tests/lib/helpers/utilities.spec.js b/GradDemo.Api/node_modules/coingecko-api/tests/lib/helpers/utilities.spec.js new file mode 100644 index 0000000..6d8f9bf --- /dev/null +++ b/GradDemo.Api/node_modules/coingecko-api/tests/lib/helpers/utilities.spec.js @@ -0,0 +1,266 @@ +//Modules +const chai = require('chai'); +var should = chai.should(); + +//Helpers +const Utils = require('../../../lib/helpers/utilities'); + +const VAR_TYPES = { + STRING: 'String', + STRING_EMPTY: '', + NULL: null, + UNDEFINED: undefined, + NUMBER: 250, + ARRAY: ['a', 'basic', 'array'], + OBJECT: { 'a': 'b', 'c': 'd' }, + DATE: new Date(), +}; + +describe('Utilities', function () { + describe('isString', function () { + it('should return true if value is string', function (done) { + Utils.isString(VAR_TYPES.STRING_EMPTY).should.be.true; + Utils.isString(VAR_TYPES.STRING).should.be.true; + + done(); + }); + + it('should return false if value is null', function (done) { + Utils.isString(VAR_TYPES.NULL).should.be.false; + + done(); + }); + + it('should return false if value is undefined', function (done) { + Utils.isString(VAR_TYPES.UNDEFINED).should.be.false; + + done(); + }); + + it('should return false if value is number', function (done) { + Utils.isString(VAR_TYPES.NUMBER).should.be.false; + + done(); + }); + + it('should return false if value is array', function (done) { + Utils.isString(VAR_TYPES.ARRAY).should.be.false; + + done(); + }); + + it('should return false if value is object', function (done) { + Utils.isString(VAR_TYPES.OBJECT).should.be.false; + + done(); + }); + + it('should return false if value is date', function (done) { + Utils.isString(VAR_TYPES.DATE).should.be.false; + + done(); + }); + }); + + describe('isStringEmpty', function () { + it('should return false if value is string with value "string"', function (done) { + Utils.isStringEmpty(VAR_TYPES.STRING).should.be.false; + + done(); + }); + + it('should return true if value is string with value ""', function (done) { + Utils.isStringEmpty(VAR_TYPES.STRING_EMPTY).should.be.true; + + done(); + }); + }); + + describe('isDate', function () { + it('should return false if value is string', function (done) { + Utils.isDate(VAR_TYPES.STRING_EMPTY).should.be.false; + Utils.isDate(VAR_TYPES.STRING).should.be.false; + + done(); + }); + + it('should return false if value is null', function (done) { + Utils.isDate(VAR_TYPES.NULL).should.be.false; + + done(); + }); + + it('should return false if value is undefined', function (done) { + Utils.isDate(VAR_TYPES.UNDEFINED).should.be.false; + + done(); + }); + + it('should return false if value is number', function (done) { + Utils.isDate(VAR_TYPES.NUMBER).should.be.false; + + done(); + }); + + it('should return false if value is array', function (done) { + Utils.isDate(VAR_TYPES.ARRAY).should.be.false; + + done(); + }); + + it('should return false if value is object', function (done) { + Utils.isDate(VAR_TYPES.OBJECT).should.be.false; + + done(); + }); + + it('should return true if value is date', function (done) { + Utils.isDate(VAR_TYPES.DATE).should.be.true; + + done(); + }); + }); + + describe('isObject', function () { + it('should return false if value is string', function (done) { + Utils.isObject(VAR_TYPES.STRING_EMPTY).should.be.false; + Utils.isObject(VAR_TYPES.STRING).should.be.false; + + done(); + }); + + it('should return false if value is null', function (done) { + Utils.isObject(VAR_TYPES.NULL).should.be.false; + + done(); + }); + + it('should return false if value is undefined', function (done) { + Utils.isObject(VAR_TYPES.UNDEFINED).should.be.false; + + done(); + }); + + it('should return false if value is number', function (done) { + Utils.isObject(VAR_TYPES.NUMBER).should.be.false; + + done(); + }); + + it('should return false if value is array', function (done) { + Utils.isObject(VAR_TYPES.ARRAY).should.be.false; + + done(); + }); + + it('should return true if value is object', function (done) { + Utils.isObject(VAR_TYPES.OBJECT).should.be.true; + + done(); + }); + + it('should return false if value is date', function (done) { + Utils.isObject(VAR_TYPES.DATE).should.be.false; + + done(); + }); + }); + + describe('isNumber', function () { + it('should return false if value is string', function (done) { + Utils.isNumber(VAR_TYPES.STRING_EMPTY).should.be.false; + Utils.isNumber(VAR_TYPES.STRING).should.be.false; + + done(); + }); + + it('should return false if value is null', function (done) { + Utils.isNumber(VAR_TYPES.NULL).should.be.false; + + done(); + }); + + it('should return false if value is undefined', function (done) { + Utils.isNumber(VAR_TYPES.UNDEFINED).should.be.false; + + done(); + }); + + it('should return true if value is number', function (done) { + Utils.isNumber(VAR_TYPES.NUMBER).should.be.true; + + done(); + }); + + it('should return false if value is array', function (done) { + Utils.isNumber(VAR_TYPES.ARRAY).should.be.false; + + done(); + }); + + it('should return false if value is object', function (done) { + Utils.isNumber(VAR_TYPES.OBJECT).should.be.false; + + done(); + }); + + it('should return false if value is date', function (done) { + Utils.isNumber(VAR_TYPES.DATE).should.be.false; + + done(); + }); + }); + + describe('isArray', function () { + it('should return false if value is string', function (done) { + Utils.isArray(VAR_TYPES.STRING_EMPTY).should.be.false; + Utils.isArray(VAR_TYPES.STRING).should.be.false; + + done(); + }); + + it('should return false if value is null', function (done) { + Utils.isArray(VAR_TYPES.NULL).should.be.false; + + done(); + }); + + it('should return false if value is undefined', function (done) { + Utils.isArray(VAR_TYPES.UNDEFINED).should.be.false; + + done(); + }); + + it('should return false if value is number', function (done) { + Utils.isArray(VAR_TYPES.NUMBER).should.be.false; + + done(); + }); + + it('should return true if value is array', function (done) { + Utils.isArray(VAR_TYPES.ARRAY).should.be.true; + + done(); + }); + + it('should return false if value is object', function (done) { + Utils.isArray(VAR_TYPES.OBJECT).should.be.false; + + done(); + }); + + it('should return false if value is date', function (done) { + Utils.isArray(VAR_TYPES.DATE).should.be.false; + + done(); + }); + }); + + describe('_WARN_', function () { + it('should return true regardless', function (done) { + Utils._WARN_('Title', 'Some detail...').should.be.true; + + done(); + }); + }); +}); \ No newline at end of file diff --git a/GradDemo.Api/node_modules/coingecko-api/tests/shared.js b/GradDemo.Api/node_modules/coingecko-api/tests/shared.js new file mode 100644 index 0000000..7a4b973 --- /dev/null +++ b/GradDemo.Api/node_modules/coingecko-api/tests/shared.js @@ -0,0 +1,29 @@ +//Modules +const mocha = require('mocha'); +const chai = require('chai'); +var should = chai.should(); + +/** + * @description - Shared tests for validating CoinGeckoClient requests + * @function + */ +exports.shouldBeAValidRequest = function () { + + it('should return object: {success, message, code, data}', function (done) { + this.data.should.be.an('object'); + + done(); + }); + + it('should be a successful request', function (done) { + this.data.success.should.be.true; + + done(); + }); + + it('should return a 200 code', function (done) { + this.data.code.should.equal(200); + + done(); + }); +}; \ No newline at end of file diff --git a/GradDemo.Api/package-lock.json b/GradDemo.Api/package-lock.json new file mode 100644 index 0000000..8908d61 --- /dev/null +++ b/GradDemo.Api/package-lock.json @@ -0,0 +1,11 @@ +{ + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "coingecko-api": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/coingecko-api/-/coingecko-api-1.0.10.tgz", + "integrity": "sha512-7YLLC85+daxAw5QlBWoHVBVpJRwoPr4HtwanCr8V/WRjoyHTa1Lb9DQAvv4MDJZHiz4no6HGnDQnddtjV35oRA==" + } + } +}