New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bfx-api-node-models

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bfx-api-node-models - npm Package Compare versions

Comparing version 1.1.5 to 1.1.6

128

lib/order_book.js

@@ -94,25 +94,25 @@ 'use strict'

if (bid) {
const price = raw ? bid[0] : Number(preparePrice(bid[0]))
let price = bid[0]
const amount = bid.length === 4 ? bid[3] : bid[2]
if (!raw && typeof price !== 'string') {
price = Number(preparePrice(price))
price = /e/.test(price + '')
? price.toFixed(Math.abs((price + '').split('e')[1]) + 1) // i.e. 1.7e-7 to fixed
: price
}
data.push(
raw
? price
: /e/.test(price + '')
? price.toFixed(Math.abs((price + '').split('e')[1]) + 1) // i.e. 1.7e-7 to fixed
: price,
bid.length === 4 ? bid[3] : bid[2] // amount
)
data.push(price, amount)
}
if (ask) {
const price = raw ? ask[0] : Number(preparePrice(ask[0]))
let price = ask[0]
const amount = ask.length === 4 ? ask[3] : ask[2]
if (!raw && typeof price !== 'string') {
price = Number(preparePrice(price))
price = /e/.test(price + '')
? price.toFixed(Math.abs((price + '').split('e')[1]) + 1) // i.e. 1.7e-7 to fixed
: price
}
data.push(
raw
? price
: /e/.test(price + '')
? price.toFixed(Math.abs((price + '').split('e')[1]) + 1) // i.e. 1.7e-7 to fixed
: price,
ask.length === 4 ? ask[3] : ask[2] //
)
data.push(price, amount)
}

@@ -136,3 +136,3 @@ }

