代码拉取完成,页面将自动刷新
package goctp
import (
"time"
"golang.org/x/text/encoding/simplifiedchinese"
)
type QuotePro struct {
*QuoteExt
OnRtnTick func(pDepthMarketData *CThostFtdcDepthMarketDataField)
// 行情 key: InstrumentID
Ticks map[string]CThostFtdcDepthMarketDataField
// 响应事件
eventChan chan Event
// 错误
errorChan chan CThostFtdcRspInfoField
}
func NewQuotePro() *QuotePro {
q := &QuotePro{}
q.QuoteExt = NewQuoteExt()
q.eventChan = make(chan Event)
q.errorChan = make(chan CThostFtdcRspInfoField)
q.Ticks = make(map[string]CThostFtdcDepthMarketDataField)
q.Quote.OnRtnDepthMarketData = func(pDepthMarketData *CThostFtdcDepthMarketDataField) {
q.Ticks[pDepthMarketData.InstrumentID.String()] = *pDepthMarketData
if q.OnRtnTick != nil {
q.OnRtnTick(pDepthMarketData)
}
}
return q
}
func (q *QuotePro) Start(cfg LoginConfig) (logInfo CThostFtdcRspUserLoginField, rsp CThostFtdcRspInfoField) {
q.Quote.OnFrontConnected = func() {
q.eventChan <- onFrontConnected
}
q.Quote.OnRspUserLogin = func(pRspUserLogin *CThostFtdcRspUserLoginField, pRspInfo *CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
if bIsLast {
if pRspInfo.ErrorID == 0 {
logInfo = *pRspUserLogin
q.eventChan <- onRspUserLogin
} else {
q.errorChan <- *pRspInfo
}
}
}
q.Quote.RegisterFront(cfg.Front)
q.Quote.Init()
// 连接
select {
case <-q.eventChan: // 连接
q.ReqUserLogin(cfg.Broker, cfg.UserID, cfg.Password)
case <-time.NewTimer(5 * time.Second).C:
bs, _ := simplifiedchinese.GB18030.NewEncoder().Bytes([]byte("连接超时 5s"))
rsp.ErrorID = -1
copy(rsp.ErrorMsg[:], bs)
return
}
// 登录
select {
case <-q.eventChan:
case rsp = <-q.errorChan:
}
return
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。