├── .gitattributes
├── .github
└── workflows
│ └── go.yml
├── .gitignore
├── LICENSE
├── Makefile
├── README.md
├── api
├── v6.6.9_20220914_api_tradeapi_se_linux64
│ ├── ThostFtdcMdApi.h
│ ├── ThostFtdcTraderApi.h
│ ├── ThostFtdcUserApiDataType.h
│ ├── ThostFtdcUserApiStruct.h
│ ├── error.dtd
│ ├── error.xml
│ ├── libthostmduserapi_se.so
│ └── libthosttraderapi_se.so
├── v6.6.9_MacOS_20220926
│ ├── DataCollect.h
│ ├── ThostFtdcMdApi.h
│ ├── ThostFtdcTraderApi.h
│ ├── ThostFtdcUserApiDataType.h
│ ├── ThostFtdcUserApiStruct.h
│ ├── libMacDataCollect.a
│ ├── libcomunicationkey.a
│ ├── libcrypto.a
│ ├── libssl.a
│ ├── libthostmduserapi_se.a
│ └── libthosttraderapi_se.a
└── v6.7.0_20230209_api_traderapi_se_linux64
│ ├── DataCollect.h
│ ├── ThostFtdcMdApi.h
│ ├── ThostFtdcTraderApi.h
│ ├── ThostFtdcUserApiDataType.h
│ ├── ThostFtdcUserApiStruct.h
│ ├── error.dtd
│ ├── error.xml
│ ├── libLinuxDataCollect.so
│ ├── libthostmduserapi_se.so
│ └── libthosttraderapi_se.so
├── convert.go
├── data_collect
├── data_collect.go
├── data_collect_darwin.go
├── data_collect_linux.go
├── data_collect_wrap.cxx
└── data_collect_wrap.h
├── go.mod
├── go.sum
├── libctp.go
├── mdapi.go
├── mdapi_impl.go
├── mdapi_lite.go
├── mdapi_wrap.cxx
├── mdapi_wrap.h
├── mdspi_base.go
├── sample
├── simple_market
│ └── simple_market.go
└── simple_trader
│ └── simple_trader.go
├── thost
├── ctp_datatype.go
└── ctp_struct.go
├── traderapi.go
├── traderapi_impl.go
├── traderapi_lite.go
├── traderapi_wrap.cxx
├── traderapi_wrap.h
├── traderspi_base.go
└── types.go
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.go linguist-language=Go
2 | *.h linguist-language=Go
3 | *.cxx linguist-language=Go
--------------------------------------------------------------------------------
/.github/workflows/go.yml:
--------------------------------------------------------------------------------
1 | name: Go
2 | on: [push]
3 | jobs:
4 |
5 | build:
6 | name: Build
7 | runs-on: ubuntu-latest
8 | steps:
9 |
10 | - uses: actions/checkout@v3
11 | - name: Set up Go 1.x
12 | uses: actions/setup-go@v3
13 | with:
14 | go-version: 1.17
15 |
16 | - name: Build
17 | run: go build
18 |
19 | - name: Build Sample
20 | run: cd sample/simple_market/ && go build
21 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled Object files, Static and Dynamic libs (Shared Objects)
2 | *.o
3 |
4 |
5 |
6 | # Folders
7 | _obj
8 | _test
9 |
10 | # Architecture specific extensions/prefixes
11 | *.[568vq]
12 | [568vq].out
13 |
14 | *.cgo1.go
15 | *.cgo2.c
16 | _cgo_defun.c
17 | _cgo_gotypes.go
18 | _cgo_export.*
19 |
20 | _testmain.go
21 |
22 | *.exe
23 | *.test
24 | *.prof
25 | .vscode
26 |
27 | .DS_Store
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 |
2 | build:
3 | go build
4 |
5 | v6.7.0:
6 | @sed -i '16c #cgo linux LDFLAGS: -fPIC -L. -L$${SRCDIR}/api/v6.7.0_20230209_api_traderapi_se_linux64 -Wl,-rpath=$${SRCDIR}/api/v6.7.0_20230209_api_traderapi_se_linux64 -lthostmduserapi_se -lthosttraderapi_se -lstdc++' libctp.go
7 | @sed -i '17c #cgo linux CPPFLAGS: -fPIC -I. -I$${SRCDIR}/api/v6.7.0_20230209_api_traderapi_se_linux64' libctp.go
8 |
9 | v6.6.9:
10 | @sed -i '16c #cgo linux LDFLAGS: -fPIC -L. -L$${SRCDIR}/api/v6.6.9_20220914_api_tradeapi_se_linux64 -Wl,-rpath=$${SRCDIR}/api/v6.6.9_20220914_api_tradeapi_se_linux64 -lthostmduserapi_se -lthosttraderapi_se -lstdc++' libctp.go
11 | @sed -i '17c #cgo linux CPPFLAGS: -fPIC -I. -I$${SRCDIR}/api/v6.6.9_20220914_api_tradeapi_se_linux64' libctp.go
12 |
13 | v6.6.7:
14 | @sed -i '16c #cgo linux LDFLAGS: -fPIC -L. -L$${SRCDIR}/api/v6.6.7_20220613_api_tradeapi_linux64 -Wl,-rpath=$${SRCDIR}/api/v6.6.7_20220613_api_tradeapi_linux64 -lthostmduserapi_se -lthosttraderapi_se -lstdc++' libctp.go
15 | @sed -i '17c #cgo linux CPPFLAGS: -fPIC -I. -I$${SRCDIR}/api/v6.6.7_20220613_api_tradeapi_linux64' libctp.go
16 |
17 | v6.6.1_P1:
18 | @sed -i '16c #cgo linux LDFLAGS: -fPIC -L. -L$${SRCDIR}/api/v6.6.1_P1_20210406_api_tradeapi_se_linux64 -Wl,-rpath=$${SRCDIR}/api/v6.6.1_P1_20210406_api_tradeapi_se_linux64 -lthostmduserapi_se -lthosttraderapi_se -lstdc++' libctp.go
19 | @sed -i '17c #cgo linux CPPFLAGS: -fPIC -I. -I/$${SRCDIR}/api/v6.6.1_P1_20210406_api_tradeapi_se_linux64/' libctp.go
20 |
21 |
22 | example:
23 | go build -linkshared sample/market/goctp_md_example.go
24 | go build -linkshared sample/trader/goctp_trader_example.go
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # GoCTP
2 | 
3 |
4 | Pure Golang bindings for CTP v2 Version without Swig
5 |
6 | 原生 Golang CTP 封装,最大限度的利用了 Go 本身的 FFI 特性
7 |
8 |
9 | ## ⚠️ Project Status: No Longer Actively Maintained
10 |
11 | This project is no longer actively maintained. Below are the details regarding its current status:
12 |
13 | - **Last Update**: 2024-11-19
14 |
15 | ### Recommended Alternatives
16 |
17 | We recommend using one of the following alternatives:
18 |
19 | - [github.com/pseudocodes/go2ctp](https://github.com/pseudocodes/go2ctp): 更简洁灵活的封装,支持 MacOS, Linux
20 |
21 | ## Why not Swig
22 | * 编译慢
23 | * 编辑器提示不友好
24 | * 封装接口太难看,不好用
25 |
26 |
27 | ## How to Build goctp
28 | > Only support Linux X64 now.
29 |
30 | ```
31 | go get github.com/pseudocodes/goctp
32 |
33 | # make build
34 | ```
35 |
36 | ## How to Build example
37 |
38 | ```
39 | make example
40 |
41 | > go build sample/simple_market/simple_market.go
42 | > go build sample/simple_trader/simple_trader.go
43 |
44 | ```
45 |
46 | ## Sample
47 |
48 | ### simple market quote
49 | ```go
50 |
51 | import "github.com/pseudocodes/goctp"
52 |
53 |
54 | type baseSpi struct {
55 | mdapi *goctp.MdApiLite
56 | mdspi *goctp.MdSpiLite
57 | }
58 |
59 | func CreateBaseSpi() *baseSpi {
60 | s := &baseSpi{
61 | mdspi: &goctp.MdSpiLite{},
62 | }
63 | s.mdspi.SetOnFrontConnected(s.OnFrontConnected)
64 |
65 | s.mdspi.SetOnFrontDisconnected(s.OnFrontDisconnected)
66 |
67 | s.mdspi.SetOnHeartBeatWarning(s.OnHeartBeatWarning)
68 |
69 | s.mdspi.SetOnRspUserLogin(s.OnRspUserLogin)
70 |
71 | s.mdspi.SetOnRspError(s.OnRspError)
72 |
73 | s.mdspi.SetOnRtnDepthMarketData(s.OnRtnDepthMarketData)
74 | return s
75 | }
76 |
77 | func (s *baseSpi) OnFrontConnected() {
78 | log.Printf("OnFrontConnected\n")
79 |
80 | ret := s.mdapi.ReqUserLogin(&goctp.ReqUserLoginField{
81 | BrokerID: "9999",
82 | UserID: os.Getenv("SIMNOW_USER_ID"), // <- 环境变量设置
83 | Password: os.Getenv("SIMNOW_USER_PASSWORD"),
84 | }, 1)
85 |
86 | log.Printf("user log: %v\n", ret)
87 | }
88 |
89 | func (s *baseSpi) OnHeartBeatWarning(timelapse int) {
90 | log.Printf("OnHeartBeatWarning: %v\n", timelapse)
91 | }
92 |
93 | func (s *baseSpi) OnFrontDisconnected(nReason int) {
94 | log.Printf("OnFrontDisconnected: %v\n", nReason)
95 | }
96 |
97 | func (s *baseSpi) OnRspUserLogin(pRspUserLogin *goctp.RspUserLoginField, rspInfo *goctp.RspInfoField, nRequestID int, bIsLast bool) {
98 | log.Printf("RspUserLogin: %+v\nRspInfo: %+v\n", pRspUserLogin, rspInfo)
99 | s.mdapi.SubscribeMarketData("ag2306")
100 | }
101 |
102 | func (s *baseSpi) OnRspSubMarketData(instrumentID string, rspInfo *goctp.RspInfoField, requestID int, isLast bool) {
103 | log.Printf("instrumentID: %+v\n RspInfo: %+v\n", instrumentID, rspInfo)
104 | }
105 |
106 | func (s *baseSpi) OnRtnDepthMarketData(quote *goctp.DepthMarketDataField) {
107 | log.Printf("tick {%+v}\n", quote)
108 | }
109 |
110 | func (s *baseSpi) OnRspError(rspInfo *goctp.RspInfoField, requestID int, isLast bool) {
111 | log.Printf("RspInfo: %+v\n", rspInfo)
112 |
113 | }
114 |
115 | ```
116 |
117 | ### simple trader
118 | ```go
119 | import "github.com/pseudocodes/goctp"
120 |
121 | type baseSpi struct {
122 | tdspi *goctp.TraderSpiLite
123 | tdapi *goctp.TraderApiLite
124 | }
125 |
126 | func CreateBaseSpi() *baseSpi {
127 | s := &baseSpi{
128 | // tdapi: tdapi,
129 | tdspi: &goctp.TraderSpiLite{},
130 | }
131 |
132 | s.tdspi.SetOnFrontConnected(s.OnFrontConnected)
133 |
134 | s.tdspi.SetOnFrontDisconnected(s.OnFrontDisconnected)
135 |
136 | s.tdspi.SetOnRspAuthenticate(s.OnRspAuthenticate)
137 |
138 | s.tdspi.SetOnRspUserLogin(s.OnRspUserLogin)
139 |
140 | s.tdspi.SetOnRspSettlementInfoConfirm(s.OnRspSettlementInfoConfirm)
141 |
142 | s.tdspi.SetOnRspQryInstrument(s.OnRspQryInstrument)
143 |
144 | s.tdspi.SetOnRtnInstrumentStatus(s.OnRtnInstrumentStatus)
145 | return s
146 | }
147 |
148 | func (s *baseSpi) OnFrontConnected() {
149 | var ret int
150 | log.Printf("OnFrontConnected\n")
151 |
152 | ret = s.tdapi.ReqAuthenticate(&goctp.ReqAuthenticateField{
153 | BrokerID: "9999",
154 | UserID: os.Getenv("SIMNOW_USER_ID"), // <- 环境变量设置
155 | AuthCode: "0000000000000000",
156 | AppID: "simnow_client_test",
157 | }, 1)
158 |
159 |
160 | log.Printf("user auth: %v\n", ret)
161 | }
162 |
163 | func (s *baseSpi) OnRspAuthenticate(f *goctp.RspAuthenticateField, r *goctp.RspInfoField, nRequestID int, bIsLast bool) {
164 | dump.Println(r)
165 | dump.Println(f)
166 | req := &goctp.ReqUserLoginField{
167 | BrokerID: "9999",
168 | UserID: os.Getenv("SIMNOW_USER_ID"), // <- 环境变量设置
169 | Password: os.Getenv("SIMNOW_USER_PASSWORD"),
170 | }
171 | dump.Println(req)
172 | ret := s.tdapi.ReqUserLogin(req, 1)
173 | log.Printf("user login: %v\n", ret)
174 | }
175 |
176 | func (s *baseSpi) OnRspSettlementInfoConfirm(f *goctp.SettlementInfoConfirmField, r *goctp.RspInfoField, nRequestID int, bIsLast bool) {
177 | dump.Println(r)
178 | dump.Println(f)
179 | }
180 |
181 | func (s *baseSpi) OnFrontDisconnected(nReason int) {
182 | log.Printf("OnFrontDissconnected: %v\n", nReason)
183 | }
184 |
185 | func (s *baseSpi) OnRspUserLogin(f *goctp.RspUserLoginField, r *goctp.RspInfoField, nRequestID int, bIsLast bool) {
186 | dump.Println(r)
187 | dump.Println(f)
188 | // req := &goctp.QryInstrumentField{}
189 | // ret := s.tdapi.ReqQryInstrument(req, 3)
190 | // log.Printf("user qry ins: %v\n", ret)
191 | }
192 |
193 | func (s *baseSpi) OnRspQryInstrument(pInstrument *goctp.InstrumentField, pRspInfo *goctp.RspInfoField, nRequestID int, bIsLast bool) {
194 | dump.Print(pRspInfo, nRequestID, bIsLast)
195 | dump.Println(pInstrument.InstrumentName)
196 |
197 | }
198 |
199 | //合约交易状态通知
200 | func (s *baseSpi) OnRtnInstrumentStatus(pInstrumentStatus *goctp.InstrumentStatusField) {
201 | dump.P(pInstrumentStatus)
202 | }
203 |
204 | func main() {
205 |
206 | tdapi := goctp.CreateTraderApiLite(goctp.TraderFlowPath("./data/"))
207 | baseSpi := CreateBaseSpi()
208 | baseSpi.tdapi = tdapi
209 | log.Printf("baseSpi %+v\n", baseSpi)
210 | tdapi.RegisterSpi(baseSpi.tdspi)
211 | tdapi.RegisterFront(SimnowEnv["td"]["7x24"])
212 |
213 | tdapi.Init()
214 |
215 | println(tdapi.GetTradingDay())
216 | println(tdapi.GetApiVersion())
217 | tdapi.Join()
218 | }
219 |
220 | ```
221 |
222 | ## 免责条款声明
223 |
224 | 本项目明确拒绝对产品做任何明示或暗示的担保。由于软件系统开发本身的复杂性,无法保证本项目完全没有错误。如选择使用本项目表示您同意错误和/或遗漏的存在,在任何情况下本项目对于直接、间接、特殊的、偶然的、或间接产生的、使用或无法使用本项目进行交易和投资造成的盈亏、直接或间接引起的赔偿、损失、债务或是任何交易中止均不承担责任和义务。
225 |
226 | 此声明永久有效
--------------------------------------------------------------------------------
/api/v6.6.9_20220914_api_tradeapi_se_linux64/ThostFtdcMdApi.h:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////
2 | ///@system 新一代交易所系统
3 | ///@company 上海期货信息技术有限公司
4 | ///@file ThostFtdcMdApi.h
5 | ///@brief 定义了客户端接口
6 | ///@history
7 | /// 20060106 赵鸿昊 创建该文件
8 | /////////////////////////////////////////////////////////////////////////
9 |
10 | #if !defined(THOST_FTDCMDAPI_H)
11 | #define THOST_FTDCMDAPI_H
12 |
13 | #if _MSC_VER > 1000
14 | #pragma once
15 | #endif // _MSC_VER > 1000
16 |
17 | #include "ThostFtdcUserApiStruct.h"
18 |
19 | #if defined(ISLIB) && defined(WIN32)
20 | #ifdef LIB_MD_API_EXPORT
21 | #define MD_API_EXPORT __declspec(dllexport)
22 | #else
23 | #define MD_API_EXPORT __declspec(dllimport)
24 | #endif
25 | #else
26 | #define MD_API_EXPORT
27 | #endif
28 |
29 | class CThostFtdcMdSpi {
30 | public:
31 | /// 当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。
32 | virtual void OnFrontConnected() {};
33 |
34 | /// 当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。
35 | ///@param nReason 错误原因
36 | /// 0x1001 网络读失败
37 | /// 0x1002 网络写失败
38 | /// 0x2001 接收心跳超时
39 | /// 0x2002 发送心跳失败
40 | /// 0x2003 收到错误报文
41 | virtual void OnFrontDisconnected(int nReason) {};
42 |
43 | /// 心跳超时警告。当长时间未收到报文时,该方法被调用。
44 | ///@param nTimeLapse 距离上次接收报文的时间
45 | virtual void OnHeartBeatWarning(int nTimeLapse) {};
46 |
47 | /// 登录请求响应
48 | virtual void OnRspUserLogin(CThostFtdcRspUserLoginField* pRspUserLogin, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {};
49 |
50 | /// 登出请求响应
51 | virtual void OnRspUserLogout(CThostFtdcUserLogoutField* pUserLogout, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {};
52 |
53 | /// 请求查询组播合约响应
54 | virtual void OnRspQryMulticastInstrument(CThostFtdcMulticastInstrumentField* pMulticastInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {};
55 |
56 | /// 错误应答
57 | virtual void OnRspError(CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {};
58 |
59 | /// 订阅行情应答
60 | virtual void OnRspSubMarketData(CThostFtdcSpecificInstrumentField* pSpecificInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {};
61 |
62 | /// 取消订阅行情应答
63 | virtual void OnRspUnSubMarketData(CThostFtdcSpecificInstrumentField* pSpecificInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {};
64 |
65 | /// 订阅询价应答
66 | virtual void OnRspSubForQuoteRsp(CThostFtdcSpecificInstrumentField* pSpecificInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {};
67 |
68 | /// 取消订阅询价应答
69 | virtual void OnRspUnSubForQuoteRsp(CThostFtdcSpecificInstrumentField* pSpecificInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {};
70 |
71 | /// 深度行情通知
72 | virtual void OnRtnDepthMarketData(CThostFtdcDepthMarketDataField* pDepthMarketData) {};
73 |
74 | /// 询价通知
75 | virtual void OnRtnForQuoteRsp(CThostFtdcForQuoteRspField* pForQuoteRsp) {};
76 | };
77 |
78 | class MD_API_EXPORT CThostFtdcMdApi {
79 | public:
80 | /// 创建MdApi
81 | ///@param pszFlowPath 存贮订阅信息文件的目录,默认为当前目录
82 | ///@return 创建出的UserApi
83 | /// modify for udp marketdata
84 | static CThostFtdcMdApi* CreateFtdcMdApi(const char* pszFlowPath = "", const bool bIsUsingUdp = false, const bool bIsMulticast = false);
85 |
86 | /// 获取API的版本信息
87 | ///@retrun 获取到的版本号
88 | static const char* GetApiVersion();
89 |
90 | /// 删除接口对象本身
91 | ///@remark 不再使用本接口对象时,调用该函数删除接口对象
92 | virtual void Release() = 0;
93 |
94 | /// 初始化
95 | ///@remark 初始化运行环境,只有调用后,接口才开始工作
96 | virtual void Init() = 0;
97 |
98 | /// 等待接口线程结束运行
99 | ///@return 线程退出代码
100 | virtual int Join() = 0;
101 |
102 | /// 获取当前交易日
103 | ///@retrun 获取到的交易日
104 | ///@remark 只有登录成功后,才能得到正确的交易日
105 | virtual const char* GetTradingDay() = 0;
106 |
107 | /// 注册前置机网络地址
108 | ///@param pszFrontAddress:前置机网络地址。
109 | ///@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:17001”。
110 | ///@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”17001”代表服务器端口号。
111 | virtual void RegisterFront(char* pszFrontAddress) = 0;
112 |
113 | /// 注册名字服务器网络地址
114 | ///@param pszNsAddress:名字服务器网络地址。
115 | ///@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:12001”。
116 | ///@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”12001”代表服务器端口号。
117 | ///@remark RegisterNameServer优先于RegisterFront
118 | virtual void RegisterNameServer(char* pszNsAddress) = 0;
119 |
120 | /// 注册名字服务器用户信息
121 | ///@param pFensUserInfo:用户信息。
122 | virtual void RegisterFensUserInfo(CThostFtdcFensUserInfoField* pFensUserInfo) = 0;
123 |
124 | /// 注册回调接口
125 | ///@param pSpi 派生自回调接口类的实例
126 | virtual void RegisterSpi(CThostFtdcMdSpi* pSpi) = 0;
127 |
128 | /// 订阅行情。
129 | ///@param ppInstrumentID 合约ID
130 | ///@param nCount 要订阅/退订行情的合约个数
131 | ///@remark
132 | virtual int SubscribeMarketData(char* ppInstrumentID[], int nCount) = 0;
133 |
134 | /// 退订行情。
135 | ///@param ppInstrumentID 合约ID
136 | ///@param nCount 要订阅/退订行情的合约个数
137 | ///@remark
138 | virtual int UnSubscribeMarketData(char* ppInstrumentID[], int nCount) = 0;
139 |
140 | /// 订阅询价。
141 | ///@param ppInstrumentID 合约ID
142 | ///@param nCount 要订阅/退订行情的合约个数
143 | ///@remark
144 | virtual int SubscribeForQuoteRsp(char* ppInstrumentID[], int nCount) = 0;
145 |
146 | /// 退订询价。
147 | ///@param ppInstrumentID 合约ID
148 | ///@param nCount 要订阅/退订行情的合约个数
149 | ///@remark
150 | virtual int UnSubscribeForQuoteRsp(char* ppInstrumentID[], int nCount) = 0;
151 |
152 | /// 用户登录请求
153 | virtual int ReqUserLogin(CThostFtdcReqUserLoginField* pReqUserLoginField, int nRequestID) = 0;
154 |
155 | /// 登出请求
156 | virtual int ReqUserLogout(CThostFtdcUserLogoutField* pUserLogout, int nRequestID) = 0;
157 |
158 | /// 请求查询组播合约
159 | virtual int ReqQryMulticastInstrument(CThostFtdcQryMulticastInstrumentField* pQryMulticastInstrument, int nRequestID) = 0;
160 |
161 | protected:
162 | ~CThostFtdcMdApi() {};
163 | };
164 |
165 | #endif
166 |
--------------------------------------------------------------------------------
/api/v6.6.9_20220914_api_tradeapi_se_linux64/error.dtd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
--------------------------------------------------------------------------------
/api/v6.6.9_20220914_api_tradeapi_se_linux64/error.xml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pseudocodes/goctp/2ae201aa1a16a49c99d07207396b0d931a5554c2/api/v6.6.9_20220914_api_tradeapi_se_linux64/error.xml
--------------------------------------------------------------------------------
/api/v6.6.9_20220914_api_tradeapi_se_linux64/libthostmduserapi_se.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pseudocodes/goctp/2ae201aa1a16a49c99d07207396b0d931a5554c2/api/v6.6.9_20220914_api_tradeapi_se_linux64/libthostmduserapi_se.so
--------------------------------------------------------------------------------
/api/v6.6.9_20220914_api_tradeapi_se_linux64/libthosttraderapi_se.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pseudocodes/goctp/2ae201aa1a16a49c99d07207396b0d931a5554c2/api/v6.6.9_20220914_api_tradeapi_se_linux64/libthosttraderapi_se.so
--------------------------------------------------------------------------------
/api/v6.6.9_MacOS_20220926/DataCollect.h:
--------------------------------------------------------------------------------
1 | #ifndef DATA_COLLECT_H
2 | #define DATA_COLLECT_H
3 |
4 | /*
5 | macOS 返回值定义
6 | 返回的int值 不为0 表示采集信息有误 具体哪个采集项有问题需要做如下判断
7 | 从低位开始分别标示 终端信息 -> 设备序列号
8 | 返回值 & (0x01 << 0) 不为0 表示终端类型未采集到
9 | 返回值 & (0x01 << 1) 不为0 表示 信息采集时间获取异常
10 | 返回值 & (0x01 << 2) 不为0 表示ip 获取失败 (采集多个相同类型信息的场景有一个采集到 即表示采集成功)
11 | 返回值 & (0x01 << 3) 不为0 表示mac 获取失败
12 | 返回值 & (0x01 << 4) 不为0 表示 设备名 获取失败
13 | 返回值 & (0x01 << 5) 不为0 表示 操作系统版本 获取失败
14 | 返回值 & (0x01 << 6) 不为0 表示 硬盘序列号 获取失败
15 | 返回值 & (0x01 << 7) 不为0 表示 设备序列号 获取失败
16 | */
17 |
18 | //pSystemInfo的空间需要调用者自己分配 至少270个字节
19 |
20 | int CTP_GetSystemInfo(char* pSystemInfo, int& nLen);
21 | int CTP_GetSystemInfoUnAesEncode(char* pSystemInfo, int& nLen);
22 |
23 |
24 | //版本号格式
25 | //Sfit + 生产还是测试秘钥(pro/tst) + 秘钥版本 + 编译时间 + 版本(内部)
26 |
27 | const char * CTP_GetDataCollectApiVersion(void);
28 |
29 |
30 | #endif
31 |
--------------------------------------------------------------------------------
/api/v6.6.9_MacOS_20220926/ThostFtdcMdApi.h:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////
2 | ///@system 新一代交易所系统
3 | ///@company 上海期货信息技术有限公司
4 | ///@file ThostFtdcMdApi.h
5 | ///@brief 定义了客户端接口
6 | ///@history
7 | /// 20060106 赵鸿昊 创建该文件
8 | /////////////////////////////////////////////////////////////////////////
9 |
10 | #if !defined(THOST_FTDCMDAPI_H)
11 | #define THOST_FTDCMDAPI_H
12 |
13 | #if _MSC_VER > 1000
14 | #pragma once
15 | #endif // _MSC_VER > 1000
16 |
17 | #include "ThostFtdcUserApiStruct.h"
18 |
19 | #if defined(ISLIB) && defined(WIN32)
20 | #ifdef LIB_MD_API_EXPORT
21 | #define MD_API_EXPORT __declspec(dllexport)
22 | #else
23 | #define MD_API_EXPORT __declspec(dllimport)
24 | #endif
25 | #else
26 | #define MD_API_EXPORT
27 | #endif
28 |
29 | class CThostFtdcMdSpi {
30 | public:
31 | /// 当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。
32 | virtual void OnFrontConnected(){};
33 |
34 | /// 当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。
35 | ///@param nReason 错误原因
36 | /// 0x1001 网络读失败
37 | /// 0x1002 网络写失败
38 | /// 0x2001 接收心跳超时
39 | /// 0x2002 发送心跳失败
40 | /// 0x2003 收到错误报文
41 | virtual void OnFrontDisconnected(int nReason){};
42 |
43 | /// 心跳超时警告。当长时间未收到报文时,该方法被调用。
44 | ///@param nTimeLapse 距离上次接收报文的时间
45 | virtual void OnHeartBeatWarning(int nTimeLapse){};
46 |
47 | /// 登录请求响应
48 | virtual void OnRspUserLogin(CThostFtdcRspUserLoginField* pRspUserLogin,
49 | CThostFtdcRspInfoField* pRspInfo,
50 | int nRequestID,
51 | bool bIsLast){};
52 |
53 | /// 登出请求响应
54 | virtual void OnRspUserLogout(CThostFtdcUserLogoutField* pUserLogout,
55 | CThostFtdcRspInfoField* pRspInfo,
56 | int nRequestID,
57 | bool bIsLast){};
58 |
59 | /// 请求查询组播合约响应
60 | virtual void OnRspQryMulticastInstrument(
61 | CThostFtdcMulticastInstrumentField* pMulticastInstrument,
62 | CThostFtdcRspInfoField* pRspInfo,
63 | int nRequestID,
64 | bool bIsLast){};
65 |
66 | /// 错误应答
67 | virtual void OnRspError(CThostFtdcRspInfoField* pRspInfo,
68 | int nRequestID,
69 | bool bIsLast){};
70 |
71 | /// 订阅行情应答
72 | virtual void OnRspSubMarketData(
73 | CThostFtdcSpecificInstrumentField* pSpecificInstrument,
74 | CThostFtdcRspInfoField* pRspInfo,
75 | int nRequestID,
76 | bool bIsLast){};
77 |
78 | /// 取消订阅行情应答
79 | virtual void OnRspUnSubMarketData(
80 | CThostFtdcSpecificInstrumentField* pSpecificInstrument,
81 | CThostFtdcRspInfoField* pRspInfo,
82 | int nRequestID,
83 | bool bIsLast){};
84 |
85 | /// 订阅询价应答
86 | virtual void OnRspSubForQuoteRsp(
87 | CThostFtdcSpecificInstrumentField* pSpecificInstrument,
88 | CThostFtdcRspInfoField* pRspInfo,
89 | int nRequestID,
90 | bool bIsLast){};
91 |
92 | /// 取消订阅询价应答
93 | virtual void OnRspUnSubForQuoteRsp(
94 | CThostFtdcSpecificInstrumentField* pSpecificInstrument,
95 | CThostFtdcRspInfoField* pRspInfo,
96 | int nRequestID,
97 | bool bIsLast){};
98 |
99 | /// 深度行情通知
100 | virtual void OnRtnDepthMarketData(
101 | CThostFtdcDepthMarketDataField* pDepthMarketData){};
102 |
103 | /// 询价通知
104 | virtual void OnRtnForQuoteRsp(CThostFtdcForQuoteRspField* pForQuoteRsp){};
105 | };
106 |
107 | class MD_API_EXPORT CThostFtdcMdApi {
108 | public:
109 | /// 创建MdApi
110 | ///@param pszFlowPath 存贮订阅信息文件的目录,默认为当前目录
111 | ///@return 创建出的UserApi
112 | /// modify for udp marketdata
113 | static CThostFtdcMdApi* CreateFtdcMdApi(const char* pszFlowPath = "",
114 | const bool bIsUsingUdp = false,
115 | const bool bIsMulticast = false);
116 |
117 | /// 获取API的版本信息
118 | ///@retrun 获取到的版本号
119 | static const char* GetApiVersion();
120 |
121 | /// 删除接口对象本身
122 | ///@remark 不再使用本接口对象时,调用该函数删除接口对象
123 | virtual void Release() = 0;
124 |
125 | /// 初始化
126 | ///@remark 初始化运行环境,只有调用后,接口才开始工作
127 | virtual void Init() = 0;
128 |
129 | /// 等待接口线程结束运行
130 | ///@return 线程退出代码
131 | virtual int Join() = 0;
132 |
133 | /// 获取当前交易日
134 | ///@retrun 获取到的交易日
135 | ///@remark 只有登录成功后,才能得到正确的交易日
136 | virtual const char* GetTradingDay() = 0;
137 |
138 | /// 注册前置机网络地址
139 | ///@param pszFrontAddress 前置机网络地址。
140 | ///@remark
141 | ///网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:17001”。
142 | ///@remark
143 | ///“tcp”代表传输协议,“127.0.0.1”代表服务器地址。”17001”代表服务器端口号。
144 | virtual void RegisterFront(char* pszFrontAddress) = 0;
145 |
146 | /// 注册名字服务器网络地址
147 | ///@param pszNsAddress 名字服务器网络地址。
148 | ///@remark
149 | ///网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:12001”。
150 | ///@remark
151 | ///“tcp”代表传输协议,“127.0.0.1”代表服务器地址。”12001”代表服务器端口号。
152 | ///@remark RegisterNameServer优先于RegisterFront
153 | virtual void RegisterNameServer(char* pszNsAddress) = 0;
154 |
155 | /// 注册名字服务器用户信息
156 | ///@param pFensUserInfo 用户信息。
157 | virtual void RegisterFensUserInfo(
158 | CThostFtdcFensUserInfoField* pFensUserInfo) = 0;
159 |
160 | /// 注册回调接口
161 | ///@param pSpi 派生自回调接口类的实例
162 | virtual void RegisterSpi(CThostFtdcMdSpi* pSpi) = 0;
163 |
164 | /// 订阅行情。
165 | ///@param ppInstrumentID 合约ID
166 | ///@param nCount 要订阅/退订行情的合约个数
167 | virtual int SubscribeMarketData(char* ppInstrumentID[], int nCount) = 0;
168 |
169 | /// 退订行情。
170 | ///@param ppInstrumentID 合约ID
171 | ///@param nCount 要订阅/退订行情的合约个数
172 | virtual int UnSubscribeMarketData(char* ppInstrumentID[], int nCount) = 0;
173 |
174 | /// 订阅询价。
175 | ///@param ppInstrumentID 合约ID
176 | ///@param nCount 要订阅/退订行情的合约个数
177 | virtual int SubscribeForQuoteRsp(char* ppInstrumentID[], int nCount) = 0;
178 |
179 | /// 退订询价。
180 | ///@param ppInstrumentID 合约ID
181 | ///@param nCount 要订阅/退订行情的合约个数
182 | virtual int UnSubscribeForQuoteRsp(char* ppInstrumentID[], int nCount) = 0;
183 |
184 | /// 用户登录请求
185 | virtual int ReqUserLogin(CThostFtdcReqUserLoginField* pReqUserLoginField,
186 | int nRequestID) = 0;
187 |
188 | /// 登出请求
189 | virtual int ReqUserLogout(CThostFtdcUserLogoutField* pUserLogout,
190 | int nRequestID) = 0;
191 |
192 | /// 请求查询组播合约
193 | virtual int ReqQryMulticastInstrument(
194 | CThostFtdcQryMulticastInstrumentField* pQryMulticastInstrument,
195 | int nRequestID) = 0;
196 |
197 | protected:
198 | ~CThostFtdcMdApi(){};
199 | };
200 |
201 | #endif
202 |
--------------------------------------------------------------------------------
/api/v6.6.9_MacOS_20220926/libMacDataCollect.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pseudocodes/goctp/2ae201aa1a16a49c99d07207396b0d931a5554c2/api/v6.6.9_MacOS_20220926/libMacDataCollect.a
--------------------------------------------------------------------------------
/api/v6.6.9_MacOS_20220926/libcomunicationkey.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pseudocodes/goctp/2ae201aa1a16a49c99d07207396b0d931a5554c2/api/v6.6.9_MacOS_20220926/libcomunicationkey.a
--------------------------------------------------------------------------------
/api/v6.6.9_MacOS_20220926/libcrypto.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pseudocodes/goctp/2ae201aa1a16a49c99d07207396b0d931a5554c2/api/v6.6.9_MacOS_20220926/libcrypto.a
--------------------------------------------------------------------------------
/api/v6.6.9_MacOS_20220926/libssl.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pseudocodes/goctp/2ae201aa1a16a49c99d07207396b0d931a5554c2/api/v6.6.9_MacOS_20220926/libssl.a
--------------------------------------------------------------------------------
/api/v6.6.9_MacOS_20220926/libthostmduserapi_se.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pseudocodes/goctp/2ae201aa1a16a49c99d07207396b0d931a5554c2/api/v6.6.9_MacOS_20220926/libthostmduserapi_se.a
--------------------------------------------------------------------------------
/api/v6.6.9_MacOS_20220926/libthosttraderapi_se.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pseudocodes/goctp/2ae201aa1a16a49c99d07207396b0d931a5554c2/api/v6.6.9_MacOS_20220926/libthosttraderapi_se.a
--------------------------------------------------------------------------------
/api/v6.7.0_20230209_api_traderapi_se_linux64/DataCollect.h:
--------------------------------------------------------------------------------
1 | #ifndef DATA_COLLECT_H
2 | #define DATA_COLLECT_H
3 |
4 | #define DLL_EXPORT __declspec(dllexport)
5 |
6 | #if defined(IS_WINCOLLECT_LIB) && defined(WIN32)
7 | #ifdef LIB_DATA_COLLECT_API_EXPORT
8 | #define DATA_COLLECT_API_EXPORT __declspec(dllexport)
9 | #else
10 | #define DATA_COLLECT_API_EXPORT __declspec(dllimport)
11 | #endif
12 | #else
13 | #define DATA_COLLECT_API_EXPORT
14 | #endif
15 |
16 | /// 获取AES加密和RSA加密的终端信息 pSystemInfo的空间需要调用者自己分配 至少270个字节
17 | /// windows返回值定义
18 | /* 返回的int值 不为0 表示采集信息有误 具体哪个采集项有问题需要做如下判断
19 | 从低位开始分别标示 终端信息 ->系统盘分区信息
20 | 返回值 & (0x01 << 0) 不为0 表示终端类型未采集到
21 | 返回值 & (0x01 << 1) 不为0 表示 信息采集时间获取异常
22 | 返回值 & (0x01 << 2) 不为0 表示ip 获取失败 (采集多个相同类型信息的场景有一个采集到 即表示采集成功)
23 | 返回值 & (0x01 << 3) 不为0 表示mac 获取失败
24 | 返回值 & (0x01 << 4) 不为0 表示 设备名 获取失败
25 | 返回值 & (0x01 << 5) 不为0 表示 操作系统版本 获取失败
26 | 返回值 & (0x01 << 6) 不为0 表示 硬盘序列号 获取失败
27 | 返回值 & (0x01 << 7) 不为0 表示 CPU序列号 获取失败
28 | 返回值 & (0x01 << 8) 不为0 表示 BIOS 获取失败
29 | 返回值 & (0x01 << 9) 不为0 表示 系统盘分区信息 获取失败
30 | */
31 |
32 | /// linux返回值定义
33 | /* 返回的int值 不为0 表示采集信息有误 具体哪个采集项有问题需要做如下判断
34 | 从低位开始分别标示 终端信息 -> BIOS信息
35 | 返回值 & (0x01 << 0) 不为0 表示终端类型未采集到
36 | 返回值 & (0x01 << 1) 不为0 表示 信息采集时间获取异常
37 | 返回值 & (0x01 << 2) 不为0 表示ip 获取失败 (采集多个相同类型信息的场景有一个采集到 即表示采集成功)
38 | 返回值 & (0x01 << 3) 不为0 表示mac 获取失败
39 | 返回值 & (0x01 << 4) 不为0 表示 设备名 获取失败
40 | 返回值 & (0x01 << 5) 不为0 表示 操作系统版本 获取失败
41 | 返回值 & (0x01 << 6) 不为0 表示 硬盘序列号 获取失败
42 | 返回值 & (0x01 << 7) 不为0 表示 CPU序列号 获取失败
43 | 返回值 & (0x01 << 8) 不为0 表示 BIOS 获取失败
44 | */
45 |
46 | DATA_COLLECT_API_EXPORT int CTP_GetSystemInfo(char* pSystemInfo, int& nLen);
47 |
48 | // 版本号格式
49 | // Sfit + 生产还是测试秘钥(pro/tst) + 秘钥版本 + 编译时间 + 版本(内部)
50 |
51 | DATA_COLLECT_API_EXPORT const char* CTP_GetDataCollectApiVersion(void);
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/api/v6.7.0_20230209_api_traderapi_se_linux64/ThostFtdcMdApi.h:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////
2 | ///@system 新一代交易所系统
3 | ///@company 上海期货信息技术有限公司
4 | ///@file ThostFtdcMdApi.h
5 | ///@brief 定义了客户端接口
6 | ///@history
7 | /// 20060106 赵鸿昊 创建该文件
8 | /////////////////////////////////////////////////////////////////////////
9 |
10 | #if !defined(THOST_FTDCMDAPI_H)
11 | #define THOST_FTDCMDAPI_H
12 |
13 | #if _MSC_VER > 1000
14 | #pragma once
15 | #endif // _MSC_VER > 1000
16 |
17 | #include "ThostFtdcUserApiStruct.h"
18 |
19 | #if defined(ISLIB) && defined(WIN32)
20 | #ifdef LIB_MD_API_EXPORT
21 | #define MD_API_EXPORT __declspec(dllexport)
22 | #else
23 | #define MD_API_EXPORT __declspec(dllimport)
24 | #endif
25 | #else
26 | #define MD_API_EXPORT
27 | #endif
28 |
29 | class CThostFtdcMdSpi {
30 | public:
31 | /// 当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。
32 | virtual void OnFrontConnected() {};
33 |
34 | /// 当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。
35 | ///@param nReason 错误原因
36 | /// 0x1001 网络读失败
37 | /// 0x1002 网络写失败
38 | /// 0x2001 接收心跳超时
39 | /// 0x2002 发送心跳失败
40 | /// 0x2003 收到错误报文
41 | virtual void OnFrontDisconnected(int nReason) {};
42 |
43 | /// 心跳超时警告。当长时间未收到报文时,该方法被调用。
44 | ///@param nTimeLapse 距离上次接收报文的时间
45 | virtual void OnHeartBeatWarning(int nTimeLapse) {};
46 |
47 | /// 登录请求响应
48 | virtual void OnRspUserLogin(CThostFtdcRspUserLoginField* pRspUserLogin, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {};
49 |
50 | /// 登出请求响应
51 | virtual void OnRspUserLogout(CThostFtdcUserLogoutField* pUserLogout, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {};
52 |
53 | /// 请求查询组播合约响应
54 | virtual void OnRspQryMulticastInstrument(CThostFtdcMulticastInstrumentField* pMulticastInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {};
55 |
56 | /// 错误应答
57 | virtual void OnRspError(CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {};
58 |
59 | /// 订阅行情应答
60 | virtual void OnRspSubMarketData(CThostFtdcSpecificInstrumentField* pSpecificInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {};
61 |
62 | /// 取消订阅行情应答
63 | virtual void OnRspUnSubMarketData(CThostFtdcSpecificInstrumentField* pSpecificInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {};
64 |
65 | /// 订阅询价应答
66 | virtual void OnRspSubForQuoteRsp(CThostFtdcSpecificInstrumentField* pSpecificInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {};
67 |
68 | /// 取消订阅询价应答
69 | virtual void OnRspUnSubForQuoteRsp(CThostFtdcSpecificInstrumentField* pSpecificInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast) {};
70 |
71 | /// 深度行情通知
72 | virtual void OnRtnDepthMarketData(CThostFtdcDepthMarketDataField* pDepthMarketData) {};
73 |
74 | /// 询价通知
75 | virtual void OnRtnForQuoteRsp(CThostFtdcForQuoteRspField* pForQuoteRsp) {};
76 | };
77 |
78 | class MD_API_EXPORT CThostFtdcMdApi {
79 | public:
80 | /// 创建MdApi
81 | ///@param pszFlowPath 存贮订阅信息文件的目录,默认为当前目录
82 | ///@return 创建出的UserApi
83 | /// modify for udp marketdata
84 | static CThostFtdcMdApi* CreateFtdcMdApi(const char* pszFlowPath = "", const bool bIsUsingUdp = false, const bool bIsMulticast = false);
85 |
86 | /// 获取API的版本信息
87 | ///@retrun 获取到的版本号
88 | static const char* GetApiVersion();
89 |
90 | /// 删除接口对象本身
91 | ///@remark 不再使用本接口对象时,调用该函数删除接口对象
92 | virtual void Release() = 0;
93 |
94 | /// 初始化
95 | ///@remark 初始化运行环境,只有调用后,接口才开始工作
96 | virtual void Init() = 0;
97 |
98 | /// 等待接口线程结束运行
99 | ///@return 线程退出代码
100 | virtual int Join() = 0;
101 |
102 | /// 获取当前交易日
103 | ///@retrun 获取到的交易日
104 | ///@remark 只有登录成功后,才能得到正确的交易日
105 | virtual const char* GetTradingDay() = 0;
106 |
107 | /// 注册前置机网络地址
108 | ///@param pszFrontAddress:前置机网络地址。
109 | ///@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:17001”。
110 | ///@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”17001”代表服务器端口号。
111 | virtual void RegisterFront(char* pszFrontAddress) = 0;
112 |
113 | /// 注册名字服务器网络地址
114 | ///@param pszNsAddress:名字服务器网络地址。
115 | ///@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:12001”。
116 | ///@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”12001”代表服务器端口号。
117 | ///@remark RegisterNameServer优先于RegisterFront
118 | virtual void RegisterNameServer(char* pszNsAddress) = 0;
119 |
120 | /// 注册名字服务器用户信息
121 | ///@param pFensUserInfo:用户信息。
122 | virtual void RegisterFensUserInfo(CThostFtdcFensUserInfoField* pFensUserInfo) = 0;
123 |
124 | /// 注册回调接口
125 | ///@param pSpi 派生自回调接口类的实例
126 | virtual void RegisterSpi(CThostFtdcMdSpi* pSpi) = 0;
127 |
128 | /// 订阅行情。
129 | ///@param ppInstrumentID 合约ID
130 | ///@param nCount 要订阅/退订行情的合约个数
131 | ///@remark
132 | virtual int SubscribeMarketData(char* ppInstrumentID[], int nCount) = 0;
133 |
134 | /// 退订行情。
135 | ///@param ppInstrumentID 合约ID
136 | ///@param nCount 要订阅/退订行情的合约个数
137 | ///@remark
138 | virtual int UnSubscribeMarketData(char* ppInstrumentID[], int nCount) = 0;
139 |
140 | /// 订阅询价。
141 | ///@param ppInstrumentID 合约ID
142 | ///@param nCount 要订阅/退订行情的合约个数
143 | ///@remark
144 | virtual int SubscribeForQuoteRsp(char* ppInstrumentID[], int nCount) = 0;
145 |
146 | /// 退订询价。
147 | ///@param ppInstrumentID 合约ID
148 | ///@param nCount 要订阅/退订行情的合约个数
149 | ///@remark
150 | virtual int UnSubscribeForQuoteRsp(char* ppInstrumentID[], int nCount) = 0;
151 |
152 | /// 用户登录请求
153 | virtual int ReqUserLogin(CThostFtdcReqUserLoginField* pReqUserLoginField, int nRequestID) = 0;
154 |
155 | /// 登出请求
156 | virtual int ReqUserLogout(CThostFtdcUserLogoutField* pUserLogout, int nRequestID) = 0;
157 |
158 | /// 请求查询组播合约
159 | virtual int ReqQryMulticastInstrument(CThostFtdcQryMulticastInstrumentField* pQryMulticastInstrument, int nRequestID) = 0;
160 |
161 | protected:
162 | ~CThostFtdcMdApi() {};
163 | };
164 |
165 | #endif
166 |
--------------------------------------------------------------------------------
/api/v6.7.0_20230209_api_traderapi_se_linux64/error.dtd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
--------------------------------------------------------------------------------
/api/v6.7.0_20230209_api_traderapi_se_linux64/error.xml:
--------------------------------------------------------------------------------
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 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 | ~
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
--------------------------------------------------------------------------------
/api/v6.7.0_20230209_api_traderapi_se_linux64/libLinuxDataCollect.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pseudocodes/goctp/2ae201aa1a16a49c99d07207396b0d931a5554c2/api/v6.7.0_20230209_api_traderapi_se_linux64/libLinuxDataCollect.so
--------------------------------------------------------------------------------
/api/v6.7.0_20230209_api_traderapi_se_linux64/libthostmduserapi_se.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pseudocodes/goctp/2ae201aa1a16a49c99d07207396b0d931a5554c2/api/v6.7.0_20230209_api_traderapi_se_linux64/libthostmduserapi_se.so
--------------------------------------------------------------------------------
/api/v6.7.0_20230209_api_traderapi_se_linux64/libthosttraderapi_se.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pseudocodes/goctp/2ae201aa1a16a49c99d07207396b0d931a5554c2/api/v6.7.0_20230209_api_traderapi_se_linux64/libthosttraderapi_se.so
--------------------------------------------------------------------------------
/data_collect/data_collect.go:
--------------------------------------------------------------------------------
1 | package dc
2 |
3 | type DataCollectSystemInfo struct {
4 | Length int32
5 | SystemInfo [344]byte
6 | }
7 |
--------------------------------------------------------------------------------
/data_collect/data_collect_darwin.go:
--------------------------------------------------------------------------------
1 | //go:build darwin && !linux
2 |
3 | package dc
4 |
5 | /*
6 | #cgo darwin LDFLAGS: -L. -L${SRCDIR}/../api/v6.6.9_MacOS_20220926 -lMacDataCollect -framework Cocoa -framework IOKit
7 | #cgo darwin CPPFLAGS: -I. -I${SRCDIR}/../api/v6.6.9_MacOS_20220926
8 |
9 | #include "data_collect_wrap.h"
10 | */
11 | import "C"
12 | import "unsafe"
13 |
14 | // CTP_GetSystemInfo 中继模式使用方法
15 | func CTP_GetSystemInfo(data *DataCollectSystemInfo) int {
16 | var arg0 = data
17 | r := C.__wrap_ctp_get_system_info((*C.struct_DataCollectSystemInfo)(unsafe.Pointer(arg0)))
18 | return int(r)
19 | }
20 |
21 | // CTP_GetSystemInfoUnAesEncode 直连模式使用方法
22 | func CTP_GetSystemInfoUnAesEncode(data *DataCollectSystemInfo) int {
23 | var arg0 = data
24 | r := C.__wrap_ctp_get_system_info_unaes_encode((*C.struct_DataCollectSystemInfo)(unsafe.Pointer(arg0)))
25 | return int(r)
26 | }
27 |
28 | // 查询采集库版本信息
29 | func CTP_GetDataCollectApiVersion() string {
30 | r := C.__wrap_ctp_get_data_collect_api_version()
31 | result := C.GoString(r)
32 | return result
33 | }
34 |
--------------------------------------------------------------------------------
/data_collect/data_collect_linux.go:
--------------------------------------------------------------------------------
1 | //go:build !darwin && linux
2 |
3 | package dc
4 |
5 | /*
6 | #cgo linux LDFLAGS: -L. -L${SRCDIR}/../api/v6.7.0_20230209_api_traderapi_se_linux64 -lLinuxDataCollect
7 | #cgo linux CPPFLAGS: -I. -I${SRCDIR}/../api/v6.7.0_20230209_api_traderapi_se_linux64
8 |
9 | #include "data_collect_wrap.h"
10 | */
11 | import "C"
12 | import "unsafe"
13 |
14 | // CTP_GetSystemInfo 中继模式使用方法
15 | func CTP_GetSystemInfo(data *DataCollectSystemInfo) int {
16 | var arg0 = data
17 | r := C.__wrap_ctp_get_system_info((*C.struct_DataCollectSystemInfo)(unsafe.Pointer(arg0)))
18 | return int(r)
19 | }
20 |
21 | // CTP_GetSystemInfoUnAesEncode 直连模式使用方法
22 | func CTP_GetSystemInfoUnAesEncode(data *DataCollectSystemInfo) int {
23 | var arg0 = data
24 | r := C.__wrap_ctp_get_system_info_unaes_encode((*C.struct_DataCollectSystemInfo)(unsafe.Pointer(arg0)))
25 | return int(r)
26 | }
27 |
28 | // 查询采集库版本信息
29 | func CTP_GetDataCollectApiVersion() string {
30 | r := C.__wrap_ctp_get_data_collect_api_version()
31 | result := C.GoString(r)
32 | return result
33 | }
34 |
--------------------------------------------------------------------------------
/data_collect/data_collect_wrap.cxx:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include "data_collect_wrap.h"
6 |
7 | #include "DataCollect.h"
8 |
9 | int __wrap_ctp_get_system_info(DataCollectSystemInfo* pSystemInfo)
10 | {
11 | char buffer[273];
12 | int nLen = 0;
13 | memset(buffer, 0, sizeof(buffer));
14 | int ret = CTP_GetSystemInfo(buffer, nLen);
15 | pSystemInfo->Length = nLen;
16 | memcpy(pSystemInfo->SystemInfo, buffer, nLen);
17 | return ret;
18 | }
19 |
20 | int __wrap_ctp_get_system_info_unaes_encode(DataCollectSystemInfo* pSystemInfo)
21 | {
22 | char buffer[273];
23 | int nLen = 0;
24 | memset(buffer, 0, sizeof(buffer));
25 | #ifdef __APPLE__
26 | int ret = CTP_GetSystemInfoUnAesEncode(buffer, nLen);
27 | #elif __linux__
28 | int ret = CTP_GetSystemInfo(buffer, nLen);
29 | #endif
30 | pSystemInfo->Length = nLen;
31 | memcpy(pSystemInfo->SystemInfo, buffer, nLen);
32 | return ret;
33 | }
34 |
35 | const char* __wrap_ctp_get_data_collect_api_version(void)
36 | {
37 | return CTP_GetDataCollectApiVersion();
38 | }
--------------------------------------------------------------------------------
/data_collect/data_collect_wrap.h:
--------------------------------------------------------------------------------
1 | #ifndef _DATA_COLLECT_WRAP_H_
2 | #define _DATA_COLLECT_WRAP_H_
3 |
4 | struct DataCollectSystemInfo {
5 | int Length;
6 | char SystemInfo[344];
7 | };
8 |
9 | #ifdef __cplusplus
10 | extern "C" {
11 | #endif
12 | int __wrap_ctp_get_system_info(struct DataCollectSystemInfo* pSystemInfo);
13 |
14 | int __wrap_ctp_get_system_info_unaes_encode(struct DataCollectSystemInfo* pSystemInfo);
15 |
16 | const char* __wrap_ctp_get_data_collect_api_version(void);
17 |
18 | #ifdef __cplusplus
19 | }
20 | #endif
21 |
22 | #endif
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/pseudocodes/goctp
2 |
3 | go 1.20
4 |
5 | require (
6 | github.com/gookit/goutil v0.6.7
7 | golang.org/x/text v0.8.0
8 | )
9 |
10 | require (
11 | github.com/gookit/color v1.5.2 // indirect
12 | github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
13 | golang.org/x/sys v0.6.0 // indirect
14 | )
15 |
--------------------------------------------------------------------------------
/go.sum:
--------------------------------------------------------------------------------
1 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3 | github.com/gookit/color v1.5.2 h1:uLnfXcaFjlrDnQDT+NCBcfhrXqYTx/rcCa6xn01Y8yI=
4 | github.com/gookit/color v1.5.2/go.mod h1:w8h4bGiHeeBpvQVePTutdbERIUf3oJE5lZ8HM0UgXyg=
5 | github.com/gookit/goutil v0.6.7 h1:Sz0y5eslPZ8M2lUhRaSMnwEeX5nb9z7SoCsw0ZbMwe4=
6 | github.com/gookit/goutil v0.6.7/go.mod h1:ti+JpLBGSN83ga6SSZa6uozhntToWSzOPm2z1hvpQSc=
7 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
8 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
9 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
10 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
11 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
12 | github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
13 | github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
14 | github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
15 | golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
16 | golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
17 | golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
18 | golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
19 | golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
20 | golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
21 | golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
22 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
23 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
24 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
25 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
26 |
--------------------------------------------------------------------------------
/libctp.go:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 (the "License");
2 | // you may not use this file except in compliance with the License.
3 | // You may obtain a copy of the License at
4 | //
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 | //
7 | // Unless required by applicable law or agreed to in writing, software
8 | // distributed under the License is distributed on an "AS IS" BASIS,
9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | // See the License for the specific language governing permissions and
11 | // limitations under the License.
12 |
13 | package goctp
14 |
15 | /*
16 | #cgo linux LDFLAGS: -fPIC -L. -L${SRCDIR}/api/v6.6.9_20220914_api_tradeapi_se_linux64 -Wl,-rpath=${SRCDIR}/api/v6.6.9_20220914_api_tradeapi_se_linux64 -lthostmduserapi_se -lthosttraderapi_se -lstdc++
17 | #cgo linux CPPFLAGS: -fPIC -I. -I${SRCDIR}/api/v6.6.9_20220914_api_tradeapi_se_linux64
18 |
19 | #cgo darwin LDFLAGS: -L. -L${SRCDIR}/api/v6.6.9_MacOS_20220926 -lthostmduserapi_se -lthosttraderapi_se -lssl -lcrypto -lcomunicationkey -lMacDataCollect -framework Cocoa -framework IOKit
20 | #cgo darwin CPPFLAGS: -I. -I${SRCDIR}/api/v6.6.9_MacOS_20220926
21 |
22 | */
23 | import "C"
24 |
--------------------------------------------------------------------------------
/mdapi.go:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 (the "License");
2 | // you may not use this file except in compliance with the License.
3 | // You may obtain a copy of the License at
4 | //
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 | //
7 | // Unless required by applicable law or agreed to in writing, software
8 | // distributed under the License is distributed on an "AS IS" BASIS,
9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | // See the License for the specific language governing permissions and
11 | // limitations under the License.
12 |
13 | package goctp
14 |
15 | import "github.com/pseudocodes/goctp/thost"
16 |
17 | type MdSpi interface {
18 |
19 | ///当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。
20 | OnFrontConnected()
21 |
22 | ///当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。
23 | ///@param nReason 错误原因
24 | /// 0x1001 网络读失败
25 | /// 0x1002 网络写失败
26 | /// 0x2001 接收心跳超时
27 | /// 0x2002 发送心跳失败
28 | /// 0x2003 收到错误报文
29 | OnFrontDisconnected(nReason int)
30 |
31 | ///心跳超时警告。当长时间未收到报文时,该方法被调用。
32 | ///@param nTimeLapse 距离上次接收报文的时间
33 | OnHeartBeatWarning(nTimeLapse int)
34 |
35 | ///登录请求响应
36 | OnRspUserLogin(pRspUserLogin *thost.CThostFtdcRspUserLoginField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool)
37 |
38 | ///登出请求响应
39 | OnRspUserLogout(pUserLogout *thost.CThostFtdcUserLogoutField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool)
40 |
41 | ///请求查询组播合约响应
42 | OnRspQryMulticastInstrument(pMulticastInstrument *thost.CThostFtdcMulticastInstrumentField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool)
43 |
44 | ///错误应答
45 | OnRspError(pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool)
46 |
47 | ///订阅行情应答
48 | OnRspSubMarketData(pSpecificInstrument *thost.CThostFtdcSpecificInstrumentField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool)
49 |
50 | ///取消订阅行情应答
51 | OnRspUnSubMarketData(pSpecificInstrument *thost.CThostFtdcSpecificInstrumentField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool)
52 |
53 | ///订阅询价应答
54 | OnRspSubForQuoteRsp(pSpecificInstrument *thost.CThostFtdcSpecificInstrumentField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool)
55 |
56 | ///取消订阅询价应答
57 | OnRspUnSubForQuoteRsp(pSpecificInstrument *thost.CThostFtdcSpecificInstrumentField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool)
58 |
59 | ///深度行情通知
60 | OnRtnDepthMarketData(pDepthMarketData *thost.CThostFtdcDepthMarketDataField)
61 |
62 | ///询价通知
63 | OnRtnForQuoteRsp(pForQuoteRsp *thost.CThostFtdcForQuoteRspField)
64 | }
65 |
66 | type MdApi interface {
67 |
68 | ///获取API的版本信息
69 | ///@retrun 获取到的版本号
70 | GetApiVersion() string
71 |
72 | ///删除接口对象本身
73 | ///@remark 不再使用本接口对象时,调用该函数删除接口对象
74 | Release()
75 |
76 | ///初始化
77 | ///@remark 初始化运行环境,只有调用后,接口才开始工作
78 | Init()
79 |
80 | ///等待接口线程结束运行
81 | ///@return 线程退出代码
82 | Join() int
83 |
84 | ///获取当前交易日
85 | ///@retrun 获取到的交易日
86 | ///@remark 只有登录成功后,才能得到正确的交易日
87 | GetTradingDay() string
88 |
89 | ///注册前置机网络地址
90 | ///@param pszFrontAddress:前置机网络地址。
91 | ///@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:17001”。
92 | ///@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”17001”代表服务器端口号。
93 | RegisterFront(frontAddress string)
94 |
95 | ///注册名字服务器网络地址
96 | ///@param pszNsAddress:名字服务器网络地址。
97 | ///@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:12001”。
98 | ///@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”12001”代表服务器端口号。
99 | ///@remark RegisterNameServer优先于RegisterFront
100 | RegisterNameServer(nsAddress string)
101 |
102 | ///注册名字服务器用户信息
103 | ///@param pFensUserInfo:用户信息。
104 | RegisterFensUserInfo(pFensUserInfo *thost.CThostFtdcFensUserInfoField)
105 |
106 | ///注册回调接口
107 | ///@param pSpi 派生自回调接口类的实例
108 | RegisterSpi(pSpi MdSpi)
109 |
110 | ///订阅行情。
111 | ///@param ppInstrumentID 合约ID
112 | ///@param nCount 要订阅/退订行情的合约个数
113 | ///@remark
114 | SubscribeMarketData(instrumentIDs ...string) int
115 |
116 | ///退订行情。
117 | ///@param ppInstrumentID 合约ID
118 | ///@param nCount 要订阅/退订行情的合约个数
119 | ///@remark
120 | UnSubscribeMarketData(instrumentIDs ...string) int
121 |
122 | ///订阅询价。
123 | ///@param ppInstrumentID 合约ID
124 | ///@param nCount 要订阅/退订行情的合约个数
125 | ///@remark
126 | SubscribeForQuoteRsp(instrumentIDs ...string) int
127 |
128 | ///退订询价。
129 | ///@param ppInstrumentID 合约ID
130 | ///@param nCount 要订阅/退订行情的合约个数
131 | ///@remark
132 | UnSubscribeForQuoteRsp(instrumentIDs ...string) int
133 |
134 | ///用户登录请求
135 | ReqUserLogin(pReqUserLoginField *thost.CThostFtdcReqUserLoginField, nRequestID int) int
136 |
137 | ///登出请求
138 | ReqUserLogout(pUserLogout *thost.CThostFtdcUserLogoutField, nRequestID int) int
139 |
140 | ///请求查询组播合约
141 | ReqQryMulticastInstrument(pQryMulticastInstrument *thost.CThostFtdcQryMulticastInstrumentField, nRequestID int) int
142 | }
143 |
--------------------------------------------------------------------------------
/mdapi_impl.go:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 (the "License");
2 | // you may not use this file except in compliance with the License.
3 | // You may obtain a copy of the License at
4 | //
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 | //
7 | // Unless required by applicable law or agreed to in writing, software
8 | // distributed under the License is distributed on an "AS IS" BASIS,
9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | // See the License for the specific language governing permissions and
11 | // limitations under the License.
12 |
13 | package goctp
14 |
15 | /*
16 | #include
17 | #include
18 |
19 | #include "ThostFtdcUserApiDataType.h"
20 | #include "ThostFtdcUserApiStruct.h"
21 |
22 | // typedef long long intgo;
23 |
24 | typedef struct { char *p; int64_t n; } _gostring_;
25 | typedef struct { void* array; int64_t len; int64_t cap; } _goslice_;
26 |
27 | extern uintptr_t _wrap_CThostFtdcMdApi_CreateFtdcMdApi();
28 | extern uintptr_t _wrap_CThostFtdcMdApi_CreateFtdcMdApi2(uintptr_t goUserApi, char*, _Bool, _Bool);
29 |
30 |
31 | extern const char * _wrap_CThostFtdcMdApi_GetApiVersion(uintptr_t);
32 |
33 | extern void _wrap_CThostFtdcMdApi_Release(uintptr_t);
34 |
35 | extern void _wrap_CThostFtdcMdApi_Init(uintptr_t);
36 |
37 | extern int64_t _wrap_CThostFtdcMdApi_Join(uintptr_t);
38 |
39 | extern const char * _wrap_CThostFtdcMdApi_GetTradingDay(uintptr_t);
40 |
41 | extern void _wrap_CThostFtdcMdApi_RegisterFront(uintptr_t, char *);
42 |
43 | extern void _wrap_CThostFtdcMdApi_RegisterNameServer(uintptr_t, char *);
44 |
45 | extern void _wrap_CThostFtdcMdApi_RegisterFensUserInfo(uintptr_t, struct CThostFtdcFensUserInfoField *);
46 |
47 | extern int64_t _wrap_CThostFtdcMdApi_SubscribeMarketData(uintptr_t, char **, int);
48 |
49 | extern int64_t _wrap_CThostFtdcMdApi_UnSubscribeMarketData(uintptr_t, char **, int);
50 |
51 | extern int64_t _wrap_CThostFtdcMdApi_SubscribeForQuoteRsp(uintptr_t, char **, int);
52 |
53 | extern int64_t _wrap_CThostFtdcMdApi_UnSubscribeForQuoteRsp(uintptr_t, char **, int);
54 |
55 | extern int64_t _wrap_CThostFtdcMdApi_ReqUserLogin(uintptr_t, struct CThostFtdcReqUserLoginField *, int);
56 |
57 | extern int64_t _wrap_CThostFtdcMdApi_ReqUserLogout(uintptr_t, struct CThostFtdcUserLogoutField *, int);
58 |
59 | extern int64_t _wrap_CThostFtdcMdApi_ReqQryMulticastInstrument(uintptr_t, struct CThostFtdcQryMulticastInstrumentField *, int);
60 |
61 | */
62 | import "C"
63 | import (
64 | "os"
65 | "runtime/cgo"
66 | "unsafe"
67 |
68 | "github.com/pseudocodes/goctp/thost"
69 | )
70 |
71 | const (
72 | defaultFlowPath = ""
73 | defaultIsUsingUdp = false
74 | defaultIsMulticast = false
75 | )
76 |
77 | type MdOption func(api *mdApi)
78 |
79 | type mdApi struct {
80 | apiPtr uintptr
81 | spi MdSpi
82 |
83 | flowPath string
84 | usingUDP bool
85 | multicast bool
86 | }
87 |
88 | func CreateMdApi(options ...MdOption) *mdApi {
89 | api := &mdApi{
90 | flowPath: defaultFlowPath,
91 | usingUDP: defaultIsUsingUdp,
92 | multicast: defaultIsMulticast,
93 | }
94 | handle := cgo.NewHandle(api)
95 | for _, opt := range options {
96 | opt(api)
97 | }
98 | if api.flowPath != "" {
99 | if err := os.MkdirAll(api.flowPath, os.ModePerm); err != nil && !os.IsExist(err) {
100 | panic(err)
101 | }
102 | }
103 | cflowPath := C.CString(api.flowPath)
104 | defer C.free(unsafe.Pointer(cflowPath))
105 |
106 | api.apiPtr = uintptr(C._wrap_CThostFtdcMdApi_CreateFtdcMdApi2(C.uintptr_t(handle), cflowPath, C._Bool(api.usingUDP), C._Bool(api.multicast)))
107 |
108 | return api
109 | }
110 |
111 | // /获取API的版本信息
112 | // /@retrun 获取到的版本号
113 | func (c *mdApi) GetApiVersion() string {
114 | cString := C._wrap_CThostFtdcMdApi_GetApiVersion(C.uintptr_t(c.apiPtr))
115 | return C.GoString(cString)
116 | }
117 |
118 | // 删除接口对象本身
119 | // /@remark 不再使用本接口对象时,调用该函数删除接口对象
120 | func (c *mdApi) Release() {
121 | C._wrap_CThostFtdcMdApi_Release(C.uintptr_t(c.apiPtr))
122 | }
123 |
124 | // 初始化
125 | // /@remark 初始化运行环境,只有调用后,接口才开始工作
126 | func (c *mdApi) Init() {
127 | C._wrap_CThostFtdcMdApi_Init(C.uintptr_t(c.apiPtr))
128 | }
129 |
130 | // 等待接口线程结束运行
131 | // /@return 线程退出代码
132 | func (c *mdApi) Join() int {
133 | return (int)(C._wrap_CThostFtdcMdApi_Join(C.uintptr_t(c.apiPtr)))
134 | }
135 |
136 | // /获取当前交易日
137 | // /@retrun 获取到的交易日
138 | // /@remark 只有登录成功后,才能得到正确的交易日
139 | func (c *mdApi) GetTradingDay() string {
140 | cString := C._wrap_CThostFtdcMdApi_GetTradingDay(C.uintptr_t(c.apiPtr))
141 | return C.GoString(cString)
142 | }
143 |
144 | func (c *mdApi) RegisterFront(frontAddress string) {
145 | addr := C.CString(frontAddress)
146 | defer C.free(unsafe.Pointer(addr))
147 | C._wrap_CThostFtdcMdApi_RegisterFront(C.uintptr_t(c.apiPtr), addr)
148 | }
149 |
150 | // 注册名字服务器用户信息
151 | func (c *mdApi) RegisterNameServer(nsAddress string) {
152 | addr := C.CString(nsAddress)
153 | defer C.free(unsafe.Pointer(addr))
154 | C._wrap_CThostFtdcMdApi_RegisterNameServer(C.uintptr_t(c.apiPtr), addr)
155 | }
156 |
157 | // /@param pFensUserInfo:用户信息。
158 | func (c *mdApi) RegisterFensUserInfo(pFensUserInfo *thost.CThostFtdcFensUserInfoField) {
159 | C._wrap_CThostFtdcMdApi_RegisterFensUserInfo(C.uintptr_t(c.apiPtr), (*C.struct_CThostFtdcFensUserInfoField)(unsafe.Pointer(pFensUserInfo)))
160 | }
161 |
162 | // 注册回调接口
163 | // /@param pSpi 派生自回调接口类的实例
164 | func (c *mdApi) RegisterSpi(pSpi MdSpi) {
165 | c.spi = pSpi
166 | }
167 |
168 | // /订阅行情。
169 | // /@param ppInstrumentID 合约ID
170 | // /@param nCount 要订阅/退订行情的合约个数
171 | // /@remark
172 | func (c *mdApi) SubscribeMarketData(instrumentIDs ...string) int {
173 | cinlist := []*C.char{}
174 | for _, ins := range instrumentIDs {
175 | cinlist = append(cinlist, C.CString(ins))
176 | }
177 | defer func() {
178 | for i := range cinlist {
179 | C.free(unsafe.Pointer(cinlist[i]))
180 | }
181 | }()
182 |
183 | return (int)(C._wrap_CThostFtdcMdApi_SubscribeMarketData(C.uintptr_t(c.apiPtr), (**C.char)(unsafe.Pointer(&cinlist[0])), C.int(len(cinlist))))
184 | }
185 |
186 | // /退订行情。
187 | // /@param ppInstrumentID 合约ID
188 | // /@param nCount 要订阅/退订行情的合约个数
189 | // /@remark
190 | func (c *mdApi) UnSubscribeMarketData(instrumentIDs ...string) int {
191 | cinlist := []*C.char{}
192 | for _, ins := range instrumentIDs {
193 | cinlist = append(cinlist, C.CString(ins))
194 | }
195 | defer func() {
196 | for i := range cinlist {
197 | C.free(unsafe.Pointer(cinlist[i]))
198 | }
199 | }()
200 |
201 | return (int)(C._wrap_CThostFtdcMdApi_UnSubscribeMarketData(C.uintptr_t(c.apiPtr), (**C.char)(unsafe.Pointer(&cinlist[0])), C.int(len(cinlist))))
202 | }
203 |
204 | // /订阅询价。
205 | // /@param ppInstrumentID 合约ID
206 | // /@param nCount 要订阅/退订行情的合约个数
207 | // /@remark
208 | func (c *mdApi) SubscribeForQuoteRsp(instrumentIDs ...string) int {
209 | cinlist := []*C.char{}
210 | for _, ins := range instrumentIDs {
211 | cinlist = append(cinlist, C.CString(ins))
212 | }
213 | defer func() {
214 | for i := range cinlist {
215 | C.free(unsafe.Pointer(cinlist[i]))
216 | }
217 | }()
218 |
219 | return (int)(C._wrap_CThostFtdcMdApi_SubscribeForQuoteRsp(C.uintptr_t(c.apiPtr), (**C.char)(unsafe.Pointer(&cinlist[0])), C.int(len(cinlist))))
220 | }
221 |
222 | // /退订询价。
223 | // /@param ppInstrumentID 合约ID
224 | // /@param nCount 要订阅/退订行情的合约个数
225 | // /@remark
226 | func (c *mdApi) UnSubscribeForQuoteRsp(instrumentIDs ...string) int {
227 | cinlist := []*C.char{}
228 | for _, ins := range instrumentIDs {
229 | cinlist = append(cinlist, C.CString(ins))
230 | }
231 | defer func() {
232 | for i := range cinlist {
233 | C.free(unsafe.Pointer(cinlist[i]))
234 | }
235 | }()
236 |
237 | return (int)(C._wrap_CThostFtdcMdApi_UnSubscribeForQuoteRsp(C.uintptr_t(c.apiPtr), (**C.char)(unsafe.Pointer(&cinlist[0])), C.int(len(cinlist))))
238 | }
239 |
240 | // 用户登录请求
241 | func (c *mdApi) ReqUserLogin(pReqUserLoginField *thost.CThostFtdcReqUserLoginField, nRequestID int) int {
242 | return (int)(C._wrap_CThostFtdcMdApi_ReqUserLogin(C.uintptr_t(c.apiPtr), (*C.struct_CThostFtdcReqUserLoginField)(unsafe.Pointer(pReqUserLoginField)), C.int(nRequestID)))
243 | }
244 |
245 | // 登出请求
246 | func (c *mdApi) ReqUserLogout(pUserLogout *thost.CThostFtdcUserLogoutField, nRequestID int) int {
247 | return (int)(C._wrap_CThostFtdcMdApi_ReqUserLogout(C.uintptr_t(c.apiPtr), (*C.struct_CThostFtdcUserLogoutField)(unsafe.Pointer(pUserLogout)), C.int(nRequestID)))
248 | }
249 |
250 | // 请求查询组播合约
251 | func (c *mdApi) ReqQryMulticastInstrument(pQryMulticastInstrument *thost.CThostFtdcQryMulticastInstrumentField, nRequestID int) int {
252 | return (int)(C._wrap_CThostFtdcMdApi_ReqQryMulticastInstrument(C.uintptr_t(c.apiPtr), (*C.struct_CThostFtdcQryMulticastInstrumentField)(unsafe.Pointer(pQryMulticastInstrument)), C.int(nRequestID)))
253 | }
254 |
255 | //export wrapMdOnFrontConnected
256 | func wrapMdOnFrontConnected(v uintptr) {
257 | api := cgo.Handle(v).Value().(*mdApi)
258 | api.spi.OnFrontConnected()
259 | }
260 |
261 | //export wrapMdOnFrontDisconnected
262 | func wrapMdOnFrontDisconnected(v uintptr, nReason C.int) {
263 | api := cgo.Handle(v).Value().(*mdApi)
264 | api.spi.OnFrontDisconnected(int(nReason))
265 | }
266 |
267 | //export wrapMdOnHeartBeatWarning
268 | func wrapMdOnHeartBeatWarning(v uintptr, nTimeLapse C.int) {
269 | api := cgo.Handle(v).Value().(*mdApi)
270 | api.spi.OnHeartBeatWarning(int(nTimeLapse))
271 | }
272 |
273 | //export wrapMdOnRspUserLogin
274 | func wrapMdOnRspUserLogin(v uintptr, pRspUserLogin *C.struct_CThostFtdcRspUserLoginField, pRspInfo *C.struct_CThostFtdcRspInfoField, nRequestID C.int, bIsLast C._Bool) {
275 | api := cgo.Handle(v).Value().(*mdApi)
276 | api.spi.OnRspUserLogin((*thost.CThostFtdcRspUserLoginField)(unsafe.Pointer(pRspUserLogin)), (*thost.CThostFtdcRspInfoField)(unsafe.Pointer(pRspInfo)), int(nRequestID), bool(bIsLast))
277 | }
278 |
279 | //export wrapMdOnRspUserLogout
280 | func wrapMdOnRspUserLogout(v uintptr, pUserLogout *C.struct_CThostFtdcUserLogoutField, pRspInfo *C.struct_CThostFtdcRspInfoField, nRequestID C.int, bIsLast C._Bool) {
281 | api := cgo.Handle(v).Value().(*mdApi)
282 | api.spi.OnRspUserLogout((*thost.CThostFtdcUserLogoutField)(unsafe.Pointer(pUserLogout)), (*thost.CThostFtdcRspInfoField)(unsafe.Pointer(pRspInfo)), int(nRequestID), bool(bIsLast))
283 | }
284 |
285 | //export wrapMdOnRspQryMulticastInstrument
286 | func wrapMdOnRspQryMulticastInstrument(v uintptr, pMulticastInstrument *C.struct_CThostFtdcMulticastInstrumentField, pRspInfo *C.struct_CThostFtdcRspInfoField, nRequestID C.int, bIsLast C._Bool) {
287 | api := cgo.Handle(v).Value().(*mdApi)
288 | api.spi.OnRspQryMulticastInstrument((*thost.CThostFtdcMulticastInstrumentField)(unsafe.Pointer(pMulticastInstrument)), (*thost.CThostFtdcRspInfoField)(unsafe.Pointer(pRspInfo)), int(nRequestID), bool(bIsLast))
289 | }
290 |
291 | //export wrapMdOnRspError
292 | func wrapMdOnRspError(v uintptr, pRspInfo *C.struct_CThostFtdcRspInfoField, nRequestID C.int, bIsLast C._Bool) {
293 | api := cgo.Handle(v).Value().(*mdApi)
294 | api.spi.OnRspError((*thost.CThostFtdcRspInfoField)(unsafe.Pointer(pRspInfo)), int(nRequestID), bool(bIsLast))
295 | }
296 |
297 | //export wrapMdOnRspSubMarketData
298 | func wrapMdOnRspSubMarketData(v uintptr, pSpecificInstrument *C.struct_CThostFtdcSpecificInstrumentField, pRspInfo *C.struct_CThostFtdcRspInfoField, nRequestID C.int, bIsLast C._Bool) {
299 | api := cgo.Handle(v).Value().(*mdApi)
300 | api.spi.OnRspSubMarketData((*thost.CThostFtdcSpecificInstrumentField)(unsafe.Pointer(pSpecificInstrument)), (*thost.CThostFtdcRspInfoField)(unsafe.Pointer(pRspInfo)), int(nRequestID), bool(bIsLast))
301 | }
302 |
303 | //export wrapMdOnRspUnSubMarketData
304 | func wrapMdOnRspUnSubMarketData(v uintptr, pSpecificInstrument *C.struct_CThostFtdcSpecificInstrumentField, pRspInfo *C.struct_CThostFtdcRspInfoField, nRequestID C.int, bIsLast C._Bool) {
305 | api := cgo.Handle(v).Value().(*mdApi)
306 | api.spi.OnRspUnSubMarketData((*thost.CThostFtdcSpecificInstrumentField)(unsafe.Pointer(pSpecificInstrument)), (*thost.CThostFtdcRspInfoField)(unsafe.Pointer(pRspInfo)), int(nRequestID), bool(bIsLast))
307 | }
308 |
309 | //export wrapMdOnRspSubForQuoteRsp
310 | func wrapMdOnRspSubForQuoteRsp(v uintptr, pSpecificInstrument *C.struct_CThostFtdcSpecificInstrumentField, pRspInfo *C.struct_CThostFtdcRspInfoField, nRequestID C.int, bIsLast C._Bool) {
311 | api := cgo.Handle(v).Value().(*mdApi)
312 | api.spi.OnRspSubForQuoteRsp((*thost.CThostFtdcSpecificInstrumentField)(unsafe.Pointer(pSpecificInstrument)), (*thost.CThostFtdcRspInfoField)(unsafe.Pointer(pRspInfo)), int(nRequestID), bool(bIsLast))
313 | }
314 |
315 | //export wrapMdOnRspUnSubForQuoteRsp
316 | func wrapMdOnRspUnSubForQuoteRsp(v uintptr, pSpecificInstrument *C.struct_CThostFtdcSpecificInstrumentField, pRspInfo *C.struct_CThostFtdcRspInfoField, nRequestID C.int, bIsLast C._Bool) {
317 | api := cgo.Handle(v).Value().(*mdApi)
318 | api.spi.OnRspUnSubForQuoteRsp((*thost.CThostFtdcSpecificInstrumentField)(unsafe.Pointer(pSpecificInstrument)), (*thost.CThostFtdcRspInfoField)(unsafe.Pointer(pRspInfo)), int(nRequestID), bool(bIsLast))
319 | }
320 |
321 | //export wrapMdOnRtnDepthMarketData
322 | func wrapMdOnRtnDepthMarketData(v uintptr, pDepthMarketData *C.struct_CThostFtdcDepthMarketDataField) {
323 | api := cgo.Handle(v).Value().(*mdApi)
324 | api.spi.OnRtnDepthMarketData((*thost.CThostFtdcDepthMarketDataField)(unsafe.Pointer(pDepthMarketData)))
325 | }
326 |
327 | //export wrapMdOnRtnForQuoteRsp
328 | func wrapMdOnRtnForQuoteRsp(v uintptr, pForQuoteRsp *C.struct_CThostFtdcForQuoteRspField) {
329 | api := cgo.Handle(v).Value().(*mdApi)
330 | api.spi.OnRtnForQuoteRsp((*thost.CThostFtdcForQuoteRspField)(unsafe.Pointer(pForQuoteRsp)))
331 | }
332 |
333 | // -----------------------------------------------------
334 | func MdFlowPath(path string) MdOption {
335 | return func(api *mdApi) {
336 | api.flowPath = path
337 | }
338 | }
339 |
340 | func MdUsingUDP(usingudp bool) MdOption {
341 | return func(api *mdApi) {
342 | api.usingUDP = usingudp
343 | }
344 | }
345 |
346 | func MdMultiCast(multicast bool) MdOption {
347 | return func(api *mdApi) {
348 | api.multicast = multicast
349 | }
350 | }
351 |
--------------------------------------------------------------------------------
/mdapi_lite.go:
--------------------------------------------------------------------------------
1 | package goctp
2 |
3 | import "github.com/pseudocodes/goctp/thost"
4 |
5 | type MdApiLite struct {
6 | *mdApi
7 | }
8 |
9 | func CreateMdApiLite(options ...MdOption) *MdApiLite {
10 | api := &MdApiLite{}
11 | mdApi := CreateMdApi(options...)
12 | api.mdApi = mdApi
13 | return api
14 | }
15 |
16 | // 用户登录请求
17 | func (t *MdApiLite) ReqUserLogin(pReqUserLoginField *ReqUserLoginField, nRequestID int) int {
18 | var f0 = toCThostFtdcReqUserLoginField(pReqUserLoginField)
19 |
20 | return t.mdApi.ReqUserLogin((f0), int(nRequestID))
21 | }
22 |
23 | type MdSpiLite struct {
24 | BaseMdSpi
25 |
26 | //当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。
27 | OnFrontConnectedCallback func()
28 |
29 | //当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。
30 | ///@param nReason 错误原因
31 | /// 0x1001 网络读失败
32 | /// 0x1002 网络写失败
33 | /// 0x2001 接收心跳超时
34 | /// 0x2002 发送心跳失败
35 | /// 0x2003 收到错误报文
36 | OnFrontDisconnectedCallback func(nReason int)
37 |
38 | //心跳超时警告。当长时间未收到报文时,该方法被调用。
39 | ///@param nTimeLapse 距离上次接收报文的时间
40 | OnHeartBeatWarningCallback func(nTimeLapse int)
41 |
42 | //登录请求响应
43 | OnRspUserLoginCallback func(pRspUserLogin *RspUserLoginField, pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
44 |
45 | //错误应答
46 | OnRspErrorCallback func(pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
47 |
48 | //深度行情通知
49 | OnRtnDepthMarketDataCallback func(pDepthMarketData *DepthMarketDataField)
50 |
51 | // 订阅行情应答
52 | OnRspSubMarketDataCallback func(specificInstrument string, pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
53 | }
54 |
55 | // 当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。
56 | func (s *MdSpiLite) OnFrontConnected() {
57 |
58 | if s.OnFrontConnectedCallback != nil {
59 | s.OnFrontConnectedCallback()
60 | }
61 | }
62 |
63 | // 当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。
64 | // /@param nReason 错误原因
65 | // / 0x1001 网络读失败
66 | // / 0x1002 网络写失败
67 | // / 0x2001 接收心跳超时
68 | // / 0x2002 发送心跳失败
69 | // / 0x2003 收到错误报文
70 | func (s *MdSpiLite) OnFrontDisconnected(nReason int) {
71 |
72 | if s.OnFrontDisconnectedCallback != nil {
73 | s.OnFrontDisconnectedCallback(int(nReason))
74 | }
75 | }
76 |
77 | // 心跳超时警告。当长时间未收到报文时,该方法被调用。
78 | // /@param nTimeLapse 距离上次接收报文的时间
79 | func (s *MdSpiLite) OnHeartBeatWarning(nTimeLapse int) {
80 |
81 | if s.OnHeartBeatWarningCallback != nil {
82 | s.OnHeartBeatWarningCallback(int(nTimeLapse))
83 | }
84 | }
85 |
86 | // 登录请求响应
87 | func (s *MdSpiLite) OnRspUserLogin(pRspUserLogin *thost.CThostFtdcRspUserLoginField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
88 | f0 := fromCThostFtdcRspUserLoginField(pRspUserLogin)
89 |
90 | var f1 *RspInfoField
91 | if pRspInfo != nil {
92 | f1 = fromCThostFtdcRspInfoField(pRspInfo)
93 | }
94 |
95 | if s.OnRspUserLoginCallback != nil {
96 | s.OnRspUserLoginCallback((f0), (f1), int(nRequestID), bool(bIsLast))
97 | }
98 | }
99 |
100 | // 错误应答
101 | func (s *MdSpiLite) OnRspError(pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
102 |
103 | var f0 *RspInfoField
104 | if pRspInfo != nil {
105 | f0 = fromCThostFtdcRspInfoField(pRspInfo)
106 | }
107 |
108 | if s.OnRspErrorCallback != nil {
109 | s.OnRspErrorCallback((f0), int(nRequestID), bool(bIsLast))
110 | }
111 | }
112 |
113 | // 深度行情通知
114 | func (s *MdSpiLite) OnRtnDepthMarketData(pDepthMarketData *thost.CThostFtdcDepthMarketDataField) {
115 | f0 := fromCThostFtdcDepthMarketDataField(pDepthMarketData)
116 |
117 | if s.OnRtnDepthMarketDataCallback != nil {
118 | s.OnRtnDepthMarketDataCallback((f0))
119 | }
120 | }
121 |
122 | // 深度行情通知
123 | func (s *MdSpiLite) OnRspSubMarketData(pSpecificInstrument *thost.CThostFtdcSpecificInstrumentField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
124 | var f0 = bytes2String(pSpecificInstrument.InstrumentID[:])
125 | var f1 *RspInfoField
126 | if pRspInfo != nil {
127 | f1 = fromCThostFtdcRspInfoField(pRspInfo)
128 | }
129 |
130 | if s.OnRspSubMarketDataCallback != nil {
131 | s.OnRspSubMarketDataCallback(f0, f1, nRequestID, bIsLast)
132 | }
133 | }
134 |
135 | func (s *MdSpiLite) SetOnFrontConnected(f func()) {
136 | s.OnFrontConnectedCallback = f
137 | }
138 |
139 | func (s *MdSpiLite) SetOnFrontDisconnected(f func(int)) {
140 | s.OnFrontDisconnectedCallback = f
141 | }
142 |
143 | func (s *MdSpiLite) SetOnHeartBeatWarning(f func(int)) {
144 | s.OnHeartBeatWarningCallback = f
145 | }
146 |
147 | func (s *MdSpiLite) SetOnRspUserLogin(f func(*RspUserLoginField, *RspInfoField, int, bool)) {
148 | s.OnRspUserLoginCallback = f
149 | }
150 |
151 | func (s *MdSpiLite) SetOnRspError(f func(*RspInfoField, int, bool)) {
152 | s.OnRspErrorCallback = f
153 | }
154 |
155 | func (s *MdSpiLite) SetOnRtnDepthMarketData(f func(*DepthMarketDataField)) {
156 | s.OnRtnDepthMarketDataCallback = f
157 | }
158 |
159 | func (s *MdSpiLite) SetOnRspSubMarketData(f func(string, *RspInfoField, int, bool)) {
160 | s.OnRspSubMarketDataCallback = f
161 | }
162 |
--------------------------------------------------------------------------------
/mdapi_wrap.cxx:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 (the "License");
2 | // you may not use this file except in compliance with the License.
3 | // You may obtain a copy of the License at
4 | //
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 | //
7 | // Unless required by applicable law or agreed to in writing, software
8 | // distributed under the License is distributed on an "AS IS" BASIS,
9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | // See the License for the specific language governing permissions and
11 | // limitations under the License.
12 |
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 |
21 | #include "ThostFtdcMdApi.h"
22 | #include "ThostFtdcTraderApi.h"
23 | #include "ThostFtdcUserApiDataType.h"
24 | #include "ThostFtdcUserApiStruct.h"
25 |
26 | #include "mdapi_wrap.h"
27 |
28 | typedef long long intgo;
29 | typedef struct
30 | {
31 | char* p;
32 | int64_t n;
33 | } _gostring_;
34 |
35 | typedef struct
36 | {
37 | void* array;
38 | int64_t len;
39 | int64_t cap;
40 | } _goslice_;
41 |
42 | #ifdef __cplusplus
43 | extern "C" {
44 | #endif
45 | QCTPMdSpi* _wrap_CThostFtdcMdApi_CreateFtdcMdApi()
46 | {
47 | CThostFtdcMdApi* pUserApi = CThostFtdcMdApi::CreateFtdcMdApi("./data/", false);
48 | QCTPMdSpi* pUserSpi = new QCTPMdSpi(pUserApi);
49 | pUserSpi->RegisterSpi(pUserSpi);
50 | return pUserSpi;
51 | }
52 |
53 | QCTPMdSpi* _wrap_CThostFtdcMdApi_CreateFtdcMdApi2(uintptr_t gUserApi, const char* pszFlowPath, const bool bIsUsingUdp, const bool bIsMulticast)
54 | {
55 | // printf("go_user_api %lu\n", gUserApi);
56 | CThostFtdcMdApi* pUserApi = CThostFtdcMdApi::CreateFtdcMdApi(pszFlowPath, bIsUsingUdp, bIsMulticast);
57 | QCTPMdSpi* pUserSpi = new QCTPMdSpi(pUserApi, gUserApi);
58 | pUserSpi->RegisterSpi(pUserSpi);
59 | return pUserSpi;
60 | }
61 |
62 | // 获取API的版本信息
63 | ///@retrun 获取到的版本号
64 | const char* _wrap_CThostFtdcMdApi_GetApiVersion(QCTPMdSpi* pMdApi)
65 | {
66 | return pMdApi->GetApiVersion();
67 | }
68 |
69 | // 删除接口对象本身
70 | ///@remark 不再使用本接口对象时,调用该函数删除接口对象
71 | void _wrap_CThostFtdcMdApi_Release(QCTPMdSpi* pMdApi)
72 | {
73 | return pMdApi->Release();
74 | }
75 |
76 | // 初始化
77 | ///@remark 初始化运行环境,只有调用后,接口才开始工作
78 | void _wrap_CThostFtdcMdApi_Init(QCTPMdSpi* pMdApi)
79 | {
80 | return pMdApi->Init();
81 | }
82 |
83 | // 等待接口线程结束运行
84 | ///@return 线程退出代码
85 | int _wrap_CThostFtdcMdApi_Join(QCTPMdSpi* pMdApi)
86 | {
87 | return pMdApi->Join();
88 | }
89 |
90 | // 获取当前交易日
91 | ///@retrun 获取到的交易日
92 | ///@remark 只有登录成功后,才能得到正确的交易日
93 | const char* _wrap_CThostFtdcMdApi_GetTradingDay(QCTPMdSpi* pMdApi)
94 | {
95 | return pMdApi->GetTradingDay();
96 | }
97 |
98 | // 注册前置机网络地址
99 | ///@param pszFrontAddress:前置机网络地址。
100 | ///@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:17001”。
101 | ///@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”17001”代表服务器端口号。
102 | void _wrap_CThostFtdcMdApi_RegisterFront(QCTPMdSpi* pMdApi, char* pszFrontAddress)
103 | {
104 | return pMdApi->RegisterFront(pszFrontAddress);
105 | }
106 |
107 | // 注册名字服务器网络地址
108 | ///@param pszNsAddress:名字服务器网络地址。
109 | ///@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:12001”。
110 | ///@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”12001”代表服务器端口号。
111 | ///@remark RegisterNameServer优先于RegisterFront
112 | void _wrap_CThostFtdcMdApi_RegisterNameServer(QCTPMdSpi* pMdApi, char* pszNsAddress)
113 | {
114 | return pMdApi->RegisterNameServer(pszNsAddress);
115 | }
116 |
117 | // 注册名字服务器用户信息
118 | ///@param pFensUserInfo:用户信息。
119 | void _wrap_CThostFtdcMdApi_RegisterFensUserInfo(QCTPMdSpi* pMdApi, CThostFtdcFensUserInfoField* pFensUserInfo)
120 | {
121 | return pMdApi->RegisterFensUserInfo(pFensUserInfo);
122 | }
123 |
124 | // 订阅行情。
125 | ///@param ppInstrumentID 合约ID
126 | ///@param nCount 要订阅/退订行情的合约个数
127 | ///@remark
128 | int _wrap_CThostFtdcMdApi_SubscribeMarketData(QCTPMdSpi* pMdApi, char** ppInstrumentID, int nCount)
129 | {
130 | return pMdApi->SubscribeMarketData(ppInstrumentID, nCount);
131 | }
132 |
133 | // 退订行情。
134 | ///@param ppInstrumentID 合约ID
135 | ///@param nCount 要订阅/退订行情的合约个数
136 | ///@remark
137 | int _wrap_CThostFtdcMdApi_UnSubscribeMarketData(QCTPMdSpi* pMdApi, char** ppInstrumentID, int nCount)
138 | {
139 | return pMdApi->UnSubscribeMarketData(ppInstrumentID, nCount);
140 | }
141 |
142 | // 订阅询价。
143 | ///@param ppInstrumentID 合约ID
144 | ///@param nCount 要订阅/退订行情的合约个数
145 | ///@remark
146 | int _wrap_CThostFtdcMdApi_SubscribeForQuoteRsp(QCTPMdSpi* pMdApi, char** ppInstrumentID, int nCount)
147 | {
148 | return pMdApi->SubscribeForQuoteRsp(ppInstrumentID, nCount);
149 | }
150 |
151 | // 退订询价。
152 | ///@param ppInstrumentID 合约ID
153 | ///@param nCount 要订阅/退订行情的合约个数
154 | ///@remark
155 | int _wrap_CThostFtdcMdApi_UnSubscribeForQuoteRsp(QCTPMdSpi* pMdApi, char** ppInstrumentID, int nCount)
156 | {
157 | return pMdApi->UnSubscribeForQuoteRsp(ppInstrumentID, nCount);
158 | }
159 |
160 | // 用户登录请求
161 | int _wrap_CThostFtdcMdApi_ReqUserLogin(QCTPMdSpi* pMdApi, CThostFtdcReqUserLoginField* pReqUserLoginField, int nRequestID)
162 | {
163 | int ret = pMdApi->ReqUserLogin(pReqUserLoginField, nRequestID);
164 | printf("req_user_login: %d", ret);
165 | return ret;
166 | }
167 |
168 | // 登出请求
169 | int _wrap_CThostFtdcMdApi_ReqUserLogout(QCTPMdSpi* pMdApi, CThostFtdcUserLogoutField* pUserLogout, int nRequestID)
170 | {
171 | return pMdApi->ReqUserLogout(pUserLogout, nRequestID);
172 | }
173 |
174 | // 请求查询组播合约
175 | int _wrap_CThostFtdcMdApi_ReqQryMulticastInstrument(QCTPMdSpi* pMdApi, CThostFtdcQryMulticastInstrumentField* pQryMulticastInstrument, int nRequestID)
176 | {
177 | return pMdApi->ReqQryMulticastInstrument(pQryMulticastInstrument, nRequestID);
178 | }
179 |
180 | #ifdef __cplusplus
181 | }
182 | #endif
183 |
184 | // 当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。
185 | extern "C" void wrapMdOnFrontConnected(uintptr_t);
186 | void QCTPMdSpi::OnFrontConnected()
187 | {
188 | wrapMdOnFrontConnected(gUserApi);
189 | }
190 |
191 | // 当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。
192 | ///@param nReason 错误原因
193 | /// 0x1001 网络读失败
194 | /// 0x1002 网络写失败
195 | /// 0x2001 接收心跳超时
196 | /// 0x2002 发送心跳失败
197 | /// 0x2003 收到错误报文
198 | extern "C" void wrapMdOnFrontDisconnected(uintptr_t, int);
199 | void QCTPMdSpi::OnFrontDisconnected(int nReason)
200 | {
201 | wrapMdOnFrontDisconnected(gUserApi, nReason);
202 | }
203 |
204 | // 心跳超时警告。当长时间未收到报文时,该方法被调用。
205 | ///@param nTimeLapse 距离上次接收报文的时间
206 | extern "C" void wrapMdOnHeartBeatWarning(uintptr_t, int);
207 | void QCTPMdSpi::OnHeartBeatWarning(int nTimeLapse)
208 | {
209 | wrapMdOnHeartBeatWarning(gUserApi, nTimeLapse);
210 | }
211 |
212 | // 登录请求响应
213 | extern "C" void wrapMdOnRspUserLogin(uintptr_t, CThostFtdcRspUserLoginField*, CThostFtdcRspInfoField*, int, bool);
214 | void QCTPMdSpi::OnRspUserLogin(CThostFtdcRspUserLoginField* pRspUserLogin, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
215 | {
216 | wrapMdOnRspUserLogin(gUserApi, pRspUserLogin, pRspInfo, nRequestID, bIsLast);
217 | }
218 |
219 | // 登出请求响应
220 | extern "C" void wrapMdOnRspUserLogout(uintptr_t, CThostFtdcUserLogoutField*, CThostFtdcRspInfoField*, int, bool);
221 | void QCTPMdSpi::OnRspUserLogout(CThostFtdcUserLogoutField* pUserLogout, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
222 | {
223 | wrapMdOnRspUserLogout(gUserApi, pUserLogout, pRspInfo, nRequestID, bIsLast);
224 | }
225 |
226 | // 请求查询组播合约响应
227 | extern "C" void wrapMdOnRspQryMulticastInstrument(uintptr_t, CThostFtdcMulticastInstrumentField*, CThostFtdcRspInfoField*, int, bool);
228 | void QCTPMdSpi::OnRspQryMulticastInstrument(CThostFtdcMulticastInstrumentField* pMulticastInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
229 | {
230 | wrapMdOnRspQryMulticastInstrument(gUserApi, pMulticastInstrument, pRspInfo, nRequestID, bIsLast);
231 | }
232 |
233 | // 错误应答
234 | extern "C" void wrapMdOnRspError(uintptr_t, CThostFtdcRspInfoField*, int, bool);
235 | void QCTPMdSpi::OnRspError(CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
236 | {
237 | wrapMdOnRspError(gUserApi, pRspInfo, nRequestID, bIsLast);
238 | }
239 |
240 | // 订阅行情应答
241 | extern "C" void wrapMdOnRspSubMarketData(uintptr_t, CThostFtdcSpecificInstrumentField*, CThostFtdcRspInfoField*, int, bool);
242 | void QCTPMdSpi::OnRspSubMarketData(CThostFtdcSpecificInstrumentField* pSpecificInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
243 | {
244 | wrapMdOnRspSubMarketData(gUserApi, pSpecificInstrument, pRspInfo, nRequestID, bIsLast);
245 | }
246 |
247 | // 取消订阅行情应答
248 | extern "C" void wrapMdOnRspUnSubMarketData(uintptr_t, CThostFtdcSpecificInstrumentField*, CThostFtdcRspInfoField*, int, bool);
249 | void QCTPMdSpi::OnRspUnSubMarketData(CThostFtdcSpecificInstrumentField* pSpecificInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
250 | {
251 | wrapMdOnRspUnSubMarketData(gUserApi, pSpecificInstrument, pRspInfo, nRequestID, bIsLast);
252 | }
253 |
254 | // 订阅询价应答
255 | extern "C" void wrapMdOnRspSubForQuoteRsp(uintptr_t, CThostFtdcSpecificInstrumentField*, CThostFtdcRspInfoField*, int, bool);
256 | void QCTPMdSpi::OnRspSubForQuoteRsp(CThostFtdcSpecificInstrumentField* pSpecificInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
257 | {
258 | wrapMdOnRspSubForQuoteRsp(gUserApi, pSpecificInstrument, pRspInfo, nRequestID, bIsLast);
259 | }
260 |
261 | // 取消订阅询价应答
262 | extern "C" void wrapMdOnRspUnSubForQuoteRsp(uintptr_t, CThostFtdcSpecificInstrumentField*, CThostFtdcRspInfoField*, int, bool);
263 | void QCTPMdSpi::OnRspUnSubForQuoteRsp(CThostFtdcSpecificInstrumentField* pSpecificInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
264 | {
265 | wrapMdOnRspUnSubForQuoteRsp(gUserApi, pSpecificInstrument, pRspInfo, nRequestID, bIsLast);
266 | }
267 |
268 | // 深度行情通知
269 | extern "C" void wrapMdOnRtnDepthMarketData(uintptr_t, CThostFtdcDepthMarketDataField*);
270 | void QCTPMdSpi::OnRtnDepthMarketData(CThostFtdcDepthMarketDataField* pDepthMarketData)
271 | {
272 | wrapMdOnRtnDepthMarketData(gUserApi, pDepthMarketData);
273 | }
274 |
275 | // 询价通知
276 | extern "C" void wrapMdOnRtnForQuoteRsp(uintptr_t, CThostFtdcForQuoteRspField*);
277 | void QCTPMdSpi::OnRtnForQuoteRsp(CThostFtdcForQuoteRspField* pForQuoteRsp)
278 | {
279 | wrapMdOnRtnForQuoteRsp(gUserApi, pForQuoteRsp);
280 | }
281 |
282 | QCTPMdSpi::QCTPMdSpi(CThostFtdcMdApi* pUserApi)
283 | {
284 | this->pUserApi = pUserApi;
285 | }
286 |
287 | QCTPMdSpi::QCTPMdSpi(CThostFtdcMdApi* pUserApi, uintptr_t gUserApi)
288 | {
289 | this->pUserApi = pUserApi;
290 | this->gUserApi = gUserApi;
291 | }
292 |
293 | uintptr_t _wrap_CThostFtdcMdApi_DestroyUserMdApi(QCTPMdSpi* pMdApi)
294 | {
295 | delete (pMdApi);
296 | return 0;
297 | }
298 |
299 | // 获取API的版本信息
300 | ///@retrun 获取到的版本号
301 | const char* QCTPMdSpi::GetApiVersion()
302 | {
303 | return this->pUserApi->GetApiVersion();
304 | }
305 |
306 | // 删除接口对象本身
307 | ///@remark 不再使用本接口对象时,调用该函数删除接口对象
308 | void QCTPMdSpi::Release()
309 | {
310 | this->pUserApi->RegisterSpi(NULL);
311 | return this->pUserApi->Release();
312 | }
313 |
314 | // 初始化
315 | ///@remark 初始化运行环境,只有调用后,接口才开始工作
316 | void QCTPMdSpi::Init()
317 | {
318 | this->pUserApi->Init();
319 | }
320 |
321 | // 等待接口线程结束运行
322 | ///@return 线程退出代码
323 | int QCTPMdSpi::Join()
324 | {
325 | return this->pUserApi->Join();
326 | }
327 |
328 | // 获取当前交易日
329 | ///@retrun 获取到的交易日
330 | ///@remark 只有登录成功后,才能得到正确的交易日
331 | const char* QCTPMdSpi::GetTradingDay()
332 | {
333 | return this->pUserApi->GetTradingDay();
334 | }
335 |
336 | // 注册前置机网络地址
337 | ///@param pszFrontAddress:前置机网络地址。
338 | ///@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:17001”。
339 | ///@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”17001”代表服务器端口号。
340 | void QCTPMdSpi::RegisterFront(char* pszFrontAddress)
341 | {
342 | this->pUserApi->RegisterFront(pszFrontAddress);
343 | }
344 |
345 | // 注册名字服务器网络地址
346 | ///@param pszNsAddress:名字服务器网络地址。
347 | ///@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:12001”。
348 | ///@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”12001”代表服务器端口号。
349 | ///@remark RegisterNameServer优先于RegisterFront
350 | void QCTPMdSpi::RegisterNameServer(char* pszNsAddress)
351 | {
352 | this->pUserApi->RegisterNameServer(pszNsAddress);
353 | }
354 |
355 | // 注册名字服务器用户信息
356 | ///@param pFensUserInfo:用户信息。
357 | void QCTPMdSpi::RegisterFensUserInfo(CThostFtdcFensUserInfoField* pFensUserInfo)
358 | {
359 | this->pUserApi->RegisterFensUserInfo(pFensUserInfo);
360 | }
361 |
362 | // 注册回调接口
363 | ///@param pSpi 派生自回调接口类的实例
364 | void QCTPMdSpi::RegisterSpi(CThostFtdcMdSpi* pSpi)
365 | {
366 | this->pUserApi->RegisterSpi(pSpi);
367 | }
368 |
369 | // 订阅行情。
370 | ///@param ppInstrumentID 合约ID
371 | ///@param nCount 要订阅/退订行情的合约个数
372 | ///@remark
373 | int QCTPMdSpi::SubscribeMarketData(char** ppInstrumentID, int nCount)
374 | {
375 | return this->pUserApi->SubscribeMarketData(ppInstrumentID, nCount);
376 | }
377 |
378 | // 退订行情。
379 | ///@param ppInstrumentID 合约ID
380 | ///@param nCount 要订阅/退订行情的合约个数
381 | ///@remark
382 | int QCTPMdSpi::UnSubscribeMarketData(char** ppInstrumentID, int nCount)
383 | {
384 | return this->pUserApi->UnSubscribeMarketData(ppInstrumentID, nCount);
385 | }
386 |
387 | // 订阅询价。
388 | ///@param ppInstrumentID 合约ID
389 | ///@param nCount 要订阅/退订行情的合约个数
390 | ///@remark
391 | int QCTPMdSpi::SubscribeForQuoteRsp(char** ppInstrumentID, int nCount)
392 | {
393 | return this->pUserApi->SubscribeForQuoteRsp(ppInstrumentID, nCount);
394 | }
395 |
396 | // 退订询价。
397 | ///@param ppInstrumentID 合约ID
398 | ///@param nCount 要订阅/退订行情的合约个数
399 | ///@remark
400 | int QCTPMdSpi::UnSubscribeForQuoteRsp(char** ppInstrumentID, int nCount)
401 | {
402 | return this->pUserApi->UnSubscribeForQuoteRsp(ppInstrumentID, nCount);
403 | }
404 |
405 | // 用户登录请求
406 | int QCTPMdSpi::ReqUserLogin(CThostFtdcReqUserLoginField* pReqUserLoginField, int nRequestID)
407 | {
408 | return this->pUserApi->ReqUserLogin(pReqUserLoginField, nRequestID);
409 | }
410 |
411 | // 登出请求
412 | int QCTPMdSpi::ReqUserLogout(CThostFtdcUserLogoutField* pUserLogout, int nRequestID)
413 | {
414 | return this->pUserApi->ReqUserLogout(pUserLogout, nRequestID);
415 | }
416 |
417 | // 请求查询组播合约
418 | int QCTPMdSpi::ReqQryMulticastInstrument(CThostFtdcQryMulticastInstrumentField* pQryMulticastInstrument, int nRequestID)
419 | {
420 | return this->pUserApi->ReqQryMulticastInstrument(pQryMulticastInstrument, nRequestID);
421 | }
422 |
--------------------------------------------------------------------------------
/mdapi_wrap.h:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 (the "License");
2 | // you may not use this file except in compliance with the License.
3 | // You may obtain a copy of the License at
4 | //
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 | //
7 | // Unless required by applicable law or agreed to in writing, software
8 | // distributed under the License is distributed on an "AS IS" BASIS,
9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | // See the License for the specific language governing permissions and
11 | // limitations under the License.
12 |
13 | #ifndef _MDAPI_WRAP_H_
14 | #define _MDAPI_WRAP_H_
15 |
16 | class QCTPMdSpi : public CThostFtdcMdSpi
17 | {
18 | public:
19 | QCTPMdSpi(CThostFtdcMdApi *pUserApi);
20 | QCTPMdSpi(CThostFtdcMdApi *pUserApi, uintptr_t gUserApi);
21 | QCTPMdSpi();
22 | ~QCTPMdSpi(){};
23 |
24 | //当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。
25 | void OnFrontConnected();
26 |
27 | //当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。
28 | ///@param nReason 错误原因
29 | /// 0x1001 网络读失败
30 | /// 0x1002 网络写失败
31 | /// 0x2001 接收心跳超时
32 | /// 0x2002 发送心跳失败
33 | /// 0x2003 收到错误报文
34 | void OnFrontDisconnected(int nReason);
35 |
36 | //心跳超时警告。当长时间未收到报文时,该方法被调用。
37 | ///@param nTimeLapse 距离上次接收报文的时间
38 | void OnHeartBeatWarning(int nTimeLapse);
39 |
40 | //登录请求响应
41 | void OnRspUserLogin(CThostFtdcRspUserLoginField *pRspUserLogin, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
42 |
43 | //登出请求响应
44 | void OnRspUserLogout(CThostFtdcUserLogoutField *pUserLogout, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
45 |
46 | //请求查询组播合约响应
47 | void OnRspQryMulticastInstrument(CThostFtdcMulticastInstrumentField *pMulticastInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
48 |
49 | //错误应答
50 | void OnRspError(CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
51 |
52 | //订阅行情应答
53 | void OnRspSubMarketData(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
54 |
55 | //取消订阅行情应答
56 | void OnRspUnSubMarketData(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
57 |
58 | //订阅询价应答
59 | void OnRspSubForQuoteRsp(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
60 |
61 | //取消订阅询价应答
62 | void OnRspUnSubForQuoteRsp(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
63 |
64 | //深度行情通知
65 | void OnRtnDepthMarketData(CThostFtdcDepthMarketDataField *pDepthMarketData);
66 |
67 | //询价通知
68 | void OnRtnForQuoteRsp(CThostFtdcForQuoteRspField *pForQuoteRsp);
69 |
70 | //获取API的版本信息
71 | ///@retrun 获取到的版本号
72 | const char *GetApiVersion();
73 |
74 | //删除接口对象本身
75 | ///@remark 不再使用本接口对象时,调用该函数删除接口对象
76 | void Release();
77 |
78 | //初始化
79 | ///@remark 初始化运行环境,只有调用后,接口才开始工作
80 | void Init();
81 |
82 | //等待接口线程结束运行
83 | ///@return 线程退出代码
84 | int Join();
85 |
86 | //获取当前交易日
87 | ///@retrun 获取到的交易日
88 | ///@remark 只有登录成功后,才能得到正确的交易日
89 | const char *GetTradingDay();
90 |
91 | //注册前置机网络地址
92 | ///@param pszFrontAddress:前置机网络地址。
93 | ///@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:17001”。
94 | ///@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”17001”代表服务器端口号。
95 | void RegisterFront(char *pszFrontAddress);
96 |
97 | //注册名字服务器网络地址
98 | ///@param pszNsAddress:名字服务器网络地址。
99 | ///@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:12001”。
100 | ///@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”12001”代表服务器端口号。
101 | ///@remark RegisterNameServer优先于RegisterFront
102 | void RegisterNameServer(char *pszNsAddress);
103 |
104 | //注册名字服务器用户信息
105 | ///@param pFensUserInfo:用户信息。
106 | void RegisterFensUserInfo(CThostFtdcFensUserInfoField *pFensUserInfo);
107 |
108 | //注册回调接口
109 | ///@param pSpi 派生自回调接口类的实例
110 | void RegisterSpi(CThostFtdcMdSpi *pSpi);
111 |
112 | //订阅行情。
113 | ///@param ppInstrumentID 合约ID
114 | ///@param nCount 要订阅/退订行情的合约个数
115 | ///@remark
116 | int SubscribeMarketData(char *ppInstrumentID[], int nCount);
117 |
118 | //退订行情。
119 | ///@param ppInstrumentID 合约ID
120 | ///@param nCount 要订阅/退订行情的合约个数
121 | ///@remark
122 | int UnSubscribeMarketData(char *ppInstrumentID[], int nCount);
123 |
124 | //订阅询价。
125 | ///@param ppInstrumentID 合约ID
126 | ///@param nCount 要订阅/退订行情的合约个数
127 | ///@remark
128 | int SubscribeForQuoteRsp(char *ppInstrumentID[], int nCount);
129 |
130 | //退订询价。
131 | ///@param ppInstrumentID 合约ID
132 | ///@param nCount 要订阅/退订行情的合约个数
133 | ///@remark
134 | int UnSubscribeForQuoteRsp(char *ppInstrumentID[], int nCount);
135 |
136 | //用户登录请求
137 | int ReqUserLogin(CThostFtdcReqUserLoginField *pReqUserLoginField, int nRequestID);
138 |
139 | //登出请求
140 | int ReqUserLogout(CThostFtdcUserLogoutField *pUserLogout, int nRequestID);
141 |
142 | //请求查询组播合约
143 | int ReqQryMulticastInstrument(CThostFtdcQryMulticastInstrumentField *pQryMulticastInstrument, int nRequestID);
144 |
145 | private:
146 | CThostFtdcMdApi *pUserApi;
147 | uintptr_t gUserApi;
148 | };
149 |
150 | #endif // end _MDAPI_WRAP_H_
151 |
--------------------------------------------------------------------------------
/mdspi_base.go:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 (the "License");
2 | // you may not use this file except in compliance with the License.
3 | // You may obtain a copy of the License at
4 | //
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 | //
7 | // Unless required by applicable law or agreed to in writing, software
8 | // distributed under the License is distributed on an "AS IS" BASIS,
9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | // See the License for the specific language governing permissions and
11 | // limitations under the License.
12 |
13 | package goctp
14 |
15 | import (
16 | "github.com/pseudocodes/goctp/thost"
17 | )
18 |
19 | var _ MdSpi = &BaseMdSpi{}
20 |
21 | type BaseMdSpi struct {
22 |
23 | // 当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。
24 | OnFrontConnectedCallback func()
25 |
26 | // 当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。
27 | ///@param nReason 错误原因
28 | /// 0x1001 网络读失败
29 | /// 0x1002 网络写失败
30 | /// 0x2001 接收心跳超时
31 | /// 0x2002 发送心跳失败
32 | /// 0x2003 收到错误报文
33 | OnFrontDisconnectedCallback func(int)
34 |
35 | // 心跳超时警告。当长时间未收到报文时,该方法被调用。
36 | ///@param nTimeLapse 距离上次接收报文的时间
37 | OnHeartBeatWarningCallback func(int)
38 |
39 | // 登录请求响应
40 | OnRspUserLoginCallback func(*thost.CThostFtdcRspUserLoginField, *thost.CThostFtdcRspInfoField, int, bool)
41 |
42 | // 登出请求响应
43 | OnRspUserLogoutCallback func(*thost.CThostFtdcUserLogoutField, *thost.CThostFtdcRspInfoField, int, bool)
44 |
45 | // 请求查询组播合约响应
46 | OnRspQryMulticastInstrumentCallback func(*thost.CThostFtdcMulticastInstrumentField, *thost.CThostFtdcRspInfoField, int, bool)
47 |
48 | // 错误应答
49 | OnRspErrorCallback func(*thost.CThostFtdcRspInfoField, int, bool)
50 |
51 | // 订阅行情应答
52 | OnRspSubMarketDataCallback func(*thost.CThostFtdcSpecificInstrumentField, *thost.CThostFtdcRspInfoField, int, bool)
53 |
54 | // 取消订阅行情应答
55 | OnRspUnSubMarketDataCallback func(*thost.CThostFtdcSpecificInstrumentField, *thost.CThostFtdcRspInfoField, int, bool)
56 |
57 | // 订阅询价应答
58 | OnRspSubForQuoteRspCallback func(*thost.CThostFtdcSpecificInstrumentField, *thost.CThostFtdcRspInfoField, int, bool)
59 |
60 | // 取消订阅询价应答
61 | OnRspUnSubForQuoteRspCallback func(*thost.CThostFtdcSpecificInstrumentField, *thost.CThostFtdcRspInfoField, int, bool)
62 |
63 | // 深度行情通知
64 | OnRtnDepthMarketDataCallback func(*thost.CThostFtdcDepthMarketDataField)
65 |
66 | // 询价通知
67 | OnRtnForQuoteRspCallback func(*thost.CThostFtdcForQuoteRspField)
68 | }
69 |
70 | // 当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。
71 | func (s *BaseMdSpi) OnFrontConnected() {
72 | if s.OnFrontConnectedCallback != nil {
73 | s.OnFrontConnectedCallback()
74 | }
75 | }
76 |
77 | // 当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。
78 | // /@param nReason 错误原因
79 | // / 0x1001 网络读失败
80 | // / 0x1002 网络写失败
81 | // / 0x2001 接收心跳超时
82 | // / 0x2002 发送心跳失败
83 | // / 0x2003 收到错误报文
84 | func (s *BaseMdSpi) OnFrontDisconnected(nReason int) {
85 | if s.OnFrontDisconnectedCallback != nil {
86 | s.OnFrontDisconnectedCallback(nReason)
87 | }
88 | }
89 |
90 | // 心跳超时警告。当长时间未收到报文时,该方法被调用。
91 | // /@param nTimeLapse 距离上次接收报文的时间
92 | func (s *BaseMdSpi) OnHeartBeatWarning(nTimeLapse int) {
93 | if s.OnHeartBeatWarningCallback != nil {
94 | s.OnHeartBeatWarningCallback(nTimeLapse)
95 | }
96 | }
97 |
98 | // 登录请求响应
99 | func (s *BaseMdSpi) OnRspUserLogin(pRspUserLogin *thost.CThostFtdcRspUserLoginField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
100 | if s.OnRspUserLoginCallback != nil {
101 | s.OnRspUserLoginCallback(pRspUserLogin, pRspInfo, nRequestID, bIsLast)
102 | }
103 | }
104 |
105 | // 登出请求响应
106 | func (s *BaseMdSpi) OnRspUserLogout(pUserLogout *thost.CThostFtdcUserLogoutField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
107 | if s.OnRspUserLogoutCallback != nil {
108 | s.OnRspUserLogoutCallback(pUserLogout, pRspInfo, nRequestID, bIsLast)
109 | }
110 | }
111 |
112 | // 请求查询组播合约响应
113 | func (s *BaseMdSpi) OnRspQryMulticastInstrument(pMulticastInstrument *thost.CThostFtdcMulticastInstrumentField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
114 | if s.OnRspQryMulticastInstrumentCallback != nil {
115 | s.OnRspQryMulticastInstrumentCallback(pMulticastInstrument, pRspInfo, nRequestID, bIsLast)
116 | }
117 | }
118 |
119 | // 错误应答
120 | func (s *BaseMdSpi) OnRspError(pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
121 | if s.OnRspErrorCallback != nil {
122 | s.OnRspErrorCallback(pRspInfo, nRequestID, bIsLast)
123 | }
124 | }
125 |
126 | // 订阅行情应答
127 | func (s *BaseMdSpi) OnRspSubMarketData(pSpecificInstrument *thost.CThostFtdcSpecificInstrumentField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
128 | if s.OnRspSubMarketDataCallback != nil {
129 | s.OnRspSubMarketDataCallback(pSpecificInstrument, pRspInfo, nRequestID, bIsLast)
130 | }
131 | }
132 |
133 | // 取消订阅行情应答
134 | func (s *BaseMdSpi) OnRspUnSubMarketData(pSpecificInstrument *thost.CThostFtdcSpecificInstrumentField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
135 | if s.OnRspUnSubMarketDataCallback != nil {
136 | s.OnRspUnSubMarketDataCallback(pSpecificInstrument, pRspInfo, nRequestID, bIsLast)
137 | }
138 | }
139 |
140 | // 订阅询价应答
141 | func (s *BaseMdSpi) OnRspSubForQuoteRsp(pSpecificInstrument *thost.CThostFtdcSpecificInstrumentField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
142 | if s.OnRspSubForQuoteRspCallback != nil {
143 | s.OnRspSubForQuoteRspCallback(pSpecificInstrument, pRspInfo, nRequestID, bIsLast)
144 | }
145 | }
146 |
147 | // 取消订阅询价应答
148 | func (s *BaseMdSpi) OnRspUnSubForQuoteRsp(pSpecificInstrument *thost.CThostFtdcSpecificInstrumentField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
149 | if s.OnRspUnSubForQuoteRspCallback != nil {
150 | s.OnRspUnSubForQuoteRspCallback(pSpecificInstrument, pRspInfo, nRequestID, bIsLast)
151 | }
152 | }
153 |
154 | // 深度行情通知
155 | func (s *BaseMdSpi) OnRtnDepthMarketData(pDepthMarketData *thost.CThostFtdcDepthMarketDataField) {
156 | if s.OnRtnDepthMarketDataCallback != nil {
157 | s.OnRtnDepthMarketDataCallback(pDepthMarketData)
158 | }
159 | }
160 |
161 | // 询价通知
162 | func (s *BaseMdSpi) OnRtnForQuoteRsp(pForQuoteRsp *thost.CThostFtdcForQuoteRspField) {
163 | if s.OnRtnForQuoteRspCallback != nil {
164 | s.OnRtnForQuoteRspCallback(pForQuoteRsp)
165 | }
166 | }
167 |
--------------------------------------------------------------------------------
/sample/simple_market/simple_market.go:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 (the "License");
2 | // you may not use this file except in compliance with the License.
3 | // You may obtain a copy of the License at
4 | //
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 | //
7 | // Unless required by applicable law or agreed to in writing, software
8 | // distributed under the License is distributed on an "AS IS" BASIS,
9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | // See the License for the specific language governing permissions and
11 | // limitations under the License.
12 |
13 | package main
14 |
15 | import (
16 | "log"
17 | "os"
18 |
19 | "github.com/gookit/goutil/dump"
20 | "github.com/pseudocodes/goctp"
21 | )
22 |
23 | /*
24 | Simnow是上期技术提供的CTP程序测试、模拟、学习的模拟平台。
25 |
26 | 7x24环境-电信:
27 | 交易前置: tcp://180.168.146.187:10130
28 | 行情前置: tcp://180.168.146.187:10131
29 |
30 | 仿真环境1-电信:交易时段同实盘
31 | 交易前置: tcp://180.168.146.187:10201
32 | 行情前置: tcp://180.168.146.187:10211
33 |
34 | 仿真环境2-电信:交易时段同实盘
35 | 交易前置: tcp://180.168.146.187:10202
36 | 行情前置: tcp://180.168.146.187:10212
37 |
38 | 仿真环境3-移动:交易时段同实盘
39 | 交易前置: tcp://218.202.237.33:10203
40 | 行情前置: tcp://218.202.237.33:10213
41 | */
42 | var SimnowEnv map[string]map[string]string = map[string]map[string]string{
43 | "td": {
44 | "7x24": "tcp://180.168.146.187:10130",
45 | "telesim1": "tcp://180.168.146.187:10201",
46 | "telesim2": "tcp://180.168.146.187:10202",
47 | "moblesim3": "tcp://218.202.237.33:10203",
48 | },
49 | "md": {
50 | "7x24": "tcp://180.168.146.187:10131",
51 | "telesim1": "tcp://180.168.146.187:10211",
52 | "telesim2": "tcp://180.168.146.187:10212",
53 | "moblesim3": "tcp://218.202.237.33:10213",
54 | },
55 | }
56 |
57 | func init() {
58 | log.SetFlags(log.LstdFlags | log.Lshortfile)
59 | }
60 |
61 | type baseSpi struct {
62 | mdapi *goctp.MdApiLite
63 | mdspi *goctp.MdSpiLite
64 | }
65 |
66 | func CreateBaseSpi() *baseSpi {
67 | s := &baseSpi{
68 | mdspi: &goctp.MdSpiLite{},
69 | }
70 | s.mdspi.SetOnFrontConnected(s.OnFrontConnected)
71 |
72 | s.mdspi.SetOnFrontDisconnected(s.OnFrontDisconnected)
73 |
74 | s.mdspi.SetOnHeartBeatWarning(s.OnHeartBeatWarning)
75 |
76 | s.mdspi.SetOnRspUserLogin(s.OnRspUserLogin)
77 |
78 | s.mdspi.SetOnRspError(s.OnRspError)
79 |
80 | s.mdspi.SetOnRspSubMarketData(s.OnRspSubMarketData)
81 |
82 | s.mdspi.SetOnRtnDepthMarketData(s.OnRtnDepthMarketData)
83 | return s
84 | }
85 |
86 | func (s *baseSpi) OnFrontConnected() {
87 | log.Printf("OnFrontConnected\n")
88 |
89 | ret := s.mdapi.ReqUserLogin(&goctp.ReqUserLoginField{
90 | BrokerID: "9999",
91 | UserID: os.Getenv("SIMNOW_USER_ID"), // <- 环境变量设置
92 | Password: os.Getenv("SIMNOW_USER_PASSWORD"),
93 | }, 1)
94 |
95 | log.Printf("user log: %v\n", ret)
96 | }
97 |
98 | func (s *baseSpi) OnHeartBeatWarning(timelapse int) {
99 | log.Printf("OnHeartBeatWarning: %v\n", timelapse)
100 | }
101 |
102 | func (s *baseSpi) OnFrontDisconnected(nReason int) {
103 | log.Printf("OnFrontDisconnected: %v\n", nReason)
104 | }
105 |
106 | func (s *baseSpi) OnRspUserLogin(pRspUserLogin *goctp.RspUserLoginField, rspInfo *goctp.RspInfoField, nRequestID int, bIsLast bool) {
107 | log.Printf("RspUserLogin: %+v\nRspInfo: %+v\n", pRspUserLogin, rspInfo)
108 | s.mdapi.SubscribeMarketData("ag2308")
109 | }
110 |
111 | func (s *baseSpi) OnRspSubMarketData(ins string, rspInfo *goctp.RspInfoField, requestID int, isLast bool) {
112 | log.Printf("instrumentID: %+v\n RspInfo: %+v\n", string(ins), rspInfo)
113 | }
114 |
115 | func (s *baseSpi) OnRtnDepthMarketData(quote *goctp.DepthMarketDataField) {
116 | // log.Printf("tick {%+v}\n", quote)
117 | log.Printf("OnRtnDeptMarketData\n")
118 | dump.Println(quote)
119 | }
120 |
121 | func (s *baseSpi) OnRspError(rspInfo *goctp.RspInfoField, requestID int, isLast bool) {
122 | log.Printf("RspInfo: %+v\n", rspInfo)
123 |
124 | }
125 |
126 | func sample1() {
127 |
128 | mdapi := goctp.CreateMdApiLite(goctp.MdFlowPath("./data/"), goctp.MdUsingUDP(false), goctp.MdMultiCast(false))
129 | baseSpi := CreateBaseSpi()
130 | baseSpi.mdapi = mdapi
131 | mdapi.RegisterSpi(baseSpi.mdspi)
132 | // mdapi.RegisterFront(SimnowEnv["md"]["7x24"])
133 | mdapi.RegisterFront(SimnowEnv["md"]["telesim1"])
134 | // mdapi.RegisterFront("tcp://0.0.0.0:9091")
135 |
136 | // mdapi.RegisterNameServer("tcp://localhost:9091")
137 | mdapi.Init()
138 |
139 | println(mdapi.GetApiVersion())
140 | println(mdapi.GetTradingDay())
141 |
142 | mdapi.Join()
143 | }
144 |
145 | func main() {
146 | sample1()
147 | }
148 |
--------------------------------------------------------------------------------
/sample/simple_trader/simple_trader.go:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 (the "License");
2 | // you may not use this file except in compliance with the License.
3 | // You may obtain a copy of the License at
4 | //
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 | //
7 | // Unless required by applicable law or agreed to in writing, software
8 | // distributed under the License is distributed on an "AS IS" BASIS,
9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | // See the License for the specific language governing permissions and
11 | // limitations under the License.
12 |
13 | package main
14 |
15 | import (
16 | "log"
17 | "os"
18 | "sync/atomic"
19 | "time"
20 |
21 | "github.com/gookit/goutil/dump"
22 | "github.com/pseudocodes/goctp"
23 | dc "github.com/pseudocodes/goctp/data_collect"
24 | )
25 |
26 | var SimnowEnv map[string]map[string]string = map[string]map[string]string{
27 | "td": {
28 | "7x24": "tcp://180.168.146.187:10130",
29 | "telesim1": "tcp://180.168.146.187:10201",
30 | "telesim2": "tcp://180.168.146.187:10202",
31 | "moblesim3": "tcp://218.202.237.33:10203",
32 | },
33 | "md": {
34 | "7x24": "tcp://180.168.146.187:10131",
35 | "telesim1": "tcp://180.168.146.187:10211",
36 | "telesim2": "tcp://180.168.146.187:10212",
37 | "moblesim3": "tcp://218.202.237.33:10213",
38 | },
39 | }
40 |
41 | func init() {
42 | log.SetFlags(log.LstdFlags | log.Lshortfile)
43 | }
44 |
45 | type baseSpi struct {
46 | tdspi *goctp.TraderSpiLite
47 | tdapi *goctp.TraderApiLite
48 |
49 | brokerID string
50 | investorID string
51 | password string
52 | appid string
53 | authCode string
54 |
55 | requestID atomic.Int32
56 | }
57 |
58 | func CreateBaseSpi() *baseSpi {
59 | s := &baseSpi{
60 | // tdapi: tdapi,
61 | tdspi: &goctp.TraderSpiLite{},
62 |
63 | brokerID: "9999",
64 | investorID: os.Getenv("SIMNOW_USER_ID"), // <- 环境变量设置
65 | password: os.Getenv("SIMNOW_USER_PASSWORD"), // <- 环境变量设置
66 | appid: "simnow_client_test",
67 | authCode: "0000000000000000",
68 | }
69 |
70 | s.tdspi.SetOnFrontConnected(s.OnFrontConnected)
71 |
72 | s.tdspi.SetOnFrontDisconnected(s.OnFrontDisconnected)
73 |
74 | s.tdspi.SetOnHeartBeatWarning(s.OnHeartBeatWarning)
75 |
76 | s.tdspi.SetOnRspAuthenticate(s.OnRspAuthenticate)
77 |
78 | s.tdspi.SetOnRspUserLogin(s.OnRspUserLogin)
79 |
80 | // s.tdspi.SetOnRspUserPasswordUpdate(s.OnRspUserPasswordUpdate)
81 |
82 | // s.tdspi.SetOnRspTradingAccountPasswordUpdate(s.OnRspTradingAccountPasswordUpdate)
83 |
84 | // s.tdspi.SetOnRspOrderInsert(s.OnRspOrderInsert)
85 |
86 | s.tdspi.SetOnRspOrderAction(s.OnRspOrderAction)
87 |
88 | s.tdspi.SetOnRspSettlementInfoConfirm(s.OnRspSettlementInfoConfirm)
89 |
90 | s.tdspi.SetOnRspQryOrder(s.OnRspQryOrder)
91 |
92 | s.tdspi.SetOnRspQryInvestorPosition(s.OnRspQryInvestorPosition)
93 |
94 | s.tdspi.SetOnRspQryTradingAccount(s.OnRspQryTradingAccount)
95 |
96 | // s.tdspi.SetOnRspQryInstrumentMarginRate(s.OnRspQryInstrumentMarginRate)
97 |
98 | // s.tdspi.SetOnRspQryInstrumentCommissionRate(s.OnRspQryInstrumentCommissionRate)
99 |
100 | s.tdspi.SetOnRspQryInstrument(s.OnRspQryInstrument)
101 |
102 | // s.tdspi.SetOnRspQrySettlementInfo(s.OnRspQrySettlementInfo)
103 |
104 | // s.tdspi.SetOnRspQryTransferSerial(s.OnRspQryTransferSerial)
105 |
106 | // s.tdspi.SetOnRspQryAccountregister(s.OnRspQryAccountregister)
107 |
108 | s.tdspi.SetOnRspError(s.OnRspError)
109 |
110 | s.tdspi.SetOnRtnOrder(s.OnRtnOrder)
111 |
112 | s.tdspi.SetOnRtnTrade(s.OnRtnTrade)
113 |
114 | // s.tdspi.SetOnErrRtnOrderInsert(s.OnErrRtnOrderInsert)
115 |
116 | s.tdspi.SetOnErrRtnOrderAction(s.OnErrRtnOrderAction)
117 |
118 | s.tdspi.SetOnRtnInstrumentStatus(s.OnRtnInstrumentStatus)
119 |
120 | // s.tdspi.SetOnRtnTradingNotice(s.OnRtnTradingNotice)
121 |
122 | // s.tdspi.SetOnRspQryContractBank(s.OnRspQryContractBank)
123 |
124 | // s.tdspi.SetOnRspQryBrokerTradingParams(s.OnRspQryBrokerTradingParams)
125 |
126 | // s.tdspi.SetOnRtnFromBankToFutureByFuture(s.OnRtnFromBankToFutureByFuture)
127 |
128 | // s.tdspi.SetOnRtnFromFutureToBankByFuture(s.OnRtnFromFutureToBankByFuture)
129 |
130 | // s.tdspi.SetOnRspQryDepthMarketData(s.OnRspQryDepthMarketData)
131 |
132 | return s
133 | }
134 |
135 | func (s *baseSpi) OnFrontDisconnected(nReason int) {
136 | log.Printf("OnFrontDissconnected: %v\n", nReason)
137 | }
138 |
139 | func (p *baseSpi) OnHeartBeatWarning(nTimeLapse int) {
140 | log.Println("(OnHeartBeatWarning) nTimerLapse=", nTimeLapse)
141 | }
142 |
143 | func (s *baseSpi) OnFrontConnected() {
144 | var ret int
145 | log.Printf("OnFrontConnected\n")
146 |
147 | ret = s.tdapi.ReqAuthenticate(&goctp.ReqAuthenticateField{
148 | BrokerID: s.brokerID,
149 | UserID: s.investorID,
150 | AuthCode: s.authCode,
151 | AppID: s.appid,
152 | }, int(s.requestID.Add(1)))
153 |
154 | log.Printf("user auth: %v\n", ret)
155 | }
156 |
157 | func (s *baseSpi) OnRspAuthenticate(f *goctp.RspAuthenticateField, r *goctp.RspInfoField, nRequestID int, bIsLast bool) {
158 | dump.Println(r)
159 | dump.Println(f)
160 | req := &goctp.ReqUserLoginField{
161 | BrokerID: "9999",
162 | UserID: os.Getenv("SIMNOW_USER_ID"), // <- 环境变量设置
163 | Password: os.Getenv("SIMNOW_USER_PASSWORD"),
164 | }
165 | dump.Println(req)
166 | ret := s.tdapi.ReqUserLogin(req, int(s.requestID.Add(1)))
167 | log.Printf("user login: %v\n", ret)
168 | }
169 |
170 | func (s *baseSpi) OnRspUserLogin(f *goctp.RspUserLoginField, r *goctp.RspInfoField, nRequestID int, bIsLast bool) {
171 | dump.Println(r)
172 | dump.Println(f)
173 |
174 | req := &goctp.SettlementInfoConfirmField{
175 | BrokerID: s.brokerID,
176 | InvestorID: s.investorID,
177 | }
178 | ret := s.tdapi.ReqSettlementInfoConfirm(req, int(s.requestID.Add(1)))
179 | log.Printf("req_settlement_info_confirm : %v\n", ret)
180 |
181 | }
182 |
183 | func (s *baseSpi) OnRspSettlementInfoConfirm(f *goctp.SettlementInfoConfirmField, r *goctp.RspInfoField, nRequestID int, bIsLast bool) {
184 | dump.Println(r)
185 | dump.Println(f)
186 |
187 | req := &goctp.QryInstrumentField{}
188 | ret := s.tdapi.ReqQryInstrument(req, 3)
189 | log.Printf("user qry ins: %v\n", ret)
190 | }
191 |
192 | // OnRspSettlementInfoConfirm 发送投资者结算单确认响应
193 |
194 | func (s *baseSpi) OnRspQryInstrument(pInstrument *goctp.InstrumentField, pRspInfo *goctp.RspInfoField, nRequestID int, bIsLast bool) {
195 | // dump.Print(pRspInfo, nRequestID, bIsLast)
196 | // dump.Println(pInstrument.InstrumentName)
197 |
198 | if bIsLast {
199 | log.Printf("qry ins finished\n")
200 |
201 | req := &goctp.QryTradingAccountField{
202 | BrokerID: s.brokerID,
203 | InvestorID: s.investorID,
204 | }
205 | ret := s.tdapi.ReqQryTradingAccount(req, int(s.requestID.Add(1)))
206 | if ret != 0 {
207 | log.Printf("req_qry_trading_account failed %v\n", ret)
208 | }
209 | }
210 | }
211 |
212 | // OnRspQryTradingAccount 请求查询资金账户响应
213 | func (s *baseSpi) OnRspQryTradingAccount(pTradingAccount *goctp.TradingAccountField, pRspInfo *goctp.RspInfoField, nRequestID int, bIsLast bool) {
214 |
215 | if bIsLast && !s.isErrorRspInfo(pRspInfo) {
216 | dump.P(pTradingAccount)
217 |
218 | req := &goctp.QryOrderField{
219 | BrokerID: s.brokerID,
220 | InvestorID: s.investorID,
221 | }
222 | time.Sleep(1500 * time.Millisecond)
223 | ret := s.tdapi.ReqQryOrder(req, int(s.requestID.Add(1)))
224 | if ret != 0 {
225 | log.Printf("req_qry_order failed: %v\n", ret)
226 | }
227 | }
228 | }
229 |
230 | // 合约交易状态通知
231 | func (s *baseSpi) OnRtnInstrumentStatus(pInstrumentStatus *goctp.InstrumentStatusField) {
232 | // dump.P(pInstrumentStatus)
233 | }
234 |
235 | func (s *baseSpi) OnRspQryOrder(pOrder *goctp.OrderField, pRspInfo *goctp.RspInfoField, nRequestID int, bIsLast bool) {
236 | if s.isErrorRspInfo(pRspInfo) {
237 | return
238 | }
239 | if pOrder == nil {
240 | log.Printf("OnRspQryOrder: %v\n", pOrder)
241 | }
242 | if bIsLast {
243 | req := &goctp.QryInvestorPositionField{
244 | BrokerID: s.brokerID,
245 | InvestorID: s.investorID,
246 | }
247 | time.Sleep(1500 * time.Millisecond)
248 | ret := s.tdapi.ReqQryInvestorPosition(req, int(s.requestID.Add(1)))
249 | if ret != 0 {
250 | log.Printf("req_qry_investor_position failed %v\n", ret)
251 | }
252 | }
253 | }
254 |
255 | func (s *baseSpi) OnRspQryInvestorPosition(pInvestorPosition *goctp.InvestorPositionField, pRspInfo *goctp.RspInfoField, nRequestID int, bIsLast bool) {
256 | if s.isErrorRspInfo(pRspInfo) {
257 | return
258 | }
259 | if bIsLast {
260 | log.Printf("finish rsp_qry_investor_position\n")
261 | }
262 |
263 | }
264 |
265 | // 错误应答
266 | func (s *baseSpi) OnRspError(pRspInfo *goctp.RspInfoField, nRequestID int, bIsLast bool) {
267 | s.isErrorRspInfo(pRspInfo)
268 | }
269 |
270 | // 报单操作错误回报
271 | func (s *baseSpi) OnErrRtnOrderAction(pOrderAction *goctp.OrderActionField, pRspInfo *goctp.RspInfoField) {
272 | s.isErrorRspInfo(pRspInfo)
273 | }
274 |
275 | // 报单操作请求响应(撤单失败会触发)
276 | func (s *baseSpi) OnRspOrderAction(pInputOrderAction *goctp.InputOrderActionField, pRspInfo *goctp.RspInfoField, nRequestID int, bIsLast bool) {
277 | s.isErrorRspInfo(pRspInfo)
278 | }
279 |
280 | // OnRtnTrade 成交通知(委托单在交易所成交了)
281 | func (s *baseSpi) OnRtnTrade(pTrade *goctp.TradeField) {
282 | }
283 |
284 | // OnRtnOrder 报单通知(委托单)
285 | func (s *baseSpi) OnRtnOrder(pOrder *goctp.OrderField) {
286 |
287 | }
288 |
289 | func (s *baseSpi) isErrorRspInfo(pRspInfo *goctp.RspInfoField) bool {
290 |
291 | // 容错处理 pRspInfo ,部分响应函数中,pRspInfo 为 0
292 | if pRspInfo == nil {
293 | return false
294 | }
295 | // 如果ErrorID != 0, 说明收到了错误的响应
296 | bResult := (pRspInfo.ErrorID != 0)
297 | if bResult {
298 | log.Printf("ErrorID=%v ErrorMsg=%v\n", pRspInfo.ErrorID, pRspInfo.ErrorMsg)
299 | }
300 | return bResult
301 |
302 | }
303 |
304 | func sample1() {
305 | var data = dc.DataCollectSystemInfo{}
306 | // dc.CTP_GetSystemInfoUnAesEncode(&data)
307 | dc.CTP_GetSystemInfo(&data)
308 |
309 | tdapi := goctp.CreateTraderApiLite(goctp.TraderFlowPath("./data/"), goctp.TraderSystemInfo(data.SystemInfo[:], int(data.Length)))
310 | baseSpi := CreateBaseSpi()
311 | baseSpi.tdapi = tdapi
312 | log.Printf("baseSpi %+v\n", baseSpi)
313 | tdapi.RegisterSpi(baseSpi.tdspi)
314 | tdapi.RegisterFront(SimnowEnv["td"]["7x24"])
315 |
316 | tdapi.Init()
317 |
318 | println(tdapi.GetTradingDay())
319 | println(tdapi.GetApiVersion())
320 |
321 | tdapi.Join()
322 | }
323 |
324 | func sample2() {
325 | dump.V(dc.CTP_GetDataCollectApiVersion())
326 | var data = dc.DataCollectSystemInfo{}
327 | // dc.CTP_GetSystemInfoUnAesEncode(&data)
328 | dc.CTP_GetSystemInfo(&data)
329 |
330 | dump.V(data)
331 | }
332 |
333 | func main() {
334 | sample1()
335 | // sample2()
336 | }
337 |
--------------------------------------------------------------------------------
/traderapi_lite.go:
--------------------------------------------------------------------------------
1 | package goctp
2 |
3 | import (
4 | "github.com/pseudocodes/goctp/thost"
5 | )
6 |
7 | type TraderApiLite struct {
8 | *traderApi
9 | }
10 |
11 | func CreateTraderApiLite(options ...TraderOption) *TraderApiLite {
12 | api := &TraderApiLite{}
13 | traderApi := CreateTraderApi(options...)
14 | api.traderApi = traderApi
15 | return api
16 | }
17 |
18 | // 客户端认证请求
19 | func (t *TraderApiLite) ReqAuthenticate(pReqAuthenticateField *ReqAuthenticateField, nRequestID int) int {
20 | var f0 = toCThostFtdcReqAuthenticateField(pReqAuthenticateField)
21 |
22 | return t.traderApi.ReqAuthenticate((f0), int(nRequestID))
23 | }
24 |
25 | // 用户登录请求
26 | func (t *TraderApiLite) ReqUserLogin(pReqUserLoginField *ReqUserLoginField, nRequestID int) int {
27 | var f0 = toCThostFtdcReqUserLoginField(pReqUserLoginField)
28 |
29 | return t.traderApi.ReqUserLogin((f0), int(nRequestID))
30 | }
31 |
32 | // 用户口令更新请求
33 | func (t *TraderApiLite) ReqUserPasswordUpdate(pUserPasswordUpdate *UserPasswordUpdateField, nRequestID int) int {
34 | var f0 = toCThostFtdcUserPasswordUpdateField(pUserPasswordUpdate)
35 |
36 | return t.traderApi.ReqUserPasswordUpdate((f0), int(nRequestID))
37 | }
38 |
39 | // 资金账户口令更新请求
40 | func (t *TraderApiLite) ReqTradingAccountPasswordUpdate(pTradingAccountPasswordUpdate *TradingAccountPasswordUpdateField, nRequestID int) int {
41 | var f0 = toCThostFtdcTradingAccountPasswordUpdateField(pTradingAccountPasswordUpdate)
42 |
43 | return t.traderApi.ReqTradingAccountPasswordUpdate((f0), int(nRequestID))
44 | }
45 |
46 | // 报单录入请求
47 | func (t *TraderApiLite) ReqOrderInsert(pInputOrder *InputOrderField, nRequestID int) int {
48 | var f0 = toCThostFtdcInputOrderField(pInputOrder)
49 |
50 | return t.traderApi.ReqOrderInsert((f0), int(nRequestID))
51 | }
52 |
53 | // 报单操作请求
54 | func (t *TraderApiLite) ReqOrderAction(pInputOrderAction *InputOrderActionField, nRequestID int) int {
55 | var f0 = toCThostFtdcInputOrderActionField(pInputOrderAction)
56 |
57 | return t.traderApi.ReqOrderAction((f0), int(nRequestID))
58 | }
59 |
60 | // 投资者结算结果确认
61 | func (t *TraderApiLite) ReqSettlementInfoConfirm(pSettlementInfoConfirm *SettlementInfoConfirmField, nRequestID int) int {
62 | var f0 = toCThostFtdcSettlementInfoConfirmField(pSettlementInfoConfirm)
63 |
64 | return t.traderApi.ReqSettlementInfoConfirm((f0), int(nRequestID))
65 | }
66 |
67 | // 请求查询报单
68 | func (t *TraderApiLite) ReqQryOrder(pQryOrder *QryOrderField, nRequestID int) int {
69 | var f0 = toCThostFtdcQryOrderField(pQryOrder)
70 |
71 | return t.traderApi.ReqQryOrder((f0), int(nRequestID))
72 | }
73 |
74 | // 请求查询成交
75 | func (t *TraderApiLite) ReqQryTrade(pQryTrade *QryTradeField, nRequestID int) int {
76 | var f0 = toCThostFtdcQryTradeField(pQryTrade)
77 |
78 | return t.traderApi.ReqQryTrade((f0), int(nRequestID))
79 | }
80 |
81 | // 请求查询投资者持仓
82 | func (t *TraderApiLite) ReqQryInvestorPosition(pQryInvestorPosition *QryInvestorPositionField, nRequestID int) int {
83 | var f0 = toCThostFtdcQryInvestorPositionField(pQryInvestorPosition)
84 |
85 | return t.traderApi.ReqQryInvestorPosition((f0), int(nRequestID))
86 | }
87 |
88 | // 请求查询资金账户
89 | func (t *TraderApiLite) ReqQryTradingAccount(pQryTradingAccount *QryTradingAccountField, nRequestID int) int {
90 | var f0 = toCThostFtdcQryTradingAccountField(pQryTradingAccount)
91 |
92 | return t.traderApi.ReqQryTradingAccount((f0), int(nRequestID))
93 | }
94 |
95 | // 请求查询合约保证金率
96 | func (t *TraderApiLite) ReqQryInstrumentMarginRate(pQryInstrumentMarginRate *QryInstrumentMarginRateField, nRequestID int) int {
97 | var f0 = toCThostFtdcQryInstrumentMarginRateField(pQryInstrumentMarginRate)
98 |
99 | return t.traderApi.ReqQryInstrumentMarginRate((f0), int(nRequestID))
100 | }
101 |
102 | // 请求查询合约手续费率
103 | func (t *TraderApiLite) ReqQryInstrumentCommissionRate(pQryInstrumentCommissionRate *QryInstrumentCommissionRateField, nRequestID int) int {
104 | var f0 = toCThostFtdcQryInstrumentCommissionRateField(pQryInstrumentCommissionRate)
105 |
106 | return t.traderApi.ReqQryInstrumentCommissionRate((f0), int(nRequestID))
107 | }
108 |
109 | // 请求查询合约
110 | func (t *TraderApiLite) ReqQryInstrument(pQryInstrument *QryInstrumentField, nRequestID int) int {
111 | var f0 = toCThostFtdcQryInstrumentField(pQryInstrument)
112 |
113 | return t.traderApi.ReqQryInstrument((f0), int(nRequestID))
114 | }
115 |
116 | // 请求查询行情
117 | func (t *TraderApiLite) ReqQryDepthMarketData(pQryDepthMarketData *QryDepthMarketDataField, nRequestID int) int {
118 | var f0 = toCThostFtdcQryDepthMarketDataField(pQryDepthMarketData)
119 |
120 | return t.traderApi.ReqQryDepthMarketData((f0), int(nRequestID))
121 | }
122 |
123 | // 请求查询投资者结算结果
124 | func (t *TraderApiLite) ReqQrySettlementInfo(pQrySettlementInfo *QrySettlementInfoField, nRequestID int) int {
125 | var f0 = toCThostFtdcQrySettlementInfoField(pQrySettlementInfo)
126 |
127 | return t.traderApi.ReqQrySettlementInfo((f0), int(nRequestID))
128 | }
129 |
130 | // 请求查询结算信息确认
131 | func (t *TraderApiLite) ReqQrySettlementInfoConfirm(pQrySettlementInfoConfirm *QrySettlementInfoConfirmField, nRequestID int) int {
132 | var f0 = toCThostFtdcQrySettlementInfoConfirmField(pQrySettlementInfoConfirm)
133 |
134 | return t.traderApi.ReqQrySettlementInfoConfirm((f0), int(nRequestID))
135 | }
136 |
137 | // 请求查询转帐流水
138 | func (t *TraderApiLite) ReqQryTransferSerial(pQryTransferSerial *QryTransferSerialField, nRequestID int) int {
139 | var f0 = toCThostFtdcQryTransferSerialField(pQryTransferSerial)
140 |
141 | return t.traderApi.ReqQryTransferSerial((f0), int(nRequestID))
142 | }
143 |
144 | // 请求查询银期签约关系
145 | func (t *TraderApiLite) ReqQryAccountregister(pQryAccountregister *QryAccountregisterField, nRequestID int) int {
146 | var f0 = toCThostFtdcQryAccountregisterField(pQryAccountregister)
147 |
148 | return t.traderApi.ReqQryAccountregister((f0), int(nRequestID))
149 | }
150 |
151 | // 请求查询签约银行
152 | func (t *TraderApiLite) ReqQryContractBank(pQryContractBank *QryContractBankField, nRequestID int) int {
153 | var f0 = toCThostFtdcQryContractBankField(pQryContractBank)
154 |
155 | return t.traderApi.ReqQryContractBank((f0), int(nRequestID))
156 | }
157 |
158 | // 请求查询经纪公司交易参数
159 | func (t *TraderApiLite) ReqQryBrokerTradingParams(pQryBrokerTradingParams *QryBrokerTradingParamsField, nRequestID int) int {
160 | var f0 = toCThostFtdcQryBrokerTradingParamsField(pQryBrokerTradingParams)
161 |
162 | return t.traderApi.ReqQryBrokerTradingParams((f0), int(nRequestID))
163 | }
164 |
165 | // 期货发起银行资金转期货请求
166 | func (t *TraderApiLite) ReqFromBankToFutureByFuture(pReqTransfer *ReqTransferField, nRequestID int) int {
167 | var f0 = toCThostFtdcReqTransferField(pReqTransfer)
168 |
169 | return t.traderApi.ReqFromBankToFutureByFuture((f0), int(nRequestID))
170 | }
171 |
172 | // 期货发起期货资金转银行请求
173 | func (t *TraderApiLite) ReqFromFutureToBankByFuture(pReqTransfer *ReqTransferField, nRequestID int) int {
174 | var f0 = toCThostFtdcReqTransferField(pReqTransfer)
175 |
176 | return t.traderApi.ReqFromFutureToBankByFuture((f0), int(nRequestID))
177 | }
178 |
179 | type TraderSpiLite struct {
180 | BaseTraderSpi
181 |
182 | //当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。
183 | OnFrontConnectedCallback func()
184 |
185 | //当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。
186 | ///@param nReason 错误原因
187 | /// 0x1001 网络读失败
188 | /// 0x1002 网络写失败
189 | /// 0x2001 接收心跳超时
190 | /// 0x2002 发送心跳失败
191 | /// 0x2003 收到错误报文
192 | OnFrontDisconnectedCallback func(nReason int)
193 |
194 | //心跳超时警告。当长时间未收到报文时,该方法被调用。
195 | ///@param nTimeLapse 距离上次接收报文的时间
196 | OnHeartBeatWarningCallback func(nTimeLapse int)
197 |
198 | //客户端认证响应
199 | OnRspAuthenticateCallback func(pRspAuthenticateField *RspAuthenticateField, pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
200 |
201 | //登录请求响应
202 | OnRspUserLoginCallback func(pRspUserLogin *RspUserLoginField, pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
203 |
204 | //用户口令更新请求响应
205 | OnRspUserPasswordUpdateCallback func(pUserPasswordUpdate *UserPasswordUpdateField, pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
206 |
207 | //资金账户口令更新请求响应
208 | OnRspTradingAccountPasswordUpdateCallback func(pTradingAccountPasswordUpdate *TradingAccountPasswordUpdateField, pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
209 |
210 | //报单录入请求响应
211 | OnRspOrderInsertCallback func(pInputOrder *InputOrderField, pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
212 |
213 | //报单操作请求响应
214 | OnRspOrderActionCallback func(pInputOrderAction *InputOrderActionField, pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
215 |
216 | //投资者结算结果确认响应
217 | OnRspSettlementInfoConfirmCallback func(pSettlementInfoConfirm *SettlementInfoConfirmField, pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
218 |
219 | //请求查询报单响应
220 | OnRspQryOrderCallback func(pOrder *OrderField, pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
221 |
222 | //请求查询投资者持仓响应
223 | OnRspQryInvestorPositionCallback func(pInvestorPosition *InvestorPositionField, pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
224 |
225 | //请求查询资金账户响应
226 | OnRspQryTradingAccountCallback func(pTradingAccount *TradingAccountField, pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
227 |
228 | //请求查询合约保证金率响应
229 | OnRspQryInstrumentMarginRateCallback func(pInstrumentMarginRate *InstrumentMarginRateField, pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
230 |
231 | //请求查询合约手续费率响应
232 | OnRspQryInstrumentCommissionRateCallback func(pInstrumentCommissionRate *InstrumentCommissionRateField, pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
233 |
234 | //请求查询合约响应
235 | OnRspQryInstrumentCallback func(pInstrument *InstrumentField, pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
236 |
237 | //请求查询行情响应
238 | OnRspQryDepthMarketDataCallback func(pDepthMarketData *DepthMarketDataField, pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
239 |
240 | //请求查询投资者结算结果响应
241 | OnRspQrySettlementInfoCallback func(pSettlementInfo *SettlementInfoField, pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
242 |
243 | //请求查询转帐流水响应
244 | OnRspQryTransferSerialCallback func(pTransferSerial *TransferSerialField, pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
245 |
246 | //请求查询银期签约关系响应
247 | OnRspQryAccountregisterCallback func(pAccountregister *AccountregisterField, pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
248 |
249 | //错误应答
250 | OnRspErrorCallback func(pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
251 |
252 | //报单通知
253 | OnRtnOrderCallback func(pOrder *OrderField)
254 |
255 | //成交通知
256 | OnRtnTradeCallback func(pTrade *TradeField)
257 |
258 | //报单录入错误回报
259 | OnErrRtnOrderInsertCallback func(pInputOrder *InputOrderField, pRspInfo *RspInfoField)
260 |
261 | //报单操作错误回报
262 | OnErrRtnOrderActionCallback func(pOrderAction *OrderActionField, pRspInfo *RspInfoField)
263 |
264 | //合约交易状态通知
265 | OnRtnInstrumentStatusCallback func(pInstrumentStatus *InstrumentStatusField)
266 |
267 | //交易通知
268 | OnRtnTradingNoticeCallback func(pTradingNoticeInfo *TradingNoticeInfoField)
269 |
270 | //请求查询签约银行响应
271 | OnRspQryContractBankCallback func(pContractBank *ContractBankField, pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
272 |
273 | //请求查询经纪公司交易参数响应
274 | OnRspQryBrokerTradingParamsCallback func(pBrokerTradingParams *BrokerTradingParamsField, pRspInfo *RspInfoField, nRequestID int, bIsLast bool)
275 |
276 | //期货发起银行资金转期货通知
277 | OnRtnFromBankToFutureByFutureCallback func(pRspTransfer *RspTransferField)
278 |
279 | //期货发起期货资金转银行通知
280 | OnRtnFromFutureToBankByFutureCallback func(pRspTransfer *RspTransferField)
281 | }
282 |
283 | // 当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。
284 | func (s *TraderSpiLite) OnFrontConnected() {
285 |
286 | if s.OnFrontConnectedCallback != nil {
287 | s.OnFrontConnectedCallback()
288 | }
289 | }
290 |
291 | // 当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。
292 | // /@param nReason 错误原因
293 | // / 0x1001 网络读失败
294 | // / 0x1002 网络写失败
295 | // / 0x2001 接收心跳超时
296 | // / 0x2002 发送心跳失败
297 | // / 0x2003 收到错误报文
298 | func (s *TraderSpiLite) OnFrontDisconnected(nReason int) {
299 |
300 | if s.OnFrontDisconnectedCallback != nil {
301 | s.OnFrontDisconnectedCallback(int(nReason))
302 | }
303 | }
304 |
305 | // 心跳超时警告。当长时间未收到报文时,该方法被调用。
306 | // /@param nTimeLapse 距离上次接收报文的时间
307 | func (s *TraderSpiLite) OnHeartBeatWarning(nTimeLapse int) {
308 |
309 | if s.OnHeartBeatWarningCallback != nil {
310 | s.OnHeartBeatWarningCallback(int(nTimeLapse))
311 | }
312 | }
313 |
314 | // 客户端认证响应
315 | func (s *TraderSpiLite) OnRspAuthenticate(pRspAuthenticateField *thost.CThostFtdcRspAuthenticateField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
316 |
317 | var f0 *RspAuthenticateField
318 | if pRspAuthenticateField != nil {
319 | f0 = fromCThostFtdcRspAuthenticateField(pRspAuthenticateField)
320 | }
321 |
322 | var f1 *RspInfoField
323 | if pRspInfo != nil {
324 | f1 = fromCThostFtdcRspInfoField(pRspInfo)
325 | }
326 |
327 | if s.OnRspAuthenticateCallback != nil {
328 | s.OnRspAuthenticateCallback((f0), (f1), int(nRequestID), bool(bIsLast))
329 | }
330 | }
331 |
332 | // 登录请求响应
333 | func (s *TraderSpiLite) OnRspUserLogin(pRspUserLogin *thost.CThostFtdcRspUserLoginField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
334 |
335 | var f0 *RspUserLoginField
336 | if pRspUserLogin != nil {
337 | f0 = fromCThostFtdcRspUserLoginField(pRspUserLogin)
338 | }
339 |
340 | var f1 *RspInfoField
341 | if pRspInfo != nil {
342 | f1 = fromCThostFtdcRspInfoField(pRspInfo)
343 | }
344 |
345 | if s.OnRspUserLoginCallback != nil {
346 | s.OnRspUserLoginCallback((f0), (f1), int(nRequestID), bool(bIsLast))
347 | }
348 | }
349 |
350 | // 用户口令更新请求响应
351 | func (s *TraderSpiLite) OnRspUserPasswordUpdate(pUserPasswordUpdate *thost.CThostFtdcUserPasswordUpdateField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
352 |
353 | var f0 *UserPasswordUpdateField
354 | if pUserPasswordUpdate != nil {
355 | f0 = fromCThostFtdcUserPasswordUpdateField(pUserPasswordUpdate)
356 | }
357 |
358 | var f1 *RspInfoField
359 | if pRspInfo != nil {
360 | f1 = fromCThostFtdcRspInfoField(pRspInfo)
361 | }
362 |
363 | if s.OnRspUserPasswordUpdateCallback != nil {
364 | s.OnRspUserPasswordUpdateCallback((f0), (f1), int(nRequestID), bool(bIsLast))
365 | }
366 | }
367 |
368 | // 资金账户口令更新请求响应
369 | func (s *TraderSpiLite) OnRspTradingAccountPasswordUpdate(pTradingAccountPasswordUpdate *thost.CThostFtdcTradingAccountPasswordUpdateField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
370 |
371 | var f0 *TradingAccountPasswordUpdateField
372 | if pTradingAccountPasswordUpdate != nil {
373 | f0 = fromCThostFtdcTradingAccountPasswordUpdateField(pTradingAccountPasswordUpdate)
374 | }
375 |
376 | var f1 *RspInfoField
377 | if pRspInfo != nil {
378 | f1 = fromCThostFtdcRspInfoField(pRspInfo)
379 | }
380 |
381 | if s.OnRspTradingAccountPasswordUpdateCallback != nil {
382 | s.OnRspTradingAccountPasswordUpdateCallback((f0), (f1), int(nRequestID), bool(bIsLast))
383 | }
384 | }
385 |
386 | // 报单录入请求响应
387 | func (s *TraderSpiLite) OnRspOrderInsert(pInputOrder *thost.CThostFtdcInputOrderField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
388 |
389 | var f0 *InputOrderField
390 | if pInputOrder != nil {
391 | f0 = fromCThostFtdcInputOrderField(pInputOrder)
392 | }
393 |
394 | var f1 *RspInfoField
395 | if pRspInfo != nil {
396 | f1 = fromCThostFtdcRspInfoField(pRspInfo)
397 | }
398 |
399 | if s.OnRspOrderInsertCallback != nil {
400 | s.OnRspOrderInsertCallback((f0), (f1), int(nRequestID), bool(bIsLast))
401 | }
402 | }
403 |
404 | // 报单操作请求响应
405 | func (s *TraderSpiLite) OnRspOrderAction(pInputOrderAction *thost.CThostFtdcInputOrderActionField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
406 |
407 | var f0 *InputOrderActionField
408 | if pInputOrderAction != nil {
409 | f0 = fromCThostFtdcInputOrderActionField(pInputOrderAction)
410 | }
411 |
412 | var f1 *RspInfoField
413 | if pRspInfo != nil {
414 | f1 = fromCThostFtdcRspInfoField(pRspInfo)
415 | }
416 |
417 | if s.OnRspOrderActionCallback != nil {
418 | s.OnRspOrderActionCallback((f0), (f1), int(nRequestID), bool(bIsLast))
419 | }
420 | }
421 |
422 | // 投资者结算结果确认响应
423 | func (s *TraderSpiLite) OnRspSettlementInfoConfirm(pSettlementInfoConfirm *thost.CThostFtdcSettlementInfoConfirmField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
424 |
425 | var f0 *SettlementInfoConfirmField
426 | if pSettlementInfoConfirm != nil {
427 | f0 = fromCThostFtdcSettlementInfoConfirmField(pSettlementInfoConfirm)
428 | }
429 |
430 | var f1 *RspInfoField
431 | if pRspInfo != nil {
432 | f1 = fromCThostFtdcRspInfoField(pRspInfo)
433 | }
434 |
435 | if s.OnRspSettlementInfoConfirmCallback != nil {
436 | s.OnRspSettlementInfoConfirmCallback((f0), (f1), int(nRequestID), bool(bIsLast))
437 | }
438 | }
439 |
440 | // 请求查询报单响应
441 | func (s *TraderSpiLite) OnRspQryOrder(pOrder *thost.CThostFtdcOrderField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
442 |
443 | var f0 *OrderField
444 | if pOrder != nil {
445 | f0 = fromCThostFtdcOrderField(pOrder)
446 | }
447 |
448 | var f1 *RspInfoField
449 | if pRspInfo != nil {
450 | f1 = fromCThostFtdcRspInfoField(pRspInfo)
451 | }
452 |
453 | if s.OnRspQryOrderCallback != nil {
454 | s.OnRspQryOrderCallback((f0), (f1), int(nRequestID), bool(bIsLast))
455 | }
456 | }
457 |
458 | // 请求查询投资者持仓响应
459 | func (s *TraderSpiLite) OnRspQryInvestorPosition(pInvestorPosition *thost.CThostFtdcInvestorPositionField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
460 |
461 | var f0 *InvestorPositionField
462 | if pInvestorPosition != nil {
463 | f0 = fromCThostFtdcInvestorPositionField(pInvestorPosition)
464 | }
465 |
466 | var f1 *RspInfoField
467 | if pRspInfo != nil {
468 | f1 = fromCThostFtdcRspInfoField(pRspInfo)
469 | }
470 |
471 | if s.OnRspQryInvestorPositionCallback != nil {
472 | s.OnRspQryInvestorPositionCallback((f0), (f1), int(nRequestID), bool(bIsLast))
473 | }
474 | }
475 |
476 | // 请求查询资金账户响应
477 | func (s *TraderSpiLite) OnRspQryTradingAccount(pTradingAccount *thost.CThostFtdcTradingAccountField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
478 |
479 | var f0 *TradingAccountField
480 | if pTradingAccount != nil {
481 | f0 = fromCThostFtdcTradingAccountField(pTradingAccount)
482 | }
483 |
484 | var f1 *RspInfoField
485 | if pRspInfo != nil {
486 | f1 = fromCThostFtdcRspInfoField(pRspInfo)
487 | }
488 |
489 | if s.OnRspQryTradingAccountCallback != nil {
490 | s.OnRspQryTradingAccountCallback((f0), (f1), int(nRequestID), bool(bIsLast))
491 | }
492 | }
493 |
494 | // 请求查询合约保证金率响应
495 | func (s *TraderSpiLite) OnRspQryInstrumentMarginRate(pInstrumentMarginRate *thost.CThostFtdcInstrumentMarginRateField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
496 |
497 | var f0 *InstrumentMarginRateField
498 | if pInstrumentMarginRate != nil {
499 | f0 = fromCThostFtdcInstrumentMarginRateField(pInstrumentMarginRate)
500 | }
501 |
502 | var f1 *RspInfoField
503 | if pRspInfo != nil {
504 | f1 = fromCThostFtdcRspInfoField(pRspInfo)
505 | }
506 |
507 | if s.OnRspQryInstrumentMarginRateCallback != nil {
508 | s.OnRspQryInstrumentMarginRateCallback((f0), (f1), int(nRequestID), bool(bIsLast))
509 | }
510 | }
511 |
512 | // 请求查询合约手续费率响应
513 | func (s *TraderSpiLite) OnRspQryInstrumentCommissionRate(pInstrumentCommissionRate *thost.CThostFtdcInstrumentCommissionRateField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
514 |
515 | var f0 *InstrumentCommissionRateField
516 | if pInstrumentCommissionRate != nil {
517 | f0 = fromCThostFtdcInstrumentCommissionRateField(pInstrumentCommissionRate)
518 | }
519 |
520 | var f1 *RspInfoField
521 | if pRspInfo != nil {
522 | f1 = fromCThostFtdcRspInfoField(pRspInfo)
523 | }
524 |
525 | if s.OnRspQryInstrumentCommissionRateCallback != nil {
526 | s.OnRspQryInstrumentCommissionRateCallback((f0), (f1), int(nRequestID), bool(bIsLast))
527 | }
528 | }
529 |
530 | // 请求查询合约响应
531 | func (s *TraderSpiLite) OnRspQryInstrument(pInstrument *thost.CThostFtdcInstrumentField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
532 |
533 | var f0 *InstrumentField
534 | if pInstrument != nil {
535 | f0 = fromCThostFtdcInstrumentField(pInstrument)
536 | }
537 |
538 | var f1 *RspInfoField
539 | if pRspInfo != nil {
540 | f1 = fromCThostFtdcRspInfoField(pRspInfo)
541 | }
542 |
543 | if s.OnRspQryInstrumentCallback != nil {
544 | s.OnRspQryInstrumentCallback((f0), (f1), int(nRequestID), bool(bIsLast))
545 | }
546 | }
547 |
548 | // 请求查询行情响应
549 | func (s *TraderSpiLite) OnRspQryDepthMarketData(pDepthMarketData *thost.CThostFtdcDepthMarketDataField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
550 |
551 | var f0 *DepthMarketDataField
552 | if pDepthMarketData != nil {
553 | f0 = fromCThostFtdcDepthMarketDataField(pDepthMarketData)
554 | }
555 |
556 | var f1 *RspInfoField
557 | if pRspInfo != nil {
558 | f1 = fromCThostFtdcRspInfoField(pRspInfo)
559 | }
560 |
561 | if s.OnRspQryDepthMarketDataCallback != nil {
562 | s.OnRspQryDepthMarketDataCallback((f0), (f1), int(nRequestID), bool(bIsLast))
563 | }
564 | }
565 |
566 | // 请求查询投资者结算结果响应
567 | func (s *TraderSpiLite) OnRspQrySettlementInfo(pSettlementInfo *thost.CThostFtdcSettlementInfoField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
568 |
569 | var f0 *SettlementInfoField
570 | if pSettlementInfo != nil {
571 | f0 = fromCThostFtdcSettlementInfoField(pSettlementInfo)
572 | }
573 |
574 | var f1 *RspInfoField
575 | if pRspInfo != nil {
576 | f1 = fromCThostFtdcRspInfoField(pRspInfo)
577 | }
578 |
579 | if s.OnRspQrySettlementInfoCallback != nil {
580 | s.OnRspQrySettlementInfoCallback((f0), (f1), int(nRequestID), bool(bIsLast))
581 | }
582 | }
583 |
584 | // 请求查询转帐流水响应
585 | func (s *TraderSpiLite) OnRspQryTransferSerial(pTransferSerial *thost.CThostFtdcTransferSerialField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
586 |
587 | var f0 *TransferSerialField
588 | if pTransferSerial != nil {
589 | f0 = fromCThostFtdcTransferSerialField(pTransferSerial)
590 | }
591 |
592 | var f1 *RspInfoField
593 | if pRspInfo != nil {
594 | f1 = fromCThostFtdcRspInfoField(pRspInfo)
595 | }
596 |
597 | if s.OnRspQryTransferSerialCallback != nil {
598 | s.OnRspQryTransferSerialCallback((f0), (f1), int(nRequestID), bool(bIsLast))
599 | }
600 | }
601 |
602 | // 请求查询银期签约关系响应
603 | func (s *TraderSpiLite) OnRspQryAccountregister(pAccountregister *thost.CThostFtdcAccountregisterField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
604 |
605 | var f0 *AccountregisterField
606 | if pAccountregister != nil {
607 | f0 = fromCThostFtdcAccountregisterField(pAccountregister)
608 | }
609 |
610 | var f1 *RspInfoField
611 | if pRspInfo != nil {
612 | f1 = fromCThostFtdcRspInfoField(pRspInfo)
613 | }
614 |
615 | if s.OnRspQryAccountregisterCallback != nil {
616 | s.OnRspQryAccountregisterCallback((f0), (f1), int(nRequestID), bool(bIsLast))
617 | }
618 | }
619 |
620 | // 错误应答
621 | func (s *TraderSpiLite) OnRspError(pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
622 |
623 | var f0 *RspInfoField
624 | if pRspInfo != nil {
625 | f0 = fromCThostFtdcRspInfoField(pRspInfo)
626 | }
627 |
628 | if s.OnRspErrorCallback != nil {
629 | s.OnRspErrorCallback((f0), int(nRequestID), bool(bIsLast))
630 | }
631 | }
632 |
633 | // 报单通知
634 | func (s *TraderSpiLite) OnRtnOrder(pOrder *thost.CThostFtdcOrderField) {
635 |
636 | var f0 *OrderField
637 | if pOrder != nil {
638 | f0 = fromCThostFtdcOrderField(pOrder)
639 | }
640 |
641 | if s.OnRtnOrderCallback != nil {
642 | s.OnRtnOrderCallback((f0))
643 | }
644 | }
645 |
646 | // 成交通知
647 | func (s *TraderSpiLite) OnRtnTrade(pTrade *thost.CThostFtdcTradeField) {
648 |
649 | var f0 *TradeField
650 | if pTrade != nil {
651 | f0 = fromCThostFtdcTradeField(pTrade)
652 | }
653 |
654 | if s.OnRtnTradeCallback != nil {
655 | s.OnRtnTradeCallback((f0))
656 | }
657 | }
658 |
659 | // 报单录入错误回报
660 | func (s *TraderSpiLite) OnErrRtnOrderInsert(pInputOrder *thost.CThostFtdcInputOrderField, pRspInfo *thost.CThostFtdcRspInfoField) {
661 |
662 | var f0 *InputOrderField
663 | if pInputOrder != nil {
664 | f0 = fromCThostFtdcInputOrderField(pInputOrder)
665 | }
666 |
667 | var f1 *RspInfoField
668 | if pRspInfo != nil {
669 | f1 = fromCThostFtdcRspInfoField(pRspInfo)
670 | }
671 |
672 | if s.OnErrRtnOrderInsertCallback != nil {
673 | s.OnErrRtnOrderInsertCallback((f0), (f1))
674 | }
675 | }
676 |
677 | // 报单操作错误回报
678 | func (s *TraderSpiLite) OnErrRtnOrderAction(pOrderAction *thost.CThostFtdcOrderActionField, pRspInfo *thost.CThostFtdcRspInfoField) {
679 |
680 | var f0 *OrderActionField
681 | if pOrderAction != nil {
682 | f0 = fromCThostFtdcOrderActionField(pOrderAction)
683 | }
684 |
685 | var f1 *RspInfoField
686 | if pRspInfo != nil {
687 | f1 = fromCThostFtdcRspInfoField(pRspInfo)
688 | }
689 |
690 | if s.OnErrRtnOrderActionCallback != nil {
691 | s.OnErrRtnOrderActionCallback((f0), (f1))
692 | }
693 | }
694 |
695 | // 合约交易状态通知
696 | func (s *TraderSpiLite) OnRtnInstrumentStatus(pInstrumentStatus *thost.CThostFtdcInstrumentStatusField) {
697 |
698 | var f0 *InstrumentStatusField
699 | if pInstrumentStatus != nil {
700 | f0 = fromCThostFtdcInstrumentStatusField(pInstrumentStatus)
701 | }
702 |
703 | if s.OnRtnInstrumentStatusCallback != nil {
704 | s.OnRtnInstrumentStatusCallback((f0))
705 | }
706 | }
707 |
708 | // 交易通知
709 | func (s *TraderSpiLite) OnRtnTradingNotice(pTradingNoticeInfo *thost.CThostFtdcTradingNoticeInfoField) {
710 |
711 | var f0 *TradingNoticeInfoField
712 | if pTradingNoticeInfo != nil {
713 | f0 = fromCThostFtdcTradingNoticeInfoField(pTradingNoticeInfo)
714 | }
715 |
716 | if s.OnRtnTradingNoticeCallback != nil {
717 | s.OnRtnTradingNoticeCallback((f0))
718 | }
719 | }
720 |
721 | // 请求查询签约银行响应
722 | func (s *TraderSpiLite) OnRspQryContractBank(pContractBank *thost.CThostFtdcContractBankField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
723 |
724 | var f0 *ContractBankField
725 | if pContractBank != nil {
726 | f0 = fromCThostFtdcContractBankField(pContractBank)
727 | }
728 |
729 | var f1 *RspInfoField
730 | if pRspInfo != nil {
731 | f1 = fromCThostFtdcRspInfoField(pRspInfo)
732 | }
733 |
734 | if s.OnRspQryContractBankCallback != nil {
735 | s.OnRspQryContractBankCallback((f0), (f1), int(nRequestID), bool(bIsLast))
736 | }
737 | }
738 |
739 | // 请求查询经纪公司交易参数响应
740 | func (s *TraderSpiLite) OnRspQryBrokerTradingParams(pBrokerTradingParams *thost.CThostFtdcBrokerTradingParamsField, pRspInfo *thost.CThostFtdcRspInfoField, nRequestID int, bIsLast bool) {
741 |
742 | var f0 *BrokerTradingParamsField
743 | if pBrokerTradingParams != nil {
744 | f0 = fromCThostFtdcBrokerTradingParamsField(pBrokerTradingParams)
745 | }
746 |
747 | var f1 *RspInfoField
748 | if pRspInfo != nil {
749 | f1 = fromCThostFtdcRspInfoField(pRspInfo)
750 | }
751 |
752 | if s.OnRspQryBrokerTradingParamsCallback != nil {
753 | s.OnRspQryBrokerTradingParamsCallback((f0), (f1), int(nRequestID), bool(bIsLast))
754 | }
755 | }
756 |
757 | // 期货发起银行资金转期货通知
758 | func (s *TraderSpiLite) OnRtnFromBankToFutureByFuture(pRspTransfer *thost.CThostFtdcRspTransferField) {
759 |
760 | var f0 *RspTransferField
761 | if pRspTransfer != nil {
762 | f0 = fromCThostFtdcRspTransferField(pRspTransfer)
763 | }
764 |
765 | if s.OnRtnFromBankToFutureByFutureCallback != nil {
766 | s.OnRtnFromBankToFutureByFutureCallback((f0))
767 | }
768 | }
769 |
770 | // 期货发起期货资金转银行通知
771 | func (s *TraderSpiLite) OnRtnFromFutureToBankByFuture(pRspTransfer *thost.CThostFtdcRspTransferField) {
772 |
773 | var f0 *RspTransferField
774 | if pRspTransfer != nil {
775 | f0 = fromCThostFtdcRspTransferField(pRspTransfer)
776 | }
777 |
778 | if s.OnRtnFromFutureToBankByFutureCallback != nil {
779 | s.OnRtnFromFutureToBankByFutureCallback((f0))
780 | }
781 | }
782 |
783 | func (s *TraderSpiLite) SetOnFrontConnected(f func()) {
784 | s.OnFrontConnectedCallback = f
785 | }
786 |
787 | func (s *TraderSpiLite) SetOnFrontDisconnected(f func(int)) {
788 | s.OnFrontDisconnectedCallback = f
789 | }
790 |
791 | func (s *TraderSpiLite) SetOnHeartBeatWarning(f func(int)) {
792 | s.OnHeartBeatWarningCallback = f
793 | }
794 |
795 | func (s *TraderSpiLite) SetOnRspAuthenticate(f func(*RspAuthenticateField, *RspInfoField, int, bool)) {
796 | s.OnRspAuthenticateCallback = f
797 | }
798 |
799 | func (s *TraderSpiLite) SetOnRspUserLogin(f func(*RspUserLoginField, *RspInfoField, int, bool)) {
800 | s.OnRspUserLoginCallback = f
801 | }
802 |
803 | func (s *TraderSpiLite) SetOnRspUserPasswordUpdate(f func(*UserPasswordUpdateField, *RspInfoField, int, bool)) {
804 | s.OnRspUserPasswordUpdateCallback = f
805 | }
806 |
807 | func (s *TraderSpiLite) SetOnRspTradingAccountPasswordUpdate(f func(*TradingAccountPasswordUpdateField, *RspInfoField, int, bool)) {
808 | s.OnRspTradingAccountPasswordUpdateCallback = f
809 | }
810 |
811 | func (s *TraderSpiLite) SetOnRspOrderInsert(f func(*InputOrderField, *RspInfoField, int, bool)) {
812 | s.OnRspOrderInsertCallback = f
813 | }
814 |
815 | func (s *TraderSpiLite) SetOnRspOrderAction(f func(*InputOrderActionField, *RspInfoField, int, bool)) {
816 | s.OnRspOrderActionCallback = f
817 | }
818 |
819 | func (s *TraderSpiLite) SetOnRspSettlementInfoConfirm(f func(*SettlementInfoConfirmField, *RspInfoField, int, bool)) {
820 | s.OnRspSettlementInfoConfirmCallback = f
821 | }
822 |
823 | func (s *TraderSpiLite) SetOnRspQryOrder(f func(*OrderField, *RspInfoField, int, bool)) {
824 | s.OnRspQryOrderCallback = f
825 | }
826 |
827 | func (s *TraderSpiLite) SetOnRspQryInvestorPosition(f func(*InvestorPositionField, *RspInfoField, int, bool)) {
828 | s.OnRspQryInvestorPositionCallback = f
829 | }
830 |
831 | func (s *TraderSpiLite) SetOnRspQryTradingAccount(f func(*TradingAccountField, *RspInfoField, int, bool)) {
832 | s.OnRspQryTradingAccountCallback = f
833 | }
834 |
835 | func (s *TraderSpiLite) SetOnRspQryInstrumentMarginRate(f func(*InstrumentMarginRateField, *RspInfoField, int, bool)) {
836 | s.OnRspQryInstrumentMarginRateCallback = f
837 | }
838 |
839 | func (s *TraderSpiLite) SetOnRspQryInstrumentCommissionRate(f func(*InstrumentCommissionRateField, *RspInfoField, int, bool)) {
840 | s.OnRspQryInstrumentCommissionRateCallback = f
841 | }
842 |
843 | func (s *TraderSpiLite) SetOnRspQryInstrument(f func(*InstrumentField, *RspInfoField, int, bool)) {
844 | s.OnRspQryInstrumentCallback = f
845 | }
846 |
847 | func (s *TraderSpiLite) SetOnRspQryDepthMarketData(f func(*DepthMarketDataField, *RspInfoField, int, bool)) {
848 | s.OnRspQryDepthMarketDataCallback = f
849 | }
850 |
851 | func (s *TraderSpiLite) SetOnRspQrySettlementInfo(f func(*SettlementInfoField, *RspInfoField, int, bool)) {
852 | s.OnRspQrySettlementInfoCallback = f
853 | }
854 |
855 | func (s *TraderSpiLite) SetOnRspQryTransferSerial(f func(*TransferSerialField, *RspInfoField, int, bool)) {
856 | s.OnRspQryTransferSerialCallback = f
857 | }
858 |
859 | func (s *TraderSpiLite) SetOnRspQryAccountregister(f func(*AccountregisterField, *RspInfoField, int, bool)) {
860 | s.OnRspQryAccountregisterCallback = f
861 | }
862 |
863 | func (s *TraderSpiLite) SetOnRspError(f func(*RspInfoField, int, bool)) {
864 | s.OnRspErrorCallback = f
865 | }
866 |
867 | func (s *TraderSpiLite) SetOnRtnOrder(f func(*OrderField)) {
868 | s.OnRtnOrderCallback = f
869 | }
870 |
871 | func (s *TraderSpiLite) SetOnRtnTrade(f func(*TradeField)) {
872 | s.OnRtnTradeCallback = f
873 | }
874 |
875 | func (s *TraderSpiLite) SetOnErrRtnOrderInsert(f func(*InputOrderField, *RspInfoField)) {
876 | s.OnErrRtnOrderInsertCallback = f
877 | }
878 |
879 | func (s *TraderSpiLite) SetOnErrRtnOrderAction(f func(*OrderActionField, *RspInfoField)) {
880 | s.OnErrRtnOrderActionCallback = f
881 | }
882 |
883 | func (s *TraderSpiLite) SetOnRtnInstrumentStatus(f func(*InstrumentStatusField)) {
884 | s.OnRtnInstrumentStatusCallback = f
885 | }
886 |
887 | func (s *TraderSpiLite) SetOnRtnTradingNotice(f func(*TradingNoticeInfoField)) {
888 | s.OnRtnTradingNoticeCallback = f
889 | }
890 |
891 | func (s *TraderSpiLite) SetOnRspQryContractBank(f func(*ContractBankField, *RspInfoField, int, bool)) {
892 | s.OnRspQryContractBankCallback = f
893 | }
894 |
895 | func (s *TraderSpiLite) SetOnRspQryBrokerTradingParams(f func(*BrokerTradingParamsField, *RspInfoField, int, bool)) {
896 | s.OnRspQryBrokerTradingParamsCallback = f
897 | }
898 |
899 | func (s *TraderSpiLite) SetOnRtnFromBankToFutureByFuture(f func(*RspTransferField)) {
900 | s.OnRtnFromBankToFutureByFutureCallback = f
901 | }
902 |
903 | func (s *TraderSpiLite) SetOnRtnFromFutureToBankByFuture(f func(*RspTransferField)) {
904 | s.OnRtnFromFutureToBankByFutureCallback = f
905 | }
906 |
--------------------------------------------------------------------------------
/types.go:
--------------------------------------------------------------------------------
1 | // Licensed under the Apache License, Version 2.0 (the "License");
2 | // you may not use this file except in compliance with the License.
3 | // You may obtain a copy of the License at
4 | //
5 | // http://www.apache.org/licenses/LICENSE-2.0
6 | //
7 | // Unless required by applicable law or agreed to in writing, software
8 | // distributed under the License is distributed on an "AS IS" BASIS,
9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | // See the License for the specific language governing permissions and
11 | // limitations under the License.
12 |
13 | package goctp
14 |
15 | // 响应信息
16 | type RspInfoField struct {
17 | ///错误代码
18 | ErrorID int32
19 | ///错误信息
20 | ErrorMsg string
21 | }
22 |
23 | // 合约状态
24 | type InstrumentStatusField struct {
25 | ///交易所代码
26 | ExchangeID string
27 | ///保留的无效字段
28 | reserve1 string
29 | ///结算组代码
30 | SettlementGroupID string
31 | ///保留的无效字段
32 | reserve2 string
33 | ///合约交易状态
34 | InstrumentStatus byte
35 | ///交易阶段编号
36 | TradingSegmentSN int
37 | ///进入本状态时间
38 | EnterTime string
39 | ///进入本状态原因
40 | EnterReason byte
41 | ///合约在交易所的代码
42 | ExchangeInstID string
43 | ///合约代码
44 | InstrumentID string
45 | }
46 |
47 | // 查询合约保证金率
48 | type QryInstrumentMarginRateField struct {
49 | ///经纪公司代码
50 | BrokerID string
51 | ///投资者代码
52 | InvestorID string
53 | ///保留的无效字段
54 | reserve1 string
55 | ///投机套保标志
56 | HedgeFlag byte
57 | ///交易所代码
58 | ExchangeID string
59 | ///投资单元代码
60 | InvestUnitID string
61 | ///合约代码
62 | InstrumentID string
63 | }
64 |
65 | // 查询签约银行响应
66 | type ContractBankField struct {
67 | ///经纪公司代码
68 | BrokerID string
69 | ///银行代码
70 | BankID string
71 | ///银行分中心代码
72 | BankBrchID string
73 | ///银行名称
74 | BankName string
75 | }
76 |
77 | // 查询投资者持仓
78 | type QryInvestorPositionField struct {
79 | ///经纪公司代码
80 | BrokerID string
81 | ///投资者代码
82 | InvestorID string
83 | ///保留的无效字段
84 | reserve1 string
85 | ///交易所代码
86 | ExchangeID string
87 | ///投资单元代码
88 | InvestUnitID string
89 | ///合约代码
90 | InstrumentID string
91 | }
92 |
93 | // 查询结算信息确认域
94 | type QrySettlementInfoConfirmField struct {
95 | ///经纪公司代码
96 | BrokerID string
97 | ///投资者代码
98 | InvestorID string
99 | ///投资者帐号
100 | AccountID string
101 | ///币种代码
102 | CurrencyID string
103 | }
104 |
105 | // 银期转账交易流水表
106 | type TransferSerialField struct {
107 | ///平台流水号
108 | PlateSerial int
109 | ///交易发起方日期
110 | TradeDate string
111 | ///交易日期
112 | TradingDay string
113 | ///交易时间
114 | TradeTime string
115 | ///交易代码
116 | TradeCode string
117 | ///会话编号
118 | SessionID int
119 | ///银行编码
120 | BankID string
121 | ///银行分支机构编码
122 | BankBranchID string
123 | ///银行帐号类型
124 | BankAccType byte
125 | ///银行帐号
126 | BankAccount string
127 | ///银行流水号
128 | BankSerial string
129 | ///期货公司编码
130 | BrokerID string
131 | ///期商分支机构代码
132 | BrokerBranchID string
133 | ///期货公司帐号类型
134 | FutureAccType byte
135 | ///投资者帐号
136 | AccountID string
137 | ///投资者代码
138 | InvestorID string
139 | ///期货公司流水号
140 | FutureSerial int
141 | ///证件类型
142 | IdCardType byte
143 | ///证件号码
144 | IdentifiedCardNo string
145 | ///币种代码
146 | CurrencyID string
147 | ///交易金额
148 | TradeAmount float64
149 | ///应收客户费用
150 | CustFee float64
151 | ///应收期货公司费用
152 | BrokerFee float64
153 | ///有效标志
154 | AvailabilityFlag byte
155 | ///操作员
156 | OperatorCode string
157 | ///新银行帐号
158 | BankNewAccount string
159 | ///错误代码
160 | ErrorID int
161 | ///错误信息
162 | ErrorMsg string
163 | }
164 |
165 | // 投资者结算结果确认信息
166 | type SettlementInfoConfirmField struct {
167 | ///经纪公司代码
168 | BrokerID string
169 | ///投资者代码
170 | InvestorID string
171 | ///确认日期
172 | ConfirmDate string
173 | ///确认时间
174 | ConfirmTime string
175 | ///结算编号
176 | SettlementID int
177 | ///投资者帐号
178 | AccountID string
179 | ///币种代码
180 | CurrencyID string
181 | }
182 |
183 | // 资金账户口令变更域
184 | type TradingAccountPasswordUpdateField struct {
185 | ///经纪公司代码
186 | BrokerID string
187 | ///投资者帐号
188 | AccountID string
189 | ///原来的口令
190 | OldPassword string
191 | ///新的口令
192 | NewPassword string
193 | ///币种代码
194 | CurrencyID string
195 | }
196 |
197 | // 经纪公司交易参数
198 | type BrokerTradingParamsField struct {
199 | ///经纪公司代码
200 | BrokerID string
201 | ///投资者代码
202 | InvestorID string
203 | ///保证金价格类型
204 | MarginPriceType byte
205 | ///盈亏算法
206 | Algorithm byte
207 | ///可用是否包含平仓盈利
208 | AvailIncludeCloseProfit byte
209 | ///币种代码
210 | CurrencyID string
211 | ///期权权利金价格类型
212 | OptionRoyaltyPriceType byte
213 | ///投资者帐号
214 | AccountID string
215 | }
216 |
217 | // 查询合约
218 | type QryInstrumentField struct {
219 | ///保留的无效字段
220 | reserve1 string
221 | ///交易所代码
222 | ExchangeID string
223 | ///保留的无效字段
224 | reserve2 string
225 | ///保留的无效字段
226 | reserve3 string
227 | ///合约代码
228 | InstrumentID string
229 | ///合约在交易所的代码
230 | ExchangeInstID string
231 | ///产品代码
232 | ProductID string
233 | }
234 |
235 | // 客户端认证请求
236 | type ReqAuthenticateField struct {
237 | ///经纪公司代码
238 | BrokerID string
239 | ///用户代码
240 | UserID string
241 | ///用户端产品信息
242 | UserProductInfo string
243 | ///认证码
244 | AuthCode string
245 | ///App代码
246 | AppID string
247 | }
248 |
249 | // 资金账户
250 | type TradingAccountField struct {
251 | ///经纪公司代码
252 | BrokerID string
253 | ///投资者帐号
254 | AccountID string
255 | ///上次质押金额
256 | PreMortgage float64
257 | ///上次信用额度
258 | PreCredit float64
259 | ///上次存款额
260 | PreDeposit float64
261 | ///上次结算准备金
262 | PreBalance float64
263 | ///上次占用的保证金
264 | PreMargin float64
265 | ///利息基数
266 | InterestBase float64
267 | ///利息收入
268 | Interest float64
269 | ///入金金额
270 | Deposit float64
271 | ///出金金额
272 | Withdraw float64
273 | ///冻结的保证金
274 | FrozenMargin float64
275 | ///冻结的资金
276 | FrozenCash float64
277 | ///冻结的手续费
278 | FrozenCommission float64
279 | ///当前保证金总额
280 | CurrMargin float64
281 | ///资金差额
282 | CashIn float64
283 | ///手续费
284 | Commission float64
285 | ///平仓盈亏
286 | CloseProfit float64
287 | ///持仓盈亏
288 | PositionProfit float64
289 | ///期货结算准备金
290 | Balance float64
291 | ///可用资金
292 | Available float64
293 | ///可取资金
294 | WithdrawQuota float64
295 | ///基本准备金
296 | Reserve float64
297 | ///交易日
298 | TradingDay string
299 | ///结算编号
300 | SettlementID int
301 | ///信用额度
302 | Credit float64
303 | ///质押金额
304 | Mortgage float64
305 | ///交易所保证金
306 | ExchangeMargin float64
307 | ///投资者交割保证金
308 | DeliveryMargin float64
309 | ///交易所交割保证金
310 | ExchangeDeliveryMargin float64
311 | ///保底期货结算准备金
312 | ReserveBalance float64
313 | ///币种代码
314 | CurrencyID string
315 | ///上次货币质入金额
316 | PreFundMortgageIn float64
317 | ///上次货币质出金额
318 | PreFundMortgageOut float64
319 | ///货币质入金额
320 | FundMortgageIn float64
321 | ///货币质出金额
322 | FundMortgageOut float64
323 | ///货币质押余额
324 | FundMortgageAvailable float64
325 | ///可质押货币金额
326 | MortgageableFund float64
327 | ///特殊产品占用保证金
328 | SpecProductMargin float64
329 | ///特殊产品冻结保证金
330 | SpecProductFrozenMargin float64
331 | ///特殊产品手续费
332 | SpecProductCommission float64
333 | ///特殊产品冻结手续费
334 | SpecProductFrozenCommission float64
335 | ///特殊产品持仓盈亏
336 | SpecProductPositionProfit float64
337 | ///特殊产品平仓盈亏
338 | SpecProductCloseProfit float64
339 | ///根据持仓盈亏算法计算的特殊产品持仓盈亏
340 | SpecProductPositionProfitByAlg float64
341 | ///特殊产品交易所保证金
342 | SpecProductExchangeMargin float64
343 | ///业务类型
344 | BizType byte
345 | ///延时换汇冻结金额
346 | FrozenSwap float64
347 | ///剩余换汇额度
348 | RemainSwap float64
349 | }
350 |
351 | // 输入报单操作
352 | type InputOrderActionField struct {
353 | ///经纪公司代码
354 | BrokerID string
355 | ///投资者代码
356 | InvestorID string
357 | ///报单操作引用
358 | OrderActionRef int
359 | ///报单引用
360 | OrderRef string
361 | ///请求编号
362 | RequestID int
363 | ///前置编号
364 | FrontID int
365 | ///会话编号
366 | SessionID int
367 | ///交易所代码
368 | ExchangeID string
369 | ///报单编号
370 | OrderSysID string
371 | ///操作标志
372 | ActionFlag byte
373 | ///价格
374 | LimitPrice float64
375 | ///数量变化
376 | VolumeChange int
377 | ///用户代码
378 | UserID string
379 | ///保留的无效字段
380 | reserve1 string
381 | ///投资单元代码
382 | InvestUnitID string
383 | ///保留的无效字段
384 | reserve2 string
385 | ///Mac地址
386 | MacAddress string
387 | ///合约代码
388 | InstrumentID string
389 | ///IP地址
390 | IPAddress string
391 | }
392 |
393 | // 请求查询转帐流水
394 | type QryTransferSerialField struct {
395 | ///经纪公司代码
396 | BrokerID string
397 | ///投资者帐号
398 | AccountID string
399 | ///银行编码
400 | BankID string
401 | ///币种代码
402 | CurrencyID string
403 | }
404 |
405 | // 查询报单
406 | type QryOrderField struct {
407 | ///经纪公司代码
408 | BrokerID string
409 | ///投资者代码
410 | InvestorID string
411 | ///保留的无效字段
412 | reserve1 string
413 | ///交易所代码
414 | ExchangeID string
415 | ///报单编号
416 | OrderSysID string
417 | ///开始时间
418 | InsertTimeStart string
419 | ///结束时间
420 | InsertTimeEnd string
421 | ///投资单元代码
422 | InvestUnitID string
423 | ///合约代码
424 | InstrumentID string
425 | }
426 |
427 | // 投资者结算结果
428 | type SettlementInfoField struct {
429 | ///交易日
430 | TradingDay string
431 | ///结算编号
432 | SettlementID int
433 | ///经纪公司代码
434 | BrokerID string
435 | ///投资者代码
436 | InvestorID string
437 | ///序号
438 | SequenceNo int
439 | ///消息正文
440 | Content string
441 | ///投资者帐号
442 | AccountID string
443 | ///币种代码
444 | CurrencyID string
445 | }
446 |
447 | // 深度行情
448 | type DepthMarketDataField struct {
449 | ///交易日
450 | TradingDay string
451 | ///保留的无效字段
452 | reserve1 string
453 | ///交易所代码
454 | ExchangeID string
455 | ///保留的无效字段
456 | reserve2 string
457 | ///最新价
458 | LastPrice float64
459 | ///上次结算价
460 | PreSettlementPrice float64
461 | ///昨收盘
462 | PreClosePrice float64
463 | ///昨持仓量
464 | PreOpenInterest float64
465 | ///今开盘
466 | OpenPrice float64
467 | ///最高价
468 | HighestPrice float64
469 | ///最低价
470 | LowestPrice float64
471 | ///数量
472 | Volume int
473 | ///成交金额
474 | Turnover float64
475 | ///持仓量
476 | OpenInterest float64
477 | ///今收盘
478 | ClosePrice float64
479 | ///本次结算价
480 | SettlementPrice float64
481 | ///涨停板价
482 | UpperLimitPrice float64
483 | ///跌停板价
484 | LowerLimitPrice float64
485 | ///昨虚实度
486 | PreDelta float64
487 | ///今虚实度
488 | CurrDelta float64
489 | ///最后修改时间
490 | UpdateTime string
491 | ///最后修改毫秒
492 | UpdateMillisec int
493 | ///申买价一
494 | BidPrice1 float64
495 | ///申买量一
496 | BidVolume1 int
497 | ///申卖价一
498 | AskPrice1 float64
499 | ///申卖量一
500 | AskVolume1 int
501 | ///申买价二
502 | BidPrice2 float64
503 | ///申买量二
504 | BidVolume2 int
505 | ///申卖价二
506 | AskPrice2 float64
507 | ///申卖量二
508 | AskVolume2 int
509 | ///申买价三
510 | BidPrice3 float64
511 | ///申买量三
512 | BidVolume3 int
513 | ///申卖价三
514 | AskPrice3 float64
515 | ///申卖量三
516 | AskVolume3 int
517 | ///申买价四
518 | BidPrice4 float64
519 | ///申买量四
520 | BidVolume4 int
521 | ///申卖价四
522 | AskPrice4 float64
523 | ///申卖量四
524 | AskVolume4 int
525 | ///申买价五
526 | BidPrice5 float64
527 | ///申买量五
528 | BidVolume5 int
529 | ///申卖价五
530 | AskPrice5 float64
531 | ///申卖量五
532 | AskVolume5 int
533 | ///当日均价
534 | AveragePrice float64
535 | ///业务日期
536 | ActionDay string
537 | ///合约代码
538 | InstrumentID string
539 | ///合约在交易所的代码
540 | ExchangeInstID string
541 | ///上带价
542 | BandingUpperPrice float64
543 | ///下带价
544 | BandingLowerPrice float64
545 | }
546 |
547 | // 合约手续费率
548 | type InstrumentCommissionRateField struct {
549 | ///保留的无效字段
550 | reserve1 string
551 | ///投资者范围
552 | InvestorRange byte
553 | ///经纪公司代码
554 | BrokerID string
555 | ///投资者代码
556 | InvestorID string
557 | ///开仓手续费率
558 | OpenRatioByMoney float64
559 | ///开仓手续费
560 | OpenRatioByVolume float64
561 | ///平仓手续费率
562 | CloseRatioByMoney float64
563 | ///平仓手续费
564 | CloseRatioByVolume float64
565 | ///平今手续费率
566 | CloseTodayRatioByMoney float64
567 | ///平今手续费
568 | CloseTodayRatioByVolume float64
569 | ///交易所代码
570 | ExchangeID string
571 | ///业务类型
572 | BizType byte
573 | ///投资单元代码
574 | InvestUnitID string
575 | ///合约代码
576 | InstrumentID string
577 | }
578 |
579 | // 输入报单
580 | type InputOrderField struct {
581 | ///经纪公司代码
582 | BrokerID string
583 | ///投资者代码
584 | InvestorID string
585 | ///保留的无效字段
586 | reserve1 string
587 | ///报单引用
588 | OrderRef string
589 | ///用户代码
590 | UserID string
591 | ///报单价格条件
592 | OrderPriceType byte
593 | ///买卖方向
594 | Direction byte
595 | ///组合开平标志
596 | CombOffsetFlag string
597 | ///组合投机套保标志
598 | CombHedgeFlag string
599 | ///价格
600 | LimitPrice float64
601 | ///数量
602 | VolumeTotalOriginal int
603 | ///有效期类型
604 | TimeCondition byte
605 | ///GTD日期
606 | GTDDate string
607 | ///成交量类型
608 | VolumeCondition byte
609 | ///最小成交量
610 | MinVolume int
611 | ///触发条件
612 | ContingentCondition byte
613 | ///止损价
614 | StopPrice float64
615 | ///强平原因
616 | ForceCloseReason byte
617 | ///自动挂起标志
618 | IsAutoSuspend int
619 | ///业务单元
620 | BusinessUnit string
621 | ///请求编号
622 | RequestID int
623 | ///用户强评标志
624 | UserForceClose int
625 | ///互换单标志
626 | IsSwapOrder int
627 | ///交易所代码
628 | ExchangeID string
629 | ///投资单元代码
630 | InvestUnitID string
631 | ///资金账号
632 | AccountID string
633 | ///币种代码
634 | CurrencyID string
635 | ///交易编码
636 | ClientID string
637 | ///保留的无效字段
638 | reserve2 string
639 | ///Mac地址
640 | MacAddress string
641 | ///合约代码
642 | InstrumentID string
643 | ///IP地址
644 | IPAddress string
645 | }
646 |
647 | // 成交
648 | type TradeField struct {
649 | ///经纪公司代码
650 | BrokerID string
651 | ///投资者代码
652 | InvestorID string
653 | ///保留的无效字段
654 | reserve1 string
655 | ///报单引用
656 | OrderRef string
657 | ///用户代码
658 | UserID string
659 | ///交易所代码
660 | ExchangeID string
661 | ///成交编号
662 | TradeID string
663 | ///买卖方向
664 | Direction byte
665 | ///报单编号
666 | OrderSysID string
667 | ///会员代码
668 | ParticipantID string
669 | ///客户代码
670 | ClientID string
671 | ///交易角色
672 | TradingRole byte
673 | ///保留的无效字段
674 | reserve2 string
675 | ///开平标志
676 | OffsetFlag byte
677 | ///投机套保标志
678 | HedgeFlag byte
679 | ///价格
680 | Price float64
681 | ///数量
682 | Volume int
683 | ///成交时期
684 | TradeDate string
685 | ///成交时间
686 | TradeTime string
687 | ///成交类型
688 | TradeType byte
689 | ///成交价来源
690 | PriceSource byte
691 | ///交易所交易员代码
692 | TraderID string
693 | ///本地报单编号
694 | OrderLocalID string
695 | ///结算会员编号
696 | ClearingPartID string
697 | ///业务单元
698 | BusinessUnit string
699 | ///序号
700 | SequenceNo int
701 | ///交易日
702 | TradingDay string
703 | ///结算编号
704 | SettlementID int
705 | ///经纪公司报单编号
706 | BrokerOrderSeq int
707 | ///成交来源
708 | TradeSource byte
709 | ///投资单元代码
710 | InvestUnitID string
711 | ///合约代码
712 | InstrumentID string
713 | ///合约在交易所的代码
714 | ExchangeInstID string
715 | }
716 |
717 | // 银行发起银行资金转期货响应
718 | type RspTransferField struct {
719 | ///业务功能码
720 | TradeCode string
721 | ///银行代码
722 | BankID string
723 | ///银行分支机构代码
724 | BankBranchID string
725 | ///期商代码
726 | BrokerID string
727 | ///期商分支机构代码
728 | BrokerBranchID string
729 | ///交易日期
730 | TradeDate string
731 | ///交易时间
732 | TradeTime string
733 | ///银行流水号
734 | BankSerial string
735 | ///交易系统日期
736 | TradingDay string
737 | ///银期平台消息流水号
738 | PlateSerial int
739 | ///最后分片标志
740 | LastFragment byte
741 | ///会话号
742 | SessionID int
743 | ///客户姓名
744 | CustomerName string
745 | ///证件类型
746 | IdCardType byte
747 | ///证件号码
748 | IdentifiedCardNo string
749 | ///客户类型
750 | CustType byte
751 | ///银行帐号
752 | BankAccount string
753 | ///银行密码
754 | BankPassWord string
755 | ///投资者帐号
756 | AccountID string
757 | ///期货密码
758 | Password string
759 | ///安装编号
760 | InstallID int
761 | ///期货公司流水号
762 | FutureSerial int
763 | ///用户标识
764 | UserID string
765 | ///验证客户证件号码标志
766 | VerifyCertNoFlag byte
767 | ///币种代码
768 | CurrencyID string
769 | ///转帐金额
770 | TradeAmount float64
771 | ///期货可取金额
772 | FutureFetchAmount float64
773 | ///费用支付标志
774 | FeePayFlag byte
775 | ///应收客户费用
776 | CustFee float64
777 | ///应收期货公司费用
778 | BrokerFee float64
779 | ///发送方给接收方的消息
780 | Message string
781 | ///摘要
782 | Digest string
783 | ///银行帐号类型
784 | BankAccType byte
785 | ///渠道标志
786 | DeviceID string
787 | ///期货单位帐号类型
788 | BankSecuAccType byte
789 | ///期货公司银行编码
790 | BrokerIDByBank string
791 | ///期货单位帐号
792 | BankSecuAcc string
793 | ///银行密码标志
794 | BankPwdFlag byte
795 | ///期货资金密码核对标志
796 | SecuPwdFlag byte
797 | ///交易柜员
798 | OperNo string
799 | ///请求编号
800 | RequestID int
801 | ///交易ID
802 | TID int
803 | ///转账交易状态
804 | TransferStatus byte
805 | ///错误代码
806 | ErrorID int
807 | ///错误信息
808 | ErrorMsg string
809 | ///长客户姓名
810 | LongCustomerName string
811 | }
812 |
813 | // 用户事件通知信息
814 | type TradingNoticeInfoField struct {
815 | ///经纪公司代码
816 | BrokerID string
817 | ///投资者代码
818 | InvestorID string
819 | ///发送时间
820 | SendTime string
821 | ///消息正文
822 | FieldContent string
823 | ///序列系列号
824 | SequenceSeries int16
825 | ///序列号
826 | SequenceNo int
827 | ///投资单元代码
828 | InvestUnitID string
829 | }
830 |
831 | // 投资者持仓
832 | type InvestorPositionField struct {
833 | ///保留的无效字段
834 | reserve1 string
835 | ///经纪公司代码
836 | BrokerID string
837 | ///投资者代码
838 | InvestorID string
839 | ///持仓多空方向
840 | PosiDirection byte
841 | ///投机套保标志
842 | HedgeFlag byte
843 | ///持仓日期
844 | PositionDate byte
845 | ///上日持仓
846 | YdPosition int
847 | ///今日持仓
848 | Position int
849 | ///多头冻结
850 | LongFrozen int
851 | ///空头冻结
852 | ShortFrozen int
853 | ///开仓冻结金额
854 | LongFrozenAmount float64
855 | ///开仓冻结金额
856 | ShortFrozenAmount float64
857 | ///开仓量
858 | OpenVolume int
859 | ///平仓量
860 | CloseVolume int
861 | ///开仓金额
862 | OpenAmount float64
863 | ///平仓金额
864 | CloseAmount float64
865 | ///持仓成本
866 | PositionCost float64
867 | ///上次占用的保证金
868 | PreMargin float64
869 | ///占用的保证金
870 | UseMargin float64
871 | ///冻结的保证金
872 | FrozenMargin float64
873 | ///冻结的资金
874 | FrozenCash float64
875 | ///冻结的手续费
876 | FrozenCommission float64
877 | ///资金差额
878 | CashIn float64
879 | ///手续费
880 | Commission float64
881 | ///平仓盈亏
882 | CloseProfit float64
883 | ///持仓盈亏
884 | PositionProfit float64
885 | ///上次结算价
886 | PreSettlementPrice float64
887 | ///本次结算价
888 | SettlementPrice float64
889 | ///交易日
890 | TradingDay string
891 | ///结算编号
892 | SettlementID int
893 | ///开仓成本
894 | OpenCost float64
895 | ///交易所保证金
896 | ExchangeMargin float64
897 | ///组合成交形成的持仓
898 | CombPosition int
899 | ///组合多头冻结
900 | CombLongFrozen int
901 | ///组合空头冻结
902 | CombShortFrozen int
903 | ///逐日盯市平仓盈亏
904 | CloseProfitByDate float64
905 | ///逐笔对冲平仓盈亏
906 | CloseProfitByTrade float64
907 | ///今日持仓
908 | TodayPosition int
909 | ///保证金率
910 | MarginRateByMoney float64
911 | ///保证金率(按手数)
912 | MarginRateByVolume float64
913 | ///执行冻结
914 | StrikeFrozen int
915 | ///执行冻结金额
916 | StrikeFrozenAmount float64
917 | ///放弃执行冻结
918 | AbandonFrozen int
919 | ///交易所代码
920 | ExchangeID string
921 | ///执行冻结的昨仓
922 | YdStrikeFrozen int
923 | ///投资单元代码
924 | InvestUnitID string
925 | ///大商所持仓成本差值,只有大商所使用
926 | PositionCostOffset float64
927 | ///tas持仓手数
928 | TasPosition int
929 | ///tas持仓成本
930 | TasPositionCost float64
931 | ///合约代码
932 | InstrumentID string
933 | }
934 |
935 | // 报单
936 | type OrderField struct {
937 | ///经纪公司代码
938 | BrokerID string
939 | ///投资者代码
940 | InvestorID string
941 | ///保留的无效字段
942 | reserve1 string
943 | ///报单引用
944 | OrderRef string
945 | ///用户代码
946 | UserID string
947 | ///报单价格条件
948 | OrderPriceType byte
949 | ///买卖方向
950 | Direction byte
951 | ///组合开平标志
952 | CombOffsetFlag string
953 | ///组合投机套保标志
954 | CombHedgeFlag string
955 | ///价格
956 | LimitPrice float64
957 | ///数量
958 | VolumeTotalOriginal int
959 | ///有效期类型
960 | TimeCondition byte
961 | ///GTD日期
962 | GTDDate string
963 | ///成交量类型
964 | VolumeCondition byte
965 | ///最小成交量
966 | MinVolume int
967 | ///触发条件
968 | ContingentCondition byte
969 | ///止损价
970 | StopPrice float64
971 | ///强平原因
972 | ForceCloseReason byte
973 | ///自动挂起标志
974 | IsAutoSuspend int
975 | ///业务单元
976 | BusinessUnit string
977 | ///请求编号
978 | RequestID int
979 | ///本地报单编号
980 | OrderLocalID string
981 | ///交易所代码
982 | ExchangeID string
983 | ///会员代码
984 | ParticipantID string
985 | ///客户代码
986 | ClientID string
987 | ///保留的无效字段
988 | reserve2 string
989 | ///交易所交易员代码
990 | TraderID string
991 | ///安装编号
992 | InstallID int
993 | ///报单提交状态
994 | OrderSubmitStatus byte
995 | ///报单提示序号
996 | NotifySequence int
997 | ///交易日
998 | TradingDay string
999 | ///结算编号
1000 | SettlementID int
1001 | ///报单编号
1002 | OrderSysID string
1003 | ///报单来源
1004 | OrderSource byte
1005 | ///报单状态
1006 | OrderStatus byte
1007 | ///报单类型
1008 | OrderType byte
1009 | ///今成交数量
1010 | VolumeTraded int
1011 | ///剩余数量
1012 | VolumeTotal int
1013 | ///报单日期
1014 | InsertDate string
1015 | ///委托时间
1016 | InsertTime string
1017 | ///激活时间
1018 | ActiveTime string
1019 | ///挂起时间
1020 | SuspendTime string
1021 | ///最后修改时间
1022 | UpdateTime string
1023 | ///撤销时间
1024 | CancelTime string
1025 | ///最后修改交易所交易员代码
1026 | ActiveTraderID string
1027 | ///结算会员编号
1028 | ClearingPartID string
1029 | ///序号
1030 | SequenceNo int
1031 | ///前置编号
1032 | FrontID int
1033 | ///会话编号
1034 | SessionID int
1035 | ///用户端产品信息
1036 | UserProductInfo string
1037 | ///状态信息
1038 | StatusMsg string
1039 | ///用户强评标志
1040 | UserForceClose int
1041 | ///操作用户代码
1042 | ActiveUserID string
1043 | ///经纪公司报单编号
1044 | BrokerOrderSeq int
1045 | ///相关报单
1046 | RelativeOrderSysID string
1047 | ///郑商所成交数量
1048 | ZCETotalTradedVolume int
1049 | ///互换单标志
1050 | IsSwapOrder int
1051 | ///营业部编号
1052 | BranchID string
1053 | ///投资单元代码
1054 | InvestUnitID string
1055 | ///资金账号
1056 | AccountID string
1057 | ///币种代码
1058 | CurrencyID string
1059 | ///保留的无效字段
1060 | reserve3 string
1061 | ///Mac地址
1062 | MacAddress string
1063 | ///合约代码
1064 | InstrumentID string
1065 | ///合约在交易所的代码
1066 | ExchangeInstID string
1067 | ///IP地址
1068 | IPAddress string
1069 | }
1070 |
1071 | // 客户开销户信息表
1072 | type AccountregisterField struct {
1073 | ///交易日期
1074 | TradeDay string
1075 | ///银行编码
1076 | BankID string
1077 | ///银行分支机构编码
1078 | BankBranchID string
1079 | ///银行帐号
1080 | BankAccount string
1081 | ///期货公司编码
1082 | BrokerID string
1083 | ///期货公司分支机构编码
1084 | BrokerBranchID string
1085 | ///投资者帐号
1086 | AccountID string
1087 | ///证件类型
1088 | IdCardType byte
1089 | ///证件号码
1090 | IdentifiedCardNo string
1091 | ///客户姓名
1092 | CustomerName string
1093 | ///币种代码
1094 | CurrencyID string
1095 | ///开销户类别
1096 | OpenOrDestroy byte
1097 | ///签约日期
1098 | RegDate string
1099 | ///解约日期
1100 | OutDate string
1101 | ///交易ID
1102 | TID int
1103 | ///客户类型
1104 | CustType byte
1105 | ///银行帐号类型
1106 | BankAccType byte
1107 | ///长客户姓名
1108 | LongCustomerName string
1109 | }
1110 |
1111 | // 合约保证金率
1112 | type InstrumentMarginRateField struct {
1113 | ///保留的无效字段
1114 | reserve1 string
1115 | ///投资者范围
1116 | InvestorRange byte
1117 | ///经纪公司代码
1118 | BrokerID string
1119 | ///投资者代码
1120 | InvestorID string
1121 | ///投机套保标志
1122 | HedgeFlag byte
1123 | ///多头保证金率
1124 | LongMarginRatioByMoney float64
1125 | ///多头保证金费
1126 | LongMarginRatioByVolume float64
1127 | ///空头保证金率
1128 | ShortMarginRatioByMoney float64
1129 | ///空头保证金费
1130 | ShortMarginRatioByVolume float64
1131 | ///是否相对交易所收取
1132 | IsRelative int
1133 | ///交易所代码
1134 | ExchangeID string
1135 | ///投资单元代码
1136 | InvestUnitID string
1137 | ///合约代码
1138 | InstrumentID string
1139 | }
1140 |
1141 | // 查询资金账户
1142 | type QryTradingAccountField struct {
1143 | ///经纪公司代码
1144 | BrokerID string
1145 | ///投资者代码
1146 | InvestorID string
1147 | ///币种代码
1148 | CurrencyID string
1149 | ///业务类型
1150 | BizType byte
1151 | ///投资者帐号
1152 | AccountID string
1153 | }
1154 |
1155 | // 请求查询银期签约关系
1156 | type QryAccountregisterField struct {
1157 | ///经纪公司代码
1158 | BrokerID string
1159 | ///投资者帐号
1160 | AccountID string
1161 | ///银行编码
1162 | BankID string
1163 | ///银行分支机构编码
1164 | BankBranchID string
1165 | ///币种代码
1166 | CurrencyID string
1167 | }
1168 |
1169 | // 查询投资者结算结果
1170 | type QrySettlementInfoField struct {
1171 | ///经纪公司代码
1172 | BrokerID string
1173 | ///投资者代码
1174 | InvestorID string
1175 | ///交易日
1176 | TradingDay string
1177 | ///投资者帐号
1178 | AccountID string
1179 | ///币种代码
1180 | CurrencyID string
1181 | }
1182 |
1183 | // 用户登录请求
1184 | type ReqUserLoginField struct {
1185 | ///交易日
1186 | TradingDay string
1187 | ///经纪公司代码
1188 | BrokerID string
1189 | ///用户代码
1190 | UserID string
1191 | ///密码
1192 | Password string
1193 | ///用户端产品信息
1194 | UserProductInfo string
1195 | ///接口端产品信息
1196 | InterfaceProductInfo string
1197 | ///协议信息
1198 | ProtocolInfo string
1199 | ///Mac地址
1200 | MacAddress string
1201 | ///动态密码
1202 | OneTimePassword string
1203 | ///保留的无效字段
1204 | reserve1 string
1205 | ///登录备注
1206 | LoginRemark string
1207 | ///终端IP端口
1208 | ClientIPPort int
1209 | ///终端IP地址
1210 | ClientIPAddress string
1211 | }
1212 |
1213 | // 查询经纪公司交易参数
1214 | type QryBrokerTradingParamsField struct {
1215 | ///经纪公司代码
1216 | BrokerID string
1217 | ///投资者代码
1218 | InvestorID string
1219 | ///币种代码
1220 | CurrencyID string
1221 | ///投资者帐号
1222 | AccountID string
1223 | }
1224 |
1225 | // 查询签约银行请求
1226 | type QryContractBankField struct {
1227 | ///经纪公司代码
1228 | BrokerID string
1229 | ///银行代码
1230 | BankID string
1231 | ///银行分中心代码
1232 | BankBrchID string
1233 | }
1234 |
1235 | // 用户口令变更
1236 | type UserPasswordUpdateField struct {
1237 | ///经纪公司代码
1238 | BrokerID string
1239 | ///用户代码
1240 | UserID string
1241 | ///原来的口令
1242 | OldPassword string
1243 | ///新的口令
1244 | NewPassword string
1245 | }
1246 |
1247 | // 用户登录应答
1248 | type RspUserLoginField struct {
1249 | ///交易日
1250 | TradingDay string
1251 | ///登录成功时间
1252 | LoginTime string
1253 | ///经纪公司代码
1254 | BrokerID string
1255 | ///用户代码
1256 | UserID string
1257 | ///交易系统名称
1258 | SystemName string
1259 | ///前置编号
1260 | FrontID int
1261 | ///会话编号
1262 | SessionID int
1263 | ///最大报单引用
1264 | MaxOrderRef string
1265 | ///上期所时间
1266 | SHFETime string
1267 | ///大商所时间
1268 | DCETime string
1269 | ///郑商所时间
1270 | CZCETime string
1271 | ///中金所时间
1272 | FFEXTime string
1273 | ///能源中心时间
1274 | INETime string
1275 | }
1276 |
1277 | // 合约
1278 | type InstrumentField struct {
1279 | ///保留的无效字段
1280 | reserve1 string
1281 | ///交易所代码
1282 | ExchangeID string
1283 | ///合约名称
1284 | InstrumentName string
1285 | ///保留的无效字段
1286 | reserve2 string
1287 | ///保留的无效字段
1288 | reserve3 string
1289 | ///产品类型
1290 | ProductClass byte
1291 | ///交割年份
1292 | DeliveryYear int
1293 | ///交割月
1294 | DeliveryMonth int
1295 | ///市价单最大下单量
1296 | MaxMarketOrderVolume int
1297 | ///市价单最小下单量
1298 | MinMarketOrderVolume int
1299 | ///限价单最大下单量
1300 | MaxLimitOrderVolume int
1301 | ///限价单最小下单量
1302 | MinLimitOrderVolume int
1303 | ///合约数量乘数
1304 | VolumeMultiple int
1305 | ///最小变动价位
1306 | PriceTick float64
1307 | ///创建日
1308 | CreateDate string
1309 | ///上市日
1310 | OpenDate string
1311 | ///到期日
1312 | ExpireDate string
1313 | ///开始交割日
1314 | StartDelivDate string
1315 | ///结束交割日
1316 | EndDelivDate string
1317 | ///合约生命周期状态
1318 | InstLifePhase byte
1319 | ///当前是否交易
1320 | IsTrading int
1321 | ///持仓类型
1322 | PositionType byte
1323 | ///持仓日期类型
1324 | PositionDateType byte
1325 | ///多头保证金率
1326 | LongMarginRatio float64
1327 | ///空头保证金率
1328 | ShortMarginRatio float64
1329 | ///是否使用大额单边保证金算法
1330 | MaxMarginSideAlgorithm byte
1331 | ///保留的无效字段
1332 | reserve4 string
1333 | ///执行价
1334 | StrikePrice float64
1335 | ///期权类型
1336 | OptionsType byte
1337 | ///合约基础商品乘数
1338 | UnderlyingMultiple float64
1339 | ///组合类型
1340 | CombinationType byte
1341 | ///合约代码
1342 | InstrumentID string
1343 | ///合约在交易所的代码
1344 | ExchangeInstID string
1345 | ///产品代码
1346 | ProductID string
1347 | ///基础商品代码
1348 | UnderlyingInstrID string
1349 | }
1350 |
1351 | // 报单操作
1352 | type OrderActionField struct {
1353 | ///经纪公司代码
1354 | BrokerID string
1355 | ///投资者代码
1356 | InvestorID string
1357 | ///报单操作引用
1358 | OrderActionRef int
1359 | ///报单引用
1360 | OrderRef string
1361 | ///请求编号
1362 | RequestID int
1363 | ///前置编号
1364 | FrontID int
1365 | ///会话编号
1366 | SessionID int
1367 | ///交易所代码
1368 | ExchangeID string
1369 | ///报单编号
1370 | OrderSysID string
1371 | ///操作标志
1372 | ActionFlag byte
1373 | ///价格
1374 | LimitPrice float64
1375 | ///数量变化
1376 | VolumeChange int
1377 | ///操作日期
1378 | ActionDate string
1379 | ///操作时间
1380 | ActionTime string
1381 | ///交易所交易员代码
1382 | TraderID string
1383 | ///安装编号
1384 | InstallID int
1385 | ///本地报单编号
1386 | OrderLocalID string
1387 | ///操作本地编号
1388 | ActionLocalID string
1389 | ///会员代码
1390 | ParticipantID string
1391 | ///客户代码
1392 | ClientID string
1393 | ///业务单元
1394 | BusinessUnit string
1395 | ///报单操作状态
1396 | OrderActionStatus byte
1397 | ///用户代码
1398 | UserID string
1399 | ///状态信息
1400 | StatusMsg string
1401 | ///保留的无效字段
1402 | reserve1 string
1403 | ///营业部编号
1404 | BranchID string
1405 | ///投资单元代码
1406 | InvestUnitID string
1407 | ///保留的无效字段
1408 | reserve2 string
1409 | ///Mac地址
1410 | MacAddress string
1411 | ///合约代码
1412 | InstrumentID string
1413 | ///IP地址
1414 | IPAddress string
1415 | }
1416 |
1417 | // 转账请求
1418 | type ReqTransferField struct {
1419 | ///业务功能码
1420 | TradeCode string
1421 | ///银行代码
1422 | BankID string
1423 | ///银行分支机构代码
1424 | BankBranchID string
1425 | ///期商代码
1426 | BrokerID string
1427 | ///期商分支机构代码
1428 | BrokerBranchID string
1429 | ///交易日期
1430 | TradeDate string
1431 | ///交易时间
1432 | TradeTime string
1433 | ///银行流水号
1434 | BankSerial string
1435 | ///交易系统日期
1436 | TradingDay string
1437 | ///银期平台消息流水号
1438 | PlateSerial int
1439 | ///最后分片标志
1440 | LastFragment byte
1441 | ///会话号
1442 | SessionID int
1443 | ///客户姓名
1444 | CustomerName string
1445 | ///证件类型
1446 | IdCardType byte
1447 | ///证件号码
1448 | IdentifiedCardNo string
1449 | ///客户类型
1450 | CustType byte
1451 | ///银行帐号
1452 | BankAccount string
1453 | ///银行密码
1454 | BankPassWord string
1455 | ///投资者帐号
1456 | AccountID string
1457 | ///期货密码
1458 | Password string
1459 | ///安装编号
1460 | InstallID int
1461 | ///期货公司流水号
1462 | FutureSerial int
1463 | ///用户标识
1464 | UserID string
1465 | ///验证客户证件号码标志
1466 | VerifyCertNoFlag byte
1467 | ///币种代码
1468 | CurrencyID string
1469 | ///转帐金额
1470 | TradeAmount float64
1471 | ///期货可取金额
1472 | FutureFetchAmount float64
1473 | ///费用支付标志
1474 | FeePayFlag byte
1475 | ///应收客户费用
1476 | CustFee float64
1477 | ///应收期货公司费用
1478 | BrokerFee float64
1479 | ///发送方给接收方的消息
1480 | Message string
1481 | ///摘要
1482 | Digest string
1483 | ///银行帐号类型
1484 | BankAccType byte
1485 | ///渠道标志
1486 | DeviceID string
1487 | ///期货单位帐号类型
1488 | BankSecuAccType byte
1489 | ///期货公司银行编码
1490 | BrokerIDByBank string
1491 | ///期货单位帐号
1492 | BankSecuAcc string
1493 | ///银行密码标志
1494 | BankPwdFlag byte
1495 | ///期货资金密码核对标志
1496 | SecuPwdFlag byte
1497 | ///交易柜员
1498 | OperNo string
1499 | ///请求编号
1500 | RequestID int
1501 | ///交易ID
1502 | TID int
1503 | ///转账交易状态
1504 | TransferStatus byte
1505 | ///长客户姓名
1506 | LongCustomerName string
1507 | }
1508 |
1509 | // 客户端认证响应
1510 | type RspAuthenticateField struct {
1511 | ///经纪公司代码
1512 | BrokerID string
1513 | ///用户代码
1514 | UserID string
1515 | ///用户端产品信息
1516 | UserProductInfo string
1517 | ///App代码
1518 | AppID string
1519 | ///App类型
1520 | AppType byte
1521 | }
1522 |
1523 | // 查询手续费率
1524 | type QryInstrumentCommissionRateField struct {
1525 | ///经纪公司代码
1526 | BrokerID string
1527 | ///投资者代码
1528 | InvestorID string
1529 | ///保留的无效字段
1530 | reserve1 string
1531 | ///交易所代码
1532 | ExchangeID string
1533 | ///投资单元代码
1534 | InvestUnitID string
1535 | ///合约代码
1536 | InstrumentID string
1537 | }
1538 |
1539 | // 查询成交
1540 | type QryTradeField struct {
1541 | ///经纪公司代码
1542 | BrokerID string
1543 | ///投资者代码
1544 | InvestorID string
1545 | ///保留的无效字段
1546 | reserve1 string
1547 | ///交易所代码
1548 | ExchangeID string
1549 | ///成交编号
1550 | TradeID string
1551 | ///开始时间
1552 | TradeTimeStart string
1553 | ///结束时间
1554 | TradeTimeEnd string
1555 | ///投资单元代码
1556 | InvestUnitID string
1557 | ///合约代码
1558 | InstrumentID string
1559 | }
1560 |
1561 | // 查询行情
1562 | type QryDepthMarketDataField struct {
1563 | ///保留的无效字段
1564 | reserve1 string
1565 | ///交易所代码
1566 | ExchangeID string
1567 | ///合约代码
1568 | InstrumentID string
1569 | }
1570 |
--------------------------------------------------------------------------------