Package: okx-integrator
[TOC]如何使用？python版本：3.6 - 3.8WebSocketAPI：建议websockets库版本为6.0第一步：下载SDK，安装相关所需库1.1 下载python SDK将SDK目录Clone或者Download到本地，选择使用okx-python-sdk-api-v5即可1.2 安装所需库poetryinstall第二步：配置个人信息2.1 如果还未有API，可点击前往官网进行申请2.2 将各项信息在example.py（RestAPI）和websocket_example.py（WebSocketAPI）中填写api_key=""secret_key=""passphrase=""第三步：调用接口RestAPI运行example.py解开相应方法的注释传参调用各接口即可WebSocketAPI运行websocket_example.py根据公共频道/私有频道/交易选择对应url、对应启动方法，传入相应参数即可# WebSocket公共频道url="wss://ws.okx.com:8443/ws/v5/public?brokerId=9999"# WebSocket私有频道url="wss://ws.okx.com:8443/ws/v5/private?brokerId=9999"# 公共频道 不需要登录（行情，持仓总量，K线，标记价格，深度，资金费率等）loop.run_until_complete(subscribe_without_login(url,channels))# 私有频道 需要登录（账户，持仓，订单等）loop.run_until_complete(subscribe(url,api_key,passphrase,seceret_key,channels))# 交易（下单，撤单，改单等）loop.run_until_complete(trade(url,api_key,passphrase,seceret_key,trade_param))附言：如果对API尚不了解，建议参考OKx官方API文档使用RestAPI的用户可以通过设置example.py文件下的flag参数来选择接入实盘或者模拟盘使用WebSocketAPI的用户可以通过解开websocket_example.py文件下对应的url注释来选择接入实盘或者模拟盘RestAPI 提供了http2的请求方式,可参考http2_example.py若使用WebSocketAPI遇到问题建议参考相关链接asyncio、websockets文档/github：https://docs.python.org/3/library/asyncio-dev.html
https://websockets.readthedocs.io/en/stable/intro.html
https://github.com/aaugustin/websockets关于code=1006：https://github.com/Rapptz/discord.py/issues/1996
https://github.com/aaugustin/websockets/issues/587How to use ?python version：3.6 - 3.8WebSocketAPI： websockets package advise version 6.0Step 1: Download the SDK and install the necessary libraries1.1 Download python SDKCloneorDownloadthe SDK directory to your local directory,choose to useokx-python-sdk-api-v51.2 Install the necessary librariespipinstallrequestspipinstallwebsockets==6.0Step 2: Configure Personal Information2.1 If you have no API，Click hereto the official websit to apply for the API2.2 Fill out all necessary informatiuon inexample.py（RestAPI）andwebsocket_example.py（WebSocketAPI）api_key=""secret_key=""passphrase=""Step 3: Call APIRestAPIRunexample.pyUncomment the corresponding method and then pass the arguments and call the interfacesWebSocketAPIRunwebsocket_example.pyAccording to thepublic channel/private channel/trade, select the correspondingurl, the corresponding start method, and pass in the corresponding parameters# WebSocket public channelurl="wss://ws.okx.com:8443/ws/v5/public?brokerId=9999"# WebSocket private channelurl="wss://ws.okx.com:8443/ws/v5/private?brokerId=9999"# Not necessary for public channel to login （Instrument, Tickers, Index, Mark price, Order Book, Funding rate, etc）loop.run_until_complete(subscribe_without_login(url,channels))# necessary for private channel to login（Account,Positions, Order, etc）loop.run_until_complete(subscribe(url,api_key,passphrase,seceret_key,channels))# trade（Place Order, Cancel Order, Amend Order, etc）loop.run_until_complete(trade(url,api_key,passphrase,seceret_key,trade_param))P.S.If  you know little about API, advise consulting the  officalAPI documentUser with RestAPI can configure parameterflaginexample.pyin  to choose to access to real trading or demo tradingUser with WebSocketAPI can ucomment the correspondingurlto choose to access to real trading or demo tradingRest API support request by http2, you can refer to http2_exampleIf you face any questions when usingWebSocketAPI,you can consult related linkasyncio、websocketsdocument/github：https://docs.python.org/3/library/asyncio-dev.htmlhttps://websockets.readthedocs.io/en/stable/intro.htmlhttps://github.com/aaugustin/websocketsAboutcode=1006：https://github.com/Rapptz/discord.py/issues/1996https://github.com/aaugustin/websockets/issues/587