Package: apollox-connector-python
apllox-connector-pythonBinance Futures Public API Connector PythonThis is a lightweight library that works as a connector toApollo Finance public APIInstallationpipinstallapollox-connector-pythonDocumentationRESTful APIsUsage examples:fromapollox.rest_apiimportClient# Get timestampclient=Client()print(client.time())client=Client(key='<api_key>',secret='<api_secret>')# Get account informationprint(client.account())# Post a new orderparams={'symbol':'BTCUSDT','side':'SELL','type':'LIMIT','timeInForce':'GTC','quantity':0.002,'price':59808}response=client.new_order(**params)print(response)Please findexamplesfolder to check for more endpoints.Base URLhttps://fapi.apollox.financeOptional parametersPEP8 suggestslowercase 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 nameresponse=client.query_order('BTCUSDT',orderListId=1)# Unrecognised parameter nameresponse=client.query_order('BTCUSDT',order_list_id=1)RecvWindow parameterAdditional parameterrecvWindowis available for endpoints requiring signature.It defaults to5000(milliseconds) and can be any value lower than60000(milliseconds).
Anything beyond the limit will result in an error response from Binance server.fromapollox.rest_apiimportClientclient=Client(key,secret)response=client.query_order('BTCUSDT',orderId=11,recvWindow=10000)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,timeoutis None. Hence, requests do not time out.fromapollox.rest_apiimportClientclient=Client(timeout=1)Proxyproxy is supportedfrombapollo.rest_apiimportClientproxies={'https':'http://1.2.3.4:8080'}client=Client(proxies=proxies)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:fromapollox.rest_apiimportClientclient=Client(show_limit_usage=True)print(client.time())You can also display full response metadata to help in debugging:client=Client(show_header=True)print(client.time())IfClientErroris received, it'll display full response meta information.Display logsSetting the log level toDEBUGwill log the request URL, payload and response text.ErrorThere are 2 types of error returned from the library:apollox.error.ClientErrorThis is thrown when server returns4XX, it's an issue from client side.It has 4 properties:status_code- HTTP status codeerror_code- Server's error code, e.g.-1102error_message- Server's error message, e.g.Unknown order sent.header- Full response header.apollox.error.ServerErrorThis is thrown when server returns5XX, it's an issue from server side.Websocketfromapollox.websocket.client.streamimportWebsocketClientasClientdefmessage_handler(message):print(message)ws_client=Client()ws_client.start()ws_client.mini_ticker(symbol='bnbusdt',id=1,callback=message_handler,)# Combine selected streamsws_client.instant_subscribe(stream=['bnbusdt@bookTicker','ethusdt@bookTicker'],callback=message_handler,)ws_client.stop()More websocket examples are available in theexamplesfolderHeartbeatOnce 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.