Skip to content

okex set-leverage not working #11975

@xmatthias

Description

@xmatthias
  • OS: linux
  • Programming Language version: python
  • CCXT version: 3.73.3

Trying to set leverage raises an exception

based on the v5 documentation - i think the parameters should be correct.

Is this a okx bug, or am i providing the wrong parameters somehow?

import ccxt
exchange = ccxt.okx({**keys, **{'options': {'defaultType': 'swap'}}})
mark = ct.loadMarkets()
ct.verbose = True
ct.set_leverage(leverage=5,
                symbol=pair,
                params={
                    "mgnMode": 'isolated',
                    "posSide": "short" , # also tested with long
                })
fetch Request: okx POST [https://www.okx.com/api/v5/account/set-leverage]() RequestHeaders: {'OK-ACCESS-KEY': 'something', 'OK-ACCESS-PASSPHRASE': 'something', 'OK-ACCESS-TIMESTAMP': '2022-02-15T16:08:22.027Z', 'Content-Type': 'application[/json]()', 'OK-ACCESS-SIGN': 'something', 'User-Agent': 'python-requests[/2.27.1]()', 'Accept-Encoding': 'gzip, deflate'} RequestBody: {"lever":5,"mgnMode":"isolated","instId":"DOT-USDT-SWAP","posSide":"short"}

fetch Response: okx POST [https://www.okx.com/api/v5/account/set-leverage]() 400 ResponseHeaders: {'Date': 'Tue, 15 Feb 2022 16:08:22 GMT', 'Content-Type': 'application[/json]()', 'Content-Length': '59', 'Connection': 'keep-alive', 'Set-Cookie': 'locale=en-US; Max-Age=604800; Expires=Tue, 22-Feb-2022 16:08:22 GMT; Path=, locale=en-US; Max-Age=604800; Expires=Tue, 22-Feb-2022 16:08:22 GMT; Path=', 'X-BrokerID': '0', 'CF-Cache-Status': 'DYNAMIC', 'Expect-CT': 'max-age=604800, report-uri="[https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct]()"', 'Server': 'cloudflare', 'CF-RAY': '6ddfcb61bc146d8c-MUC'} ResponseBody: {"code":"51000","data":[],"msg":"Parameter posSide  error"}
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
~/.pyenv/versions/3.9.7/envs/trade_397/lib/python3.9/site-packages/ccxt/base/exchange.py in fetch(self, url, method, headers, body)
    657             self.logger.debug("%s %s, Response: %s %s %s", method, url, http_status_code, headers, http_response)
--> 658             response.raise_for_status()
    659 

~/.pyenv/versions/3.9.7/envs/trade_397/lib/python3.9/site-packages/requests/models.py in raise_for_status(self)
    959         if http_error_msg:
--> 960             raise HTTPError(http_error_msg, response=self)
    961 

HTTPError: 400 Client Error:  for url: https://www.okx.com/api/v5/account/set-leverage

During handling of the above exception, another exception occurred:

BadRequest                                Traceback (most recent call last)
/tmp/ipykernel_1520147/1210820506.py in <module>
      1 ct.verbose = True
----> 2 ct.set_leverage(leverage=5,
      3                 symbol=pair,
      4                 params={
      5                     "mgnMode": 'isolated',

~/.pyenv/versions/3.9.7/envs/trade_397/lib/python3.9/site-packages/ccxt/okx.py in set_leverage(self, leverage, symbol, params)
   3635             'instId': market['id'],
   3636         }
-> 3637         response = self.privatePostAccountSetLeverage(self.extend(request, params))
   3638         #
   3639         #     {

~/.pyenv/versions/3.9.7/envs/trade_397/lib/python3.9/site-packages/ccxt/base/exchange.py in inner(_self, params, context)
    498                 if context is not None:
    499                     inner_kwargs['context'] = params
--> 500                 return entry(_self, **inner_kwargs)
    501             return inner
    502         to_bind = partialer()

~/.pyenv/versions/3.9.7/envs/trade_397/lib/python3.9/site-packages/ccxt/base/exchange.py in request(self, path, api, method, params, headers, body, config, context)
    549     def request(self, path, api='public', method='GET', params={}, headers=None, body=None, config={}, context={}):
    550         """Exchange.request is the entry point for all generated methods"""
--> 551         return self.fetch2(path, api, method, params, headers, body, config, context)
    552 
    553     @staticmethod

~/.pyenv/versions/3.9.7/envs/trade_397/lib/python3.9/site-packages/ccxt/base/exchange.py in fetch2(self, path, api, method, params, headers, body, config, context)
    545         self.lastRestRequestTimestamp = self.milliseconds()
    546         request = self.sign(path, api, method, params, headers, body)
--> 547         return self.fetch(request['url'], request['method'], request['headers'], request['body'])
    548 
    549     def request(self, path, api='public', method='GET', params={}, headers=None, body=None, config={}, context={}):

~/.pyenv/versions/3.9.7/envs/trade_397/lib/python3.9/site-packages/ccxt/base/exchange.py in fetch(self, url, method, headers, body)
    672         except HTTPError as e:
    673             details = ' '.join([self.id, method, url])
--> 674             skip_further_error_handling = self.handle_errors(http_status_code, http_status_text, url, method, headers, http_response, json_response, request_headers, request_body)
    675             if not skip_further_error_handling:
    676                 self.handle_http_status_code(http_status_code, http_status_text, url, method, http_response)

~/.pyenv/versions/3.9.7/envs/trade_397/lib/python3.9/site-packages/ccxt/okx.py in handle_errors(self, httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody)
   3900                 self.throw_exactly_matched_exception(self.exceptions['exact'], errorCode, feedback)
   3901                 self.throw_broadly_matched_exception(self.exceptions['broad'], message, feedback)
-> 3902             self.throw_exactly_matched_exception(self.exceptions['exact'], code, feedback)
   3903             raise ExchangeError(feedback)  # unknown message

~/.pyenv/versions/3.9.7/envs/trade_397/lib/python3.9/site-packages/ccxt/base/exchange.py in throw_exactly_matched_exception(self, exact, string, message)
    563     def throw_exactly_matched_exception(self, exact, string, message):
    564         if string in exact:
--> 565             raise exact[string](message)
    566 
    567     def throw_broadly_matched_exception(self, broad, string, message):

BadRequest: okx {"code":"51000","data":[],"msg":"Parameter posSide  error"}

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions