Socket
Socket
Sign inDemoInstall

bfx-api-node-rest

Package Overview
Dependencies
8
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.2 to 3.0.3

2

package.json
{
"name": "bfx-api-node-rest",
"version": "3.0.2",
"version": "3.0.3",
"description": "Official Bitfinex REST v1 & v2 API interfaces",

@@ -5,0 +5,0 @@ "engines": {

/* eslint-env mocha */
'use strict'
const PORT = 1337
const PORT = 1339

@@ -11,2 +11,15 @@ const assert = require('assert')

describe('rest integration test', () => {
let server = null
afterEach((done) => {
if (server) {
server.close(() => {
server = null
done()
})
} else {
done()
}
})
it('should get the fundingbook asks, zero bids, 100 asks', (done) => {

@@ -16,21 +29,22 @@ const opts = { limit_bids: 0, limit_asks: 10 }

const testResBody = `
{"bids":[],"asks":[
{"rate":"72.25","amount":"67.5","period":30,"timestamp":"1495565109.0","frr":"No"},
{"rate":"72.2501","amount":"297.58737203","period":2,"timestamp":"1495565054.0","frr":"No"},
{"rate":"72.2601","amount":"200.0","period":2,"timestamp":"1495565002.0","frr":"No"},
{"rate":"72.9535","amount":"211.8299","period":2,"timestamp":"1495565037.0","frr":"No"},
{"rate":"73.0","amount":"1319.59397488","period":30,"timestamp":"1495564972.0","frr":"No"},
{"rate":"76.0827","amount":"1511.9115692","period":30,"timestamp":"1495564965.0","frr":"Yes"},
{"rate":"76.0827","amount":"19849.81630455","period":30,"timestamp":"1495564972.0","frr":"Yes"},
{"rate":"76.0827","amount":"1052.68464219","period":30,"timestamp":"1495564972.0","frr":"Yes"},
{"rate":"109.5","amount":"55.33131648","period":3,"timestamp":"1495565103.0","frr":"No"},
{"rate":"153.1999","amount":"134.86","period":2,"timestamp":"1495565106.0","frr":"No"}]}
`
const server = http.createServer((req, res) => {
res.writeHead(200, {
'Content-Type': 'application/json'
})
const testResBody = [
'{"bids":[],"asks":[',
'{"rate":"72.25","amount":"67.5","period":30,"timestamp":"1495565109.0","frr":"No"},',
'{"rate":"72.2501","amount":"297.58737203","period":2,"timestamp":"1495565054.0","frr":"No"},',
'{"rate":"72.2601","amount":"200.0","period":2,"timestamp":"1495565002.0","frr":"No"},',
'{"rate":"72.9535","amount":"211.8299","period":2,"timestamp":"1495565037.0","frr":"No"},',
'{"rate":"73.0","amount":"1319.59397488","period":30,"timestamp":"1495564972.0","frr":"No"},',
'{"rate":"76.0827","amount":"1511.9115692","period":30,"timestamp":"1495564965.0","frr":"Yes"},',
'{"rate":"76.0827","amount":"19849.81630455","period":30,"timestamp":"1495564972.0","frr":"Yes"},',
'{"rate":"76.0827","amount":"1052.68464219","period":30,"timestamp":"1495564972.0","frr":"Yes"},',
'{"rate":"109.5","amount":"55.33131648","period":3,"timestamp":"1495565103.0","frr":"No"},',
'{"rate":"153.1999","amount":"134.86","period":2,"timestamp":"1495565106.0","frr":"No"}]}'
].join('')
server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'application/json' })
res.end(testResBody)
}).listen(PORT, () => {
})
server.listen(PORT, () => {
bhttp.fundingbook('USD', opts, (err, data) => {

@@ -41,3 +55,2 @@ if (err) throw err

assert.strictEqual(data.asks.length, 10)
server.close()
done()

@@ -49,2 +62,3 @@ })

it('new_order -- post_only: postonly used and true', (done) => {
const testResBody = '{}'
const bhttp = new RESTv1({

@@ -56,7 +70,4 @@ apiKey: 'dummykey',

const testResBody = '{}'
const server = http.createServer((req, res) => {
res.writeHead(200, {
'Content-Type': 'application/json'
})
server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'application/json' })
const payload = JSON.parse(

@@ -67,8 +78,7 @@ Buffer.from(req.headers['x-bfx-payload'], 'base64').toString('ascii')

assert.strictEqual(payload.post_only, true)
res.end(testResBody)
}).listen(PORT, () => {
})
server.listen(PORT, () => {
bhttp.new_order('btcusd', '0.1', '0.1', 'bitfinex', 'buy', 'exchange limit', false, true, (err, data) => {
if (err) throw err
server.close()
done()

@@ -80,2 +90,3 @@ })

it('new_order -- post_only: postonly not used and hidden true', (done) => {
const testResBody = '{}'
const bhttp = new RESTv1({

@@ -87,7 +98,4 @@ apiKey: 'dummykey',

const testResBody = '{}'
const server = http.createServer((req, res) => {
res.writeHead(200, {
'Content-Type': 'application/json'
})
server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'application/json' })
const payload = JSON.parse(

@@ -99,8 +107,8 @@ Buffer.from(req.headers['x-bfx-payload'], 'base64').toString('ascii')

assert.strictEqual(payload.post_only, undefined)
res.end(testResBody)
})
res.end(testResBody)
}).listen(PORT, () => {
server.listen(PORT, () => {
bhttp.new_order('btcusd', '0.1', '0.1', 'bitfinex', 'buy', 'exchange limit', true, (err, data) => {
if (err) throw err
server.close()
done()

@@ -112,2 +120,3 @@ })

it('new_order -- post_only: postonly not used and hidden not used', (done) => {
const testResBody = '{}'
const bhttp = new RESTv1({

@@ -119,7 +128,4 @@ apiKey: 'dummykey',

const testResBody = '{}'
const server = http.createServer((req, res) => {
res.writeHead(200, {
'Content-Type': 'application/json'
})
server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'application/json' })
const payload = JSON.parse(

@@ -131,8 +137,7 @@ Buffer.from(req.headers['x-bfx-payload'], 'base64').toString('ascii')

assert.strictEqual(payload.post_only, undefined)
res.end(testResBody)
}).listen(PORT, () => {
})
server.listen(PORT, () => {
bhttp.new_order('btcusd', '0.1', '0.1', 'bitfinex', 'buy', 'exchange limit', (err, data) => {
if (err) throw err
server.close()
done()

@@ -139,0 +144,0 @@ })

@@ -92,2 +92,12 @@ /* eslint-env mocha */

describe('RESTv2 integration (mock server) tests', () => {
let srv = null
afterEach(async () => {
if (srv) {
await srv.close()
}
srv = null
})
// [rest2MethodName, finalMockResponseKey, rest2MethodArgs]

@@ -137,3 +147,3 @@ const methods = [

it(`${name}: fetches expected data`, (done) => {
const srv = new MockRESTv2Server({ listen: true })
srv = new MockRESTv2Server({ listen: true })
const r = getTestREST2()

@@ -144,7 +154,7 @@ srv.setResponse(dataKey, [42])

if (err) {
return srv.close().then(() => done(err)).catch(done)
return done(err)
}
assert.deepStrictEqual(res, [42])
srv.close().then(done).catch(done)
done()
})

@@ -156,4 +166,4 @@

it('correctly parses funding offer response', (done) => {
const srv = new MockRESTv2Server({ listen: true })
it('correctly parses funding offer response', async () => {
srv = new MockRESTv2Server({ listen: true })
const r = getTestREST2({ transform: true })

@@ -163,10 +173,8 @@

r.fundingOffers('fUSD').then(([fo]) => {
auditTestFundingOffer(fo)
return srv.close()
}).then(done).catch(done)
const [fo] = await r.fundingOffers('fUSD')
auditTestFundingOffer(fo)
})
it('correctly parses funding loan response', (done) => {
const srv = new MockRESTv2Server({ listen: true })
it('correctly parses funding loan response', async () => {
srv = new MockRESTv2Server({ listen: true })
const r = getTestREST2({ transform: true })

@@ -176,10 +184,8 @@

r.fundingLoans('fUSD').then(([fo]) => {
auditTestFundingLoan(fo)
return srv.close()
}).then(done).catch(done)
const [fo] = await r.fundingLoans('fUSD')
auditTestFundingLoan(fo)
})
it('correctly parses funding credit response', (done) => {
const srv = new MockRESTv2Server({ listen: true })
it('correctly parses funding credit response', async () => {
srv = new MockRESTv2Server({ listen: true })
const r = getTestREST2({ transform: true })

@@ -189,7 +195,5 @@

r.fundingCredits('fUSD').then(([fc]) => {
auditTestFundingCredit(fc)
return srv.close()
}).then(done).catch(done)
const [fc] = await r.fundingCredits('fUSD')
auditTestFundingCredit(fc)
})
})
/* eslint-env mocha */
'use strict'
const PORT = 1337
const assert = require('assert')
const http = require('http')
const REST2 = require('../../lib/rest2')
const PORT = 1337
const bhttp = new REST2({

@@ -20,44 +18,26 @@ apiKey: 'dummy',

describe('rest2 api client: issue 80 - argumment length auth request', () => {
it('errors if no payload defined', (done) => {
const server = http.createServer((req, res) => {
res.writeHead(200, {
'Content-Type': 'text/plain'
})
let server = null
beforeEach((done) => {
server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' })
res.end(testResBody)
})
server.listen(PORT, () => {
bhttp._makeAuthRequest('/auth/r/orders').then(() => {
server.close()
done()
}).catch(err => {
server.close()
done(err)
})
})
server.listen(PORT, done)
})
it('succeeds with the right argument length', (done) => {
const server = http.createServer((req, res) => {
res.writeHead(200, {
'Content-Type': 'text/plain'
})
res.end(testResBody)
})
afterEach(() => {
server.close()
})
server.listen(PORT, () => {
bhttp._makeAuthRequest('/auth/r/orders', {}).then(res => {
assert.deepStrictEqual(
res,
['ente', 'gans', 'scholle']
)
it('errors if no payload defined', async () => {
await bhttp._makeAuthRequest('/auth/r/orders')
})
server.close()
done()
}).catch(err => {
server.close()
done(err)
})
})
it('succeeds with the right argument length', async () => {
const res = await bhttp._makeAuthRequest('/auth/r/orders', {})
assert.deepStrictEqual(res, ['ente', 'gans', 'scholle'])
})
})
/* eslint-env mocha */
'use strict'
const PORT = 1337
const assert = require('assert')

@@ -10,2 +8,3 @@ const http = require('http')

const PORT = 1338
const bhttp = new REST2({

@@ -29,20 +28,29 @@ apiKey: 'dummy',

describe('rest2 api client', () => {
it('gets a response as JSON', (done) => {
const server = http.createServer((req, res) => {
res.writeHead(200, {
'Content-Type': 'text/plain'
let server = null
afterEach((done) => {
if (server) {
server.close(() => {
server = null
done()
})
} else {
done()
}
})
it('gets a response as JSON', async () => {
server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' })
res.end(testResBody)
})
server.listen(PORT, () => {
bhttp.ticker('tBTCUSD', (err, res) => {
assert.strictEqual(err, null)
assert.deepStrictEqual(
res,
JSON.parse(testResBody)
)
return new Promise((resolve) => {
server.listen(PORT, () => {
bhttp.ticker('tBTCUSD', (err, res) => {
assert.strictEqual(err, null)
assert.deepStrictEqual(res, JSON.parse(testResBody))
server.close()
done()
resolve()
})
})

@@ -49,0 +57,0 @@ })

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