Skip to content

Commit bf00a35

Browse files
authored
Merge pull request #350 from robertkowalski/orderbook-unserial
orderbooks: unserialize fix for raw books
2 parents a1aaf72 + 01b5ce4 commit bf00a35

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/models/order_book.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ class OrderBook extends EventEmitter {
383383
*/
384384
static unserialize (arr, raw = false) {
385385
if (Array.isArray(arr[0])) {
386-
const entries = arr.map(e => OrderBook.unserialize(e))
386+
const entries = arr.map(e => OrderBook.unserialize(e, raw))
387387
const bids = entries.filter(e => e.amount > 0)
388388
const asks = entries.filter(e => e.amount < 0)
389389

test/lib/models/order_book.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ describe('OrderBook model', () => {
653653
assert.deepEqual(ob.asks, [{ price: 200, count: 2, amount: -10 }])
654654
})
655655

656-
it('unserialiez: returns map for entries', () => {
656+
it('unserialize: returns map for entries', () => {
657657
const entry = OrderBook.unserialize([150, 0, -1])
658658

659659
assert.deepEqual(entry, {
@@ -662,4 +662,22 @@ describe('OrderBook model', () => {
662662
amount: -1
663663
})
664664
})
665+
666+
it('unserialize: supports raw books', () => {
667+
const entry = OrderBook.unserialize([[1337, 150, -1], [1338, 151, 1]], true)
668+
669+
const exp = {
670+
asks: [{
671+
orderID: 1337,
672+
price: 150,
673+
amount: -1
674+
}],
675+
bids: [{
676+
orderID: 1338,
677+
price: 151,
678+
amount: 1
679+
}]
680+
}
681+
assert.deepEqual(entry, exp)
682+
})
665683
})

0 commit comments

Comments
 (0)