Skip to main content

Python SDK for OKX

Project description

Overview

This is an unofficial Python wrapper for the OKX exchange v5 API

If you came here looking to purchase cryptocurrencies from the OKX exchange, please go here.

Source code

https://github.com/okxapi/python-okx

API trading tutorials

Make sure you update often and check the Changelog for new features and bug fixes.

Features

  • Implementation of all Rest API endpoints.
  • Private and Public Websocket implementation
  • Testnet support
  • Websocket handling with reconnection and multiplexed connections

Quick start

Prerequisites

python version:>=3.7

Step 1: Register an account on OKX and apply for an API key

Step 2: Install python-okx

pip install python-okx

API Credentials

Option 1: Hardcoded credentials

from okx import Account

account = Account.AccountAPI(
    api_key="your-api-key-here",
    api_secret_key="your-api-secret-here",
    passphrase="your-passphrase-here",
    flag="1",  # 0 = live trading, 1 = demo trading
    debug=False
)

Option 2: Using .env file (recommended)

Create a .env file in your project root:

OKX_API_KEY=your-api-key-here
OKX_API_SECRET=your-api-secret-here
OKX_PASSPHRASE=your-passphrase-here
OKX_FLAG=1

Then load it in your code:

import os
from dotenv import load_dotenv
from okx import Account

load_dotenv()

account = Account.AccountAPI(
    api_key=os.getenv('OKX_API_KEY'),
    api_secret_key=os.getenv('OKX_API_SECRET'),
    passphrase=os.getenv('OKX_PASSPHRASE'),
    flag=os.getenv('OKX_FLAG', '1'),
    debug=False
)

Development Setup

For contributors or local development:

# Clone the repository
git clone https://github.com/okxapi/python-okx.git
cd python-okx

# Install dependencies
pip install -r requirements.txt
pip install -e .

# Run tests
pytest test/unit/ -v

Step 3: Run examples

  • Fill in API credentials in the corresponding examples
api_key = ""
secret_key = ""
passphrase = ""

Note

  • To learn more about OKX API, visit official OKX API documentation

  • If you face any questions when using WebSocketAPI,you can consult the following links

    • asynciowebsockets document/github

      https://docs.python.org/3/library/asyncio-dev.html
      https://websockets.readthedocs.io/en/stable/intro.html
      https://github.com/aaugustin/websockets
      
    • About code=1006

      https://github.com/Rapptz/discord.py/issues/1996
      https://github.com/aaugustin/websockets/issues/587
      

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-0.4.2.tar.gz (39.5 kB view details)

Uploaded Source

Built Distribution

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

python_okx-0.4.2-py3-none-any.whl (38.2 kB view details)

Uploaded Python 3

File details

Details for the file python_okx-0.4.2.tar.gz.

File metadata

  • Download URL: python_okx-0.4.2.tar.gz
  • Upload date:
  • Size: 39.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for python_okx-0.4.2.tar.gz
Algorithm Hash digest
SHA256 68255f63fab2a585f40dee3f23b6e9efbb20072e986b3c5c3e904aeb9979ee97
MD5 0a1c98fe705797ca37f4c100d9b12742
BLAKE2b-256 230d4067e1608c17e0244109ef799e8763a5dbef6979a092ba1c08afdbf6fd77

See more details on using hashes here.

File details

Details for the file python_okx-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: python_okx-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 38.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for python_okx-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6e7c5f00c106373b9d12ae46336408b9df57fb585b3644e3e5651fd94ec4982b
MD5 02b9652ac9343718618ec56a5a8419cd
BLAKE2b-256 063d5cf29f627aa506c21b1cc9bc342f79cf057c5f7c37ab76bf2b965709cced

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