Skip to content

Refactor: Documentation Update 1.0.10 #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"presets": [
"env"
["@babel/preset-env", {
"targets": {
"node": "8.3.0"
}
}]
],
"plugins": [
"transform-regenerator",
"transform-object-rest-spread"
"@babel/plugin-transform-regenerator",
"@babel/plugin-proposal-object-rest-spread"
]
}
3 changes: 0 additions & 3 deletions .eslintrc

This file was deleted.

58 changes: 38 additions & 20 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
{
"parser": "babel-eslint",
"extends": [
"standard"
"root": true,

"plugins": [
"jsdoc",
"mocha"
],
"rules": {
"jsx-quotes": ["error", "prefer-single"],
"semi": [1, "never"],
"max-len": 0,
"import/no-named-as-default": 0,
"import/no-named-as-default-member": 0

"env": {
"es6": true,
"node": true,
"es2020": true
},
"settings": {
"import/resolver": {
"node": {
"moduleDirectory": [
"node_modules",
"lib"
]
}
}

"extends": [
"standard",
"eslint:recommended",
"plugin:promise/recommended",
"plugin:node/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:lodash/recommended",
"plugin:mocha/recommended",
"plugin:jsdoc/recommended"
],

"parserOptions": {
"ecmaVersion": 2020
},
"env": {
"jest": true

"rules": {
"jsdoc/check-tag-names": 0,
"jsdoc/no-undefined-types": 0,
"no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 1 }],
"promise/no-callback-in-promise": 0,
"lodash/prefer-lodash-method": 0,
"lodash/prefer-noop": 0,
"lodash/prefer-constant": 0,
"node/no-unpublished-require": 0,
"mocha/no-mocha-arrows": 0,
"mocha/no-setup-in-describe": 0,
"mocha/no-skipped-tests": 0
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ todo
package-lock.json
.env
dist/
tags
.nyc_output
coverage
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 1.0.10
- meta: bump deps
- meta: normalize eslint config
- refactor: improve doclets

# 1.0.9
- meta: bump bignumber.js dep to 9.0.0

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const n = nonce()

### Docs

[Refer to `docs/func_docs.md`](/docs/func_docs.md) for JSDoc-generated API documentation
API documentation can be found in [`docs/reference.md`](docs/reference.md), and
examples in the [`examples`](examples) folder.

### Example: Padding Candles

Expand Down
108 changes: 76 additions & 32 deletions docs/func_docs.md → docs/reference.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
## Modules

<dl>
<dt><a href="#module_bfx-api-node-util">bfx-api-node-util</a></dt>
<dd><p>This module contains minor utilities shared by the Bitfinex Node.JS API
libraries.</p>
</dd>
</dl>

## Functions

<dl>
<dt><a href="#genAuthSig">genAuthSig(apiSecret, payload)</a> ⇒ <code>Object</code></dt>
<dt><a href="#genAuthSig">genAuthSig(secret, [payload])</a> ⇒ <code><a href="#AuthSignature">AuthSignature</a></code></dt>
<dd><p>Generates an auth signature, payload, and nonce for passing to the WS &amp; REST
APIs</p>
</dd>
<dt><a href="#isClass">isClass(f)</a> ⇒ <code>boolean</code></dt>
<dd></dd>
<dd><p>Query if the provided argument is a class</p>
</dd>
<dt><a href="#isSnapshot">isSnapshot(msg)</a> ⇒ <code>boolean</code></dt>
<dd></dd>
<dd><p>Query if the provided message is a websocket snapshot packet</p>
</dd>
<dt><a href="#nonce">nonce()</a> ⇒ <code>number</code></dt>
<dd><p>Generates a new nonce for usage with the Bitfinex APIs</p>
</dd>
<dt><a href="#padCandles">padCandles(candles, candleWidth)</a> ⇒ <code>Array.&lt;Array&gt;</code></dt>
<dd><p>Fills in missing (0 volume) candles on the provided dataset. The result is a
new array (does not mutate)</p>
</dd>
<dt><a href="#setSigFig">setSigFig(n, maxSigs)</a> ⇒ <code>string</code></dt>
<dt><a href="#setSigFig">setSigFig(number, [maxSigs])</a> ⇒ <code>string</code></dt>
<dd><p>Smartly set the precision (decimal) on a value based off of the significant
digit maximum. For example, calling with 3.34 when the max sig figs allowed
is 5 would return &#39;3.3400&#39;, the representation number of decimals IF they
weren&#39;t zeros.</p>
</dd>
<dt><a href="#setPrecision">setPrecision(number, decimals)</a> ⇒ <code>string</code></dt>
<dt><a href="#setPrecision">setPrecision(number, [decimals])</a> ⇒ <code>string</code></dt>
<dd><p>Casts the provided value to a number if required, and limits the number of
decimals to the specified value. Returns a decimal string.</p>
</dd>
Expand All @@ -34,39 +45,58 @@ decimals to the specified value. Returns a decimal string.</p>
</dd>
</dl>

## Typedefs

<dl>
<dt><a href="#AuthSignature">AuthSignature</a> : <code>object</code></dt>
<dd><p>Authorization signature for WS &amp; REST APIs.</p>
</dd>
</dl>

<a name="module_bfx-api-node-util"></a>

## bfx-api-node-util
This module contains minor utilities shared by the Bitfinex Node.JS API
libraries.

**License**: MIT
<a name="genAuthSig"></a>

## genAuthSig(apiSecret, payload) ⇒ <code>Object</code>
## genAuthSig(secret, [payload]) ⇒ [<code>AuthSignature</code>](#AuthSignature)
Generates an auth signature, payload, and nonce for passing to the WS & REST
APIs

**Kind**: global function
**Returns**: <code>Object</code> - authSignature
**Returns**: [<code>AuthSignature</code>](#AuthSignature) - authSignature

| Param | Type | Description |
| --- | --- | --- |
| apiSecret | <code>string</code> | |
| payload | <code>string</code> | optional signature payload, generated by default |
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| secret | <code>string</code> | | API secret |
| [payload] | <code>string</code> | <code>&quot;&#x27;&#x27;&quot;</code> | signature payload, generated by default |

<a name="isClass"></a>

## isClass(f) ⇒ <code>boolean</code>
Query if the provided argument is a class

**Kind**: global function
**Returns**: <code>boolean</code> - isClass

| Param | Type |
| --- | --- |
| f | <code>Class</code> |
| Param | Type | Description |
| --- | --- | --- |
| f | <code>function</code> | function to check |

<a name="isSnapshot"></a>

## isSnapshot(msg) ⇒ <code>boolean</code>
Query if the provided message is a websocket snapshot packet

**Kind**: global function
**Returns**: <code>boolean</code> - isSnapshot

| Param | Type |
| --- | --- |
| msg | <code>Array</code> \| <code>Array.&lt;Array&gt;</code> |
| Param | Type | Description |
| --- | --- | --- |
| msg | <code>Array</code> \| <code>Array.&lt;Array&gt;</code> | message |

<a name="nonce"></a>

Expand All @@ -91,7 +121,7 @@ new array (does not mutate)

<a name="setSigFig"></a>

## setSigFig(n, maxSigs) ⇒ <code>string</code>
## setSigFig(number, [maxSigs]) ⇒ <code>string</code>
Smartly set the precision (decimal) on a value based off of the significant
digit maximum. For example, calling with 3.34 when the max sig figs allowed
is 5 would return '3.3400', the representation number of decimals IF they
Expand All @@ -100,24 +130,24 @@ weren't zeros.
**Kind**: global function
**Returns**: <code>string</code> - str

| Param | Type | Description |
| --- | --- | --- |
| n | <code>number</code> | |
| maxSigs | <code>number</code> | default 5 |
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| number | <code>number</code> | <code>0</code> | number |
| [maxSigs] | <code>number</code> | <code>5</code> | max significant figures |

<a name="setPrecision"></a>

## setPrecision(number, decimals) ⇒ <code>string</code>
## setPrecision(number, [decimals]) ⇒ <code>string</code>
Casts the provided value to a number if required, and limits the number of
decimals to the specified value. Returns a decimal string.

**Kind**: global function
**Returns**: <code>string</code> - result

| Param | Type | Default |
| --- | --- | --- |
| number | <code>number</code> \| <code>string</code> | <code>0</code> |
| decimals | <code>number</code> | <code>0</code> |
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| number | <code>number</code> \| <code>string</code> | <code>0</code> | number |
| [decimals] | <code>number</code> | <code>0</code> | decimal precision |

<a name="prepareAmount"></a>

Expand All @@ -127,9 +157,9 @@ Prepares a amount for submitting via the API
**Kind**: global function
**Returns**: <code>string</code> - preparedAmount

| Param | Type | Default |
| --- | --- | --- |
| amount | <code>number</code> \| <code>string</code> | <code>0</code> |
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| amount | <code>number</code> \| <code>string</code> | <code>0</code> | amount |

<a name="preparePrice"></a>

Expand All @@ -139,7 +169,21 @@ Prepares a price for submitting via the API
**Kind**: global function
**Returns**: <code>string</code> - preparedPrice

| Param | Type | Default |
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| price | <code>number</code> \| <code>string</code> | <code>0</code> | price |

<a name="AuthSignature"></a>

## AuthSignature : <code>object</code>
Authorization signature for WS & REST APIs.

**Kind**: global typedef
**Properties**

| Name | Type | Description |
| --- | --- | --- |
| price | <code>number</code> \| <code>string</code> | <code>0</code> |
| payload | <code>string</code> | request payload, default 'AUTH${nonce}${nonce}'' |
| sig | <code>string</code> | signature in hexadecimal |
| nonce | <code>number</code> | used nonce |

8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ const isSnapshot = require('./lib/is_snapshot')
const isClass = require('./lib/is_class')
const padCandles = require('./lib/pad_candles')

/**
* This module contains minor utilities shared by the Bitfinex Node.JS API
* libraries.
*
* @license MIT
* @module bfx-api-node-util
*/

module.exports = {
...precision,
nonce,
Expand Down
17 changes: 14 additions & 3 deletions lib/gen_auth_sig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@
const crypto = require('crypto')
const getNonce = require('./nonce')

/**
* Authorization signature for WS & REST APIs.
*
* @typedef {object} AuthSignature
* @property {string} payload - request payload, default
* 'AUTH${nonce}${nonce}''
* @property {string} sig - signature in hexadecimal
* @property {number} nonce - used nonce
*/

/**
* Generates an auth signature, payload, and nonce for passing to the WS & REST
* APIs
* @param {string} apiSecret
* @param {string?} payload - optional signature payload, generated by default
* @return {Object} authSignature
*
* @param {string} secret - API secret
* @param {string} [payload=''] - signature payload, generated by default
* @returns {AuthSignature} authSignature
*/
const genAuthSig = (secret, payload = '') => {
const nonce = getNonce()
Expand Down
18 changes: 10 additions & 8 deletions lib/is_class.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
'use strict'

const _isFunction = require('lodash/isFunction')

/**
* @param {Class} f
* @return {boolean} isClass
* Query if the provided argument is a class
*
* @param {Function} f - function to check
* @returns {boolean} isClass
*/
const isClass = (f) => {
return (
(typeof f === 'function') &&
(/^class\s/.test(Function.prototype.toString.call(f)))
)
}
const isClass = f => (
_isFunction(f) &&
(/^class\s/.test(Function.prototype.toString.call(f)))
)

module.exports = isClass
10 changes: 7 additions & 3 deletions lib/is_snapshot.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
'use strict'

const _isArray = require('lodash/isArray')

/**
* @param {Array|Array[]} msg
* @return {boolean} isSnapshot
* Query if the provided message is a websocket snapshot packet
*
* @param {Array|Array[]} msg - message
* @returns {boolean} isSnapshot
*/
const isSnapshot = msg => msg[0] && Array.isArray(msg[0])
const isSnapshot = msg => msg[0] && _isArray(msg[0])

module.exports = isSnapshot
Loading