frostybot-js icon indicating copy to clipboard operation
frostybot-js copied to clipboard

Long trade SL suddenly switches side when set to a profitable price level

Open Ichibot200 opened this issue 3 years ago • 0 comments

I am working with dev branch and testing a multilevel takeprofit + single stoploss strategy. I have stumbled upon a strange and quite dangerous behaviour. When I had a LONG position opened and SL was below the entry price, the stoploss command was executed normally. But when the SL was moved to a profitable price level (above entry price 123.90), the stoploss command failed with the following log:

2021-06-26 23:12:02 | NOTICE  | Command Parameters: {command: trade:stoploss, stoptrigger: 124.1360995459, symbol: LTC/USDT, stub: mystub}
2021-06-26 23:12:03 | DEBUG   | Execute permission granted using standard permission set: trade:stoploss => [core, singleuser]
2021-06-26 23:12:03 | DEBUG   | Fetched 1 pre-cached records from datasource exchange:positions
2021-06-26 23:12:03 | DEBUG   | Current position and open orders calculated to potential position: {price: 123.94, base: 0.943, quote: 116.908425, sizing: base, side: **sell**, amount: 0.943, totals: {position: 0.943, orders: false, queue: false}}
2021-06-26 23:12:03 | DEBUG   | Exchange uses base sizing. Order size converted to LTC (0.943)
2021-06-26 23:12:03 | NOTICE  | Order added to queue: {symbol: LTC/USDT, type: STOP_MARKET, side: **buy**, amount: 0.943, params: {reduceOnly: true, stopPrice: 124.1360995459}}
2021-06-26 23:12:04 | WARNING | Unhandled Exception: ExchangeError: binance {"code":-2021,"msg":"Order would immediately trigger."} at binance.handleErrors (binance.js:3135:19))
2021-06-26 23:12:04 | WARNING | Unhandled Exception: TypeError: Cannot read property 'type' of undefined at frostybot_queue_module.submit (mod.queue.js:111:36))

Why would it consider that my long position is suddenly a sell side and placing SL order as buy side?

Ichibot200 avatar Jun 27 '21 08:06 Ichibot200