Convert getOrderBook and add unit test

This commit is contained in:
Chris Clark
2015-06-25 16:34:03 -07:00
parent 6a763fab18
commit 3e0f43e44e
17 changed files with 1736 additions and 229 deletions

View File

@@ -1,11 +1,28 @@
/* @flow */
'use strict';
const assert = require('assert');
const parseOrderBase = require('./order-base');
const utils = require('./utils');
const parseAmount = require('./amount');
const flags = utils.core.Transaction.flags.OfferCreate;
function parseOrder(tx: Object): Object {
assert(tx.TransactionType === 'OfferCreate');
return parseOrderBase(tx.TakerGets, tx.TakerPays, tx.Flags);
const direction = (tx.Flags & flags.Sell) === 0 ? 'buy' : 'sell';
const takerGetsAmount = parseAmount(tx.TakerGets);
const takerPaysAmount = parseAmount(tx.TakerPays);
const quantity = (direction === 'buy') ? takerPaysAmount : takerGetsAmount;
const totalPrice = (direction === 'buy') ? takerGetsAmount : takerPaysAmount;
return utils.removeUndefined({
direction: direction,
quantity: quantity,
totalPrice: totalPrice,
passive: ((tx.Flags & flags.Passive) !== 0) || undefined,
immediateOrCancel: ((tx.Flags & flags.ImmediateOrCancel) !== 0)
|| undefined,
fillOrKill: ((tx.Flags & flags.FillOrKill) !== 0) || undefined
});
}
module.exports = parseOrder;