for (let i = 0; i < arr.length; i += 1) {
if ((arr[i].length === 4 ? -arr[i][3] : arr[i][2]) < 0) {
if ((arr[i].length === 4 ? Number(-arr[i][3]) : Number(arr[i][2])) < 0) {
topAskI = i

@@ -159,25 +159,23 @@ break

if (bid) {
const price = raw ? bid[0] : Number(preparePrice(bid[0]))
data.push(
raw
? bid[0]
: /e/.test(price + '')
? price.toFixed(Math.abs((price + '').split('e')[1]) + 1) // i.e. 1.7e-7 to fixed
: price, // order ID or price
bid.length === 4 ? bid[3] : bid[2] // amount
)
let price = bid[0]
const amount = bid.length === 4 ? bid[3] : bid[2]
if (!raw && typeof price !== 'string') {
price = Number(preparePrice(price))
price = /e/.test(price + '')
? price.toFixed(Math.abs((price + '').split('e')[1]) + 1) // i.e. 1.7e-7 to fixed
: price
}
data.push(price, amount)
}
if (ask) {
const price = raw ? ask[0] : Number(preparePrice(ask[0]))
data.push(
raw
? ask[0]
: /e/.test(price + '')
? price.toFixed(Math.abs((price + '').split('e')[1]) + 1) // i.e. 1.7e-7 to fixed
: price,
ask.length === 4 ? ask[3] : ask[2]
)
let price = ask[0]
const amount = ask.length === 4 ? ask[3] : ask[2]
if (!raw && typeof price !== 'string') {
price = Number(preparePrice(price))
price = /e/.test(price + '')
? price.toFixed(Math.abs((price + '').split('e')[1]) + 1) // i.e. 1.7e-7 to fixed
: price
}
data.push(price, amount)
}

@@ -189,8 +187,2 @@ }

/**
* Resets the internal bid/ask arrays and re-populates them with the provided
* snapshot.
*
* @param {Array[]} snapshot
*/
updateFromSnapshot (snapshot) {

@@ -206,3 +198,3 @@ this.bids = []

if (snapshot[i].length === 4) {
if (snapshot[i][3] < 0) {
if (Number(snapshot[i][3]) < 0) {
this.bids.push(snapshot[i])

@@ -213,3 +205,3 @@ } else {

} else {
if (snapshot[i][2] < 0) {
if (Number(snapshot[i][2]) < 0) {
this.asks.push(snapshot[i])

@@ -235,10 +227,11 @@ } else {

: 0
const count = raw ? -1 : entry.length === 4 ? entry[2] : entry[1]
const price = entry[priceI]
const oID = entry[0] // only for raw books
const amount = entry.length === 4 ? entry[3] : entry[2]
const dir = entry.length === 4
const numEntry = entry.map((x) => Number(x))
const count = raw ? -1 : numEntry.length === 4 ? numEntry[2] : numEntry[1]
const price = numEntry[priceI]
const oID = numEntry[0] // only for raw books
const amount = numEntry.length === 4 ? numEntry[3] : numEntry[2]
const dir = numEntry.length === 4
? amount < 0 ? 1 : -1
: amount < 0 ? -1 : 1
const side = entry.length === 4
const side = numEntry.length === 4
? amount < 0 ? this.bids : this.asks

@@ -259,3 +252,3 @@ : amount < 0 ? this.asks : this.bids

for (let i = 0; i < side.length; i++) {
if ((!raw && side[i][priceI] === price) || (raw && side[i][0] === oID)) {
if ((!raw && Number(side[i][priceI]) === price) || (raw && Number(side[i][0]) === oID)) {
if ((!raw && count === 0) || (raw && price === 0)) {

@@ -278,3 +271,3 @@ side.splice(i, 1) // remove

for (let i = 0; i < side.length; i++) {
pl = side[i]
pl = side[i].map((x) => Number(x))

@@ -417,5 +410,2 @@ if (insertIndex === -1 && (

/**
* @return {Array[]} - arr
*/
serialize () {

@@ -449,8 +439,8 @@ return (this.asks || []).concat(this.bids || [])

: 0
const price = entry[priceI]
const amount = entry.length === 4 ? entry[3] : entry[2]
const price = Number(entry[priceI])
const amount = entry.length === 4 ? Number(entry[3]) : Number(entry[2])
const dir = entry.length === 4
? amount < 0 ? 1 : -1
: amount < 0 ? -1 : 1
const count = raw ? -1 : entry.length === 4 ? entry[2] : entry[1]
const count = raw ? -1 : entry.length === 4 ? Number(entry[2]) : Number(entry[1])
let insertIndex = -1

@@ -460,7 +450,7 @@ let pl // price level

for (let i = 0; i < ob.length; i++) {
pl = ob[i]
pl = ob[i].map((x) => Number(x))
if (
(!raw && pl[priceI] === price) ||
(raw && pl[0] === entry[0])
(raw && pl[0] === Number(entry[0]))
) {

@@ -483,3 +473,3 @@ if ((!raw && count === 0) || (raw && price === 0)) {

for (let i = 0; i < ob.length; i++) {
pl = ob[i]
pl = ob[i].map((x) => Number(x))

@@ -489,5 +479,5 @@ if (insertIndex === -1) {

(dir === -1 && (pl.length === 4 ? -pl[3] : pl[2]) < 0 && price < pl[priceI]) || // by price
(dir === -1 && (pl.length === 4 ? -pl[3] : pl[2]) < 0 && price === pl[priceI] && (raw && entry[0] < pl[0])) || // by order ID
(dir === -1 && (pl.length === 4 ? -pl[3] : pl[2]) < 0 && price === pl[priceI] && (raw && Number(entry[0]) < pl[0])) || // by order ID
(dir === 1 && (pl.length === 4 ? -pl[3] : pl[2]) > 0 && price > pl[priceI]) ||
(dir === 1 && (pl.length === 4 ? -pl[3] : pl[2]) > 0 && price === pl[priceI] && (raw && entry[0] < pl[0])) ||
(dir === 1 && (pl.length === 4 ? -pl[3] : pl[2]) > 0 && price === pl[priceI] && (raw && Number(entry[0]) < pl[0])) ||
(dir === 1 && (pl.length === 4 ? -pl[3] : pl[2]) < 0)

@@ -511,8 +501,2 @@ ) {

/**
* Resolves the mid-price of an array-format OB
*
* @param {Array[]} ob
* @param {boolean?} raw - default false
*/
static arrayOBMidPrice (ob = [], raw = false) {

@@ -519,0 +503,0 @@ if (ob.length === 0) return null

{
"name": "bfx-api-node-models",
"version": "1.1.5",
"version": "1.1.6",
"description": "Object models for usage with the Bitfinex node API",

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

@@ -63,2 +63,22 @@ /* eslint-env mocha */

it('checksum: returns expected value for high precision numbers', () => {
const ob = new OrderBook({
bids: [['0.000000001', 1, 1], ['0.0000000001', 1, '0.0000000002']],
asks: [['0.000000002', 1, -3], ['0.000000003', 1, -4]]
})
assert.strictEqual(ob.checksum(), CRC.str('0.000000001:1:0.000000002:-3:0.0000000001:0.0000000002:0.000000003:-4'))
})
it('updateWith: string update place the entry in the correct position in the book', () => {
const ob = new OrderBook({
bids: [['0.1', 1, 1], ['0.09', 1, '5']],
asks: [['0.2', 1, -3], ['0.3', 1, -4]]
})
ob.updateWith(['0.15', 1, -1])
ob.updateWith(['0.089', 1, 1])
assert.strictEqual(ob.checksum(), CRC.str('0.1:1:0.15:-1:0.09:5:0.2:-3:0.089:1:0.3:-4'))
})
it('checksum: returns expected value for raw OB', () => {

@@ -65,0 +85,0 @@ const ob = new OrderBook({

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc