python-binance icon indicating copy to clipboard operation
python-binance copied to clipboard

help in getting start with python-binance

Open grahmani opened this issue 8 years ago • 8 comments

I just want to read data from binance. I made an account in Binance, got my api_key and api_secret. Then from senttings, project interpreter, installed the python-binance package (already installed visual c++). Now I want to start. This is my code:

from binance.client import Client api_key='....' api_secret='...' client = Client(api_key, api_secret) depth = client.get_order_book(symbol='BNBBTC')

when I run the code up to here, I get lots of errors:

File "D:\PycharmProjects\venv\lib\site-packages\urllib3\connection.py", line 171, in _new_conn (self._dns_host, self.port), self.timeout, **extra_kw) File "D:\PycharmProjects\venv\lib\site-packages\urllib3\util\connection.py", line 79, in create_connection raise err File "D:\PycharmProjects\venv\lib\site-packages\urllib3\util\connection.py", line 69, in create_connection sock.connect(sa) ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it .... and other errors as well. could you please help me?

grahmani avatar Oct 19 '18 12:10 grahmani

What are you trying to do with the data? I.e. do you want to get historical data, daily data, live data? This library is solid, but that also makes it versatile.

BrentLewis avatar Oct 20 '18 15:10 BrentLewis

Just want to learn how to get one kind of data and write it into a file. It doesn’t matter what. But I face with errors. I wish There was just a step by step tutorial how to get just a simple data from binance. Could you please help me with this regard?

grahmani avatar Oct 20 '18 19:10 grahmani

Can't comment on pycharm, as I tried to use it and never had any luck. I would recommend Anaconda and as the environment, I use Spyder as I learned to code on Matlab and Spyder's interface is most similar to Matlab. Maybe try Anaconda and Jupyter notebook or Spyder.

CJ1976 avatar Dec 29 '18 08:12 CJ1976

@grahmani from the 'ConnectionRefusedError' that you're getting, I suspect your credentials may not be getting accepted by the Binance API. You can check this by looking at the API response exceptions if you change your code to:

from binance.client import Client
api_key = 'enter your actual API key here'
api_secret = 'enter your actual API secret here'

try:
    client = Client(api_key, api_secret)
    depth = client.get_order_book(symbol='BNBBTC')
except BinanceAPIException as e:
    print(e.status_code)
    print(e.message)
    print(e.code)

After running this, you should be able to see a reason why the connection was rejected by the Binance API. Feel free to post the results of this if you're still not sure why it's happening.

anson-vandoren avatar Jan 06 '19 19:01 anson-vandoren

(analysis) chirag@chirag-Lenovo-ideapad-330-15IKB:~/Desktop$ python cm.py 
Traceback (most recent call last):
  File "cm.py", line 1, in <module>
    from binance.client import Client
  File "/home/chirag/Desktop/binance.py", line 7, in <module>
    from binance.client import Client
ModuleNotFoundError: No module named 'binance.client'; 'binance' is not a package


(analysis) chirag@chirag-Lenovo-ideapad-330-15IKB:~/Desktop$ cat cm.py 
from binance.client import Client
api_key = 'enter your actual API key here'
api_secret = 'enter your actual API secret here'

try:
    client = Client(api_key, api_secret)
    depth = client.get_order_book(symbol='BNBBTC')
except BinanceAPIException as e:
    print(e.status_code)
    print(e.message)
    print(e.code)


(analysis) chirag@chirag-Lenovo-ideapad-330-15IKB:~/Desktop$ python
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from binance.client import Client
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/chirag/Desktop/binance.py", line 7, in <module>
    from binance.client import Client
ModuleNotFoundError: No module named 'binance.client'; 'binance' is not a package
>>> exit()


(analysis) chirag@chirag-Lenovo-ideapad-330-15IKB:~/Desktop$ pip list
Package         Version   
--------------- ----------
binance         0.3       
certifi         2018.11.29
chardet         3.0.4     
dateparser      0.7.0     
idna            2.8       
pip             18.1      
pkg-resources   0.0.0     
python-dateutil 2.7.5     
pytz            2018.9    
regex           2018.11.22
requests        2.21.0    
setuptools      40.6.3    
six             1.12.0    
tzlocal         1.5.1     
urllib3         1.24.1    
wheel           0.32.3    

Not able to import binance , Note : binance is installed .

python 3.6 binance 0.3

cmaliwal avatar Jan 10 '19 07:01 cmaliwal

Is binance installed in your path? If you are using Spyder, go to tools and check your path under PYTHONPATH. If you don't see the folder that contains your binance module, click the "add path" button and it will open up a file browser that will allow you to navigate to the folder that the binance modules is in. Save that as part of your path. If you don't have the path to your binance folder in your path, python doesn't know it's on your computer. Path is basically you telling python what folders you want it to look in, if you don't let it look in the folder binance is in, it will never see it.

https://youtu.be/A7E18apPQJs There is a vid about path

CJ1976 avatar Jan 10 '19 07:01 CJ1976

The library you have installed binance 0.3 is not Sam McHardy's library, but rather this one from toshima

Please try: pip uninstall binance pip install python-binance

and then test your program again. This should show up in pip list as python-binance 0.7.0

anson-vandoren avatar Jan 10 '19 15:01 anson-vandoren

Anson, totally missed that in my response., thanks.

CJ1976 avatar Jan 12 '19 05:01 CJ1976