-
Notifications
You must be signed in to change notification settings - Fork 3
/
mdapi_lite.go
161 lines (125 loc) · 4.86 KB
/
mdapi_lite.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package goctp
import "github.com/pseudocodes/goctp/thost"
type MdApiLite struct {
*mdApi
}
func CreateMdApiLite(options ...MdOption) *MdApiLite {
api := &MdApiLite{}
mdApi := CreateMdApi(options...)
api.mdApi = mdApi
return api
}
// 用户登录请求
func (t *MdApiLite) ReqUserLogin(pReqUserLoginField *ReqUserLoginField, nRequestID int) int {
var f0 = toCThostFtdcReqUserLoginField(pReqUserLoginField)
return t.mdApi.ReqUserLogin((f0), int(nRequestID))
}
type MdSpiLite struct {
BaseMdSpi
//当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。
OnFrontConnectedCallback func()
//当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。
///@param nReason 错误原因
/// 0x1001 网络读失败
/// 0x1002 网络写失败
/// 0x2001 接收心跳超时
/// 0x2002 发送心跳失败
/// 0x2003 收到错误报文
OnFrontDisconnectedCallback func(nReason int)
//心跳超时警告。当长时间未收到报文时,该方法被调用。
///@param nTimeLapse 距离上次接收报文的时间
OnHeartBeatWarningCallback func(nTimeLapse int)
//登录请求响应
OnRspUserLoginCallback func(pRspUserLogin *RspUserLoginField, pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
//错误应答
OnRspErrorCallback func(pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
//深度行情通知
OnRtnDepthMarketDataCallback func(pDepthMarketData *DepthMarketDataField)
// 订阅行情应答
OnRspSubMarketDataCallback func(specificInstrument string, pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
}
// 当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。
func (s *MdSpiLite) OnFrontConnected() {
if s.OnFrontConnectedCallback != nil {
s.OnFrontConnectedCallback()
}
}
// 当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。
// /@param nReason 错误原因
// / 0x1001 网络读失败
// / 0x1002 网络写失败
// / 0x2001 接收心跳超时
// / 0x2002 发送心跳失败
// / 0x2003 收到错误报文
func (s *MdSpiLite) OnFrontDisconnected(nReason int) {
if s.OnFrontDisconnectedCallback != nil {
s.OnFrontDisconnectedCallback(int(nReason))
}
}
// 心跳超时警告。当长时间未收到报文时,该方法被调用。
// /@param nTimeLapse 距离上次接收报文的时间
func (s *MdSpiLite) OnHeartBeatWarning(nTimeLapse int) {
if s.OnHeartBeatWarningCallback != nil {
s.OnHeartBeatWarningCallback(int(nTimeLapse))
}
}
// 登录请求响应
func (s *MdSpiLite) OnRspUserLogin(pRspUserLogin *thost.CThostFtdcRspUserLoginField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
f0 := fromCThostFtdcRspUserLoginField(pRspUserLogin)
var f1 *RspInfoField
if pRspInfo != nil {
f1 = fromCThostFtdcRspInfoField(pRspInfo)
}
if s.OnRspUserLoginCallback != nil {
s.OnRspUserLoginCallback((f0), (f1), int(nRequestID), bool(bIsLast))
}
}
// 错误应答
func (s *MdSpiLite) OnRspError(pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
var f0 *RspInfoField
if pRspInfo != nil {
f0 = fromCThostFtdcRspInfoField(pRspInfo)
}
if s.OnRspErrorCallback != nil {
s.OnRspErrorCallback((f0), int(nRequestID), bool(bIsLast))
}
}
// 深度行情通知
func (s *MdSpiLite) OnRtnDepthMarketData(pDepthMarketData *thost.CThostFtdcDepthMarketDataField) {
f0 := fromCThostFtdcDepthMarketDataField(pDepthMarketData)
if s.OnRtnDepthMarketDataCallback != nil {
s.OnRtnDepthMarketDataCallback((f0))
}
}
// 深度行情通知
func (s *MdSpiLite) OnRspSubMarketData(pSpecificInstrument *thost.CThostFtdcSpecificInstrumentField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
var f0 = bytes2String(pSpecificInstrument.InstrumentID[:])
var f1 *RspInfoField
if pRspInfo != nil {
f1 = fromCThostFtdcRspInfoField(pRspInfo)
}
if s.OnRspSubMarketDataCallback != nil {
s.OnRspSubMarketDataCallback(f0, f1, nRequestID, bIsLast)
}
}
func (s *MdSpiLite) SetOnFrontConnected(f func()) {
s.OnFrontConnectedCallback = f
}
func (s *MdSpiLite) SetOnFrontDisconnected(f func(int)) {
s.OnFrontDisconnectedCallback = f
}
func (s *MdSpiLite) SetOnHeartBeatWarning(f func(int)) {
s.OnHeartBeatWarningCallback = f
}
func (s *MdSpiLite) SetOnRspUserLogin(f func(*RspUserLoginField, *RspInfoField, int, bool)) {
s.OnRspUserLoginCallback = f
}
func (s *MdSpiLite) SetOnRspError(f func(*RspInfoField, int, bool)) {
s.OnRspErrorCallback = f
}
func (s *MdSpiLite) SetOnRtnDepthMarketData(f func(*DepthMarketDataField)) {
s.OnRtnDepthMarketDataCallback = f
}
func (s *MdSpiLite) SetOnRspSubMarketData(f func(string, *RspInfoField, int, bool)) {
s.OnRspSubMarketDataCallback = f
}