aio-binance-futures
Binance Futures Public Async API Connector Python
This is a lightweight library that works as a connector to Binance Futures public API
- Supported APIs:
- USDT-M Futures `/fapi/*``
- Futures/Delivery Websocket Market Stream
- Futures/Delivery User Data Stream
- Inclusion of examples
- Response metadata can be displayed
Installation
pip install aio-binance
RESTful APIs
Usage examples:
import asyncio
from aio_binance.futures.usdt import Client
async def main():
client = Client()
res = await client.time()
print(res)
client = Client(key='<api_key>', secret='<api_secret>')
# Get account information
res = await client.account()
print(res)
# Post a new order
params = {
'symbol': 'BTCUSDT',
'side': 'SELL',
'type': 'LIMIT',
'timeInForce': 'GTC',
'quantity': 0.002,
'price': 59808
}
res = await client.new_order(**params)
print(response)
asyncio.run(main())
Please find examples folder to check for more endpoints.
Testnet
You can choose testnet
from aio_binance.futures.usdt import Client
client= Client(testnet=True)
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.
# Recognised parameter name
response = client.query_order('BTCUSDT', orderListId=1)
# Unrecognised parameter name
response = client.query_order('BTCUSDT', order_list_id=1)
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=5
from aio_binance.futures.usdt import Client
client= Client(timeout=1)
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:
from aio_binance.futures.usdt import Client
client = Client(show_limit_usage=True)
print(client.time())
returns:
{'data': {'serverTime': 1647990837551}, 'limit_usage': 40}
You can also display full response metadata to help in debugging:
client = Client(show_header=True)
print(client.time())
returns:
{'data': {'serverTime': 1587990847650}, 'header': {'Context-Type': 'application/json;charset=utf-8', ...}}
User agent
client = Client(agent='name_app')
You can pass the name of your application.
Websocket
This is an example of connecting to multiple streams
import asyncio
from aio_binance.futures.usdt import WsClient
async def calback_event(data: dict):
print(data)
async def main():
ws = WsClient()
stream = [
ws.liquidation_order(),
ws.book_ticker(),
ws.ticker('BTCUSDT')
]
res = await asyncio.gather(*stream)
await ws.subscription_streams(res, calback_event)
asyncio.run(main())
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 5 minutes period. This package handles the pong responses automatically.
Metadata
Release files for aio-binance-library 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| aio-binance-library-2.0.1.tar.gz | 17.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aio_binance_library-2.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 36.2 kB
Release files / aio-binance-library-2.0.1.tar.gz
| Download URL | aio-binance-library-2.0.1.tar.gz |
|---|---|
| Size | 17.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a0a2ff7b4a6f32a52a799a295b70e26fb5b4b92222e091273dc6d84fcabd3fd9
|
|
BLAKE2b-256 checksum How to use checksums |
4090f3c4216ab2efd0bb378da66950437be1d9f8b6b4f28243fea9f88f82a9fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1
|
Release files / aio_binance_library-2.0.1-py3-none-any.whl
| Download URL | aio_binance_library-2.0.1-py3-none-any.whl |
|---|---|
| Size | 18.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bec948723de1be89dbef249187c71df4a3cf5d08f6e7b1ff7170768fff611da4
|
|
BLAKE2b-256 checksum How to use checksums |
7ebfc3b76e2cf95b43955807ca0a9698ad618c8b17b121d946f313309e9c8646
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1
|
Security for aio-binance-library 2.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.