Kucoin / kucoin-futures-python-sdk

MIT License
7 stars 3 forks source link

Implementing a stop order with closeOrder option #52

Closed jmarunix closed 11 months ago

jmarunix commented 11 months ago

In the docs https://www.kucoin.com/docs/rest/futures-trading/orders/place-order appears this statement:

closeOrder | boolean | No | A mark to close the position. Set to false by default. If closeOrder is set to TRUE, the system will close the position and the position size will become 0. Side, Size and Leverage fields can be left empty and the system will determine the side and size automatically.

To achieve it I have trying this request: {'symbol': 'XBTUSDTM', 'size': None, 'side': None, 'price': 24446.0, 'leverage': None, 'type': 'limit', 'clientOid': '0f23d4167aeb11eeadea80fa5b3993a2', 'kwargs': {'remark': '', 'stop': 'down', 'stopPriceType': 'MP', 'stopPrice': 24712.0, 'reduceOnly': False, 'closeOrder': True, 'forceHold': False, 'timeInForde': 'GTC', 'postOnly': False, 'hidden': False, 'iceberg': False, 'visibleSize': 0}}

With the output: raise Exception("{}-{}".format(response_data.status_code, response_data.text)) Exception: 200-{"msg":"Leverage parameter invalid.","code":"100001"}

I have tried the values {}, '{}', '', 0 and 'null' too, same output. Really, I dont know more options in json to declare an empty var. In the function create_limit_order the parameters size, side and leverage are positional so they can`t be omitted, still, I tried it without success.

Can you help me, please?

jmarunix commented 11 months ago

To remember... The python function definition of create_limit_order is:

def create_limit_order(self, symbol, side, lever, size, price, clientOid='', **kwargs): params = { 'symbol': symbol, 'size': size, 'side': side, 'price': price, 'leverage': lever, 'type': 'limit' } if not clientOid: clientOid = self.return_unique_id params['clientOid'] = clientOid if kwargs: params.update(kwargs) <<<—— MY PROBLEM WAS HERE!!!!!!!!!! print(params) return self._request('POST', '/api/v1/orders', params=params)

Well, since params is a dict, if you want to update it with another pairs(keys:values), you need another dict inside this method.....eh, HOW I thought THIS I passed a dict var to the function.... and what is the function doing? this is the best part >> **kwargs assigns the set of values to the key kwarg, and of course, the kucoin order system, since it does not know kwarg as a valid variable, discards its contents.

Arrggggg, I had forgotten how much I hated the behavior of the double pointers 🤣🤣🤣

So, well, the solution is as simple as passing each and every one of the pairs of values that you specify in the function.