sammchardy / python-binance

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

v3 is here #1420

Open dfrankmv opened 1 month ago

dfrankmv commented 1 month ago

Binance has released a v3 for some endpoint (today July 24th). See the changelog https://binance-docs.github.io/apidocs/futures/en/#get-position-margin-change-history-trade

Can we pass the version as a parameter?

tsunamilx commented 1 month ago

I think the project is dead, we are on our own to maintain the lib. I usually add/overwrite api methods by using my own client extending the original client class, for example (I am using AsyncClient):

from binance import AsyncClient

class AsyncClient2(AsyncClient):

    # the new methods
    async def futures_account_config(self, **params):
        return await self._request_futures_api('get', 'accountConfig', signed=True, version=1, data=params)

     async def futures_symbol_config(self, **params):
        return await self._request_futures_api('get', 'symbolConfig', signed=True, version=1, data=params)

    # the v3 methods
    async def futures_account_balance(self, **params):
        return await self._request_futures_api('get', 'balance', signed=True, version=3, data=params)

    async def futures_position_information(self, **params):
        return await self._request_futures_api('get', 'positionRisk', signed=True, version=3, data=params)

    def _create_futures_api_uri(self, path: str, version=1) -> str:
        url = self.FUTURES_URL
        if self.testnet:
            url = self.FUTURES_TESTNET_URL
        return f'{url}/v{version}/{path}'