%global _empty_manifest_terminate_build 0 Name: python-binance-connector Version: 2.0.0 Release: 1 Summary: This is a lightweight library that works as a connector to Binance public API. License: MIT URL: https://github.com/binance/binance-connector-python Source0: https://mirrors.nju.edu.cn/pypi/web/packages/ea/a3/2c0dc032fa7b59f8191b5e40ba79fecd44d9b966d8dfb2c69de2d4789094/binance-connector-2.0.0.tar.gz BuildArch: noarch Requires: python3-autobahn Requires: python3-Twisted Requires: python3-requests Requires: python3-pyOpenSSL Requires: python3-service-identity Requires: python3-pycryptodome %description # Binance Public API Connector Python [![PyPI version](https://img.shields.io/pypi/v/binance-connector)](https://pypi.python.org/pypi/binance-connector) [![Python version](https://img.shields.io/pypi/pyversions/binance-connector)](https://www.python.org/downloads/) [![Documentation](https://img.shields.io/badge/docs-latest-blue)](https://binance-connector.readthedocs.io/en/stable/) [![Code Style](https://img.shields.io/badge/code_style-black-black)](https://black.readthedocs.io/en/stable/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) This is a lightweight library that works as a connector to [Binance public API](https://github.com/binance/binance-spot-api-docs) - Supported APIs: - `/api/*` - `/sapi/*` - Spot Websocket Market Stream - Spot User Data Stream - Inclusion of test cases and examples - Customizable base URL, request timeout and HTTP proxy - Response metadata can be displayed ## Installation ```bash pip install binance-connector ``` ## Documentation [https://binance-connector.readthedocs.io](https://binance-connector.readthedocs.io) ## RESTful APIs Usage examples: ```python from binance.spot import Spot client = Spot() # Get server timestamp print(client.time()) # Get klines of BTCUSDT at 1m interval print(client.klines("BTCUSDT", "1m")) # Get last 10 klines of BNBUSDT at 1h interval print(client.klines("BNBUSDT", "1h", limit=10)) # API key/secret are required for user data endpoints client = Spot(api_key='', api_secret='') # Get account and balance information print(client.account()) # Post a new order params = { 'symbol': 'BTCUSDT', 'side': 'SELL', 'type': 'LIMIT', 'timeInForce': 'GTC', 'quantity': 0.002, 'price': 9500 } response = client.new_order(**params) print(response) ``` Please find `examples` folder to check for more endpoints. - In order to set your API and Secret Key for use of the examples, create a file `examples/config.ini` with your keys. - Eg: ```ini # examples/config.ini [keys] api_key=abc123456 api_secret=cba654321 ``` ### Authentication Binance supports HMAC and RSA API authentication. ```python # HMAC: pass API key and secret client = Client(api_key, api_secret) print(client.account()) # RSA Keys client = Client(api_key=api_key, private_key=private_key) print(client.account()) # Encrypted RSA Key client = Client(api_key=api_key, private_key=private_key, private_key_pass='password') print(client.account()) ``` Please find `examples/spot/trade/get_account.py` for more details. ### Testnet [Spot Testnet](https://testnet.binance.vision/) is available, it can be used to test `/api/*` endpoints. - `/sapi/*` endpoints are not available. - No UI. - Steps to setup testnet API key. [https://dev.binance.vision/t/99](https://dev.binance.vision/t/99) To use testnet: ```python from binance.spot import Spot as Client client = Client(base_url='https://testnet.binance.vision') print(client.time()) ``` ### Base URL If `base_url` is not provided, it defaults to `api.binance.com`.
It's recommended to pass in the `base_url` parameter, even in production as Binance provides alternative URLs in case of performance issues: - `https://api1.binance.com` - `https://api2.binance.com` - `https://api3.binance.com` ### Optional parameters PEP8 suggests _lowercase with words separated by underscores_, but for this connector, the methods' optional parameters should follow their exact naming as in the API documentation. ```python # Recognised parameter name response = client.cancel_oco_order('BTCUSDT', orderListId=1) # Unrecognised parameter name response = client.cancel_oco_order('BTCUSDT', order_list_id=1) ``` ### RecvWindow parameter Additional parameter `recvWindow` is available for endpoints requiring signature.
It defaults to `5000` (milliseconds) and can be any value lower than `60000`(milliseconds). Anything beyond the limit will result in an error response from Binance server. ```python from binance.spot import Spot as Client client = Client(api_key, api_secret) response = client.get_order('BTCUSDT', orderId=11, recvWindow=10000) ``` ### Timeout `timeout` is available to be assigned with the number of seconds you find most appropriate to wait for a server response.
Please remember the value as it won't be shown in error message _no bytes have been received on the underlying socket for timeout seconds_.
By default, `timeout` is None. Hence, requests do not time out. ```python from binance.spot import Spot as Client client= Client(timeout=1) ``` ### Proxy Proxy is supported. ```python from binance.spot import Spot as Client proxies = { 'https': 'http://1.2.3.4:8080' } client= Client(proxies=proxies) ``` ### Response Metadata The Binance API server provides weight usages in the headers of each response. You can display them by initializing the client with `show_limit_usage=True`: ```python from binance.spot import Spot as Client client = Client(show_limit_usage=True) print(client.time()) ``` returns: ```python {'data': {'serverTime': 1587990847650}, 'limit_usage': {'x-mbx-used-weight': '31', 'x-mbx-used-weight-1m': '31'}} ``` You can also display full response metadata to help in debugging: ```python client = Client(show_header=True) print(client.time()) ``` returns: ```python {'data': {'serverTime': 1587990847650}, 'header': {'Context-Type': 'application/json;charset=utf-8', ...}} ``` If `ClientError` is received, it'll display full response meta information. ### Display logs Setting the log level to `DEBUG` will log the request URL, payload and response text. ### Error There are 2 types of error returned from the library: - `binance.error.ClientError` - This is thrown when server returns `4XX`, it's an issue from client side. - It has 5 properties: - `status_code` - HTTP status code - `error_code` - Server's error code, e.g. `-1102` - `error_message` - Server's error message, e.g. `Unknown order sent.` - `header` - Full response header. - `error_data`* - Additional detailed data which supplements the `error_message`. - **Only applicable on select endpoints, eg. `cancelReplace`* - `binance.error.ServerError` - This is thrown when server returns `5XX`, it's an issue from server side. ## Websocket ```python from binance.websocket.spot.websocket_client import SpotWebsocketClient as WebsocketClient def message_handler(message): print(message) ws_client = WebsocketClient() ws_client.start() ws_client.mini_ticker( symbol='bnbusdt', id=1, callback=message_handler, ) # Combine selected streams ws_client.instant_subscribe( stream=['bnbusdt@bookTicker', 'ethusdt@bookTicker'], callback=message_handler, ) ws_client.stop() ``` More websocket examples are available in the `examples` folder ### Heartbeat Once connected, the websocket server sends a ping frame every 3 minutes and requires a response pong frame back within a 10 minutes period. This package handles the pong responses automatically. ### Testnet ```python from binance.websocket.spot.websocket_client import SpotWebsocketClient as WebsocketClient ws_client = WebsocketClient(stream_url='wss://testnet.binance.vision') ``` ## Test Case ```python # In case packages are not installed yet pip install -r requirements/requirements-test.txt pytest ``` ## Limitation Futures and Vanilla Options APIs are not supported: - `/fapi/*` - `/dapi/*` - `/vapi/*` - Associated Websocket Market and User Data Streams ## Contributing Contributions are welcome.
If you've found a bug within this project, please open an issue to discuss what you would like to change.
If it's an issue with the API, please open a topic at [Binance Developer Community](https://dev.binance.vision) %package -n python3-binance-connector Summary: This is a lightweight library that works as a connector to Binance public API. Provides: python-binance-connector BuildRequires: python3-devel BuildRequires: python3-setuptools BuildRequires: python3-pip %description -n python3-binance-connector # Binance Public API Connector Python [![PyPI version](https://img.shields.io/pypi/v/binance-connector)](https://pypi.python.org/pypi/binance-connector) [![Python version](https://img.shields.io/pypi/pyversions/binance-connector)](https://www.python.org/downloads/) [![Documentation](https://img.shields.io/badge/docs-latest-blue)](https://binance-connector.readthedocs.io/en/stable/) [![Code Style](https://img.shields.io/badge/code_style-black-black)](https://black.readthedocs.io/en/stable/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) This is a lightweight library that works as a connector to [Binance public API](https://github.com/binance/binance-spot-api-docs) - Supported APIs: - `/api/*` - `/sapi/*` - Spot Websocket Market Stream - Spot User Data Stream - Inclusion of test cases and examples - Customizable base URL, request timeout and HTTP proxy - Response metadata can be displayed ## Installation ```bash pip install binance-connector ``` ## Documentation [https://binance-connector.readthedocs.io](https://binance-connector.readthedocs.io) ## RESTful APIs Usage examples: ```python from binance.spot import Spot client = Spot() # Get server timestamp print(client.time()) # Get klines of BTCUSDT at 1m interval print(client.klines("BTCUSDT", "1m")) # Get last 10 klines of BNBUSDT at 1h interval print(client.klines("BNBUSDT", "1h", limit=10)) # API key/secret are required for user data endpoints client = Spot(api_key='', api_secret='') # Get account and balance information print(client.account()) # Post a new order params = { 'symbol': 'BTCUSDT', 'side': 'SELL', 'type': 'LIMIT', 'timeInForce': 'GTC', 'quantity': 0.002, 'price': 9500 } response = client.new_order(**params) print(response) ``` Please find `examples` folder to check for more endpoints. - In order to set your API and Secret Key for use of the examples, create a file `examples/config.ini` with your keys. - Eg: ```ini # examples/config.ini [keys] api_key=abc123456 api_secret=cba654321 ``` ### Authentication Binance supports HMAC and RSA API authentication. ```python # HMAC: pass API key and secret client = Client(api_key, api_secret) print(client.account()) # RSA Keys client = Client(api_key=api_key, private_key=private_key) print(client.account()) # Encrypted RSA Key client = Client(api_key=api_key, private_key=private_key, private_key_pass='password') print(client.account()) ``` Please find `examples/spot/trade/get_account.py` for more details. ### Testnet [Spot Testnet](https://testnet.binance.vision/) is available, it can be used to test `/api/*` endpoints. - `/sapi/*` endpoints are not available. - No UI. - Steps to setup testnet API key. [https://dev.binance.vision/t/99](https://dev.binance.vision/t/99) To use testnet: ```python from binance.spot import Spot as Client client = Client(base_url='https://testnet.binance.vision') print(client.time()) ``` ### Base URL If `base_url` is not provided, it defaults to `api.binance.com`.
It's recommended to pass in the `base_url` parameter, even in production as Binance provides alternative URLs in case of performance issues: - `https://api1.binance.com` - `https://api2.binance.com` - `https://api3.binance.com` ### Optional parameters PEP8 suggests _lowercase with words separated by underscores_, but for this connector, the methods' optional parameters should follow their exact naming as in the API documentation. ```python # Recognised parameter name response = client.cancel_oco_order('BTCUSDT', orderListId=1) # Unrecognised parameter name response = client.cancel_oco_order('BTCUSDT', order_list_id=1) ``` ### RecvWindow parameter Additional parameter `recvWindow` is available for endpoints requiring signature.
It defaults to `5000` (milliseconds) and can be any value lower than `60000`(milliseconds). Anything beyond the limit will result in an error response from Binance server. ```python from binance.spot import Spot as Client client = Client(api_key, api_secret) response = client.get_order('BTCUSDT', orderId=11, recvWindow=10000) ``` ### Timeout `timeout` is available to be assigned with the number of seconds you find most appropriate to wait for a server response.
Please remember the value as it won't be shown in error message _no bytes have been received on the underlying socket for timeout seconds_.
By default, `timeout` is None. Hence, requests do not time out. ```python from binance.spot import Spot as Client client= Client(timeout=1) ``` ### Proxy Proxy is supported. ```python from binance.spot import Spot as Client proxies = { 'https': 'http://1.2.3.4:8080' } client= Client(proxies=proxies) ``` ### Response Metadata The Binance API server provides weight usages in the headers of each response. You can display them by initializing the client with `show_limit_usage=True`: ```python from binance.spot import Spot as Client client = Client(show_limit_usage=True) print(client.time()) ``` returns: ```python {'data': {'serverTime': 1587990847650}, 'limit_usage': {'x-mbx-used-weight': '31', 'x-mbx-used-weight-1m': '31'}} ``` You can also display full response metadata to help in debugging: ```python client = Client(show_header=True) print(client.time()) ``` returns: ```python {'data': {'serverTime': 1587990847650}, 'header': {'Context-Type': 'application/json;charset=utf-8', ...}} ``` If `ClientError` is received, it'll display full response meta information. ### Display logs Setting the log level to `DEBUG` will log the request URL, payload and response text. ### Error There are 2 types of error returned from the library: - `binance.error.ClientError` - This is thrown when server returns `4XX`, it's an issue from client side. - It has 5 properties: - `status_code` - HTTP status code - `error_code` - Server's error code, e.g. `-1102` - `error_message` - Server's error message, e.g. `Unknown order sent.` - `header` - Full response header. - `error_data`* - Additional detailed data which supplements the `error_message`. - **Only applicable on select endpoints, eg. `cancelReplace`* - `binance.error.ServerError` - This is thrown when server returns `5XX`, it's an issue from server side. ## Websocket ```python from binance.websocket.spot.websocket_client import SpotWebsocketClient as WebsocketClient def message_handler(message): print(message) ws_client = WebsocketClient() ws_client.start() ws_client.mini_ticker( symbol='bnbusdt', id=1, callback=message_handler, ) # Combine selected streams ws_client.instant_subscribe( stream=['bnbusdt@bookTicker', 'ethusdt@bookTicker'], callback=message_handler, ) ws_client.stop() ``` More websocket examples are available in the `examples` folder ### Heartbeat Once connected, the websocket server sends a ping frame every 3 minutes and requires a response pong frame back within a 10 minutes period. This package handles the pong responses automatically. ### Testnet ```python from binance.websocket.spot.websocket_client import SpotWebsocketClient as WebsocketClient ws_client = WebsocketClient(stream_url='wss://testnet.binance.vision') ``` ## Test Case ```python # In case packages are not installed yet pip install -r requirements/requirements-test.txt pytest ``` ## Limitation Futures and Vanilla Options APIs are not supported: - `/fapi/*` - `/dapi/*` - `/vapi/*` - Associated Websocket Market and User Data Streams ## Contributing Contributions are welcome.
If you've found a bug within this project, please open an issue to discuss what you would like to change.
If it's an issue with the API, please open a topic at [Binance Developer Community](https://dev.binance.vision) %package help Summary: Development documents and examples for binance-connector Provides: python3-binance-connector-doc %description help # Binance Public API Connector Python [![PyPI version](https://img.shields.io/pypi/v/binance-connector)](https://pypi.python.org/pypi/binance-connector) [![Python version](https://img.shields.io/pypi/pyversions/binance-connector)](https://www.python.org/downloads/) [![Documentation](https://img.shields.io/badge/docs-latest-blue)](https://binance-connector.readthedocs.io/en/stable/) [![Code Style](https://img.shields.io/badge/code_style-black-black)](https://black.readthedocs.io/en/stable/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) This is a lightweight library that works as a connector to [Binance public API](https://github.com/binance/binance-spot-api-docs) - Supported APIs: - `/api/*` - `/sapi/*` - Spot Websocket Market Stream - Spot User Data Stream - Inclusion of test cases and examples - Customizable base URL, request timeout and HTTP proxy - Response metadata can be displayed ## Installation ```bash pip install binance-connector ``` ## Documentation [https://binance-connector.readthedocs.io](https://binance-connector.readthedocs.io) ## RESTful APIs Usage examples: ```python from binance.spot import Spot client = Spot() # Get server timestamp print(client.time()) # Get klines of BTCUSDT at 1m interval print(client.klines("BTCUSDT", "1m")) # Get last 10 klines of BNBUSDT at 1h interval print(client.klines("BNBUSDT", "1h", limit=10)) # API key/secret are required for user data endpoints client = Spot(api_key='', api_secret='') # Get account and balance information print(client.account()) # Post a new order params = { 'symbol': 'BTCUSDT', 'side': 'SELL', 'type': 'LIMIT', 'timeInForce': 'GTC', 'quantity': 0.002, 'price': 9500 } response = client.new_order(**params) print(response) ``` Please find `examples` folder to check for more endpoints. - In order to set your API and Secret Key for use of the examples, create a file `examples/config.ini` with your keys. - Eg: ```ini # examples/config.ini [keys] api_key=abc123456 api_secret=cba654321 ``` ### Authentication Binance supports HMAC and RSA API authentication. ```python # HMAC: pass API key and secret client = Client(api_key, api_secret) print(client.account()) # RSA Keys client = Client(api_key=api_key, private_key=private_key) print(client.account()) # Encrypted RSA Key client = Client(api_key=api_key, private_key=private_key, private_key_pass='password') print(client.account()) ``` Please find `examples/spot/trade/get_account.py` for more details. ### Testnet [Spot Testnet](https://testnet.binance.vision/) is available, it can be used to test `/api/*` endpoints. - `/sapi/*` endpoints are not available. - No UI. - Steps to setup testnet API key. [https://dev.binance.vision/t/99](https://dev.binance.vision/t/99) To use testnet: ```python from binance.spot import Spot as Client client = Client(base_url='https://testnet.binance.vision') print(client.time()) ``` ### Base URL If `base_url` is not provided, it defaults to `api.binance.com`.
It's recommended to pass in the `base_url` parameter, even in production as Binance provides alternative URLs in case of performance issues: - `https://api1.binance.com` - `https://api2.binance.com` - `https://api3.binance.com` ### Optional parameters PEP8 suggests _lowercase with words separated by underscores_, but for this connector, the methods' optional parameters should follow their exact naming as in the API documentation. ```python # Recognised parameter name response = client.cancel_oco_order('BTCUSDT', orderListId=1) # Unrecognised parameter name response = client.cancel_oco_order('BTCUSDT', order_list_id=1) ``` ### RecvWindow parameter Additional parameter `recvWindow` is available for endpoints requiring signature.
It defaults to `5000` (milliseconds) and can be any value lower than `60000`(milliseconds). Anything beyond the limit will result in an error response from Binance server. ```python from binance.spot import Spot as Client client = Client(api_key, api_secret) response = client.get_order('BTCUSDT', orderId=11, recvWindow=10000) ``` ### Timeout `timeout` is available to be assigned with the number of seconds you find most appropriate to wait for a server response.
Please remember the value as it won't be shown in error message _no bytes have been received on the underlying socket for timeout seconds_.
By default, `timeout` is None. Hence, requests do not time out. ```python from binance.spot import Spot as Client client= Client(timeout=1) ``` ### Proxy Proxy is supported. ```python from binance.spot import Spot as Client proxies = { 'https': 'http://1.2.3.4:8080' } client= Client(proxies=proxies) ``` ### Response Metadata The Binance API server provides weight usages in the headers of each response. You can display them by initializing the client with `show_limit_usage=True`: ```python from binance.spot import Spot as Client client = Client(show_limit_usage=True) print(client.time()) ``` returns: ```python {'data': {'serverTime': 1587990847650}, 'limit_usage': {'x-mbx-used-weight': '31', 'x-mbx-used-weight-1m': '31'}} ``` You can also display full response metadata to help in debugging: ```python client = Client(show_header=True) print(client.time()) ``` returns: ```python {'data': {'serverTime': 1587990847650}, 'header': {'Context-Type': 'application/json;charset=utf-8', ...}} ``` If `ClientError` is received, it'll display full response meta information. ### Display logs Setting the log level to `DEBUG` will log the request URL, payload and response text. ### Error There are 2 types of error returned from the library: - `binance.error.ClientError` - This is thrown when server returns `4XX`, it's an issue from client side. - It has 5 properties: - `status_code` - HTTP status code - `error_code` - Server's error code, e.g. `-1102` - `error_message` - Server's error message, e.g. `Unknown order sent.` - `header` - Full response header. - `error_data`* - Additional detailed data which supplements the `error_message`. - **Only applicable on select endpoints, eg. `cancelReplace`* - `binance.error.ServerError` - This is thrown when server returns `5XX`, it's an issue from server side. ## Websocket ```python from binance.websocket.spot.websocket_client import SpotWebsocketClient as WebsocketClient def message_handler(message): print(message) ws_client = WebsocketClient() ws_client.start() ws_client.mini_ticker( symbol='bnbusdt', id=1, callback=message_handler, ) # Combine selected streams ws_client.instant_subscribe( stream=['bnbusdt@bookTicker', 'ethusdt@bookTicker'], callback=message_handler, ) ws_client.stop() ``` More websocket examples are available in the `examples` folder ### Heartbeat Once connected, the websocket server sends a ping frame every 3 minutes and requires a response pong frame back within a 10 minutes period. This package handles the pong responses automatically. ### Testnet ```python from binance.websocket.spot.websocket_client import SpotWebsocketClient as WebsocketClient ws_client = WebsocketClient(stream_url='wss://testnet.binance.vision') ``` ## Test Case ```python # In case packages are not installed yet pip install -r requirements/requirements-test.txt pytest ``` ## Limitation Futures and Vanilla Options APIs are not supported: - `/fapi/*` - `/dapi/*` - `/vapi/*` - Associated Websocket Market and User Data Streams ## Contributing Contributions are welcome.
If you've found a bug within this project, please open an issue to discuss what you would like to change.
If it's an issue with the API, please open a topic at [Binance Developer Community](https://dev.binance.vision) %prep %autosetup -n binance-connector-2.0.0 %build %py3_build %install %py3_install install -d -m755 %{buildroot}/%{_pkgdocdir} if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi pushd %{buildroot} if [ -d usr/lib ]; then find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/lib64 ]; then find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/bin ]; then find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/sbin ]; then find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst fi touch doclist.lst if [ -d usr/share/man ]; then find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst fi popd mv %{buildroot}/filelist.lst . mv %{buildroot}/doclist.lst . %files -n python3-binance-connector -f filelist.lst %dir %{python3_sitelib}/* %files help -f doclist.lst %{_docdir}/* %changelog * Fri May 05 2023 Python_Bot - 2.0.0-1 - Package Spec generated