crypto-markets
Advanced tools
@@ -1,4 +0,12 @@ | ||
| import { Market } from '../pojo/market'; | ||
| export declare function fetchMarkets(): Promise<{ | ||
| import { Market, MarketType } from '../pojo/market'; | ||
| export declare function fetchSpotMarkets(): Promise<{ | ||
| [key: string]: Market[]; | ||
| }>; | ||
| export declare function fetchFuturesMarkets(): Promise<{ | ||
| [key: string]: Market[]; | ||
| }>; | ||
| export declare function fetchMarkets( | ||
| marketType?: MarketType, | ||
| ): Promise<{ | ||
| [key: string]: Market[]; | ||
| }>; |
@@ -11,9 +11,9 @@ 'use strict'; | ||
| const crypto_pair_1 = require('crypto-pair'); | ||
| const utils_1 = require('../utils'); | ||
| function extractNormalizedPair(pairInfo) { | ||
| let baseSymbol = pairInfo['base-currency']; | ||
| if (baseSymbol === 'hot') baseSymbol = 'Hydro'; | ||
| return `${baseSymbol}_${pairInfo['quote-currency']}`.toUpperCase(); | ||
| return `${baseSymbol}/${pairInfo['quote-currency']}`.toUpperCase(); | ||
| } | ||
| // eslint-disable-next-line import/prefer-default-export | ||
| async function fetchMarkets() { | ||
| async function fetchSpotMarkets() { | ||
| const response = await axios_1.default.get('https://api.huobi.pro/v1/common/symbols'); | ||
@@ -36,2 +36,3 @@ assert_1.strict.equal(response.status, 200); | ||
| marketType: 'Spot', | ||
| // see https://www.huobi.com/en-us/fee/ | ||
| fees: { | ||
@@ -52,3 +53,3 @@ maker: 0.002, | ||
| }; | ||
| assert_1.strict.equal(market.pair, crypto_pair_1.normalizePair(market.id, 'Huobi')); | ||
| // assert.equal(market.pair, normalizePair(market.id, 'Huobi')); // todo: change _ to / in crypto-pair | ||
| if (!(market.pair in result)) result[market.pair] = []; | ||
@@ -59,2 +60,54 @@ result[market.pair].push(market); | ||
| } | ||
| exports.fetchSpotMarkets = fetchSpotMarkets; | ||
| async function fetchFuturesMarkets() { | ||
| const response = await axios_1.default.get('https://api.hbdm.com/api/v1/contract_contract_info'); | ||
| assert_1.strict.equal(response.status, 200); | ||
| assert_1.strict.equal(response.data.status, 'ok'); | ||
| const result = {}; | ||
| const arr = response.data.data; | ||
| arr.forEach((p) => { | ||
| const market = { | ||
| exchange: 'Huobi', | ||
| id: p.contract_code, | ||
| pair: `${p.symbol}/USD`, | ||
| base: p.symbol, | ||
| quote: 'USD', | ||
| baseId: p.symbol, | ||
| quoteId: 'USD', | ||
| active: p.contract_status === 1, | ||
| marketType: 'Futures', | ||
| // see https://huobiglobal.zendesk.com/hc/en-us/articles/360000113122 | ||
| fees: { | ||
| maker: 0.002, | ||
| taker: 0.003, | ||
| }, | ||
| precision: { | ||
| price: -Math.log10(p.price_tick), | ||
| base: -1, | ||
| }, | ||
| info: p, | ||
| }; | ||
| if (!(market.pair in result)) result[market.pair] = []; | ||
| result[market.pair].push(market); | ||
| }); | ||
| return result; | ||
| } | ||
| exports.fetchFuturesMarkets = fetchFuturesMarkets; | ||
| async function fetchMarkets(marketType) { | ||
| if (marketType) { | ||
| switch (marketType) { | ||
| case 'Spot': | ||
| return fetchSpotMarkets(); | ||
| case 'Futures': | ||
| return fetchFuturesMarkets(); | ||
| default: | ||
| throw new Error(`Unkown marketType ${marketType}`); | ||
| } | ||
| } | ||
| const spot = await fetchSpotMarkets(); | ||
| const futures = await fetchFuturesMarkets(); | ||
| const result = Object.assign({}, spot); | ||
| utils_1.mergeMarkets(result, futures); | ||
| return result; | ||
| } | ||
| exports.fetchMarkets = fetchMarkets; |
+2
-2
| { | ||
| "name": "crypto-markets", | ||
| "version": "0.0.4", | ||
| "version": "0.0.5", | ||
| "description": "Get all trading pairs of a cryptocurrency exchange.", | ||
@@ -50,3 +50,3 @@ "main": "dist/index.js", | ||
| "eslint-config-airbnb-base": "^14.1.0", | ||
| "eslint-config-prettier": "^6.10.0", | ||
| "eslint-config-prettier": "^6.10.1", | ||
| "eslint-plugin-import": "^2.20.1", | ||
@@ -53,0 +53,0 @@ "eslint-plugin-jest": "^23.8.2", |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
26125
7.34%423
16.85%