New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

bitfinex-api-node

Package Overview
Dependencies
Maintainers
4
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitfinex-api-node - npm Package Compare versions

Comparing version
4.0.16
to
5.0.0
+24
examples/rest2/key_permissions.js
'use strict'
const runExample = require('../util/run_example')
module.exports = runExample({
name: 'rest-key-permissions',
rest: {
env: true,
transform: true
}
}, async ({ debug, debugTable, rest }) => {
debug('fetching permissions')
const perms = await rest.keyPermissions()
const rows = perms.map(({ key, read, write }) => [
key.toUpperCase(), read ? 'Y' : 'N', write ? 'Y' : 'N'
])
debugTable({
rows,
headers: ['Scope', 'Read', 'Write']
})
})
'use strict'
const { PulseMessage } = require('bfx-api-node-models')
const runExample = require('../util/run_example')
module.exports = runExample({
name: 'rest-pulse',
rest: { env: true, transform: true }
}, async ({ debug, debugTable, rest }) => {
debug('gettting pulse history..')
const pulseHistRes = await rest.pulseHistory()
debug('pulse history response')
debugTable({
headers: [
'PID', 'MTS', 'PUID', 'TITLE', 'CONTENT', 'COMMENTS'
],
rows: pulseHistRes.map(({ id, mts, userID, title, content, comments }) => [
id,
new Date(mts).toLocaleString(),
userID,
(title && title.substring(0, 15)) || '-',
content.substring(0, 15),
comments // number of comments
])
})
const pulseMsg = new PulseMessage({
title: 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
content: 'Contrary to popular belief, Lorem Ipsum is not simply random text.',
isPublic: 0,
isPin: 1
})
debug('submitting pulse message: %s', pulseMsg.toString())
let pulse
try {
pulse = await rest.addPulse(pulseMsg)
} catch (e) {
return debug('pulse message submittion failed: %s', e.message)
}
debug('pulse message submission response')
debugTable({
headers: [
'PID', 'MTS', 'PUID', 'TITLE', 'CONTENT'
],
rows: [[
pulse.id,
new Date(pulse.mts).toLocaleString(),
pulse.userID,
(pulse.title && pulse.title.substring(0, 15)) || '-',
pulse.content.substring(0, 15)
]]
})
const pulseComment = new PulseMessage({
parent: pulse.id,
content: 'No more seven warlords of the sea',
isPublic: 0,
isPin: 1
})
debug('submitting pulse comment: %s', pulseComment.toString())
let comment
try {
comment = await rest.addPulseComment(pulseComment)
} catch (e) {
return debug('pulse comment submittion failed: %s', e.message)
}
debug('pulse comment submission response')
debugTable({
headers: [
'PID', 'MTS', 'PARENT', 'PUID', 'COMMENT'
],
rows: [[
comment.id,
new Date(comment.mts).toLocaleString(),
comment.parent,
comment.userID,
comment.content.substring(0, 15)
]]
})
debug('gettting pulse comments..')
const pulseComments = await rest.fetchPulseComments({
parent: pulse.id,
isPublic: 0, // 0 for comments made by you; 1 for all comments of the pulse
limit: 3, // fetch given number of comments for this pulse
end: 0 // fetch comments from a given starttime in milliseconds
})
debug('pulse comments response')
debugTable({
headers: [
'PID', 'MTS', 'PUID', 'COMMENT'
],
rows: pulseComments.map(({ id, mts, userID, content }) => [
id,
new Date(mts).toLocaleString(),
userID,
content.substring(0, 15)
])
})
})
'use strict'
const _uniq = require('lodash/uniq')
const _capitalize = require('lodash/capitalize')
const _isFinite = require('lodash/isFinite')
const _isEmpty = require('lodash/isEmpty')
const { prepareAmount } = require('bfx-api-node-util')
const runExample = require('../util/run_example')
module.exports = runExample({
name: 'rest-wallets',
rest: {
env: true,
transform: true
},
params: {
hideZeroBalances: true,
filterByType: false,
filterByCurrency: false,
valueCCY: 'USD'
}
}, async ({ debug, debugTable, rest, params }) => {
const {
valueCCY, hideZeroBalances, filterByType, filterByCurrency
} = params
const symbolForWallet = w => `t${w.currency}${valueCCY}`
debug('fetching balances')
const allWallets = await rest.wallets() // actual balance fetch
const balances = allWallets.filter(w => !( // filter as requested
(hideZeroBalances && +w.balance === 0) ||
(!_isEmpty(filterByType) && (w.type.toLowerCase() !== filterByType.toLowerCase())) ||
(!_isEmpty(filterByCurrency) && (w.currency.toLowerCase() !== filterByCurrency.toLowerCase()))
)).map(w => ({
...w,
currency: w.currency.toUpperCase(),
inValueCurrency: w.currency.toUpperCase() === valueCCY
}))
if (balances.length === 0) {
return debug('no wallets match provided filters')
}
debug('found %d balances', balances.length)
// Pull in ticker data for balances which are not in the requested value ccy
// Balance in BTC, value in USD -> We need to fetch tBTCUSD (last price)
const lastPrices = {}
const balancesToConvert = balances.filter(w => w.currency !== valueCCY)
const symbols = _uniq(balancesToConvert.map(symbolForWallet))
if (symbols.length > 0) {
debug('fetching tickers for: %s', symbols.join(', '))
const tickers = await rest.tickers(symbols)
tickers.forEach(({ symbol, lastPrice }) => (lastPrices[symbol] = +lastPrice))
}
let totalValue = 0
const rows = balances.map(({ currency, type, balance, balanceAvailable }) => {
const value = currency !== valueCCY
? (lastPrices[symbolForWallet({ currency })] * +balance) || 0
: +balance
totalValue += value
return [
_capitalize(type),
currency,
prepareAmount(balance),
prepareAmount(balanceAvailable),
...(_isFinite(value) ? [
prepareAmount(value),
currency !== valueCCY
? prepareAmount(lastPrices[symbolForWallet({ currency })])
: 1
] : [
'-',
'-'
])
]
})
debugTable({
rows,
headers: [
'Type', 'Symbol', 'Total', 'Available', `Value (${valueCCY})`,
`Unit Price (${valueCCY})`
]
})
debug('total value: %d %s', prepareAmount(totalValue), valueCCY)
})
+7
-0

