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

Refactor method for notification. #852

Merged
merged 1 commit into from
Dec 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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