From d8f21fcecf252aba1bd9b1a6831ca47fd525d0ad Mon Sep 17 00:00:00 2001 From: Pierre Dulac Date: Tue, 18 Jul 2017 12:07:12 +0200 Subject: [PATCH] setRawMode is not supported on some remote consoles (no tty) (#380) --- commands/trade.js | 58 ++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/commands/trade.js b/commands/trade.js index 4d5cc5db4d..f011161a35 100644 --- a/commands/trade.js +++ b/commands/trade.js @@ -154,34 +154,36 @@ module.exports = function container (get, set, clear) { forwardScan() setInterval(forwardScan, c.poll_trades) readline.emitKeypressEvents(process.stdin) - process.stdin.setRawMode(true) - process.stdin.on('keypress', function (key, info) { - if (key === 'b' && !info.ctrl ) { - engine.executeSignal('buy') - } - else if (key === 'B' && !info.ctrl) { - engine.executeSignal('buy', null, null, false, true) - } - else if (key === 's' && !info.ctrl) { - engine.executeSignal('sell') - } - else if (key === 'S' && !info.ctrl) { - engine.executeSignal('sell', null, null, false, true) - } - else if ((key === 'c' || key === 'C') && !info.ctrl) { - delete s.buy_order - delete s.sell_order - } - else if ((key === 'm' || key === 'M') && !info.ctrl) { - so.manual = !so.manual - console.log('\nmanual mode: ' + (so.manual ? 'ON' : 'OFF') + '\n') - } - else if (info.name === 'c' && info.ctrl) { - // @todo: cancel open orders before exit - console.log() - process.exit() - } - }) + if (process.stdin.setRawMode) { + process.stdin.setRawMode(true) + process.stdin.on('keypress', function (key, info) { + if (key === 'b' && !info.ctrl ) { + engine.executeSignal('buy') + } + else if (key === 'B' && !info.ctrl) { + engine.executeSignal('buy', null, null, false, true) + } + else if (key === 's' && !info.ctrl) { + engine.executeSignal('sell') + } + else if (key === 'S' && !info.ctrl) { + engine.executeSignal('sell', null, null, false, true) + } + else if ((key === 'c' || key === 'C') && !info.ctrl) { + delete s.buy_order + delete s.sell_order + } + else if ((key === 'm' || key === 'M') && !info.ctrl) { + so.manual = !so.manual + console.log('\nmanual mode: ' + (so.manual ? 'ON' : 'OFF') + '\n') + } + else if (info.name === 'c' && info.ctrl) { + // @todo: cancel open orders before exit + console.log() + process.exit() + } + }) + } }) }) return