@@ -0,1 +1,8 @@

5.0.0
- upgrade: upgraded bfx-api-node-rest to 4.0.0, breaks previous versions compatibility
- fix: jsdocs
4.0.17
- added pulse examples
4.0.16

@@ -2,0 +9,0 @@ - fix: unsubscribe fails depending on channel id type

+1
-1

@@ -487,3 +487,3 @@ <!DOCTYPE html>

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Tue Mar 10 2020 21:05:28 GMT+0700 (Indochina Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.6</a> on Mon Jan 25 2021 16:36:37 GMT+0100 (Central European Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

@@ -490,0 +490,0 @@

@@ -80,5 +80,5 @@ <!DOCTYPE html>

<h3>Docs</h3>
<p><a href="/docs/ws2.md">See <code>docs/ws2.md</code></a> for WS2 API methods,
<a href="/docs/usage.md">and <code>docs/usage.md</code></a> for a basic usage guide. For executable
examples, <a href="/examples">refer to the <code>examples/</code></a> folder.</p>
<p>Refer to the <a href="https://cdn.statically.io/gh/bitfinexcom/bitfinex-api-node/master/docs/index.html"><code>docs/</code></a>
folder for JSDoc-generated HTML documentation, and the <a href="/examples"><code>examples/</code></a>
folder for executable examples covering common use cases.</p>
<p>Official API documentation at <a href="https://docs.bitfinex.com/v2/reference">https://docs.bitfinex.com/v2/reference</a></p>

@@ -240,3 +240,3 @@ <h3>Examples</h3>

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Tue Mar 10 2020 21:05:28 GMT+0700 (Indochina Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.6</a> on Mon Jan 25 2021 16:36:37 GMT+0100 (Central European Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

@@ -243,0 +243,0 @@

@@ -106,3 +106,3 @@ <!DOCTYPE html>

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Tue Mar 10 2020 21:05:28 GMT+0700 (Indochina Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.6</a> on Mon Jan 25 2021 16:36:37 GMT+0100 (Central European Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

@@ -109,0 +109,0 @@

@@ -72,3 +72,3 @@ <!DOCTYPE html>

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Tue Mar 10 2020 21:05:28 GMT+0700 (Indochina Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.6</a> on Mon Jan 25 2021 16:36:37 GMT+0100 (Central European Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

@@ -75,0 +75,0 @@

@@ -71,3 +71,3 @@ <!DOCTYPE html>

* @example
* const rest = new RESTv2()
* const rest = new RESTv2({ transform: true })
* const details = await rest.symbolDetails()

@@ -130,4 +130,4 @@ * const symbols = details.map(d => `t${d.pair.toUpperCase()}`)

* @param {object} [authArgs] - cached for all internal socket auth() calls
* @param {object} [authArgs.calc] - default 0
* @param {object} [authArgs.dms] - default 0
* @param {number} [authArgs.calc] - default 0
* @param {number} [authArgs.dms] - default 0
*/

@@ -151,4 +151,4 @@ constructor (socketArgs, authArgs = { calc: 0, dms: 0 }) {

* @param {object} args - arguments
* @param {object} [args.calc] - calc value
* @param {object} [args.dms] - active 4
* @param {number} [args.calc] - calc value
* @param {number} [args.dms] - active 4
*/

@@ -235,6 +235,6 @@ setAuthArgs (args = {}) {

* @param {object} args - arguments
* @param {object} args.apiKey - saved if not already provided
* @param {object} args.apiSecret - saved if not already provided
* @param {object} [args.calc] - default 0
* @param {object} [args.dms] - dead man switch, active 4
* @param {string} args.apiKey - saved if not already provided
* @param {string} args.apiSecret - saved if not already provided
* @param {number} [args.calc] - default 0
* @param {number} [args.dms] - dead man switch, active 4
*/

@@ -623,3 +623,3 @@ auth ({ apiKey, apiSecret, calc, dms } = {}) {

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Tue Mar 10 2020 21:05:28 GMT+0700 (Indochina Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.6</a> on Mon Jan 25 2021 16:36:37 GMT+0100 (Central European Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

@@ -626,0 +626,0 @@

@@ -7,3 +7,3 @@ 'use strict'

name: 'rest-get-symbol-details',
rest: true
rest: { transform: true }
}, async ({ rest, debug, debugTable }) => {

@@ -16,3 +16,3 @@ debug('fetching symbol details...')

headers: [
'Pair', 'Precision', 'Initial Margin', 'Min Margin', 'Max Order',
'Pair', 'Initial Margin', 'Min Margin', 'Max Order',
'Min Order', 'Margin'

@@ -22,9 +22,9 @@ ],

rows: details.map(({
pair, price_precision, initial_margin, minimum_margin, // eslint-disable-line
maximum_order_size, minimum_order_size, margin // eslint-disable-line
pair, initialMargin, minimumMargin, // eslint-disable-line
maximumOrderSize, minimumOrderSize, margin // eslint-disable-line
}) => [
pair.toUpperCase(), price_precision, initial_margin, minimum_margin, // eslint-disable-line
maximum_order_size, minimum_order_size, margin ? 'Y' : 'N' // eslint-disable-line
pair.toUpperCase(), initialMargin, minimumMargin, // eslint-disable-line
maximumOrderSize, minimumOrderSize, margin ? 'Y' : 'N' // eslint-disable-line
])
})
})

@@ -11,2 +11,3 @@ 'use strict'

module.exports = runExample({
name: 'ws2-manger',
rest: { transform: true }

@@ -13,0 +14,0 @@ }, async ({ rest, env }) => {

+12
-12

@@ -13,10 +13,10 @@ 'use strict'

/**
* @param {object} opts - options
* @param {string} opts.apiKey - API key
* @param {string} opts.apiSecret - API secret
* @param {string} opts.authToken - optional auth option
* @param {string} opts.transform - if true, packets are converted to models
* @param {string} opts.nonceGenerator - optional
* @param {string} opts.ws - ws transport options
* @param {string} opts.rest - rest transport options
* @param {object} [opts] - options
* @param {string} [opts.apiKey] - API key
* @param {string} [opts.apiSecret] - API secret
* @param {string} [opts.authToken] - optional auth option
* @param {string} [opts.company] - optional auth option
* @param {boolean} [opts.transform] - if true, packets are converted to models
* @param {object} [opts.ws] - ws transport options
* @param {object} [opts.rest] - rest transport options
*/

@@ -72,4 +72,4 @@ constructor (opts = {

*
* @param {number} version - 1 or 2 (default)
* @param {object} extraOpts - passed to transport constructor
* @param {number} [version] - 1 or 2 (default)
* @param {object} [extraOpts] - passed to transport constructor
* @returns {RESTv1|RESTv2} transport

@@ -99,4 +99,4 @@ */

*
* @param {number} version - 1 or 2 (default)
* @param {object} extraOpts - passed to transport constructor
* @param {number} [version] - 1 or 2 (default)
* @param {object} [extraOpts] - passed to transport constructor
* @returns {WSv1|WSv2} transport

@@ -103,0 +103,0 @@ */

@@ -27,3 +27,3 @@ 'use strict'

* @example
* const rest = new RESTv2()
* const rest = new RESTv2({ transform: true })
* const details = await rest.symbolDetails()

@@ -86,4 +86,4 @@ * const symbols = details.map(d => `t${d.pair.toUpperCase()}`)

* @param {object} [authArgs] - cached for all internal socket auth() calls
* @param {object} [authArgs.calc] - default 0
* @param {object} [authArgs.dms] - default 0
* @param {number} [authArgs.calc] - default 0
* @param {number} [authArgs.dms] - default 0
*/

@@ -107,4 +107,4 @@ constructor (socketArgs, authArgs = { calc: 0, dms: 0 }) {

* @param {object} args - arguments
* @param {object} [args.calc] - calc value
* @param {object} [args.dms] - active 4
* @param {number} [args.calc] - calc value
* @param {number} [args.dms] - active 4
*/

@@ -191,6 +191,6 @@ setAuthArgs (args = {}) {

* @param {object} args - arguments
* @param {object} args.apiKey - saved if not already provided
* @param {object} args.apiSecret - saved if not already provided
* @param {object} [args.calc] - default 0
* @param {object} [args.dms] - dead man switch, active 4
* @param {string} args.apiKey - saved if not already provided
* @param {string} args.apiSecret - saved if not already provided
* @param {number} [args.calc] - default 0
* @param {number} [args.dms] - dead man switch, active 4
*/

@@ -197,0 +197,0 @@ auth ({ apiKey, apiSecret, calc, dms } = {}) {

{
"name": "bitfinex-api-node",
"version": "4.0.16",
"version": "5.0.0",
"description": "Node reference library for Bitfinex API",

@@ -36,3 +36,4 @@ "engines": {

"Simone Poggi <simone@bitfinex.com> (https://www.bitfinex.com)",
"Paolo Ardoino <paolo@bitfinex.com> (https://www.bitfinex.com)"
"Paolo Ardoino <paolo@bitfinex.com> (https://www.bitfinex.com)",
"Abhishek Shrestha <abhishek.shrestha@bitfinex.com> (https://www.bitfinex.com)"
],

@@ -71,4 +72,4 @@ "license": "MIT",

"cli-table3": "^0.6.0",
"bfx-api-node-models": "^1.2.1",
"bfx-api-node-rest": "^3.0.8",
"bfx-api-node-models": "^1.3.1",
"bfx-api-node-rest": "^4.0.0",
"bfx-api-node-util": "^1.0.2",

@@ -75,0 +76,0 @@ "bfx-api-node-ws1": "^1.0.0",

'use strict'
const _uniq = require('lodash/uniq')
const _capitalize = require('lodash/capitalize')
const _isFinite = require('lodash/isFinite')
const _isEmpty = require('lodash/isEmpty')
const { prepareAmount } = require('bfx-api-node-util')
const runExample = require('../util/run_example')
module.exports = runExample({
name: 'rest-balances',
rest: {
env: true,
transform: true
},
params: {
hideZeroBalances: true,
filterByType: false,
filterByCurrency: false,
valueCCY: 'USD'
}
}, async ({ debug, debugTable, rest, params }) => {
const {
valueCCY, hideZeroBalances, filterByType, filterByCurrency
} = params
const symbolForWallet = w => `t${w.currency}${valueCCY}`
debug('fetching balances')
const allWallets = await rest.balances() // actual balance fetch
const balances = allWallets.filter(w => !( // filter as requested
(hideZeroBalances && +w.amount === 0) ||
(!_isEmpty(filterByType) && (w.type.toLowerCase() !== filterByType.toLowerCase())) ||
(!_isEmpty(filterByCurrency) && (w.currency.toLowerCase() !== filterByCurrency.toLowerCase()))
)).map(w => ({
...w,
currency: w.currency.toUpperCase(),
inValueCurrency: w.currency.toUpperCase() === valueCCY
}))
if (balances.length === 0) {
return debug('no wallets match provided filters')
}
debug('found %d balances', balances.length)
// Pull in ticker data for balances which are not in the requested value ccy
// Balance in BTC, value in USD -> We need to fetch tBTCUSD (last price)
const lastPrices = {}
const balancesToConvert = balances.filter(w => w.currency !== valueCCY)
const symbols = _uniq(balancesToConvert.map(symbolForWallet))
if (symbols.length > 0) {
debug('fetching tickers for: %s', symbols.join(', '))
const tickers = await rest.tickers(symbols)
tickers.forEach(({ symbol, lastPrice }) => (lastPrices[symbol] = +lastPrice))
}
let totalValue = 0
const rows = balances.map(({ currency, type, amount, available }) => {
const value = currency !== valueCCY
? (lastPrices[symbolForWallet({ currency })] * +amount) || 0
: +amount
totalValue += value
return [
_capitalize(type),
currency,
prepareAmount(amount),
prepareAmount(available),
...(_isFinite(value) ? [
prepareAmount(value),
currency !== valueCCY
? prepareAmount(lastPrices[symbolForWallet({ currency })])
: 1
] : [
'-',
'-'
])
]
})
debugTable({
rows,
headers: [
'Type', 'Symbol', 'Total', 'Available', `Value (${valueCCY})`,
`Unit Price (${valueCCY})`
]
})
debug('total value: %d %s', prepareAmount(totalValue), valueCCY)
})

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display