DeviaVir / zenbot

Zenbot is a command-line cryptocurrency trading bot using Node.js and MongoDB.
MIT License
8.24k stars 2.03k forks source link

unable to cancel order on binance after some API issues #890

Open vitorego opened 6 years ago

vitorego commented 6 years ago

When the API goes down for some reason the bot seems to lose the cached orders and is unable to cancel it when the signal just changed:

2017-12-16 12:27:01 - order status: open
2017-12-16 12:26:59  695.000 ETH-USDT   +0.21%       33   64 ++   00693.277    00693.525  selling  0.02019164 ETH  0.01677777 USDT   +0.43%    0.00%
Binance API is down! unable to call getOrder, retrying in 20s
{ Error: binance GET https://api.binance.com/api/v3/order?timestamp=1513427252342&symbol=ETHUSDT&orderId=6931239&signature=ed110644dab43d398b741b28cadb6093b936e582d7932834daec2826df240a3f request timed out (10000 ms)
    at timeout.catch.e (/home/vitorego/download/zenbot_master/node_modules/ccxt/js/base/Exchange.js:266:27)
    at <anonymous> constructor: [Function: RequestTimeout] }
[ { order_id: '6931239', product_id: 'ETH-USDT' } ]
An error occurred { Error: binance GET https://api.binance.com/api/v1/aggTrades?symbol=ETHUSDT&startTime=1513427219255&endTime=1513470419255 request timed out (10000 ms)
    at timeout.catch.e (/home/vitorego/download/zenbot_master/node_modules/ccxt/js/base/Exchange.js:266:27)
    at <anonymous> constructor: [Function: RequestTimeout] }

Binance API is down! unable to call getOrder, retrying in 20s
{ Error: binance GET https://api.binance.com/api/v3/order?timestamp=1513427282364&symbol=ETHUSDT&orderId=6931239&signature=ef09994347f37a811370f18af7a844862d0f53431df4aa5a03287f3f7b06b8dc request timed out (10000 ms)
    at timeout.catch.e (/home/vitorego/download/zenbot_master/node_modules/ccxt/js/base/Exchange.js:266:27)
    at <anonymous> constructor: [Function: RequestTimeout] }
[ { order_id: '6931239', product_id: 'ETH-USDT' } ]
An error occurred { Error: binance GET https://api.binance.com/api/v1/aggTrades?symbol=ETHUSDT&startTime=1513427219255&endTime=1513470419255 request timed out (10000 ms)
    at timeout.catch.e (/home/vitorego/download/zenbot_master/node_modules/ccxt/js/base/Exchange.js:266:27)
    at <anonymous> constructor: [Function: RequestTimeout] }
An error occurred { Error: binance GET https://api.binance.com/api/v1/aggTrades?symbol=ETHUSDT&startTime=1513427219255&endTime=1513470419255 request timed out (10000 ms)
    at timeout.catch.e (/home/vitorego/download/zenbot_master/node_modules/ccxt/js/base/Exchange.js:266:27)
    at <anonymous> constructor: [Function: RequestTimeout] }

