Package: aio-binance-library
aio-binance-libraryAsync library for connecting to the Binance API on PythonThis is a lightweight library that works as a connector toBinance Futures public APISupported APIs:USDT-M Futures `/fapi/*``Futures/Delivery Websocket Market StreamFutures/Delivery User Data StreamInclusion of examplesResponse metadata can be displayedInstallationpipinstallaio-binance-libraryGetting startedREST APIUsage examples:importasynciofromaio_binance.futures.usdtimportClientasyncdefmain():client=Client()res=awaitclient.get_public_time()print(res)client=Client(key='<api_key>',secret='<api_secret>')# Get account informationres=awaitclient.get_private_account_info()print(res)# Post a new orderparams={'symbol':'BTCUSDT','side':'SELL','type_order':'LIMIT','time_in_force':'GTC','quantity':0.002,'price':59808}res=awaitclient.create_private_order(**params)print(res)asyncio.run(main())Or you can use session (For multiple requests, this acts faster):importasynciofromaio_binance.futures.usdtimportApiSessionasyncdefmain():asyncwithApiSession(key='<api_key>',secret='<api_secret>')assession:res=awaitsession.get_public_time()print(res)# Get account informationres=awaitsession.get_private_account_info()print(res)# Post a new orderparams={'symbol':'BTCUSDT','side':'SELL','type_order':'LIMIT','time_in_force':'GTC','quantity':0.002,'price':59808}res=awaitsession.create_private_order(**params)print(res)asyncio.run(main())Please findexamplesfolder to check for more endpoints.NotesThe methods you need, adheres to a hierarchy<method>_<availability>_<method_name>

create_private_order()
or
get_public_time()Methods:create, get, delete, change, updateAvailability:private- methods where key_api and secret_api are requiredpublic- you can get information without a keyTestnetYou can choose testnetfromaio_binance.futures.usdtimportClientclient=Client(testnet=True)Optional parametersParameters can be passed in different formats as in Binance api documents or PEP8 suggestslowercase with words separated by underscores# Binance apiresponse=awaitclient.get_private_open_order('BTCUSDT',orderListId=1)# PEP8response=awaitclient.get_private_open_order('BTCUSDT',order_list_id=1)Timeouttimeoutis 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 messageno bytes have been received on the underlying socket for timeout seconds.By default,timeout=5fromaio_binance.futures.usdtimportClientclient=Client(timeout=1)Response MetadataThe Binance API server provides weight usages in the headers of each response.
You can display them by initializing the client withshow_limit_usage=True:fromaio_binance.futures.usdtimportClientclient=Client(show_limit_usage=True)res=awaitclient.time()print(res)returns:{'data':{'serverTime':1647990837551},'limit_usage':40}You can also display full response metadata to help in debugging:client=Client(show_header=True)res=awaitclient.time()print(res)returns:{'data':{'serverTime':1587990847650},'header':{'Context-Type':'application/json;charset=utf-8',...}}User agentclient=Client(agent='name_app')You can pass the name of your application.WebsocketThis is an example of connecting to multiple streamsimportasynciofromaio_binance.futures.usdtimportWsClientasyncdefcallback_event(data:dict):print(data)asyncdefmain():ws=WsClient()stream=[ws.stream_liquidation_order(),ws.stream_book_ticker(),ws.stream_ticker('BTCUSDT')]res=awaitasyncio.gather(*stream)awaitws.subscription_streams(res,callback_event)asyncio.run(main())More websocket examples are available in theexamplesfolderNoteStream methods start with the wordstreamExample:stream_<name_method>Subscribing to multiple streams:subscription_streams()HeartbeatOnce 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.