// Copyright 2013-2014 Fuzamei tech Ltd. All rights reserved. package gocctp import ( "log" "testing" "time" ) type MyMdSpi struct { SpiBase } func (spi *MyMdSpi) OnRspUserLogin(errMsg string) { log.Println("OnRspUserLogin return:", errMsg) } func (spi *MyMdSpi) OnRtnDepthMarketData(pDepthMarketData *CThostFtdcDepthMarketDataField) { log.Println("OnRtnDepthMarketData return:", pDepthMarketData.InstrumentID, pDepthMarketData.AskPrice1, pDepthMarketData.BidPrice1) } type MyTdSpi struct { SpiBase insMap map[string]*CThostFtdcInstrumentField insAllDone chan bool } func (spi *MyTdSpi) OnRspUserLogin(errMsg string) { log.Println("OnRspUserLogin return:", errMsg) } func (spi *MyTdSpi) OnRspQryExchange(field *CThostFtdcExchangeField, errMsg string, isLast bool) { log.Println(field.ExchangeName, errMsg, isLast) } func (spi *MyTdSpi) OnRspQryInstrument(field *CThostFtdcInstrumentField, errMsg string, isLast bool) { log.Println(field.InstrumentName, errMsg, isLast) spi.insMap[field.InstrumentID.String()] = field if isLast { spi.insAllDone <- true } } func TestMdSubscribe(t *testing.T) { mdspi := &MyMdSpi{} mdApi := NewMdApi(mdspi) mdApi.Login("tcp://ctp1-md5.citicsf.com:41213", "66666", "1011000", "317496") tdspi := &MyTdSpi{insMap: make(map[string]*CThostFtdcInstrumentField), insAllDone: make(chan bool)} tdApi := NewTdApi(tdspi) tdApi.Login("tcp://ctp1-front5.citicsf.com:41205", "66666", "1011000", "317496", "", "") tdApi.QryExchange("") tdApi.QryInstrument("") <-tdspi.insAllDone insIds := []string{} for insId, _ := range tdspi.insMap { insIds = append(insIds, insId) } log.Println(insIds) mdApi.SubscribeMarketData(insIds) time.Sleep(time.Minute) }