A package for OPENCTP TTS


Keywords
openctp, tts, ctpapi, trading, investment, ctp, python
License
BSD-3-Clause
Install
pip install openctp-tts==6.7.2.3

Documentation

openctp-tts


🚀以 Python 的方式,简化对接 openctp TTS 的过程,节省精力,快速上手。

openctp TTS 提供了稳定的7x24模拟交易平台, 其接口 TTSAPI 完全兼容上期技术官方 CTPAPI 接口,但同样也是 C++ 版本。 本项目提供了 TTSAPI 对应的 Python 库,用于使用 Python 接入 openctp TTS 系统。

📝 openctp TTSAPI 详情参见 github/openctpopenctp模拟柜台(TTS)

支持版本

TTSAPI(C++) openctp-tts(python) win x86 win x64 linux x86 mac x64 mac arm64
6.3.15 6.3.15.* ✔️ ✔️ ✔️ ✔️ ✔️
6.3.19_P1 6.3.19.* ✔️ ✔️ ✔️ ✔️ ✔️
6.5.1 6.5.1.* ✔️ ✔️ ✔️ ✔️ ✔️
6.6.1_P1 6.6.1.* ✔️ ✔️ ✔️ ✔️ ✔️
6.6.7 6.6.7.* ✔️ ✔️ ✔️ ✔️ ✔️
6.6.9 6.6.9.* ✔️ ✔️ ✔️ ✔️ ✔️
6.7.0 6.7.0.* ✔️ ✔️ ✔️
6.7.1 6.7.1.* ✔️ ✔️ ✔️
6.7.2 6.7.2.* ✔️ ✔️ ✔️

使用方式

需要自行提前准备好 Python 环境, 选择一个版本安装,如 6.6.9

pip install openctp-tts==6.6.9.* -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host=pypi.tuna.tsinghua.edu.cn

zsh安装:

pip install openctp-tts==6.6.9.\* -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host=pypi.tuna.tsinghua.edu.cn

引用方法:

from openctp_tts import tdapi, mdapi

更多的接口使用方法参考 代码示例

代码示例

本项目提供了一些 openctp-tts 的基本使用方式及部分接口示例,具体如下:

代码示例仅仅作为参考,只是完成 openctp-tts 库及 ttsapi 接口本身的功能,未考虑项目及工程性场景逻辑, 若要将 openctp-tts 引入项目,勿照搬示例代码。

工具脚本

  • ttsping 检查前置服务是否可正常连接

字符集问题

Linux下安装后,需要安装中文字符集,否则导入时报错:

>>> import openctp_tts
terminate called after throwing an instance of 'std::runtime_error'
what():  locale::facet::_S_create_c_locale name not valid
Aborted

需要安装 GB18030 字符集,这里提供 ubuntu/debian/centos 的方案:

# Ubuntu (20.04)
sudo apt-get install -y locales
sudo locale-gen zh_CN.GB18030

# Debian (11)
sudo apt install locales-all
sudo localedef -c -f GB18030 -i zh_CN zh_CN.GB18030

# CentOS (7)
sudo yum install -y kde-l10n-Chinese
sudo yum reinstall -y glibc-common

说明

  • 限于时间/精力有限,只是在 openctp 7x24 模拟平台进行了简单的测试
  • 后续会完善更多的测试
  • 更新日志