Skip to main content

This is a lightweight library that works as a connector to Apollox Finance public API.

Project description

apllox-connector-python

Python 3.6 License: MIT

This is a lightweight library that works as a connector to Apollo Finance public API

Installation

pip install apollox-connector-python

Documentation

RESTful APIs

Usage examples:

from apollox.rest_api import Client 

# Get timestamp
client = Client()
print(client.time())


client = Client(key='<api_key>', secret='<api_secret>')

# Get account information
print(client.account())

# Post a new order
params = {
    'symbol': 'BTCUSDT',
    'side': 'SELL',
    'type': 'LIMIT',
    'timeInForce': 'GTC',
    'quantity': 0.002,
    'price': 59808
}

response = client.new_order(**params)
print(response)

Please find examples folder to check for more endpoints.

Base URL

https://fapi.apollox.finance

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)

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 ApolloX server.

from apollox.rest_api import Client

client = Client(key, secret)
response = client.query_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.

from apollox.rest_api import Client

client= Client(timeout=1)

Proxy

proxy is supported

from bapollo.rest_api import Client

proxies = { 'https': 'http://1.2.3.4:8080' }

client= Client(proxies=proxies)

Response Metadata

The ApolloX 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 apollox.rest_api import Client

client = 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())

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:

  • apollox.error.ClientError
    • This is thrown when server returns 4XX, it's an issue from client side.
    • It has 4 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.
  • apollox.error.ServerError
    • This is thrown when server returns 5XX, it's an issue from server side.

Websocket

from apollox.websocket.client.stream import WebsocketClient as Client

def message_handler(message):
    print(message)

ws_client = Client()
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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

apollox-connector-python1.2-1.2.0.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

apollox_connector_python1.2-1.2.0-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file apollox-connector-python1.2-1.2.0.tar.gz.

File metadata

File hashes

Hashes for apollox-connector-python1.2-1.2.0.tar.gz
Algorithm Hash digest
SHA256 51f8954c5e36e76a54a37982126124fecaab19977d5dd9cafe5293728fc613c1
MD5 87e5474383017225fb944fdf27bbb7c9
BLAKE2b-256 718ff3f4308881f3a3af075bfeff80e397db9a6326f0f88c61e4f692d16b628e

See more details on using hashes here.

File details

Details for the file apollox_connector_python1.2-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for apollox_connector_python1.2-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6ab141947fff808ba3604c5045ccb4276a6cf0b229f2e2ee69313532a4754270
MD5 02f691154cac3bef1eba237e28859e50
BLAKE2b-256 d0ae05cc44ab399a4ccbe44148ae9183275995a76f24f68e9dab275332b0053c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page