I ❤ Open Source. I love Python and Go.
I'm looking for GitHub sponsors.
Golang bindings for CTP.
License: MIT License
I ❤ Open Source. I love Python and Go.
I'm looking for GitHub sponsors.
登录交易时每次都报同样的错
分别使用了simnow的账号,和方正中期的生成账号,报同样的错
请问登录交易的时候有啥其他配置吗?
我的配置如下:
broker_id = flag.String("BrokerID", "9999", "经纪公司编号,SimNow BrokerID统一为:9999")
investor_id = flag.String("InvestorID", "058014", "交易用户代码")
pass_word = flag.String("Password", "147147", "交易用户密码")
market_front = flag.String("MarketFront", "tcp://180.168.146.187:10010", "行情前置,SimNow的测试环境: tcp://180.168.146.187:10031")
trade_front = flag.String("TradeFront", "tcp://180.168.146.187:10000", "交易前置,SimNow的测试环境:
我在ubuntu 18.04 下执行make build和make example成功。但是执行下面的命令时出错:
./goctp_trader_example -InvestorID=090622 -Password XXXXXX -MarketFront tcp://180.168.146.187:10131 -TradeFront tcp://180.168.146.187:10130
错误信息如下:
Bad format user system info
CTP: 2019/08/11 16:20:53.476229 发送用户登录请求: 失败
我使用的API版本是"6.3.15_20190220 15:47:00"
到底问题出在哪里?有其他人遇到这个问题吗?
/usr/bin/ld: cannot find -lthostmduserapi
/usr/bin/ld: cannot find -lthosttraderapi
var code string
fmt.Println("输入行情监控合约代码")
fmt.Scanln(&code)
code = strings.ToLower(code)
//ppInstrumentID := []string{code}
ppInstrumentID := []string{"rb1901"}
log.Println(" ppInstrumentID", ppInstrumentID)
p.SubscribeMarketData(ppInstrumentID)
如果采用注释的//ppInstrumentID := []string{code},通不过,怎么才能绕开这个坑
pTraderSpi := goctp.NewDirectorCThostFtdcTraderSpi(&GoCThostFtdcTraderSpi{Client: CTP})
CTP.TraderApi.RegisterSpi(pTraderSpi) // 注册回调接口,派生自回调接口类的实例
CTP.TraderApi.SubscribePublicTopic(0/*THOST_TERT_RESTART*/) //订阅公共流,要在init之前
CTP.TraderApi.SubscribePrivateTopic(0/*THOST_TERT_RESTART*/)
CTP.TraderApi.RegisterFront(CTP.TraderFront) // 注册前置机器网络地址
CTP.TraderApi.Init() // 初始化运行环境,只有被调用后,接口才开始工作
req := goctp.NewCThostFtdcReqUserLoginField() //这段代码是自己添加的
req.SetBrokerID(CTP.BrokerID)
req.SetUserID(CTP.InvestorID)
req.SetPassword(CTP.Password)
i := CTP.TraderApi.ReqUserLogin(req,CTP.GetTraderRequestID())
fmt.Println("用户主动注册返回结果:",i) //返回值为-1,说明未连接成功,十分不解
CTP.TraderApi.Join() // 等待接口线程结束运行
CTP.TraderApi.Release() // 删除接口对象本身
fmt.Println("主程序运行结束") // 这句不会执行,协程一直在运行
这是tradeApi_example中的主要代码,原作者使用的方法是通过回调函数OnfrontConnect来调用一系列主动函数,而我想直接通过traderApi调用主动函数,总是失败,还请大神指点迷津,不慎感激!!!!!
osx系统好像不能使用, 因为golang不支持shard这个构建模式
CTP: 2017/08/22 20:35:37.332966 GoCThostFtdcTraderSpi.OnRspQryInstrument: fu1808 SHFE ȼ1808 fu1808 fu 49 2018 8 30 1 500 1 50 1 20170703 20170801 20180731 20180801 20180807 4 false
CTP: 2017/08/22 20:35:37.332987 GoCThostFtdcTraderSpi.OnRspQryInstrument: a1709 DCE 9 a1709 a 49 2017 9 1000 1 1000 1 10 1 20160205 20160315 20170914 20170915 20170919 4 false
CTP: 2017/08/22 20:35:37.333027 GoCThostFtdcTraderSpi.OnRspQryInstrument: scefp INE scefp scefp scefp 53 2037 12 30 1 500 1 1000 0.1 20140117 20140120 20371231 20380102 20380103 4 true
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x822990]
runtime stack:
runtime.throw(0x90a923, 0x2a)
/usr/local/go/src/runtime/panic.go:596 +0x95
runtime.sigpanic()
/usr/local/go/src/runtime/signal_unix.go:274 +0x2db
goroutine 17 [syscall, locked to thread]:
runtime.cgocall(0x809f80, 0xc420051a30, 0x90c948)
/usr/local/go/src/runtime/cgocall.go:131 +0xe2 fp=0xc4200519f0 sp=0xc4200519b0
github.com/qerio/goctp._Cfunc__wrap_CThostFtdcRspInfoField_ErrorID_get_goctp_715aa2fe86d79dcf(0x0, 0x0)
github.com/qerio/goctp/_obj/_cgo_gotypes.go:83020 +0x4e fp=0xc420051a30 sp=0xc4200519f0
github.com/qerio/goctp.SwigcptrCThostFtdcRspInfoField.GetErrorID(0x0, 0x0)
github.com/qerio/goctp/_obj/goctp.go:15748 +0x2b fp=0xc420051a50 sp=0xc420051a30
github.com/qerio/goctp.(*SwigcptrCThostFtdcRspInfoField).GetErrorID(0xc4200cbd40, 0xe6fec0)
:492 +0x4d fp=0xc420051a90 sp=0xc420051a50
main.(*GoCThostFtdcTraderSpi).IsErrorRspInfo(0xc420078080, 0xe65720, 0xc4200cbd40, 0xc4200cbe88)
/home/sm/workspace/go/src/github.com/qerio/goctp/_example/goctp_trader_example.go:100 +0x3b fp=0xc420051b08 sp=0xc420051a90
main.(GoCThostFtdcTraderSpi).OnRspQryInstrument(0xc420078080, 0xe6a8c0, 0xc4200cbd38, 0xe65720, 0xc4200cbd40, 0x4, 0xc4200cbd01)
/home/sm/workspace/go/src/github.com/qerio/goctp/_example/goctp_trader_example.go:259 +0x8ed fp=0xc420051d98 sp=0xc420051b08
github.com/qerio/goctp.(_swig_DirectorCThostFtdcTraderSpi).OnRspQryInstrument(0xc42000c240, 0xe6a8c0, 0xc4200cbd38, 0xe65720, 0xc4200cbd40, 0x4, 0xe6e201)
github.com/qerio/goctp/_obj/goctp.go:86519 +0xa3 fp=0xc420051de8 sp=0xc420051d98
github.com/qerio/goctp.Swig_DirectorCThostFtdcTraderSpi_callback_OnRspQryInstrument_goctp_715aa2fe86d79dcf(0x1, 0x7f845b7fd9f0, 0x0, 0x4, 0x1)
github.com/qerio/goctp/_obj/goctp.go:86540 +0xfc fp=0xc420051e58 sp=0xc420051de8
github.com/qerio/goctp._cgoexpwrap_5857374ac24d_Swig_DirectorCThostFtdcTraderSpi_callback_OnRspQryInstrument_goctp_715aa2fe86d79dcf(0x1, 0x7f845b7fd9f0, 0x0, 0x4, 0x501160001)
github.com/qerio/goctp/_obj/_cgo_gotypes.go:114805 +0x52 fp=0xc420051e90 sp=0xc420051e58
runtime.call64(0x0, 0x7f845b7fd8e8, 0x7f845b7fd980, 0x28)
/usr/local/go/src/runtime/asm_amd64.s:515 +0x48 fp=0xc420051ee0 sp=0xc420051e90
runtime.cgocallbackg1(0x0)
/usr/local/go/src/runtime/cgocall.go:301 +0x19d fp=0xc420051f58 sp=0xc420051ee0
runtime.cgocallbackg(0x0)
/usr/local/go/src/runtime/cgocall.go:184 +0x84 fp=0xc420051fc0 sp=0xc420051f58
runtime.cgocallback_gofunc(0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/runtime/asm_amd64.s:767 +0x74 fp=0xc420051fe0 sp=0xc420051fc0
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:2197 +0x1 fp=0xc420051fe8 sp=0xc420051fe0
goroutine 1 [syscall, locked to thread]:
github.com/qerio/goctp._Cfunc__wrap_CThostFtdcTraderApi_Join_goctp_715aa2fe86d79dcf(0x28cbcd0, 0x0)
github.com/qerio/goctp/_obj/_cgo_gotypes.go:94180 +0x4e
github.com/qerio/goctp.SwigcptrCThostFtdcTraderApi.Join(0x28cbcd0, 0x7ffea007876f)
github.com/qerio/goctp/_obj/goctp.go:89769 +0x2b
github.com/qerio/goctp.(*SwigcptrCThostFtdcTraderApi).Join(0xc4200122a0, 0x7ffea007876f)
:15365 +0x4d
main.main()
/home/sm/workspace/go/src/github.com/qerio/goctp/_example/goctp_trader_example.go:365 +0x2d1
goroutine 18 [syscall, locked to thread]:
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:2197 +0x1
如题,自己卡了很久,可以麻烦你也封装下windows64的吗,谢谢了
swig 版本必须 >= 3.0以上,最新的4.1;
yum install gcc-c++ 安装C++;
Go 低版本的 比如: 1.8.7 编译时报错 -std 的问题; 升级 Go版本, 1.10以上未出现问题,1.9不清楚;
# 注释掉如下代码 => 在 example/goctp_md_example.go 中,修改如下:
func (p *GoCThostFtdcMdSpi) SubscribeMarketData(symbols []string) {
args := make([]*C.char, 0)
for _, v := range symbols {
symbol := C.CString(v)
defer C.free(unsafe.Pointer(symbol))
args = append(args, symbol)
}
iResult := p.Client.MdApi.SubscribeMarketData((*string)(unsafe.Pointer(&args[0])), len(symbols))
if iResult != 0 {
log.Println("发送行情订阅请求: 失败.")
} else {
log.Println("发送行情订阅请求: 成功.")
}
}
func (p *GoCThostFtdcMdSpi) SubscribeForQuoteRsp(symbols []string) {
args := make([]*C.char, 0)
for _, v := range symbols {
symbol := C.CString(v)
defer C.free(unsafe.Pointer(symbol))
args = append(args, symbol)
}
iResult := p.Client.MdApi.SubscribeForQuoteRsp((*string)(unsafe.Pointer(&args[0])), len(symbols))
if iResult != 0 {
log.Println("发送询价订阅请求: 失败.")
} else {
log.Println("发送询价订阅请求: 成功.")
}
}
//%typemap(gotype) (char **ppInstrumentID, int nCount) "[]string"
//
//%typemap(in) (char *ppInstrumentID, int nCount)
//%{
// {
// int i;
// _gostring_* a;
//
// $2 = $input.len;
// a = (_gostring_*) $input.array;
// $1 = (char **) malloc (($2 + 1) * sizeof (char *));
// for (i = 0; i < $2; i++) {
//
// /* Not work */
// //_gostring_ *ps = &a[i];
// //$1[i] = (char *) ps->p;
// //$1[i][ps->n] = '\0';
//
// /*Work well*/
// _gostring_ *ps = &a[i];
// $1[i] = (char*) malloc(ps->n + 1);
// memcpy($1[i], ps->p, ps->n);
// $1[i][ps->n] = '\0';
//
// }
// $1[i] = NULL;
// }
//%}
//
//%typemap(argout) (char *ppInstrumentID, int nCount) "" /* override char *[] default */
//
//%typemap(freearg) (char **ppInstrumentID, int nCount)
//%{
// {
// int i;
// for (i = 0; i < $2; i++)
// {
// free ($1[i]);
// }
// free($1);
// }
//%}
# v6.3.15_20190220_api_tradeapi_se_linux64 版本的该头文件 将字符串以 ''括起来,导致 SWIG翻译时报错;
将类似 '102001' 的都转为 ""; 否则编译成.go之后 出现
const THOST_FTDC_VTC_BankBankToFuture byte '102001' 编译器退出报错;
实际上应该是:
const THOST_FTDC_VTC_BankBankToFuture string "102001"
#define THOST_FTDC_VTC_BankBankToFuture "102001"
#define THOST_FTDC_VTC_BankFutureToBank "102002"
#define THOST_FTDC_VTC_FutureBankToFuture "202001"
#define THOST_FTDC_VTC_FutureFutureToBank "202002"
#define THOST_FTDC_FTC_BankLaunchBankToBroker "102001"
#define THOST_FTDC_FTC_BrokerLaunchBankToBroker "202001"
#define THOST_FTDC_FTC_BankLaunchBrokerToBank "102002"
#define THOST_FTDC_FTC_BrokerLaunchBrokerToBank "202002"
# 默认的动态加载库在 /usr/lib 目录下,而非 /usr/local/lib (建立软连接即可)
sudo ln -s /usr/local/lib/libthostmduserapi.so /usr/lib/libthostmduserapi.so
sudo ln -s /usr/local/lib/libthosttraderapi.so /usr/lib/libthosttraderapi.so
./goctp_md_example
CTP: 2019/07/10 13:49:33.854960 usage: ./goctp_md_example -BrokerID 9999 -InvestorID 000000 -Password 000000 -MarketFront tcp://180.168.146.187:10010 -TradeFront tcp://180.168.146.187:10000
go get -u github.com/qerio/goctp 以后显示以下错误,请问如何解决
/usr/bin/ld: 找不到 -lthostmduserapi
/usr/bin/ld: 找不到 -lthosttraderapi
collect2: error: ld returned 1 exit status
请问有没有在win64下编译的注意事项?我编译出现如下错误:
go build github.com/qerio/goctp: invalid flag in #cgo LDFLAGS: -Wl,-rpath=C:/Users/admin/go/src/github.com/qerio/goctp/api/ThostTraderApi_v6.3.6/win64
go version go1.10 windows/amd64
example和git里面没有找到相关改动
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.