qetrader交易接口
简介
qetrader交易接口可以通过pip直接安装在用户本地,实现在任意python环境下进行策略开发、回测、模拟交易和实盘交易。
安装说明
首先,您的系统上必须已经安装了python环境(版本3.7或以上),推荐使用anaconda3. 然后,就可以按照如下步骤安装了。
-
windows环境
-
安装Microsoft C++ Build Tools
下载链接:
注:该工具版本号需要在14以上
-
安装Redis-server数据库服务
宽易提供了小工具InstallRedis.exe方便安装配套的redis-server服务。下载链接:
下载后运行该工具即可
qetrader使用的Redis端口号是6379。若需要修改为其他端口号,需要在qetrader安装完毕后修改qetrader的配置
-
安装qetrader
pip install -U qetrader --timeout=60
注: 若要加快安装速度,可以使用国内镜像站点
-
-
linux环境配置
-
安装Redis
linux下安装Redis最简单快捷的方式是使用Docker安装
首先用docker pull 下载redis最新版本
sudo docker pull redis然后启动redis容器
sudo docker run -itd --name redis-server -p 6379:6379 redis -
安装qetrader
pip install -U qetrader --timeout=60
注: 若要加快安装速度,可以使用国内镜像站点
-
使用说明
-
启动网页服务
-
写一个python文件命名为runWeb.py
from qetrader.qeweb import runWebpage runWebpage()
-
在Anaconda的命令行环境下进入runWeb.py所在目录,并运行如下命令
python runWeb.py运行后web网页服务将启动,用户可以实时查看订单委托,成交,持仓,权益和日志信息,并可以观察行情图。
按键Ctrl+C或者关闭窗口可以终止该服务,网页将无法查看,重新运行上述命令后可恢复。
-
-
编写策略文件并运行
-
如下是一个python策略文件范例
import qesdk from datetime import datetime,timedelta from qetrader import * qesdk.auth('Your username','Your authcode') user_setting = {'investorid':'000000', 'password':'XXXXXXXXXXXXXX','broker':'simnow'} user = 'myname' def getLastToken(user): acclist = listSimuAccounts(user) if len(acclist)>0: return acclist[-1] else: return createSimuAccount(user, initCap=10000000) class mystrat(qeStratBase): def __init__(self): self.instid=['AG2306.SFE'] self.datamode='minute' self.freq = 1 def crossDay(self,context): pass def onBar(self,context): print(get_bar(context,1)) def handleData(self,context): pass if __name__=='__main__': strat1 = mystrat() token_code = getLastToken(user) runStrat(user,'real', [strat1], simu_token=token_code, real_account=user_setting)
注:
1.auth语句中授权码需要在https://quantease.cn上注册登录后点击主页右上角菜单'授权码'获取。
2.user_setting中账户信息需要换成您自己的账户信息
3.运行后复制给出的网页链接在浏览器中查看运行结果即可
-
-
修改系统配置
-
获取系统配置
from qetrader import read_sysconfig read_sysconfig()
获取结果为
{'redis': {'host': '127.0.0.1', 'port': 6379, 'password': ''}, 'webpage': {'host': '127.0.0.1', 'port': 5814}} -
修改Redis配置
接口函数为
setRedisConfig(host='127.0.0.1', port=6379, password='')
根据您本地Redis-server配置修改该接口,使得qetrader可以访问您的本地数据库。
比如您本地Redis端口号为6380, 那么可以这么运行
from qetrader import setRedisConfig setRedisConfig(port=6380)
恢复默认出厂设置仅需要调用不带参数的setRedisConfig即可
from qetrader import setRedisConfig setRedisConfig()
-
修改网页配置
接口函数为
setWebConfig(host='127.0.0.1',port=5814)
如果qetrader网页服务默认端口号5814和您本地端口冲突,您可以修改为其他端口号,比如修改为5008。
from qetrader import setWebConfig setWebConfig(port=5008)
恢复默认出厂设置仅需要调用不带参数的setWebConfig即可
from qetrader import setWebConfig setWebConfig()在浏览器测试一下输入网址http://127.0.0.1:5814, 出现如下文字代表启动成功
qetrader网页展示服务已经成功启动
-
如何编写策略
请参照官方文档文档说明
PyPI公开版本说明
从 qetrader 1.1.0 开始,PyPI公开发行包只包含可审查的Python源码和必要的静态资源。
公开包不再包含、安装或下载客户专用闭源插件,也不包含混淆、加密、打包后的不可审查代码或平台专用二进制运行时。
qetrader.qeplugins.installPlugin() 保留为兼容旧代码的接口,但在PyPI公开版本中会直接抛出异常,不会联网下载、解压、写入或动态加载任何插件代码。
如需客户专用扩展,请通过独立的私有交付流程处理,不应打包进PyPI公开发行物。
Metadata
Release files for qetrader 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| qetrader-1.1.0.tar.gz | 188.9 kB | Without provenance | Details for qetrader-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| qetrader-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for qetrader-1.1.0-py3-none-any.whl |
Total release size: 390.8 kB
Release files / qetrader-1.1.0.tar.gz
| Download URL | qetrader-1.1.0.tar.gz |
|---|---|
| Size | 188.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7b7970dc95f7908ad083341b4bb8790e2043138ae7dbd7af9b1a56b233438292
|
|
BLAKE2b-256 checksum How to use checksums |
1b70e351083cccefd92305b4c4db3c5d37ecbc4d5267c7002b8ae3e77898022d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|
Release files / qetrader-1.1.0-py3-none-any.whl
| Download URL | qetrader-1.1.0-py3-none-any.whl |
|---|---|
| Size | 201.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
27621374af1ba5b00958f1fccfef069afc6969f01d3dfc83de9c5cee9a8ece5e
|
|
BLAKE2b-256 checksum How to use checksums |
7d3bf3e398106ff140febce6cf13983fdffd2c209e3c915170a43c9ffaf6d855
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|
Security for qetrader 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.