sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
5.89k stars 2.2k forks source link

Can't get new isolated-margin crypto values. #598

Open ZENALC opened 3 years ago

ZENALC commented 3 years ago

Describe the bug If you try to get your account's values for coins that are in the isolated-margin caps, you will receive an error. For example, if you try to get LUNA values, you will receive an error.

To Reproduce client.get_margin_asset(asset='LUNA')

Expected behavior You are supposed to get the amount of Luna owned and borrowed.

Environment (please complete the following information):

Logs or Additional context Binance announced new endpoints for this feature. These endpoints have not been added to the library.

ZENALC commented 3 years ago

Figured it out. You can directly do it from a private function like so: self.binanceClient._request_margin_api('get', 'margin/isolated/account', True, data=params)

xulngx commented 3 years ago

Hi~ I have tried your way to change function myself but got error msg:

KeyError                                  Traceback (most recent call last)
<ipython-input-5-fb6f58ee1624> in <module>
----> 1 client._handle_response()

~/miniconda3/envs/jp/lib/python3.7/site-packages/binance/client.py in _handle_response(self)
    228         """
    229         if not str(self.response.status_code).startswith('2'):
--> 230             raise BinanceAPIException(self.response)
    231         try:
    232             return self.response.json()

~/miniconda3/envs/jp/lib/python3.7/site-packages/binance/exceptions.py in __init__(self, response)
     11             self.message = 'Invalid JSON error message from Binance: {}'.format(response.text)
     12         else:
---> 13             self.code = json_res['code']
     14             self.message = json_res['msg']
     15         self.status_code = response.status_code

KeyError: 'code'

Can you tell me how to solve this problem please~ Thank you!!!

kimchirichie commented 3 years ago

ideally we would have an interface for the call. interested in creating a PR?

ZENALC commented 3 years ago

Hi~ I have tried your way to change function myself but got error msg:

KeyError                                  Traceback (most recent call last)
<ipython-input-5-fb6f58ee1624> in <module>
----> 1 client._handle_response()

~/miniconda3/envs/jp/lib/python3.7/site-packages/binance/client.py in _handle_response(self)
    228         """
    229         if not str(self.response.status_code).startswith('2'):
--> 230             raise BinanceAPIException(self.response)
    231         try:
    232             return self.response.json()

~/miniconda3/envs/jp/lib/python3.7/site-packages/binance/exceptions.py in __init__(self, response)
     11             self.message = 'Invalid JSON error message from Binance: {}'.format(response.text)
     12         else:
---> 13             self.code = json_res['code']
     14             self.message = json_res['msg']
     15         self.status_code = response.status_code

KeyError: 'code'

Can you tell me how to solve this problem please~ Thank you!!!

Hey. Here is how I fixed it:

def get_isolated_margin_account(self, params) -> dict: """ Retrieves margin isolated account information. :param params: kwargs that normally go to binanceClient's request_margin_api function. :return: Margin isolated account information """ return self.binanceClient._request_margin_api('get', 'margin/isolated/account', True, data=params)

kimchirichie commented 3 years ago

@ZENALC if you open up a PR, i can merge it in

kimchirichie commented 3 years ago

looks like @xulngx beat me to it. #616