2017-12-16 12:28:33 - order status: open
2017-12-16 12:28:00  693.600 ETH-USDT   +0.01%       49   57 ++   00693.447    00693.534  selling  0.02019164 ETH  0.01677777 USDT   +0.23%    0.00%
2017-12-16 12:28:37  693.620 ETH-USDT   +0.00%       32   57 ++   00693.447    00693.534  selling  0.02019164 ETH  0.01677777 USDT   +0.23%    0.00%
2017-12-16 12:29:05 - order status: open
2017-12-16 12:29:05  693.500 ETH-USDT   -0.01%       42   56 ++   00693.447    00693.534  selling  0.02019164 ETH  0.01677777 USDT   +0.22%    0.00%
2017-12-16 12:29:36 - order status: open
2017-12-16 12:29:33  693.500 ETH-USDT   -0.01%       46   56 ++   00693.447    00693.534  selling  0.02019164 ETH  0.01677777 USDT   +0.22%    0.00%
2017-12-16 12:30:09 - order status: open
2017-12-16 12:30:00  693.500 ETH-USDT   -0.01%       50   56 ++   00693.540    00693.543  selling  0.02019164 ETH  0.01677777 USDT   +0.22%    0.00%
2017-12-16 12:30:32  693.500 ETH-USDT   +0.00%       13   56 ++   00693.540    00693.543  selling  0.02019164 ETH  0.01677777 USDT   +0.22%    0.00%
2017-12-16 12:30:40 - order status: open
2017-12-16 12:31:08  693.060 ETH-USDT   -0.06%       22   53 +    00693.540    00693.543  selling  0.02019164 ETH  0.01677777 USDT   +0.15%    0.00%
2017-12-16 12:31:12 - order status: open
2017-12-16 12:31:38  693.510 ETH-USDT   +0.00%       32   56 ++   00693.540    00693.543  selling  0.02019164 ETH  0.01677777 USDT   +0.22%    0.00%
2017-12-16 12:31:43 - order status: open
2017-12-16 12:32:00  693.020 ETH-USDT   -0.07%       35   53 +    00693.540    00693.551  selling  0.02019164 ETH  0.01677777 USDT   +0.15%    0.00%
2017-12-16 12:32:06  693.600 ETH-USDT   +0.08%        1   56 ++   00693.540    00693.551  selling  0.02019164 ETH  0.01677777 USDT   +0.23%    0.00%
2017-12-16 12:32:15 - order status: open
2017-12-16 12:32:09  693.600 ETH-USDT   +0.08%        1   56 ++   00693.540    00693.551  selling  0.02019164 ETH  0.01677777 USDT   +0.23%    0.00%
2017-12-16 12:32:46 - order status: open
2017-12-16 12:33:07  693.670 ETH-USDT   +0.09%        4   57 ++   00693.540    00693.551  selling  0.02019164 ETH  0.01677777 USDT   +0.24%    0.00%
2017-12-16 12:33:19 - order status: open
2017-12-16 12:33:36  693.650 ETH-USDT   +0.09%       10   57 ++   00693.540    00693.551  selling  0.02019164 ETH  0.01677777 USDT   +0.24%    0.00%
2017-12-16 12:33:50 - order status: open
2017-12-16 12:33:48  694.290 ETH-USDT   +0.18%       14   60 ++   00693.540    00693.551  selling  0.02019164 ETH  0.01677777 USDT   +0.33%    0.00%
2017-12-16 12:34:22 - order status: open
2017-12-16 12:34:00  694.290 ETH-USDT   +0.18%       14   60 ++   00693.373    00693.555  selling  0.02019164 ETH  0.01677777 USDT   +0.33%    0.00%
2017-12-16 12:34:38  693.620 ETH-USDT   -0.10%       14   55 ++   00693.373    00693.555  selling  0.02019164 ETH  0.01677777 USDT   +0.23%    0.00%
2017-12-16 12:34:53 - order status: open
2017-12-16 12:34:59  693.660 ETH-USDT   -0.09%       18   55 ++   00693.373    00693.555  selling  0.02019164 ETH  0.01677777 USDT   +0.24%    0.00%
2017-12-16 12:35:25 - order status: open
2017-12-16 12:35:23  694.940 ETH-USDT   +0.09%       25   63 ++   00693.373    00693.555  selling  0.02019164 ETH  0.01677777 USDT   +0.42%    0.00%
2017-12-16 12:35:56 - order status: open
2017-12-16 12:36:00  693.000 ETH-USDT   -0.19%       25   51 +    00693.603    00693.560      buy  0.02019164 ETH  0.01677777 USDT   +0.14%    0.00%
2017-12-16 12:36:07  694.890 ETH-USDT   +0.27%        0   60 ++   00693.603    00693.560           0.02019164 ETH  0.01677777 USDT   +0.42%    0.00%
2017-12-16 12:36:28 - signal switched during sell, aborting

2017-12-16 12:36:28 - cancelling order

Binance API is down! unable to call cancelOrder, retrying in 20s
{ Error: binance cancelOrder() error: {"code":-2011,"msg":"UNKNOWN_ORDER"}
    at binance.cancelOrder (/home/vitorego/download/zenbot_master/node_modules/ccxt/js/binance.js:531:23)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7) constructor: [Function: OrderNotFound] }
[ { order_id: '6931239', product_id: 'ETH-USDT' } ]
tulga commented 6 years ago

its not zenbot bug, its "ccxt" node module bug.

kroitor commented 6 years ago

@Tulga not really, because from the output you can see that Binance returned: binance cancelOrder() error: {"code":-2011,"msg":"UNKNOWN_ORDER"} – this is an error report from Binance, which is properly handled by CCXT (throws a OrderNotFound exception). However, the other concern is, why it failed to cancel the order on the first try with a timeout...

kilowatt1 commented 6 years ago

2018-01-28 20:20:00 0.104106 ETH-BTC -0.25% 208 -- 40.00 -0.0352 0.0162 buy 0.00176500 ETH 0.02434880 BTC +0.11% +0.39% 2018-01-28 20:21:08 0.104159 ETH-BTC +0.05% 80 -- 42.20 -0.0237 0.0170 buying 0.00176500 ETH 0.02434880 BTC +0.11% +0.34% cancelOrder retry - unknown Order: {"order_id":"64813998","product_id":"ETH-BTC"} - Error: binance {"code":-2011,"msg":"UNKNOWN_ORDER"}

getting the same error