https://github.com/vinitjames/binancepy
An unofficial python wrapper for binance exchange API
https://github.com/vinitjames/binancepy
binance binance-api binance-python binance-python-api
Last synced: 5 months ago
JSON representation
An unofficial python wrapper for binance exchange API
- Host: GitHub
- URL: https://github.com/vinitjames/binancepy
- Owner: vinitjames
- License: mit
- Created: 2021-01-30T19:46:20.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-13T17:16:42.000Z (about 5 years ago)
- Last Synced: 2026-01-03T12:25:58.988Z (5 months ago)
- Topics: binance, binance-api, binance-python, binance-python-api
- Language: Python
- Homepage:
- Size: 174 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
================================
BinancePy
================================
.. image:: https://img.shields.io/github/workflow/status/vinitjames/binancepy/Python%20package?color=green%20
:target: https://github.com/vinitjames/binancepy/actions
.. image:: https://img.shields.io/pypi/v/binancepy?color=blue
:target: https://pypi.org/project/binancepy/
.. image:: https://img.shields.io/github/license/vinitjames/binancepy
:target: https://github.com/vinitjames/binancepy/blob/master/LICENSE
|
This is an unofficial Python wrapper for the `Binance exchange REST API v3 `_.
Source code
https://github.com/vinitjames/binancepy
Documentation
https://binancepy.readthedocs.io/en/latest/
Binance API Telegram
https://t.me/binance_api_english
Make sure you update often and check the `Changelog `_ for new features and bug fixes.
Features
--------
- Implementation of Market Data, Trading and Wallet endpoints
- Market Data Endpoints accessible without binance api key
- No need to generate timestamps yourself, the wrapper does it for you
- Response exception handling
- Historical Kline/Candle fetching function
- Simple handling of authentication
- Spot Trading
- Margin Trading
- Futures Trading
- Wallet Info and Transfer functionality
- Support other domains (.us, .jp, etc)
Quick Start
-----------
To install as Python package run
.. code-block:: bash
pip install binancepy
Or clone the repo with git and install with version you want
.. code-block:: bash
git clone -b 'branch name' https://github.com/vinitjames/binancepy.git
cd binancepy
pip install .
To run the sample public client which does not require api keys run the command below:-
.. code-block:: bash
python examples/sample_public_client.py
Fetching Market Data
--------------------
To fetch market data with binance market data endpoints both PublicClient and AuthenticatedClient can be used. PublicClient can be used without without an API key.
.. code-block:: python
from binance.client import PublicClient
# creating a public client with default request params
client = PublicClient()
#getting server time
result = client.get_server_time()
# getting exchange info
ex_info = client.get_exchange_info()
# getting exchange info
sym_info = client.get_symbol_info(symbol='ETHEUR')
#getting price_ticker if symbol not included value for all symbols are returned
price_ticker = client.get_price_ticker(symbol='ETHEUR')
#getting orderbook ticker if symbol not included value for all symbols are returned
orderbook_ticker = client.get_orderbook_ticker(symbol='ETHEUR')
#getting orderbook for a symbol
orderbook = client.get_order_book(symbol='ETHEUR', limit = 10)
#getting average price, for the specified symbol
avg_price = client.get_avg_price('ETHEUR')
#getting 24hr price ticker, if symbol not included value for all symbols are returned
_24_hr_ticker = client.get_24hr_ticker('ETHEUR')
#getting recent trades for a symbol
recent_trades = client.get_recent_trades('ETHEUR', limit=5)
#getting historical klines/candelstick for a symbol,
klines = client.get_historical_klines(symbol = 'ETHUSDT',
interval = client.KLINE_INTERVAL.ONEDAY,
startTime = '2/12/2018',
endTime = '12/12/2019')
Trading and Getting Account/Wallet Info with API keys
-----------------------------------------------------
To use trading(Spot, Margin, Future) and wallet endpoints a binance account create a binance account.
`Register an account with Binance `_.
`Generate an API Key `_ and assign relevant permissions.
.. code-block:: python
from binance.client import AuthenticatedClient
client = AuthenticatedClient(api_key, api_secret)
# get market depth
depth = client.get_order_book(symbol='BNBBTC')
# place a test market buy order, to place an actual order use the create_order function
order = client.create_test_order(
symbol='BNBBTC',
side=Client.SIDE_BUY,
type=Client.ORDER_TYPE_MARKET,
quantity=100)
# get all symbol prices
prices = client.get_all_tickers()
# withdraw 100 ETH
# check docs for assumptions around withdrawals
from binance.exceptions import BinanceAPIError, BinanceWithdrawError
try:
result = client.withdraw(
asset='ETH',
address='',
amount=100)
except BinanceAPIException as e:
print(e)
except BinanceWithdrawException as e:
print(e)
else:
print("Success")
# fetch list of withdrawals
withdraws = client.get_withdraw_history()
# fetch list of ETH withdrawals
eth_withdraws = client.get_withdraw_history(asset='ETH')
# get a deposit address for BTC
address = client.get_deposit_address(asset='BTC')
# start aggregated trade websocket for BNBBTC
def process_message(msg):
print("message type: {}".format(msg['e']))
print(msg)
For more `check out the documentation `_.