Go to file
Kate Hu 24efd1f71e enriched README.md 2023-02-15 18:59:11 +08:00
example set leverage revisions 2022-11-07 16:29:17 +08:00
okx Update WsPublic.py 2022-12-15 21:20:47 +08:00
test Update WsPrivateTest.py 2022-12-15 21:18:41 +08:00
.DS_Store test 2022-10-31 18:23:57 +08:00
.gitignore add README 2022-10-12 11:23:11 +08:00
README.md enriched README.md 2023-02-15 18:59:11 +08:00

README.md

Overview

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

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

Source code

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

OKX API Telegram

https://t.me/OKXAPI

API trading tutorials

  • Spot trading:
  • Derivative trading:

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.9

WebSocketAPI websockets package advise version 6.0

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

  • Register account:
  • Apply for an API key:

Step 2: install python-okx

pip install python-okx

Step 3: Run examples

  • Fill in API credentials in the corresponding examples
api_key = ""
secret_key = ""
passphrase = ""
  • RestAPI
  • WebSocketAPI
    • Run test/WsPrivateTest.py for private websocket channels
    • Run test/WsPublicTest.py for public websocket channels
    • Use different URLs for different environment
# WebSocket public channel
# live trading
url = "wss://ws.okx.com:8443/ws/v5/public?brokerId=9999"
# demo trading
url = "wss://wspap.okx.com:8443/ws/v5/public?brokerId=9999"

# WebSocket private channel
# live trading
url = "wss://ws.okx.com:8443/ws/v5/private?brokerId=9999"
# demo trading
url = "wss://wspap.okx.com:8443/ws/v5/private?brokerId=9999"

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