Skip to content

Commit

Permalink
API: Always calculate fees
Browse files Browse the repository at this point in the history
  • Loading branch information
defkev committed Jan 23, 2018
1 parent 56f9e05 commit b354f21
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,20 +579,28 @@ module.exports = function container (get, set, clear) {
if (s.buy_order) {
if (so.mode === 'live' || trade.price <= Number(s.buy_order.price)) {
price = s.buy_order.price
if (so.order_type === 'maker') {
if (s.exchange.makerFee) {
fee = n(s.buy_order.size).multiply(s.exchange.makerFee / 100).value()
}
}
if (so.order_type === 'taker') {
if (s.exchange.takerFee) {
fee = n(s.buy_order.size).multiply(s.exchange.takerFee / 100).value()
}
}
if (so.mode !== 'live') {
s.balance.asset = n(s.balance.asset).add(s.buy_order.size).format('0.00000000')
let total = n(price).multiply(s.buy_order.size)
s.balance.currency = n(s.balance.currency).subtract(total).format('0.00000000')
if (so.order_type === 'maker') {
price = n(s.buy_order.price).add(n(s.buy_order.price).multiply(so.avg_slippage_pct / 100)).format('0.00000000')
if (s.exchange.makerFee) {
fee = n(s.buy_order.size).multiply(s.exchange.makerFee / 100).value()
s.balance.asset = n(s.balance.asset).subtract(fee).format('0.00000000')
}
}
if (so.order_type === 'taker') {
if (s.exchange.takerFee) {
fee = n(s.buy_order.size).multiply(s.exchange.takerFee / 100).value()
s.balance.asset = n(s.balance.asset).subtract(fee).format('0.00000000')
}
}
Expand Down Expand Up @@ -631,20 +639,28 @@ module.exports = function container (get, set, clear) {
else if (s.sell_order) {
if (so.mode === 'live' || trade.price >= s.sell_order.price) {
price = s.sell_order.price
if (so.order_type === 'maker') {
if (s.exchange.makerFee) {
fee = n(s.sell_order.size).multiply(s.exchange.makerFee / 100).multiply(price).value()
}
}
if (so.order_type === 'taker') {
if (s.exchange.takerFee) {
fee = n(s.sell_order.size).multiply(s.exchange.takerFee / 100).multiply(price).value()
}
}
if (so.mode !== 'live') {
s.balance.asset = n(s.balance.asset).subtract(s.sell_order.size).value()
let total = n(price).multiply(s.sell_order.size)
s.balance.currency = n(s.balance.currency).add(total).value()
if (so.order_type === 'maker') {
price = n(s.sell_order.price).subtract(n(s.sell_order.price).multiply(so.avg_slippage_pct / 100)).format('0.00000000')
if (s.exchange.makerFee) {
fee = n(s.sell_order.size).multiply(s.exchange.makerFee / 100).multiply(price).value()
s.balance.currency = n(s.balance.currency).subtract(fee).format('0.00000000')
}
}
if (so.order_type === 'taker') {
if (s.exchange.takerFee) {
fee = n(s.sell_order.size).multiply(s.exchange.takerFee / 100).multiply(price).value()
s.balance.currency = n(s.balance.currency).subtract(fee).format('0.00000000')
}
}
Expand Down

0 comments on commit b354f21

Please sign in to comment.