Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Commit

Permalink
Refactor method for notification. (#852)
Browse files Browse the repository at this point in the history
  • Loading branch information
darland authored and DeviaVir committed Dec 13, 2017
1 parent bba3b75 commit 55d877a
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ module.exports = function container (get, set, clear) {
}
}

function pushMessage(str) {
if (so.mode === 'live' || so.mode === 'paper') {
notify.pushMessage(str)
}
}

function fa (amt) {
return n(amt).format('0.00000000') + ' ' + s.asset
}
Expand Down Expand Up @@ -184,7 +190,7 @@ module.exports = function container (get, set, clear) {
s.start_price = n(quote.ask).value()
s.start_capital = n(s.balance.currency).add(n(s.balance.asset).multiply(quote.ask)).value()

notify.pushMessage('Balance ' + s.exchange.name.toUpperCase(), 'sync balance ' + s.start_capital + ' ' + s.currency + '\n')
pushMessage('Balance ' + s.exchange.name.toUpperCase(), 'sync balance ' + s.start_capital + ' ' + s.currency + '\n')

cb()
})
Expand Down Expand Up @@ -451,9 +457,7 @@ module.exports = function container (get, set, clear) {
}, c.wait_for_settlement)
}
else {
if (so.mode === 'live' || so.mode === 'paper') {
notify.pushMessage('Buying ' + s.exchange.name.toUpperCase(), 'placing buy order at ' + fc(price) + ', ' + fc(quote.bid - Number(price)) + ' under best bid\n')
}
pushMessage('Buying ' + s.exchange.name.toUpperCase(), 'placing buy order at ' + fc(price) + ', ' + fc(quote.bid - Number(price)) + ' under best bid\n')
doOrder()
}
}
Expand Down Expand Up @@ -494,9 +498,7 @@ module.exports = function container (get, set, clear) {
}, c.wait_for_settlement)
}
else {
if (so.mode === 'live' || so.mode === 'paper') {
notify.pushMessage('Selling ' + s.exchange.name.toUpperCase(), 'placing sell order at ' + fc(price) + ', ' + fc(Number(price) - quote.bid) + ' over best ask\n')
}
pushMessage('Selling ' + s.exchange.name.toUpperCase(), 'placing sell order at ' + fc(price) + ', ' + fc(Number(price) - quote.bid) + ' over best ask\n')
doOrder()
}
}
Expand Down Expand Up @@ -586,9 +588,7 @@ module.exports = function container (get, set, clear) {
if (so.stats) {
order_complete = '\nbuy order completed at ' + moment(trade.time).format('YYYY-MM-DD HH:mm:ss') + ':\n\n' + fa(my_trade.size) + ' at ' + fc(my_trade.price) + '\ntotal ' + fc(my_trade.size * my_trade.price) + '\n' + n(my_trade.slippage).format('0.0000%') + ' slippage (orig. price ' + fc(s.buy_order.orig_price) + ')\nexecution: ' + moment.duration(my_trade.execution_time).humanize() + '\n'
console.log((order_complete).cyan)
if (so.mode === 'live' || so.mode === 'paper') {
notify.pushMessage('Buy ' + s.exchange.name.toUpperCase(), order_complete)
}
pushMessage('Buy ' + s.exchange.name.toUpperCase(), order_complete)
}
s.last_buy_price = my_trade.price
delete s.buy_order
Expand Down Expand Up @@ -638,9 +638,7 @@ module.exports = function container (get, set, clear) {
if (so.stats) {
order_complete = '\nsell order completed at ' + moment(trade.time).format('YYYY-MM-DD HH:mm:ss') + ':\n\n' + fa(my_trade.size) + ' at ' + fc(my_trade.price) + '\ntotal ' + fc(my_trade.size * my_trade.price) + '\n' + n(my_trade.slippage).format('0.0000%') + ' slippage (orig. price ' + fc(s.sell_order.orig_price) + ')\nexecution: ' + moment.duration(my_trade.execution_time).humanize() + '\n'
console.log((order_complete).cyan)
if (so.mode === 'live' || so.mode === 'paper') {
notify.pushMessage('Sell ' + s.exchange.name.toUpperCase(), order_complete)
}
pushMessage('Sell ' + s.exchange.name.toUpperCase(), order_complete)
}
s.last_sell_price = my_trade.price
delete s.sell_order
Expand Down

0 comments on commit 55d877a

Please sign in to comment.