Haehnchen / crypto-trading-bot

Cryptocurrency trading bot in javascript for Bitfinex, Bitmex, Binance, Bybit ... (public edition)
MIT License
3.13k stars 993 forks source link

Limit Order gets created multiple times in some situations #47

Open ghost opened 5 years ago

ghost commented 5 years ago

Hey there,

I have just noticed the following since updating to the latest commits.

It seems that my limits orders sometimes get created multiple times! I think this could be related to the message 'Unknown order cleanup'. This is a wrong message as actually the order has filled in that moment per what I saw so far. I am assuming the system takes this error message and creates another buy order? Strange, I didn't saw this behavior before the latest commits, but I am not 100% sure.

Here is a bit of log from that situation. Hopefully that helps.

Thanks a lot for your work here!!

` THE ORIGINAL BUY ORDER:

Bitmex 2, [27.05.19 17:20] Bitmex: Order updated:{"body":"{\"orderID\":\"6c20dXXX\",\"clOrdID\":\"734XXX\",\"clOrdLinkID\":\"\",\"account\":XXX,\"symbol\":\"ETHUSD\",\"side\":\"Buy\",\"simpleOrderQty\":null,\"orderQty\":100,\"price\":268.65,\"displayQty\":null,\"stopPx\":null,\"pegOffsetValue\":null,\"pegPriceType\":\"\",\"currency\":\"USD\",\"settlCurrency\":\"XBt\",\"ordType\":\"Limit\",\"timeInForce\":\"GoodTillCancel\",\"execInst\":\"ParticipateDoNotInitiate\",\"contingencyType\":\"\",\"exDestination\":\"XBME\",\"ordStatus\":\"New\",\"triggered\":\"\",\"workingIndicator\":true,\"ordRejReason\":\"\",\"simpleLeavesQty\":null,\"leavesQty\":100,\"simpleCumQty\":null,\"cumQty\":0,\"avgPx\":null,\"multiLegReportingType\":\"SingleSecurity\",\"text\":\"Amended price: Powered by your awesome crypto-bot watchdog\nPowered by your awesome crypto-bot watchdog\",\"transactTime\":\"2019-05-27T21:20:26.761Z\",\"timestamp\":\"2019-05-27T21:20:26.761Z\"}"}

Bitmex 2, [27.05.19 17:20] OrderAdjust: Order adjusted with orderbook price: ["6c20dXXX",268.55,268.65,"bitmex","ETHUSD"]

Bitmex 2, [27.05.19 17:20] OrderAdjust: No price update needed:["6c20dXXX",268.65,268.65,"bitmex","ETHUSD"]

SUDDENLY THE NEW ORDER (if my Strat would have created it, we would see an additional log entry): Bitmex 2, [27.05.19 17:20] Pair State: Create position open order: ["bitmex","ETHUSD","long",{}]

Bitmex 2, [27.05.19 17:20] Order created: ["b64cXXX","bitmex","ETHUSD",{"id":694XXX,"symbol":"ETHUSD","side":"long","price":268.6,"amount":100,"type":"limit","options":{"adjust_price":true,"post_only":true}},{"id":"b64cXXX","symbol":"ETHUSD","status":"open","price":268.6,"amount":100,"retry":false,"ourId":"694XXX","side":"buy","type":"limit","createdAt":"2019-05-27T21:20:49.306Z","updatedAt":"2019-05-27T21:20:49.420Z","raw":{"orderID":"b64cXXX","clOrdID":"694XXX","clOrdLinkID":"","account":XXX,"symbol":"ETHUSD","side":"Buy","simpleOrderQty":null,"orderQty":100,"price":268.6,"displayQty":null,"stopPx":null,"pegOffsetValue":null,"pegPriceType":"","currency":"USD","settlCurrency":"XBt","ordType":"Limit","timeInForce":"GoodTillCancel","execInst":"ParticipateDoNotInitiate","contingencyType":"","exDestination":"XBME","ordStatus":"New","triggered":"","workingIndicator":true,"ordRejReason":"","simpleLeavesQty":null,"leavesQty":100,"simpleCumQty":null,"cumQty":0,"avgPx":null,"multiLegReportingType":"SingleSecurity","text":"Powered by your awesome crypto-bot watchdog","transactTime":"2019-05-27T21:20:49.306Z","timestamp":"2019-05-27T21:20:49.306Z"},"options":{}}]

Bitmex 2, [27.05.19 17:20] OrderAdjust: Unknown order cleanup: ["6c20dXXX","bitmex",null]

Bitmex 2, [27.05.19 17:20] OrderAdjust: No price update needed:["b64cXXX",268.6,268.6,"bitmex","ETHUSD"]

ANOTHER ORDER: Bitmex 2, [27.05.19 17:20] Pair State: Create position open order: ["bitmex","ETHUSD","long",{}]

Bitmex 2, [27.05.19 17:20] Bitmex: Order created:{"body":"{\"orderID\":\"63f06XXX\",\"clOrdID\":\"142XXX\",\"clOrdLinkID\":\"\",\"account\":XXX,\"symbol\":\"ETHUSD\",\"side\":\"Buy\",\"simpleOrderQty\":null,\"orderQty\":100,\"price\":268.6,\"displayQty\":null,\"stopPx\":null,\"pegOffsetValue\":null,\"pegPriceType\":\"\",\"currency\":\"USD\",\"settlCurrency\":\"XBt\",\"ordType\":\"Limit\",\"timeInForce\":\"GoodTillCancel\",\"execInst\":\"ParticipateDoNotInitiate\",\"contingencyType\":\"\",\"exDestination\":\"XBME\",\"ordStatus\":\"New\",\"triggered\":\"\",\"workingIndicator\":true,\"ordRejReason\":\"\",\"simpleLeavesQty\":null,\"leavesQty\":100,\"simpleCumQty\":null,\"cumQty\":0,\"avgPx\":null,\"multiLegReportingType\":\"SingleSecurity\",\"text\":\"Powered by your awesome crypto-bot watchdog\",\"transactTime\":\"2019-05-27T21:20:58.564Z\",\"timestamp\":\"2019-05-27T21:20:58.564Z\"}"}

Bitmex 2, [27.05.19 17:20] Order created: ["b64c3XXX","bitmex","ETHUSD",{"id":694XXX,"symbol":"ETHUSD","side":"long","price":268.6,"amount":100,"type":"limit","options":{"adjust_price":true,"post_only":true}},{"id":"b64c3XXX","symbol":"ETHUSD","status":"open","price":268.6,"amount":100,"retry":false,"ourId":"694XXX","side":"buy","type":"limit","createdAt":"2019-05-27T21:20:49.306Z","updatedAt":"2019-05-27T21:20:49.420Z","raw":{"orderID":"b64c3XXX","clOrdID":"694XXX","clOrdLinkID":"","account":XXX,"symbol":"ETHUSD","side":"Buy","simpleOrderQty":null,"orderQty":100,"price":268.6,"displayQty":null,"stopPx":null,"pegOffsetValue":null,"pegPriceType":"","currency":"USD","settlCurrency":"XBt","ordType":"Limit","timeInForce":"GoodTillCancel","execInst":"ParticipateDoNotInitiate","contingencyType":"","exDestination":"XBME","ordStatus":"New","triggered":"","workingIndicator":true,"ordRejReason":"","simpleLeavesQty":null,"leavesQty":100,"simpleCumQty":null,"cumQty":0,"avgPx":null,"multiLegReportingType":"SingleSecurity","text":"Powered by your awesome crypto-bot watchdog","transactTime":"2019-05-27T21:20:49.306Z","timestamp":"2019-05-27T21:20:49.306Z"},"options":{}}]

Bitmex 2, [27.05.19 17:20] OrderAdjust: Unknown order cleanup: ["6c20dXXX","bitmex",null]

Bitmex 2, [27.05.19 17:20] OrderAdjust: No price update needed:["b64cXXX",268.6,268.6,"bitmex","ETHUSD"]

Bitmex 2, [27.05.19 17:20] Pair State: Create position open order: ["bitmex","ETHUSD","long",{}]

Bitmex 2, [27.05.19 17:20] Bitmex: Order created:{"body":"{\"orderID\":\"63f06XXX\",\"clOrdID\":\"142XXX\",\"clOrdLinkID\":\"\",\"account\":XXX,\"symbol\":\"ETHUSD\",\"side\":\"Buy\",\"simpleOrderQty\":null,\"orderQty\":100,\"price\":268.6,\"displayQty\":null,\"stopPx\":null,\"pegOffsetValue\":null,\"pegPriceType\":\"\",\"currency\":\"USD\",\"settlCurrency\":\"XBt\",\"ordType\":\"Limit\",\"timeInForce\":\"GoodTillCancel\",\"execInst\":\"ParticipateDoNotInitiate\",\"contingencyType\":\"\",\"exDestination\":\"XBME\",\"ordStatus\":\"New\",\"triggered\":\"\",\"workingIndicator\":true,\"ordRejReason\":\"\",\"simpleLeavesQty\":null,\"leavesQty\":100,\"simpleCumQty\":null,\"cumQty\":0,\"avgPx\":null,\"multiLegReportingType\":\"SingleSecurity\",\"text\":\"Powered by your awesome crypto-bot watchdog\",\"transactTime\":\"2019-05-27T21:20:58.564Z\",\"timestamp\":\"2019-05-27T21:20:58.564Z\"}"}`

