Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error on minute mark unsupported operand type(s) for -: 'NoneType' and 'float' #417

Open
zlly20 opened this issue Oct 28, 2023 · 4 comments

Comments

@zlly20
Copy link

zlly20 commented Oct 28, 2023

I have run this bot for a couple of weeks, it run quite smoothly without errors, and the bot was run on a couple of trading pairs on Bybit for live trading as well as on OKX for demo trading.

One day all of a sudden it shows the following error on ADAUSDT pair on Bybit.

2023-10-28T15:43:34 INFO starting bot...
2023-10-28T15:44:20 INFO heartbeat ADA/USDT:USDT
2023-10-28T15:44:20 INFO long: 3561.0 @ 0.2971 lWE: 0.8969 pprc diff 0.002 EMAs: [0.29597, 0.29586, 0.29565] e 0.0 @ 0.0 | c 3561.0 @ None
2023-10-28T15:44:20 INFO short: -4000.0 @ 0.2824 sWE: 0.9577 pprc diff 0.050 EMAs: [0.29256, 0.29123, 0.28994] e 0.0 @ 0.0 | c 0.0 @ 0.0
2023-10-28T15:44:20 INFO balance: 1179.49 equity: 1121.11 last price: 0.2964 liq: 0.0
2023-10-28T15:44:24 ERROR error on minute mark unsupported operand type(s) for -: 'NoneType' and 'float'
Traceback (most recent call last):
File "D:\My Project\passivbot\passivbot.py", line 1541, in on_minute_mark
await self.cancel_and_create()
File "D:\My Project\passivbot\passivbot.py", line 1059, in cancel_and_create
to_cancel = sorted(to_cancel, key=lambda x: calc_diff(x["price"], self.price))
File "D:\My Project\passivbot\passivbot.py", line 1059, in
to_cancel = sorted(to_cancel, key=lambda x: calc_diff(x["price"], self.price))
File "D:\My Project\passivbot\njit_funcs.py", line 48, in calc_diff
return abs(x - y) / abs(y)
TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'

The error seems to be only on ADAUSDT, all other pairs are running fine. Restarting the bot doesn't help either, I was suspecting some data corruption on the cached exchange data, but after cleaning all cached data, the error still showed on restarting the bot. Any pointer to get this fixed would be good.

@zlly20
Copy link
Author

zlly20 commented Oct 28, 2023

upon investigation, it is because I manually placed a market order for this pair, and when passivbot is staring up, it calls the update_open_order function which retrieves the open order, it shows the following:

open_orders are: [{'order_id': '721c3dd7-3088-42c5-a110-523435343', 'custom_id': None, 'symbol': 'ADA/USDT:USDT', 'price': None, 'qty': 3561.0, 'type': 'market', 'side': 'sell', 'position_side': 'long', 'timestamp': 1698470303860}]

The price is None in this case. this order is an open position that is already filled, shouldn't it have a price when filled? is it normal to have the price as none for all market orders? I did manually place orders sometimes, but this error never happened before.

@zlly20
Copy link
Author

zlly20 commented Oct 28, 2023

upon further investigation, the actual data returned from the exchange is

[ { "info": { "orderId": "721c3dd7-3088-42c5-a110-425f0e4210f5", "orderLinkId": "", "blockTradeId": "", "symbol": "ADAUSDT", "price": "0.0000", "qty": "3561", "side": "Sell", "isLeverage": "", "positionIdx": "1", "orderStatus": "Untriggered", "cancelType": "UNKNOWN", "rejectReason": "EC_NoError", "avgPrice": "0", "leavesQty": "3561", "leavesValue": "0", "cumExecQty": "0", "cumExecValue": "0", "cumExecFee": "0", "timeInForce": "IOC", "orderType": "Market", "stopOrderType": "TakeProfit", "orderIv": "", "triggerPrice": "0.3020", "takeProfit": "0.0000", "stopLoss": "0.0000", "tpTriggerBy": "UNKNOWN", "slTriggerBy": "UNKNOWN", "triggerDirection": "1", "triggerBy": "LastPrice", "lastPriceOnCreated": "0.2969", "reduceOnly": true, "closeOnTrigger": true, "smpType": "None", "smpGroup": "0", "smpOrderId": "", "tpslMode": "Full", "tpLimitPrice": "", "slLimitPrice": "", "placeType": "", "createdTime": "1698470303860", "updatedTime": "1698470646957", "nextPageCursor": "page_args%3D721c3dd7-3088-42c5-a110-425f0e4210f5%26" }, "id": "721c3dd7-3088-42c5-a110-425f0e4210f5", "clientOrderId": null, "timestamp": 1698470303860, "datetime": "2023-10-28T05:18:23.860Z", "lastTradeTimestamp": 1698470646957, "lastUpdateTimestamp": 1698470646957, "symbol": "ADA/USDT:USDT", "type": "market", "timeInForce": "IOC", "postOnly": false, "reduceOnly": true, "side": "sell", "price": null, "stopPrice": 0.302, "triggerPrice": 0.302, "takeProfitPrice": 0.302, "stopLossPrice": null, "amount": 3561.0, "cost": 0.0, "average": null, "filled": 0.0, "remaining": 3561.0, "status": "open", "fee": { "cost": 0.0, "currency": "USDT" }, "trades": [], "fees": [ { "cost": 0.0, "currency": "USDT" } ] } ]

this is weird that this order is a FILLED market order, as it show up in the exchange interface as an Open Position, it should have a price or avgPrice based on my understanding.

@enarjord
Copy link
Owner

It happens when there are special orders, like TP or SL, in which price returned is None. Verified it by making such orders manually, and saw the same error as you did.

Fixed now in latest master by catching price=None when fetching open orders, setting price to current market price, triggering the order's cancellation.

@zlly20
Copy link
Author

zlly20 commented Oct 31, 2023

Great, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants