-
Notifications
You must be signed in to change notification settings - Fork 500
/
order-base.js
27 lines (24 loc) · 1.01 KB
/
order-base.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* @flow */
'use strict';
const utils = require('./utils');
const parseAmount = require('./amount');
const orderFlags = utils.core.Transaction.flags.OfferCreate;
/*:: type Amount = string | {currency: string, issuer: string, value: string} */
function parseOrder(takerGets: Amount, takerPays: Amount, flags: number):
Object {
const direction = (flags & orderFlags.Sell) === 0 ? 'buy' : 'sell';
const takerGetsAmount = parseAmount(takerGets);
const takerPaysAmount = parseAmount(takerPays);
const quantity = (direction === 'buy') ? takerPaysAmount : takerGetsAmount;
const totalPrice = (direction === 'buy') ? takerGetsAmount : takerPaysAmount;
return utils.removeUndefined({
direction: direction,
quantity: quantity,
totalPrice: totalPrice,
passive: ((flags & orderFlags.Passive) !== 0) || undefined,
immediateOrCancel: ((flags & orderFlags.ImmediateOrCancel) !== 0)
|| undefined,
fillOrKill: ((flags & orderFlags.FillOrKill) !== 0) || undefined
});
}
module.exports = parseOrder;