ghost commented 5 years ago

I just saw live on Bitmex how the bot created another order immediately in the moment when the previous order filled! That would confirm the suspicion that it could be related to the "Unknown order cleanup" message.

mrseeker commented 5 years ago

I see this also, might be related to the fact that the limit order gets immediately filled after creation, and from the bot's perspective looks like it failed.

ghost commented 5 years ago

Also had this case. The Limit Order did not get filled immediately, but just normal after maybe 20-30 seconds. I saw this in the logs:

OrderAdjust: Unknown order cleanup: ["f2ffe6b6-9135-XXX","bitmex",null]

Afterwards the bot created the next limit order. When the second limit order got created and filled, the bot stopped to create new orders:

`Bitmex DEV, [27.06.19 18:59] OrderAdjust: No price update needed:["23660d75-a092-XXX",296.5,296.5,"bitmex","ETHUSD"]

Bitmex DEV, [27.06.19 18:59] Position opened:["bitmex","ETHUSD",{"_exchange":"bitmex","_position":{"symbol":"ETHUSD","side":"long","amount":50,"profit":0.06749915626054204,"updatedAt":"2019-06-28T04:59:17.743Z","entry":296.3,"createdAt":"2019-06-28T04:00:00.000Z"}}]

Bitmex , [27.06.19 18:59] OrderAdjust: Unknown order cleanup: ["23660d75-XXX","bitmex",null]`