From f8511e9479d79541be6a66b0a61530c11dc66d49 Mon Sep 17 00:00:00 2001 From: Vitaliy Stoliarov Date: Fri, 18 Feb 2022 20:07:19 +0200 Subject: [PATCH 1/4] add tests for public trade snapshot --- test/lib/models/public_trade.js | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/lib/models/public_trade.js b/test/lib/models/public_trade.js index f6c042b..2adfea3 100644 --- a/test/lib/models/public_trade.js +++ b/test/lib/models/public_trade.js @@ -8,6 +8,11 @@ const { PublicTrade } = require('../../../lib') const testModel = require('../../helpers/test_model') const testModelValidation = require('../../helpers/test_model_validation') +const snapshot = [ + [267951933, 1645117845846, -5862.1, 0.002, 2], + [267947377, 1645115432454, -83763.1, 0.003, 3] +] + describe('Public Trade model', () => { testModel({ model: PublicTrade, @@ -64,6 +69,40 @@ describe('Public Trade model', () => { }) }).timeout(60000) + it('unserializes snapshot', async () => { + const serialized = PublicTrade.unserialize(snapshot) + + serialized.forEach((item, i) => { + Object.keys(PublicTrade.FUNDING_FIELDS).forEach(field => { + assert.strictEqual(item[field], snapshot[i][PublicTrade.FUNDING_FIELDS[field]]) + }) + }) + }).timeout(60000) + + it('creates instance from unserialized snapshot ', async () => { + const trades = new PublicTrade(PublicTrade.unserialize(snapshot)) + + for (let i = 0; i < trades.length; i++) { + const item = trades[i] + + Object.keys(PublicTrade.FUNDING_FIELDS).forEach(field => { + assert.strictEqual(item[field], snapshot[i][PublicTrade.FUNDING_FIELDS[field]]) + }) + } + }).timeout(60000) + + it('creates instance from snapshot', async () => { + const trades = new PublicTrade(snapshot) + + for (let i = 0; i < trades.length; i++) { + const item = trades[i] + + Object.keys(PublicTrade.FUNDING_FIELDS).forEach(field => { + assert.strictEqual(item[field], snapshot[i][PublicTrade.FUNDING_FIELDS[field]]) + }) + } + }).timeout(60000) + describe('toString', () => { it('includes pertinent information', () => { const t = new PublicTrade({ From 5be5a6f805360af359bc446f10cc33f3bd0497c6 Mon Sep 17 00:00:00 2001 From: Vitaliy Stoliarov Date: Mon, 21 Feb 2022 14:50:24 +0200 Subject: [PATCH 2/4] fix public trade unserializing from snapshot --- lib/public_trade.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/public_trade.js b/lib/public_trade.js index 2cb54b2..71d2b94 100644 --- a/lib/public_trade.js +++ b/lib/public_trade.js @@ -56,7 +56,7 @@ class PublicTrade extends Model { * @returns {object} pojo */ static unserialize (data) { - if ((_isArray(data[0]) && data[0].length === 5) || (data.length === 5)) { + if ((_isArray(data[0]) && data[0].length === 5) || (_isObject(data[0]) && data[0].rate) || data.length === 5) { return super.unserialize({ data, fields: FUNDING_FIELDS }) } else { return super.unserialize({ data, fields: TRADING_FIELDS }) From 4d361ab50beccccb933e6a3c4eca9819faa4a5a9 Mon Sep 17 00:00:00 2001 From: Vitaliy Stoliarov Date: Mon, 21 Feb 2022 16:25:23 +0200 Subject: [PATCH 3/4] 1.6.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f10aa9d..161ed20 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bfx-api-node-models", - "version": "1.6.2", + "version": "1.6.3", "description": "Object models for usage with the Bitfinex node API", "engines": { "node": ">=8.3.0" From 7e720ef7398f3c7f5307ecacd6e87d433373eb40 Mon Sep 17 00:00:00 2001 From: Vitaliy Stoliarov Date: Mon, 21 Feb 2022 16:25:38 +0200 Subject: [PATCH 4/4] update changelog --- CHANGELOG | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index c0e1ba6..5fd17e7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +#1.6.3 +- fix: public trade unserializing from snapshot + #1.6.2 - feature: visible on hit option supported for hidden orders