python version:3.6+
WebSocketAPI: websockets package advise version 6.0
1.1 Download python SDK
Clone
orDownload
the SDK directory to your local directory,choose to useokex-python-sdk-api-v5
1.2 Install the necessary libraries
pip install requests
pip install websockets==6.0
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 = ""
- RestAPI
- Run
example.py
- Uncomment the corresponding method and then pass the arguments and call the interfaces
- Run
- WebSocketAPI
- Run
websocket_example.py
- According to the
public channel
/private channel
/trade
, select the correspondingurl
, the corresponding start method, and pass in the corresponding parameters
- Run
# 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"
# 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 offical API document
-
User with RestAPI can configure parameter
flag
inexample.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 -
If you face any questions when using
WebSocketAPI
,you can consult related link-
asyncio
、websockets
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
-