help in getting start with python-binance
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?
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.
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?
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.
@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.
(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
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
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, totally missed that in my response., thanks.