Skip to content

Commit 04f8631

Browse files
authored
Merge pull request #78 from vitaliystoliarovcc/fix/public-trade-snapshot
Fix/public trade snapshot
2 parents d8b5f17 + 7e720ef commit 04f8631

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#1.6.3
2+
- fix: public trade unserializing from snapshot
3+
14
#1.6.2
25
- feature: visible on hit option supported for hidden orders
36

lib/public_trade.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class PublicTrade extends Model {
5656
* @returns {object} pojo
5757
*/
5858
static unserialize (data) {
59-
if ((_isArray(data[0]) && data[0].length === 5) || (data.length === 5)) {
59+
if ((_isArray(data[0]) && data[0].length === 5) || (_isObject(data[0]) && data[0].rate) || data.length === 5) {
6060
return super.unserialize({ data, fields: FUNDING_FIELDS })
6161
} else {
6262
return super.unserialize({ data, fields: TRADING_FIELDS })

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bfx-api-node-models",
3-
"version": "1.6.2",
3+
"version": "1.6.3",
44
"description": "Object models for usage with the Bitfinex node API",
55
"engines": {
66
"node": ">=8.3.0"

test/lib/models/public_trade.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ const { PublicTrade } = require('../../../lib')
88
const testModel = require('../../helpers/test_model')
99
const testModelValidation = require('../../helpers/test_model_validation')
1010

11+
const snapshot = [
12+
[267951933, 1645117845846, -5862.1, 0.002, 2],
13+
[267947377, 1645115432454, -83763.1, 0.003, 3]
14+
]
15+
1116
describe('Public Trade model', () => {
1217
testModel({
1318
model: PublicTrade,
@@ -64,6 +69,40 @@ describe('Public Trade model', () => {
6469
})
6570
}).timeout(60000)
6671

72+
it('unserializes snapshot', async () => {
73+
const serialized = PublicTrade.unserialize(snapshot)
74+
75+
serialized.forEach((item, i) => {
76+
Object.keys(PublicTrade.FUNDING_FIELDS).forEach(field => {
77+
assert.strictEqual(item[field], snapshot[i][PublicTrade.FUNDING_FIELDS[field]])
78+
})
79+
})
80+
}).timeout(60000)
81+
82+
it('creates instance from unserialized snapshot ', async () => {
83+
const trades = new PublicTrade(PublicTrade.unserialize(snapshot))
84+
85+
for (let i = 0; i < trades.length; i++) {
86+
const item = trades[i]
87+
88+
Object.keys(PublicTrade.FUNDING_FIELDS).forEach(field => {
89+
assert.strictEqual(item[field], snapshot[i][PublicTrade.FUNDING_FIELDS[field]])
90+
})
91+
}
92+
}).timeout(60000)
93+
94+
it('creates instance from snapshot', async () => {
95+
const trades = new PublicTrade(snapshot)
96+
97+
for (let i = 0; i < trades.length; i++) {
98+
const item = trades[i]
99+
100+
Object.keys(PublicTrade.FUNDING_FIELDS).forEach(field => {
101+
assert.strictEqual(item[field], snapshot[i][PublicTrade.FUNDING_FIELDS[field]])
102+
})
103+
}
104+
}).timeout(60000)
105+
67106
describe('toString', () => {
68107
it('includes pertinent information', () => {
69108
const t = new PublicTrade({

0 commit comments

Comments
 (0)