Skip to main content

Python SDK with async support for the OKX v5 API

Project description

About

python-okx-async is an unofficial Python wrapper for the OKX exchange v5 API that comes with async support. The wrapper is an extension of the python-okx package, which supports synchronous REST requests and websocket streams.

Installation

To install the package, run

pip install python-okx-async

Quick start

Create an OKX account

Create API credentials

  • Log into your OK account and select API keys in the user menu
  • Click the + Create V5 API key button
  • Follow the instructions to create API credentials (key, passhprase, secret)

Save API credentials

  • If there isn't a .env file in your home directory, create one and make sure it can only be read and written to by you.
touch ~/.env
chmod 600 ~/.env
  • Add the following lines to the .env file, replacing the text to the right of the equal signs with the credentials created above. Note that the credentials should NOT be enclosed in quotation marks.
OKX_API_KEY=<key>
OKX_API_PASSPHRASE=<passphrase>
OKX_API_SECRET=<secret>

API credentials are stored in a .env file for security reasons. It is not advisable to include API credentials directly in source code or to supply them as command line arguments.

Run examples

Import and instantiate the API wrapper class AsyncTradeAPI, which is used for order placement, as shown below. You may first need to run pip install python-dotenv to install the dotenv package on your system.

import os
from dotenv import load_dotenv
from okx_async.AsyncTrade import AsyncTradeAPI

load_dotenv()

tradeAPI = AsyncTradeAPI(os.getenv("OKX_API_KEY"), os.getenv("OKX_API_SECRET"), os.getenv("OKX_API_PASSPHRASE"))

The other REST API classes can be instantiated similarly. Note that async classes are initialized with default arguments flag='1' and debug=True, i.e. async classes are by default in the OKX production environment and not in debug mode.

For a complete example see the example_order_book.py file included in the Github repository. The script prints the order book for the XCH-USDT spot market to a depth of 20 levels.

Also make sure to check out the documentation of python-okx, and the additional examples included in that repository.

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

python-okx-async-0.1.1.tar.gz (34.4 kB view details)

Uploaded Source

Built Distribution

python_okx_async-0.1.1-py3-none-any.whl (53.4 kB view details)

Uploaded Python 3

File details

Details for the file python-okx-async-0.1.1.tar.gz.

File metadata

  • Download URL: python-okx-async-0.1.1.tar.gz
  • Upload date:
  • Size: 34.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for python-okx-async-0.1.1.tar.gz
Algorithm Hash digest
SHA256 377997c3c385e87f5e46978592c8a022d20feec06d7ad728f290dda41fded1dc
MD5 385ba22bcb4572eafdbf76c24d78ad5b
BLAKE2b-256 dd3080d973126361edc718fef84dba5ba0b15c9554b2ecb72e1f57f5688a56bd

See more details on using hashes here.

File details

Details for the file python_okx_async-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for python_okx_async-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eedc2b623bf6d64b823057f0e82397d5a30701cf225c6afde1b3cf5d98b22fde
MD5 1f509b0fbae501117b7646001b095203
BLAKE2b-256 77753de4b29f4f699c3d4342b442475facb6b80c6a55c3b6273ae31b4af21b74

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