Skip to main content

Unofficial python wrapper for the OKX V5 API

Project description

pyokx

Downloads Tests

Installation

pip install pyokx

Introduction

pyokx is a completely unofficial python API wrapper developed to interact with the OKX V5 API. It's unique insofar as that it has been developed by scraping the API documentation to dynamically generate python code to provide an intuitive pythonic interface for exact same API. This idea essentially is to avoid the need to create separate documentation for this wrapper and instead you can simply refer to the official OKX docs for API usage.

It's used by creating a base client instance to make and receive requests and passing that client to each API class (APIComponent), which has been dynamically generated from the API docs.

Let's start with an example.

Let's say we want to check all current positions.

Check out the docs for get balance here: https://www.okx.com/docs-v5/en/#rest-api-account-get-positions

We can see the endpoint belongs to the Account API and needs to be called with 3 parameters: OKX-docs

In pyokx, you can see the method signature for the Account class is exactly the same:

def get_positions(
        self,
        instType: str = None,
        instId: str = None,
        posId: str = None,
        use_proxy: bool = False,
    ) -> APIReturn:

So this can be easily implemented like so:

from pyokx import Account, OKXClient

# create the base client dependency
cli = OKXClient(
    key="key",
    secret="secret",
    passphrase="passphrase",
)

# create a component for the Account API by passing the client dependency
a = Account(cli)

# get positions
api_return = a.get_positions()

# to convert to a pandas dataframe
df = api_return.to_df()

# to look at the raw response
response = api_return.response

That simple.


Key features

APIReturn

This is essentially a wrapper around the response that is returned from every endpoint. This is to provide some useful helper methods such as dataframe conversion.

Proxies

As is common with a lot of exchange APIs, for calls that require authentication (usually account/trade-related), it is strongly encouraged to limit your API key to a select list IP addresses to protect your account. On some systems this may require routing traffic through a forward proxy. pyokx supports this pattern by allowing you to pass the necessary proxies to the base client and you can trigger this behaviour by setting the use_proxy parameter to True. For example:

proxies = {
    "http": "http://your-proxy-server.com",
    "https": "https://your-proxy-server.com",
}
cli = OKXClient(
    key="key",
    secret="secret",
    passphrase="passphrase",
    proxies=proxies
)

# trigger the use of the proxy server with use_proxy
a = Account(cli)
api_return = a.get_positions(use_proxy=True)

Development progress

It's still a very early version - so issues, feature requests and bugs are very welcome!

  • REST API implementation.
  • Fix pythonic naming conventions when API names contain special characters
  • Enhance documentation
  • Websocket API implementation.

Disclaimer

NB. pyokx is totally unofficial and is in no way affiliated with OKEX Crypto exchange and simply exists as a helpful wrapper to interact with the V5 API.

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

pyokx-0.2.2.tar.gz (32.5 kB view details)

Uploaded Source

Built Distribution

pyokx-0.2.2-py3-none-any.whl (50.4 kB view details)

Uploaded Python 3

File details

Details for the file pyokx-0.2.2.tar.gz.

File metadata

  • Download URL: pyokx-0.2.2.tar.gz
  • Upload date:
  • Size: 32.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.9 Linux/5.13.0-52-generic

File hashes

Hashes for pyokx-0.2.2.tar.gz
Algorithm Hash digest
SHA256 9021c5f0a12fa971c3c4f2ebe2cde51de31bf4aee865ebb3781d61df1b54760e
MD5 fcf97a42e5e11e44e6cf3f4075206f98
BLAKE2b-256 fb0a76de3a4a4f7f45726be91ca274198710fc6b3041f85e69bac22f351d7492

See more details on using hashes here.

File details

Details for the file pyokx-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: pyokx-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 50.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.9 Linux/5.13.0-52-generic

File hashes

Hashes for pyokx-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 69d2ac3cc321bf27e92f029be01c136ae6b182849a946a8da32f3612151e80fe
MD5 d5799e780f434f755290d2f5f12f8bc0
BLAKE2b-256 60d7de08c6d5c4f891c813cee758ead986a8bd42d0456f397c078162b0d73978

See more details on using hashes here.

Supported by

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