Skip to main content

Python SDK for OKX

Project description

[TOC]

如何使用?

`python版本:>=3.9

WebSocketAPI:autobahn.twisted>=22.10.0

第一步:下载SDK,安装相关所需库

1.1 下载python SDK

  • 将SDK目录Clone或者Download到本地,选择使用okx-python-sdk-api-v5即可

1.2 安装所需库

pip install requests
pip install autobahn\[twisted\]
pip install pyOpenSSL

第二步:配置个人信息

2.1 如果还未有API,可点击前往官网进行申请

api_key = ""
secret_key = ""
passphrase = ""

第三步:调用接口

  • RestAPI

    • 运行example.py

    • 解开相应方法的注释传参调用各接口即可

  • WebSocketAPI

    • 参考Test文件夹下WsPrivateWsPublic文件示例;
    • 根据公共频道/私有频道选择对应url(如果是私有频道需要设置登陆信息),传入相应参数即可。
    # WebSocket公共频道
    url = "wss://ws.okx.com:8443/ws/v5/public"
    # WebSocket私有频道
    url = "wss://ws.okx.com:8443/ws/v5/private"
    
    # 公共频道 不需要登录(行情,持仓总量,K线,标记价格,深度,资金费率等)
    参考 WsPublicTest.py
    
    # 私有频道 需要登录(账户,持仓,订单等)
    参考 WsPrivateTest.py
    

附言:

How to use ?

python version:>=3.9

WebSocketAPI: autobahn.twisted>=22.10.0

Step 1: Download the SDK and install the necessary libraries

1.1 Download python SDK

  • Clone or Download the SDK directory to your local directory,choose to use okx-python-sdk-api-v5

1.2 Install the necessary libraries

pip install requests
pip install autobahn\[twisted\]
pip install pyOpenSSL

Step 2: Configure Personal Information

2.1 If you have no API,Click here to the official websit to apply for the API

2.2 Fill out all necessary informatiuon in example.py(RestAPI) and websocket_example.py(WebSocketAPI)

api_key = ""
secret_key = ""
passphrase = ""

Step 3: Call API

  • RestAPI
    • Run example.py
    • Uncomment the corresponding method and then pass the arguments and call the interfaces
  • WebSocketAPI
    • Open websocket_example.py
    • According to the public channel/private channel, select the corresponding url, the corresponding start method, and pass in the corresponding parameters
# WebSocket public channel
url = "wss://ws.okx.com:8443/ws/v5/public?brokerId=9999"

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

P.S.

  • If you know little about API, advise consulting the offical API document

  • User with RestAPI can configure parameter flag in example.py in to choose to access to real trading or demo trading

  • User with WebSocketAPI can ucomment the corresponding url to choose to access to real trading or demo trading

  • Rest API support request by http2, you can refer to http2_example

  • If you face any questions when using WebSocketAPI,you can consult related link

    • 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.1.2.tar.gz (22.6 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.1.2-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

Details for the file python-okx-0.1.2.tar.gz.

File metadata

  • Download URL: python-okx-0.1.2.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.5

File hashes

Hashes for python-okx-0.1.2.tar.gz
Algorithm Hash digest
SHA256 47be5695a4785bbf8ef12d82b97a85cbdff3e91fed8af49c447acb4ff0d3d98f
MD5 b08c7681dd337ff986dbfb4f70d3a2dc
BLAKE2b-256 a8f98a6e7e5c7d489be513e59ef76ae39b00841df3956da59ae474d20c93d738

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_okx-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 30.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.5

File hashes

Hashes for python_okx-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 eaff6d9a4b5a6b38c54743f3fc2a71b0de83283f7a3e5ddfc97bea3538dce667
MD5 423425e94c39f78d0b82d86ff2ed3a94
BLAKE2b-256 46eb47dbe51e5aa7a9ccbf4513a22983c6768e6aed2fb5cb2fdabdd182b60cae

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