-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathConnection.h
85 lines (70 loc) · 2.26 KB
/
Connection.h
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
/*****************************************************************************
File name: Connection.cpp
Description: Defined connection struct for operate CTP
Author: jebin
Date: 2014/07/10
History: see git log
*****************************************************************************/
#ifndef CONNECTION_H
#define CONNECTION_H
#include "MdUserApi.h"
#include "TraderApi.h"
using namespace std;
//定义连接结构
class Connection
{
public:
Connection()
{
msgQueue = new CTPMsgQueue();
callbackSet = new FunctionCallBackSet();
msgQueue->RegisterCallback(callbackSet);
md = new MdUserApi();
md->RegisterMsgQueue(msgQueue);
td = new TraderApi();
td->RegisterMsgQueue(msgQueue);
msgQueue->StartThread();
}
~Connection()
{
msgQueue->StopThread();
msgQueue->Clear();
td->Disconnect();
md->Disconnect();
delete td;
delete md;
delete callbackSet;
delete msgQueue;
}
//读取配置信息
void readInifile(const char* file, const char *servername)
{
GetPrivateProfileStringA(servername, "path", "", tmp, sizeof(tmp), file);
streamPath = tmp;
GetPrivateProfileStringA(servername, "mdserver", "", tmp, sizeof(tmp), file);
mdServer = tmp;
GetPrivateProfileStringA(servername, "tdserver", "", tmp, sizeof(tmp), file);
tdServer = tmp;
GetPrivateProfileStringA(servername, "brokerid", "", tmp, sizeof(tmp), file);
brokerId = tmp;
GetPrivateProfileStringA(servername, "investorid", "", tmp, sizeof(tmp), file);
investorId = tmp;
GetPrivateProfileStringA(servername, "password", "", tmp, sizeof(tmp), file);
password = tmp;
GetPrivateProfileStringA(servername, "instrument", "", tmp, sizeof(tmp), file);
instrumentId = tmp;
}
char tmp[105];
CTPMsgQueue *msgQueue;//回报消息队列
FunctionCallBackSet *callbackSet;//实时回调信息
MdUserApi *md;//行情连接口
TraderApi *td;//交易连接口
string streamPath;//数据流路径
string mdServer;//行情服务器
string tdServer;//交易服务器
string brokerId;//期商ID
string investorId;//投资者ID
string password;//投资者密码
string instrumentId;//合约名
};
#endif