okx-integrator


Nameokx-integrator JSON
Version 0.1.1 PyPI version JSON
download
home_page
Summary
upload_time2023-04-19 14:17:09
maintainer
docs_urlNone
authorDexter
requires_python>=3.8.10,<4.0.0
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [TOC]

### 如何使用?

`python版本:3.6 - 3.8`

`WebSocketAPI:建议websockets库版本为6.0`

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

1.1 下载`python SDK`

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

1.2 安装所需库

```python
poetry install
```

#### 第二步:配置个人信息

2.1 如果还未有API,可[点击](https://www.okx.com/account/users/myApi)前往官网进行申请

2.2 将各项信息在`example.py(RestAPI)`和`websocket_example.py(WebSocketAPI)`中填写

```python
api_key = ""
secret_key = ""
passphrase = ""
```

#### 第三步:调用接口

* RestAPI

  * 运行`example.py`

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

* WebSocketAPI

  * 运行`websocket_example.py`

  * 根据`公共频道`/`私有频道`/`交易`选择对应`url`、对应启动方法,传入相应参数即可

  ```python
  # WebSocket公共频道
  url = "wss://ws.okx.com:8443/ws/v5/public?brokerId=9999"
  
  # WebSocket私有频道
  url = "wss://ws.okx.com:8443/ws/v5/private?brokerId=9999"
  ```

  ```python
  # 公共频道 不需要登录(行情,持仓总量,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文档](https://www.okx.com/docs-v5/zh/)

* 使用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/587



### How to use ?

`python version:3.6 - 3.8`

`WebSocketAPI: websockets package advise version 6.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

```python
pip install requests
pip install websockets==6.0
```

#### Step 2: Configure Personal Information

2.1 If you have no API,[Click here](https://www.okx.com/account/users/myApi) 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)`

```python 
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
  - Run `websocket_example.py`
  - According to the `public channel`/`private channel`/`trade`, select the corresponding `url`, the corresponding start method, and pass in the corresponding parameters

```python 
# 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"
```

```Python
# 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](https://www.okx.com/docs-v5/en/)

- 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

  - `asyncio`、`websockets` document/`github`:

    ```python 
    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`:

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

    


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "okx-integrator",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8.10,<4.0.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Dexter",
    "author_email": "wbolivar@dexterdevelopment.io",
    "download_url": "https://files.pythonhosted.org/packages/2c/e4/a73c771467df3e3a5a925b698e524bf2cc040506b8d359ed03ab6cda56c7/okx_integrator-0.1.1.tar.gz",
    "platform": null,
    "description": "[TOC]\n\n### \u5982\u4f55\u4f7f\u7528\uff1f\n\n`python\u7248\u672c\uff1a3.6 - 3.8`\n\n`WebSocketAPI\uff1a\u5efa\u8baewebsockets\u5e93\u7248\u672c\u4e3a6.0`\n\n#### \u7b2c\u4e00\u6b65\uff1a\u4e0b\u8f7dSDK\uff0c\u5b89\u88c5\u76f8\u5173\u6240\u9700\u5e93\n\n1.1 \u4e0b\u8f7d`python SDK`\n\n* \u5c06SDK\u76ee\u5f55`Clone`\u6216\u8005`Download`\u5230\u672c\u5730\uff0c\u9009\u62e9\u4f7f\u7528`okx-python-sdk-api-v5`\u5373\u53ef\n\n1.2 \u5b89\u88c5\u6240\u9700\u5e93\n\n```python\npoetry install\n```\n\n#### \u7b2c\u4e8c\u6b65\uff1a\u914d\u7f6e\u4e2a\u4eba\u4fe1\u606f\n\n2.1 \u5982\u679c\u8fd8\u672a\u6709API\uff0c\u53ef[\u70b9\u51fb](https://www.okx.com/account/users/myApi)\u524d\u5f80\u5b98\u7f51\u8fdb\u884c\u7533\u8bf7\n\n2.2 \u5c06\u5404\u9879\u4fe1\u606f\u5728`example.py\uff08RestAPI\uff09`\u548c`websocket_example.py\uff08WebSocketAPI\uff09`\u4e2d\u586b\u5199\n\n```python\napi_key = \"\"\nsecret_key = \"\"\npassphrase = \"\"\n```\n\n#### \u7b2c\u4e09\u6b65\uff1a\u8c03\u7528\u63a5\u53e3\n\n* RestAPI\n\n  * \u8fd0\u884c`example.py`\n\n  * \u89e3\u5f00\u76f8\u5e94\u65b9\u6cd5\u7684\u6ce8\u91ca\u4f20\u53c2\u8c03\u7528\u5404\u63a5\u53e3\u5373\u53ef\n\n* WebSocketAPI\n\n  * \u8fd0\u884c`websocket_example.py`\n\n  * \u6839\u636e`\u516c\u5171\u9891\u9053`/`\u79c1\u6709\u9891\u9053`/`\u4ea4\u6613`\u9009\u62e9\u5bf9\u5e94`url`\u3001\u5bf9\u5e94\u542f\u52a8\u65b9\u6cd5\uff0c\u4f20\u5165\u76f8\u5e94\u53c2\u6570\u5373\u53ef\n\n  ```python\n  # WebSocket\u516c\u5171\u9891\u9053\n  url = \"wss://ws.okx.com:8443/ws/v5/public?brokerId=9999\"\n  \n  # WebSocket\u79c1\u6709\u9891\u9053\n  url = \"wss://ws.okx.com:8443/ws/v5/private?brokerId=9999\"\n  ```\n\n  ```python\n  # \u516c\u5171\u9891\u9053 \u4e0d\u9700\u8981\u767b\u5f55\uff08\u884c\u60c5\uff0c\u6301\u4ed3\u603b\u91cf\uff0cK\u7ebf\uff0c\u6807\u8bb0\u4ef7\u683c\uff0c\u6df1\u5ea6\uff0c\u8d44\u91d1\u8d39\u7387\u7b49\uff09\n  loop.run_until_complete(subscribe_without_login(url, channels))\n  \n  # \u79c1\u6709\u9891\u9053 \u9700\u8981\u767b\u5f55\uff08\u8d26\u6237\uff0c\u6301\u4ed3\uff0c\u8ba2\u5355\u7b49\uff09\n  loop.run_until_complete(subscribe(url, api_key, passphrase, seceret_key, channels))\n  \n  # \u4ea4\u6613\uff08\u4e0b\u5355\uff0c\u64a4\u5355\uff0c\u6539\u5355\u7b49\uff09\n  loop.run_until_complete(trade(url, api_key, passphrase, seceret_key, trade_param))\n  ```\n\n\u9644\u8a00\uff1a\n\n* \u5982\u679c\u5bf9API\u5c1a\u4e0d\u4e86\u89e3\uff0c\u5efa\u8bae\u53c2\u8003`OKx`\u5b98\u65b9[API\u6587\u6863](https://www.okx.com/docs-v5/zh/)\n\n* \u4f7f\u7528RestAPI\u7684\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e`example.py`\u6587\u4ef6\u4e0b\u7684flag\u53c2\u6570\u6765\u9009\u62e9\u63a5\u5165\u5b9e\u76d8\u6216\u8005\u6a21\u62df\u76d8\n\n* \u4f7f\u7528WebSocketAPI\u7684\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u89e3\u5f00`websocket_example.py`\u6587\u4ef6\u4e0b\u5bf9\u5e94\u7684url\u6ce8\u91ca\u6765\u9009\u62e9\u63a5\u5165\u5b9e\u76d8\u6216\u8005\u6a21\u62df\u76d8\n\n* RestAPI \u63d0\u4f9b\u4e86http2\u7684\u8bf7\u6c42\u65b9\u5f0f,\u53ef\u53c2\u8003http2_example.py\n\n* \u82e5\u4f7f\u7528`WebSocketAPI`\u9047\u5230\u95ee\u9898\u5efa\u8bae\u53c2\u8003\u76f8\u5173\u94fe\u63a5\n\n  * `asyncio`\u3001`websockets`\u6587\u6863/`github`\uff1a\n\n        https://docs.python.org/3/library/asyncio-dev.html\n        https://websockets.readthedocs.io/en/stable/intro.html\n        https://github.com/aaugustin/websockets\n\n  * \u5173\u4e8e`code=1006`\uff1a\n\n        https://github.com/Rapptz/discord.py/issues/1996\n        https://github.com/aaugustin/websockets/issues/587\n\n\n\n### How to use ?\n\n`python version\uff1a3.6 - 3.8`\n\n`WebSocketAPI\uff1a websockets package advise version 6.0`\n\n#### Step 1: Download the SDK and install the necessary libraries\n\n1.1 Download python SDK \n\n- `Clone` or `Download` the SDK directory to your local directory,choose to use `okx-python-sdk-api-v5`\n\n1.2 Install the necessary libraries\n\n```python\npip install requests\npip install websockets==6.0\n```\n\n#### Step 2: Configure Personal Information\n\n2.1 If you have no API\uff0c[Click here](https://www.okx.com/account/users/myApi) to the official websit to apply for the API\n\n2.2 Fill out all necessary informatiuon in `example.py\uff08RestAPI\uff09`  and `websocket_example.py\uff08WebSocketAPI\uff09`\n\n```python \napi_key = \"\"\nsecret_key = \"\"\npassphrase = \"\"\n```\n\n#### Step 3: Call API \n\n- RestAPI\n  - Run `example.py`\n  - Uncomment the corresponding method and then pass the arguments and call the interfaces\n- WebSocketAPI\n  - Run `websocket_example.py`\n  - According to the `public channel`/`private channel`/`trade`, select the corresponding `url`, the corresponding start method, and pass in the corresponding parameters\n\n```python \n# WebSocket public channel\nurl = \"wss://ws.okx.com:8443/ws/v5/public?brokerId=9999\"\n\n# WebSocket private channel\nurl = \"wss://ws.okx.com:8443/ws/v5/private?brokerId=9999\"\n```\n\n```Python\n# Not necessary for public channel to login \uff08Instrument, Tickers, Index, Mark price, Order Book, Funding rate, etc\uff09\nloop.run_until_complete(subscribe_without_login(url, channels))\n\n# necessary for private channel to login\uff08Account,Positions, Order, etc\uff09\nloop.run_until_complete(subscribe(url, api_key, passphrase, seceret_key, channels))\n\n# trade\uff08Place Order, Cancel Order, Amend Order, etc\uff09\nloop.run_until_complete(trade(url, api_key, passphrase, seceret_key, trade_param))\n```\n\nP.S. \n\n- If  you know little about API, advise consulting the  offical [API document](https://www.okx.com/docs-v5/en/)\n\n- User with RestAPI can configure parameter `flag` in `example.py` in  to choose to access to real trading or demo trading \n\n- User with WebSocketAPI can ucomment the corresponding `url`  to choose to access to real trading or demo trading \n\n- Rest API support request by http2, you can refer to http2_example  \n\n- If you face any questions when using `WebSocketAPI`,you can consult related link\n\n  - `asyncio`\u3001`websockets` document/`github`\uff1a\n\n    ```python \n    https://docs.python.org/3/library/asyncio-dev.html\n    https://websockets.readthedocs.io/en/stable/intro.html\n    https://github.com/aaugustin/websockets\n    ```\n\n  - About `code=1006`\uff1a\n\n    ```python \n    https://github.com/Rapptz/discord.py/issues/1996\n    https://github.com/aaugustin/websockets/issues/587\n    ```\n\n    \n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "",
    "version": "0.1.1",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cb81726ed03063ab235a3dfde714983ac0ca9031f3b7d1c62aacbdf852c46289",
                "md5": "cbe59f076bfbb3a834484f6f274eee24",
                "sha256": "587fdbb8eb0d86ded3ffc284046096696e3f87aa1466c9e3f7a1236f3d38d3e1"
            },
            "downloads": -1,
            "filename": "okx_integrator-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cbe59f076bfbb3a834484f6f274eee24",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8.10,<4.0.0",
            "size": 59362,
            "upload_time": "2023-04-19T14:17:07",
            "upload_time_iso_8601": "2023-04-19T14:17:07.546012Z",
            "url": "https://files.pythonhosted.org/packages/cb/81/726ed03063ab235a3dfde714983ac0ca9031f3b7d1c62aacbdf852c46289/okx_integrator-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2ce4a73c771467df3e3a5a925b698e524bf2cc040506b8d359ed03ab6cda56c7",
                "md5": "84e54a4c930887fb53c91cc7ea2d1dd1",
                "sha256": "b21444ab2df031446811ae78907776e807dc11e12c00fd330da27906dabcc1d8"
            },
            "downloads": -1,
            "filename": "okx_integrator-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "84e54a4c930887fb53c91cc7ea2d1dd1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8.10,<4.0.0",
            "size": 44322,
            "upload_time": "2023-04-19T14:17:09",
            "upload_time_iso_8601": "2023-04-19T14:17:09.891421Z",
            "url": "https://files.pythonhosted.org/packages/2c/e4/a73c771467df3e3a5a925b698e524bf2cc040506b8d359ed03ab6cda56c7/okx_integrator-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-19 14:17:09",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "okx-integrator"
}
        
Elapsed time: 0.38702s