Giter Club home page Giter Club logo

goctp's Introduction

goctp

上海期货交易所 ctp 接口 Golang版 (for linux64) 支持 testctp 回测

环境安装

go(版本 go1.20.x)
swig(版本 4.0.2)

构建

码云地址(国内的速度快)
go get -u gitee.com/mayiweb/goctp

github
go get -u github.com/mayiweb/goctp

构建过程比较慢,需要多等一会儿
通过 go get 下载会自动构建,也可以手动构建,进入 gitee.com/mayiweb/goctp 目录 执行 make install 即可

依赖

ctp 默认使用 gbk 编码,需要用到开源库转换为 utf8
go get -u github.com/axgle/mahonia

编译

进入 gitee.com/mayiweb/goctp/demo 目录,或将该目录里面的文件全部复制出来组成一个新项目
make build
编译成功后会在当前目录生成 ctp 可执行文件(可以修改 Makefile 文件改变生成的文件名)
./ctp [运行模式|默认test]

部署发布

生成 ctp 文件后,使用 ldd ctp 命令查看依赖关系,并将如下文件放在同一文件夹(注意需要有执行权限):
    ctp
    libruntime,sync-atomic.so
    libthostmduserapi_se.so
    libthosttraderapi_se.so

将部署目录路径写入 /etc/ld.so.conf 文件最后一行,并执行 /sbin/ldconfig 命令

goctp's People

Contributors

mayiweb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

goctp's Issues

demo下trader.go中似乎有错误

mInstrumentInfo.OptionsType = string(pInstrument.GetOptionsType())
这行结果是给这个字段设置为二进制0,实际结构中保存的也是二进制0

大神能否写个例子参考下

小弟刚学的go,很多地方还看不明白,能否写个行情收集以及简单的交易策略的例子?小弟研究了好多天,只捣鼓出了把tick数据写成文件,go语言相关的资料太少了。不胜感激。

关于使用SWIG编译CTP测试版本的问题

各位好,我在进行测试版本的编译的时候做了如下事情:
1:替换了API中的版本,替换成测试版本,版本号为:v6.3.16_T1_20190508_api_tradeapi_se_linux64
2:同时修改了goctp.swigcxx的 内容如下
image
3:同时也修改了libgoctp.go中的文件,也换成相应的版本,如下
image
然后按照步骤在goctp目录下下运行make install .但是出现了错误

image
我想问的是为什么会有这样的错误?怎么解决这样的错误?这种使用SWIG进行封装的步骤对吗,因为如果不了解封装的步骤,哪天CTP更新了,这样自己也不知道怎么封装,比较被动,避免被动。我想了解详细的步骤,就封装了测试版本,并且向期货公司申请账号的时候也需要在测试环境下测试,才会给批准授权码。有知道的大哥帮忙解答下,感恩无限。

老大,有下面的报错。

我百度到,问题可能是:代码commit后,手工把goctp替换github.com/mayiweb/goctp造成的

github.com/mayiweb/goctp: github.com/mayiweb/[email protected]: parsing go.mod:
module declares its path as: goctp
but was required as: github.com/mayiweb/goctp
image

系统版本:centos7
go version: go1.16.13

如何退出Ctp?

Release() 没有启作用,一会又 OnFrontConnected了.

想让系统定时关闭, 真正退出CTP, 有什么办法吗? 谢谢

illegal rune litera

我按照源码,自己想动手做一个非常小的demo, 发现没搞定。 希望能指出我这边疏漏的地方哈

目录 ctptest

├── ctptest.swigcxx
├── demo
│   └── main.go
├── libctptest.go
└── v6.5.1_20200908_api_tradeapi_se_linux64
    ├── error.dtd
    ├── error.xml
    ├── libthostmduserapi_se.so
    ├── libthosttraderapi_se.so
    ├── ThostFtdcMdApi.h
    ├── ThostFtdcTraderApi.h
    ├── ThostFtdcUserApiDataType.h
    └── ThostFtdcUserApiStruct.h

ctptest.swigcxx的内容如下

%module(directors="1") ctptest

%{
#include "./v6.5.1_20200908_api_tradeapi_se_linux64/ThostFtdcMdApi.h"
#include "./v6.5.1_20200908_api_tradeapi_se_linux64/ThostFtdcTraderApi.h"
#include "./v6.5.1_20200908_api_tradeapi_se_linux64/ThostFtdcUserApiDataType.h"
#include "./v6.5.1_20200908_api_tradeapi_se_linux64/ThostFtdcUserApiStruct.h"
%}

%feature("director") CThostFtdcMdSpi;
%feature("director") CThostFtdcTraderSpi;

%include "./v6.5.1_20200908_api_tradeapi_se_linux64/ThostFtdcMdApi.h"
%include "./v6.5.1_20200908_api_tradeapi_se_linux64/ThostFtdcTraderApi.h"
%include "./v6.5.1_20200908_api_tradeapi_se_linux64/ThostFtdcUserApiDataType.h"
%include "./v6.5.1_20200908_api_tradeapi_se_linux64/ThostFtdcUserApiStruct.h"

libctptest.go的内容如下

package ctptest

/*
#cgo linux LDFLAGS: -fPIC -L${SRCDIR}/v6.5.1_20200908_api_tradeapi_se_linux64 -Wl,-rpath,${SRCDIR}/v6.5.1_20200908_api_tradeapi_se_linux64 -lthostmduserapi_se -lthosttraderapi_se -lstdc++
#cgo linux CPPFLAGS: -fPIC -I${SRCDIR}/v6.5.1_20200908_api_tradeapi_se_linux64
*/
import "C"

demo/main.go的内容如下 :

package main

import (
	"ctptest"
	"fmt"
)

func main() {
	ver := ctptest.CThostFtdcMdApiGetApiVersion()
	fmt.Printf("ver:%s", ver)
}

然后我在目录下
go build -v -x -linkshared -o ctptest ./demo/*.go
报错

# ctptest
./v6.5.1_20200908_api_tradeapi_se_linux64/ThostFtdcMdApi.h:30: Warning 514: Director base class CThostFtdcMdSpi has no virtual destructor.
./v6.5.1_20200908_api_tradeapi_se_linux64/ThostFtdcTraderApi.h:30: Warning 514: Director base class CThostFtdcTraderSpi has no virtual destructor.
# ctptest
/tmp/go-build875878434/b002/_ctptest_swig.go:21766:46: illegal rune literal
/tmp/go-build875878434/b002/_ctptest_swig.go:21767:46: illegal rune literal
/tmp/go-build875878434/b002/_ctptest_swig.go:21768:48: illegal rune literal
/tmp/go-build875878434/b002/_ctptest_swig.go:21769:48: illegal rune literal
/tmp/go-build875878434/b002/_ctptest_swig.go:22084:52: illegal rune literal
/tmp/go-build875878434/b002/_ctptest_swig.go:22085:54: illegal rune literal
/tmp/go-build875878434/b002/_ctptest_swig.go:22086:52: illegal rune literal
/tmp/go-build875878434/b002/_ctptest_swig.go:22087:54: illegal rune literal

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.