Package: binance-aio
binance-aio 0.0.3Announcement:binance-aiohas been replaced by a new librarycryptoxlib-aio.cryptoxlib-aiooffers the very same functionality asbinance-aiobut on top it provides access to multiple cryptoexchanges and other (mostly technical) new features. You can keep usingbinance-aiobut please note no new features/bugfixes will be implemented. We recommend to migrate tocryptoxlib-aio.binance-aiois a Python library providing access tobinance crypto exchange. Library implements binance's REST API as well as websockets.binance-aiois designed as an asynchronous library utilizing modern features of Python and of supporting asynchronous libraries (mainlyasync websocketsandaiohttp).For changes seeCHANGELOG.Featuresaccess to limited binance's REST API (account details, market data, order management, ...) and websockets (account feed, market data feed, orderbook feed, ...). Missing REST calls and websocket streams will be added on request and based on our availability.channels bundled in one or multiple websockets processed in parallellean architecture setting ground for the future extensions and customizationsfully asynchronous design aiming for the best performanceInstallationpipinstallbinance-aioPrerequisitesDue to dependencies and Python features used by the library please make sure you use Python3.6or3.7.Before starting usingbinance-aio, it is necessary to take care of:downloading your Binance API and SECRET key from your binance accountgenerating your certificate that will be used to secure SSL connections. Certificatecertificate.pemcan be generated easily byopensslreq-newkeyrsa:2048-new-nodes-x509-days3650-keyoutkey.pem-outcertificate.pemExamplesREST APIimportasyncioimportpathlibimportloggingimportosfromdatetimeimportdatetimefrombinance.BinanceClientimportBinanceClientfrombinance.PairimportPairfrombinance.enumsimportOrderSide,TimeInForce,OrderResponseTypeLOG=logging.getLogger("binance")LOG.setLevel(logging.DEBUG)LOG.addHandler(logging.StreamHandler())print(f"Available loggers:{[namefornameinlogging.root.manager.loggerDict]}\n")asyncdefaccount_update(response:dict)->None:print(f"Callback{account_update.__name__}: [{response}]")asyncdeforder_book_update(response:dict)->None:print(f"Callback{order_book_update.__name__}: [{response}]")asyncdeftrade_update(response:dict)->None:local_timestamp_ms=int(datetime.now().timestamp()*1000)server_timestamp_ms=response['E']print(f"Trade update timestamp diff [ms]:{local_timestamp_ms-server_timestamp_ms}")asyncdeforderbook_ticker_update(response:dict)->None:print(f"Callback{orderbook_ticker_update.__name__}: [{response}]")asyncdefrun():print("STARTING BINANCE CLIENT\n")# to generate a certificate use 'openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out certificate.pem'certificate_path=pathlib.Path(__file__).with_name("certificate.pem")# to retrieve your API/SEC key go to your binance website, create the keys and store them in APIKEY/SECKEY# environment variablesapi_key=os.environ['APIKEY']sec_key=os.environ['SECKEY']client=BinanceClient(certificate_path,api_key,sec_key)# REST api callsprint("REST API")print("\nPing:")awaitclient.ping()print("\nServer time:")awaitclient.get_time()print("\nExchange info:")awaitclient.get_exchange_info()print("\nBest order book ticker:")awaitclient.get_best_orderbook_ticker(pair=Pair('ETH','BTC'))print("\nAccount:")awaitclient.get_account(recv_window_ms=5000)print("\nCreate limit order:")awaitclient.create_limit_order(Pair("ETH","BTC"),OrderSide.BUY,"1","0",time_in_force=TimeInForce.GOOD_TILL_CANCELLED,new_order_response_type=OrderResponseType.FULL)print("\nDelete order:")awaitclient.delete_order(pair=Pair('ETH','BTC'),order_id="1")awaitclient.close()if__name__=="__main__":asyncio.run(run())WEBSOCKETSimportasyncioimportpathlibimportloggingimportosfromdatetimeimportdatetimefrombinance.BinanceClientimportBinanceClientfrombinance.PairimportPairfrombinance.subscriptionsimportBestOrderBookTickerSubscription,TradeSubscription,AccountSubscriptionLOG=logging.getLogger("binance")LOG.setLevel(logging.DEBUG)LOG.addHandler(logging.StreamHandler())print(f"Available loggers:{[namefornameinlogging.root.manager.loggerDict]}\n")asyncdefaccount_update(response:dict)->None:print(f"Callback{account_update.__name__}: [{response}]")asyncdeforder_book_update(response:dict)->None:print(f"Callback{order_book_update.__name__}: [{response}]")asyncdeftrade_update(response:dict)->None:local_timestamp_ms=int(datetime.now().timestamp()*1000)server_timestamp_ms=response['E']print(f"Trade update timestamp diff [ms]:{local_timestamp_ms-server_timestamp_ms}")asyncdeforderbook_ticker_update(response:dict)->None:print(f"Callback{orderbook_ticker_update.__name__}: [{response}]")asyncdefrun():print("STARTING BINANCE CLIENT\n")# to generate a certificate use 'openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out certificate.pem'certificate_path=pathlib.Path(__file__).with_name("certificate.pem")# to retrieve your API/SEC key go to your binance website, create the keys and store them in API_KEY/SEC_KEY# environment variablesapi_key=os.environ['APIKEY']sec_key=os.environ['SECKEY']client=BinanceClient(certificate_path,api_key,sec_key)# Websocketsprint("\nWEBSOCKETS\n")print("\nCreate listen key:")listen_key=awaitclient.get_listen_key()# Bundle several subscriptions into a single websocketclient.compose_subscriptions([BestOrderBookTickerSubscription(callbacks=[orderbook_ticker_update]),TradeSubscription(pair=Pair('ETH','BTC'),callbacks=[trade_update])])# Bundle another subscriptions into a separate websocketprint(listen_key)client.compose_subscriptions([AccountSubscription(client,callbacks=[account_update])])# Execute all websockets asynchronouslyawaitclient.start_subscriptions()awaitclient.close()if__name__=="__main__":asyncio.run(run())All examples can be found inclient-example/client.pyin the GitHub repository.SupportIf you like the library and you feel like you want to support its further development, enhancements and bugfixing, then it will be of great help and most appreciated if you:file bugs, proposals, pull requests, ...spread the worddonate an arbitrary tipBTC: 15JUgVq3YFoPedEj5wgQgvkZRx5HQoKJC4ETH: 0xf29304b6af5831030ba99aceb290a3a2129b993dADA: DdzFFzCqrhshyLV3wktXFvConETEr9mCfrMo9V3dYz4pz6yNq9PjJusfnn4kzWKQR91pWecEbKoHodPaJzgBHdV2AKeDSfR4sckrEk79XRP: rhVWrjB9EGDeK4zuJ1x2KXSjjSpsDQSaU6+ tag599790141ContactIf you feel you want to get in touch, then pleasepreferably use Github Issues, orsend an e-mail toAffiliationIn case you are interested in an automated trading bot, check out our other projectcreten.