Socket
Socket
Sign inDemoInstall

bfx-api-node-rest

Package Overview
Dependencies
60
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.1.0 to 4.0.0

4

DOCUMENTATION.md

@@ -63,6 +63,2 @@ # Bitfinex RESTv1 & RESTv2 APIs for Node.JS

### NOTE: v1 REST and WS clients
Both v1 client classes & server APIs have been deprecated, and will be removed. In the meantime, some methods available via `RESTv1` have been exposed on `RESTv2` to prevent future migration issues. Although the underlying implementation of these methods is likely to change once they are fully ported to v2, the signatures should remain the same.
## FAQ

@@ -69,0 +65,0 @@

144

lib/rest2.js

@@ -40,7 +40,9 @@ 'use strict'

PulseMessage,
Invoice
Invoice,
SymbolDetails,
TransactionFee,
AccountSummary,
AuthPermission
} = require('bfx-api-node-models')
const RESTv1 = require('./rest1')
const BASE_TIMEOUT = 15000

@@ -95,5 +97,2 @@ const API_URL = 'https://api.bitfinex.com'

this._affCode = opts.affCode
// Used for methods that are not yet implemented on REST v2
this._rest1 = new RESTv1(opts)
}

@@ -208,41 +207,2 @@

/**
* Legacy REST1 public method wrapper, that also provides legacy cb
* support. Oh my!
*
* @deprecated
* @param {string} method - REST1 method name
* @param {Function?} [cb] - optional legacy cb
* @returns {Promise} p - use this
* @private
*/
_makePublicLegacyRequest (method, cb) {
return new Promise((resolve, reject) => {
this._rest1.make_public_request(method, (err, data) => {
return this._cb(err, data, cb) // eslint-disable-line
.then(resolve)
.catch(reject)
})
})
}
/**
* See _makePublicLegacyRequest
*
* @param {string} method - method (i.e. GET)
* @param {?object} params - params
* @param {Function?} [cb] - callback
* @returns {Promise} p
* @private
*/
_makeAuthLegacyRequest (method, params = {}, cb) {
return new Promise((resolve, reject) => {
this._rest1.make_request(method, params, (err, data) => {
return this._cb(err, data, cb) // eslint-disable-line
.then(resolve)
.catch(reject)
})
})
}
/**
* @param {object} data

@@ -433,3 +393,3 @@ * @param {object|Function} transformer - model class or function

*/
status (cb = () => {}) {
status (cb = () => { }) {
return this._makePublicRequest('/platform/status', cb)

@@ -557,3 +517,3 @@ }

*/
conf (keys = [], cb = () => {}) {
conf (keys = [], cb = () => { }) {
if (_isEmpty(keys)) {

@@ -574,3 +534,3 @@ return Promise.resolve([])

*/
currencies (cb = () => {}) {
currencies (cb = () => { }) {
const suffix = (this._company) ? ':' + this._company : ''

@@ -1087,3 +1047,3 @@ const url = `/conf/${[

*/
symbols (cb = () => {}) {
symbols (cb = () => { }) {
const url = '/conf/pub:list:pair:exchange'

@@ -1102,3 +1062,3 @@ return this._makePublicRequest(url, cb, (data) => {

*/
inactiveSymbols (cb = () => {}) {
inactiveSymbols (cb = () => { }) {
const url = '/conf/pub:list:pair:exchange:inactive'

@@ -1117,3 +1077,3 @@ return this._makePublicRequest(url, cb, (data) => {

*/
futures (cb = () => {}) {
futures (cb = () => { }) {
const url = '/conf/pub:list:pair:futures'

@@ -1147,19 +1107,11 @@ return this._makePublicRequest(url, cb, (data) => {

* @returns {Promise} p
* @deprecated
* @see https://docs.bitfinex.com/v1/reference#rest-public-symbol-details
* @see https://docs.bitfinex.com/reference#rest-public-conf
*/
symbolDetails (cb) {
return this._makePublicLegacyRequest('symbols_details', cb)
}
const url = '/conf/pub:info:pair'
const transformer = (data) => {
return data && this._classTransform(data[0], SymbolDetails)
}
/**
* Request information about your account
*
* @param {Function} [cb] - callback
* @returns {Promise} p
* @deprecated
* @see https://docs.bitfinex.com/v1/reference#rest-auth-account-info
*/
accountInfo (cb) {
return this._makeAuthLegacyRequest('account_infos', {}, cb)
return this._makePublicRequest(url, cb, transformer)
}

@@ -1172,7 +1124,10 @@

* @returns {Promise} p
* @deprecated
* @see https://docs.bitfinex.com/v1/reference#rest-auth-fees
*/
accountFees (cb) {
return this._makeAuthLegacyRequest('account_fees', {}, cb)
const url = '/conf/pub:map:currency:tx:fee'
const transformer = (data) => {
return data && this._classTransform(data[0], TransactionFee)
}
return this._makePublicRequest(url, cb, transformer)
}

@@ -1186,35 +1141,20 @@

* @returns {Promise} p
* @see https://docs.bitfinex.com/v1/reference#rest-auth-summary
* @see https://docs.bitfinex.com/reference#rest-auth-summary
*/
accountSummary (cb) {
const url = '/auth/r/int/summary'
const pickSummary = (res) => res && res[0] && res[0].summary
return this._makeAuthRequest(url, { }, cb, pickSummary)
const url = '/auth/r/summary'
return this._makeAuthRequest(url, {}, cb, AccountSummary)
}
/**
* Fetch the permissions of the key being used to generate this request
* Fetch the permissions of the key or token being used to generate this request
*
* @param {Function} [cb] - callback
* @returns {Promise} p
* @deprecated
* @see https://docs.bitfinex.com/v1/reference#auth-key-permissions
*/
keyPermissions (cb) {
return this._makeAuthLegacyRequest('key_info', {}, cb)
return this._makeAuthRequest('/auth/r/permissions', {}, cb, AuthPermission)
}
/**
* Request your wallet balances
*
* @param {Function} [cb] - callback
* @returns {Promise} p
* @deprecated
* @see https://docs.bitfinex.com/v1/reference#rest-auth-wallet-balances
*/
balances (cb) {
return this._makeAuthLegacyRequest('balances', {}, cb)
}
/**
* @param {object} params - parameters

@@ -1224,7 +1164,29 @@ * @param {number} params.position_id - position ID

* @returns {Promise} p
* @deprecated
* @see https://docs.bitfinex.com/v1/reference#rest-auth-close-position
*
* @see https://docs.bitfinex.com/reference#rest-auth-submit-order
*/
closePosition (params, cb) {
return this._rest1.make_request('positions/close', params, cb)
return this.positions()
.then(res => {
if (!this._transform) {
res = res.map(row => new Position(row, this))
}
const position = res.find(p => p.id === params.position_id && p.status === 'ACTIVE')
if (!position) throw new Error('position not found')
return position
})
.then(position => {
const order = new Order({
type: Order.type.MARKET,
symbol: position.symbol,
amount: position.amount * -1,
flags: Order.flags.POS_CLOSE
})
return this.submitOrder(order)
})
.then(res => this._cb(null, res, cb))
.catch(err => this._cb(err, null, cb))
}

@@ -1231,0 +1193,0 @@

{
"name": "bfx-api-node-rest",
"version": "3.1.0",
"version": "4.0.0",
"description": "Official Bitfinex REST v1 & v2 API interfaces",

@@ -18,3 +18,3 @@ "engines": {

"unit": "NODE_ENV=test nyc --check-coverage --lines 45 --branches 19 --functions 39 --statements 44 --reporter=lcov --reporter=html mocha -b --recursive",
"docs": "rm -rf docs && node_modules/.bin/jsdoc --configure .jsdoc.json --verbose"
"docs": "rm -rf docs && jsdoc --configure .jsdoc.json --verbose"
},

@@ -39,3 +39,4 @@ "repository": {

"Jacob Plaster <jacob.plaster@bitfinex.com> (https://www.bitfinex.com)",
"Abhishek Shrestha <abhishek.shrestha@bitfinex.com> (https://www.bitfinex.com)"
"Abhishek Shrestha <abhishek.shrestha@bitfinex.com> (https://www.bitfinex.com)",
"Vigan Abdurrahmani <vigan.abdurrahmani@bitfinex.com> (https://www.bitfinex.com)"
],

@@ -47,8 +48,3 @@ "license": "MIT",

"devDependencies": {
"babel-cli": "^6.26.0",
"babel-eslint": "^10.1.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-regenerator": "^6.26.0",
"babel-preset-env": "^1.7.0",
"bfx-api-mock-srv": "^1.0.12",
"bfx-api-mock-srv": "^1.1.1",
"chai": "^4.2.0",

@@ -76,3 +72,2 @@ "docdash": "^1.2.0",

"bluebird": "^3.5.5",
"copy": "^0.3.2",
"debug": "^4.1.1",

@@ -79,0 +74,0 @@ "lodash": "^4.17.15",

@@ -70,10 +70,2 @@ # Bitfinex RESTv1 & RESTv2 APIs for Node.JS

### NOTE: v1 REST and WS clients
Both v1 client classes & server APIs have been deprecated, and will be removed.
In the meantime, some methods available via `RESTv1` have been exposed on
`RESTv2` to prevent future migration issues. Although the underlying
implementation of these methods is likely to change once they are fully ported
to v2, the signatures should remain the same.
## FAQ

@@ -80,0 +72,0 @@

@@ -7,2 +7,3 @@ /* eslint-env mocha */

const { MockRESTv2Server } = require('bfx-api-mock-srv')
const { Order } = require('bfx-api-node-models')

@@ -151,3 +152,7 @@ const getTestREST2 = (args = {}) => {

['cancelOrderMulti', 'cancel_order_multi.123', [{ id: [123] }]],
['orderMultiOp', 'order_multi_op', [[[]]]]
['orderMultiOp', 'order_multi_op', [[[]]]],
['accountSummary', 'account_summary', []],
['symbolDetails', 'info_pairs', []],
['submitOrder', 'order_submit', [new Order({ type: 'EXCHANGE_MARKET', symbol: 'tBTCUST', price: 17832, amount: 0.3 })]],
['keyPermissions', 'auth_permissions', []]
]

@@ -207,2 +212,119 @@

})
it('correctly parses accountSummary response', async () => {
srv = new MockRESTv2Server({ listen: true })
const r = getTestREST2({ transform: true })
srv.setResponse('account_summary', [
null, null, null, null,
[
[0.001, 0.001, 0.001, null, null, -0.0002],
[0.002, 0.0021, 0.0022, null, null, 0.00075]
],
null, null, null, null,
{ leo_lev: 0, leo_amount_avg: 0.002 }
])
const summary = await r.accountSummary()
assert.strictEqual(summary.makerFee, 0.001)
assert.strictEqual(summary.derivMakerRebate, -0.0002)
assert.strictEqual(summary.takerFeeToCrypto, 0.002)
assert.strictEqual(summary.takerFeeToStable, 0.0021)
assert.strictEqual(summary.takerFeeToFiat, 0.0022)
assert.strictEqual(summary.derivTakerFee, 0.00075)
assert.strictEqual(summary.leoLev, 0)
assert.strictEqual(summary.leoAmountAvg, 0.002)
})
it('correctly parses symbolDetails response', async () => {
srv = new MockRESTv2Server({ listen: true })
const r = getTestREST2({ transform: true })
srv.setResponse('info_pairs', [
[
['BTCUSD', [null, null, null, '0.0002', '2002.0', null, null, null, 0.2, 0.1]],
['BTCEUR', [null, null, null, '0.00021', '2000.0', null, null, null, null, null]]
]
])
const details = await r.symbolDetails()
assert.strictEqual(details[0].pair, 'BTCUSD')
assert.strictEqual(details[0].initialMargin, 0.2)
assert.strictEqual(details[0].minimumMargin, 0.1)
assert.strictEqual(details[0].maximumOrderSize, '2002.0')
assert.strictEqual(details[0].minimumOrderSize, '0.0002')
assert.strictEqual(details[0].margin, true)
assert.strictEqual(details[1].pair, 'BTCEUR')
assert.strictEqual(details[1].initialMargin, null)
assert.strictEqual(details[1].minimumMargin, null)
assert.strictEqual(details[1].maximumOrderSize, '2000.0')
assert.strictEqual(details[1].minimumOrderSize, '0.00021')
assert.strictEqual(details[1].margin, false)
})
it('correctly parses keyPermissions response', async () => {
srv = new MockRESTv2Server({ listen: true })
const r = getTestREST2({ transform: true })
srv.setResponse('auth_permissions', [
['account', 0, 0],
['orders', 1, 0],
['funding', 0, 1],
['settings', 1, 1]
])
const perms = await r.keyPermissions()
assert.strictEqual(perms[0].key, 'account')
assert.strictEqual(perms[0].read, false)
assert.strictEqual(perms[0].write, false)
assert.strictEqual(perms[1].key, 'orders')
assert.strictEqual(perms[1].read, true)
assert.strictEqual(perms[1].write, false)
assert.strictEqual(perms[2].key, 'funding')
assert.strictEqual(perms[2].read, false)
assert.strictEqual(perms[2].write, true)
assert.strictEqual(perms[3].key, 'settings')
assert.strictEqual(perms[3].read, true)
assert.strictEqual(perms[3].write, true)
})
it('correctly executes closePosition method', async () => {
srv = new MockRESTv2Server({ listen: true })
const r = getTestREST2({ transform: true })
const orderRes = [
54866913445, null, 1607956105914, 'tBTCUST',
1607956106828, 1607956106828, -20, -20, 'MARKET', null,
null, null, 512, 'ACTIVE (note:POSCLOSE)', null, null,
19107, 0, 0, 0, null, null, null, 0, 0, null, null, null,
'API>BFX', null, null, null
]
srv.setResponse('positions', [
[
'tBTCUST', 'ACTIVE', 20, 19112.589492392, 0, 0, -896.029847839973, -0.034477234990170615,
13768.237954491486, 1.757758329330831, null, 145287699, null, null, null, 0, null, 0, 0,
{
reason: 'TRADE',
order_id: 54864866189,
order_id_oppo: 54866447371,
liq_stage: null,
trade_price: '19119.0',
trade_amount: '0.59455843'
}
]
])
srv.setResponse('order_submit', [
1567590617.442, 'on-req', 1235, null, [orderRes],
null, 'SUCCESS', 'Submitting1 orders.'
])
const order = await r.closePosition({ position_id: 145287699 })
assert.deepStrictEqual(order, orderRes)
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc