sammchardy / python-binance

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

renew 3 interface in client #1342

Closed zweix123 closed 1 year ago

zweix123 commented 1 year ago

solves #1341

add version default arg of _create_futures_api_uti add version default arg of _create_futures_api_uti

use the arg in

nikitaGetman commented 1 year ago

Please merge it. Actual API is broken with error: binance.exceptions.BinanceAPIException: APIError(code=-5000): GET /fapi/v1/account is retired, please use GET /fapi/v2/account

nikitaGetman commented 1 year ago

@sammchardy

zweix123 commented 1 year ago

Hello, I have an error on get_loop which doesn't exist in helpers.py and indeed it doesn't exist when I go to the file.

Connected to pydev debugger (build 231.9225.15)
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/user/virtualenv/workspace/Env python/project/lib/python3.8/site-packages/binance/__init__.py", line 9, in <module>
    from binance.client import Client, AsyncClient  # noqa
  File "/home/user/virtualenv/workspace/Env python/project/lib/python3.8/site-packages/binance/client.py", line 17, in <module>
    from .helpers import interval_to_milliseconds, convert_ts_str, get_loop
ImportError: cannot import name 'get_loop' from 'binance.helpers' (/home/user/virtualenv/workspace/Env python/projetc/lib/python3.8/site-packages/binance/helpers.py)

Process finished with exit code 1

Works if I apply the changes directly to 1.0.17 (master), as I don't have a get_loop import: Here are the declarations I have in client.py

from base64 import b64encode
from pathlib import Path
from typing import Dict, Optional, List, Tuple, Union

import aiohttp
import asyncio
import hashlib
import hmac
import requests
import time
from Crypto.PublicKey import RSA
from Crypto.Hash import SHA256
from Crypto.Signature import pkcs1_15
from operator import itemgetter
from urllib.parse import urlencode

from .helpers import interval_to_milliseconds, convert_ts_str
from .exceptions import BinanceAPIException, BinanceRequestException, NotImplementedException
from .enums import HistoricalKlinesType

The code for python-binance is different on Github and Pypi now. get_loop related code on Github, so my PR also includes it.

I guess you may have only copied the code from the client. py file. If you want to use my modifications, you can replace the entire library.

mindedman commented 1 year ago

Hi, there, I'm not familiar with this, thanks for the clarification. I need this package and pypi only offers version 1.0.17 with error for this binance api change. As a result, I'm going to turn to the github code and once installed and validated on my workstation, I won't hesitate to notify whether the code is valid or not. Thanks

zweix123 commented 1 year ago

Seems ok, but the same must be done for async functions.

Thank you for your reminder. I have made the modifications. Could you please conduct another code review?

sammchardy commented 1 year ago

Thanks @zweix123

zweix123 commented 1 year ago

I have two more questions now (please forgive my lack of engineering experience)

  1. There are many issues related to this bug, can we close them now?
  2. Although the project library has been updated, it seems that PyPi has not been updated, and the current version of pip is still the old version.
sharmasachin233 commented 1 year ago

If you're experiencing issues and can't wait for the module to update on PyPi, you can use the following commands:

  1. Uninstall the current version of python-binance pip uninstall python-binance

  2. Install the latest version from the master branch of the GitHub repository pip install git+https://github.com/sammchardy/python-binance.git@master

as fix is merged in master.

MehmetSever09 commented 1 year ago

I have encountered the following api error:

BinanceAPIException: APIError(code=-5000): GET /fapi/v1/account is retired, please use GET /fapi/v2/account

The endpoints for account, balance, and PositionRisk have been changed by Binance. So I change my attribute as follows and it fixed the problems:

acc_balance = client.futures_account_balance(version=2) for check_balance in acc_balance: if check_balance["asset"] == asset: asset_balance = float(check_balance["balance"]) acc_balance variable returns the usdt balance in my account. I hope this helps