-
Notifications
You must be signed in to change notification settings - Fork 239
Expand file tree
/
Copy pathXApiC.cpp
More file actions
217 lines (171 loc) · 5.51 KB
/
XApiC.cpp
File metadata and controls
217 lines (171 loc) · 5.51 KB
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
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include "../include/XApiC.h"
#include "../include/QueueHeader.h"
#include "../include/QueueEnum.h"
#if defined WINDOWS || WIN32
#include <libloaderapi.h>
#else
#include <dlfcn.h>
#include <errno.h>
#endif
void* X_LoadLib(char* libPath)
{
if (libPath == nullptr)
return nullptr;
#if defined WINDOWS || WIN32
return LoadLibraryExA(libPath, nullptr, LOAD_WITH_ALTERED_SEARCH_PATH);
#else
return dlopen(libPath, RTLD_NOW);
#endif
}
char* X_GetLastError()
{
#if defined WINDOWS || WIN32
char szBuf[256] = {0};
LPVOID lpMsgBuf;
DWORD dw = GetLastError();
FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&lpMsgBuf,
0, NULL);
return (char*)lpMsgBuf;
#else
extern int errno;
errno = 0;
return dlerror();
#endif
}
void* X_GetFunction(void* lib,char* ProcName)
{
if (lib == nullptr)
return nullptr;
#if defined WINDOWS || WIN32
return GetProcAddress((HMODULE)lib, ProcName);
#else
return (dlsym(lib, ProcName));
#endif
}
void X_FreeLib(void* lib)
{
if (lib == nullptr)
return;
#if defined WINDOWS || WIN32
FreeLibrary((HMODULE)lib);
#else
dlclose(lib);
#endif
}
ApiType X_GetApiType(void* pFun)
{
if (pFun == nullptr)
return ApiType::Nono;
void* p = ((fnOnRespone)pFun)(RequestType::GetApiType, nullptr, nullptr, 0, 0, nullptr, 0, nullptr, 0, nullptr, 0);
return (ApiType)(char)(long long)(p);
}
char* X_GetApiVersion(void* pFun)
{
if (pFun == nullptr)
return nullptr;
return (char*)((fnOnRespone)pFun)(RequestType::GetApiVersion, nullptr, nullptr, 0, 0, nullptr, 0, nullptr, 0, nullptr, 0);
}
char* X_GetApiName(void* pFun)
{
if (pFun == nullptr)
return nullptr;
return (char*)((fnOnRespone)pFun)(RequestType::GetApiName, nullptr, nullptr, 0, 0, nullptr, 0, nullptr, 0, nullptr, 0);
}
void* X_Create(void* pFun)
{
if (pFun == nullptr)
return nullptr;
return ((fnOnRespone)pFun)(RequestType::Create, nullptr, nullptr, 0, 0, nullptr, 0, nullptr, 0, nullptr, 0);
}
void X_Register(void* pFun, void* pApi, void* pCallback, void* pClass)
{
if (pFun == nullptr || pApi == nullptr)
return;
((fnOnRespone)pFun)(RequestType::Register, pApi, nullptr, 0, 0, pCallback, 0, pClass, 0, nullptr, 0);
}
void X_Connect(void* pFun, void* pApi, char* szPath, ServerInfoField* pServerInfo, UserInfoField* pUserInfo, int count)
{
if (pFun == nullptr || pApi == nullptr)
return;
((fnOnRespone)pFun)(RequestType::Connect, pApi, nullptr, 0, 0, pServerInfo, 0, pUserInfo, count, szPath, 0);
}
void X_Disconnect(void* pFun, void* pApi)
{
if (pFun == nullptr || pApi == nullptr)
return;
((fnOnRespone)pFun)(RequestType::Disconnect, pApi, nullptr, 0, 0, nullptr, 0, nullptr, 0, nullptr, 0);
}
void X_Subscribe(void* pFun, void* pApi, char* szInstrument, char* szExchange)
{
if (pFun == nullptr || pApi == nullptr)
return;
((fnOnRespone)pFun)(RequestType::Subscribe, pApi, nullptr, 0, 0, szInstrument, 0, szExchange, 0, nullptr, 0);
}
void X_Unsubscribe(void* pFun, void* pApi, char* szInstrument, char* szExchange)
{
if (pFun == nullptr || pApi == nullptr)
return;
((fnOnRespone)pFun)(RequestType::Unsubscribe, pApi, nullptr, 0, 0, szInstrument, 0, szExchange, 0, nullptr, 0);
}
void X_SubscribeQuote(void* pFun, void* pApi, char* szInstrument, char* szExchange)
{
if (pFun == nullptr || pApi == nullptr)
return;
((fnOnRespone)pFun)(RequestType::SubscribeQuote, pApi, nullptr, 0, 0, szInstrument, 0, szExchange, 0, nullptr, 0);
}
void X_UnsubscribeQuote(void* pFun, void* pApi, char* szInstrument, char* szExchange)
{
if (pFun == nullptr || pApi == nullptr)
return;
((fnOnRespone)pFun)(RequestType::UnsubscribeQuote, pApi, nullptr, 0, 0, szInstrument, 0, szExchange, 0, nullptr, 0);
}
void X_ReqQryInstrument(void* pFun, void* pApi, char* szInstrument, char* szExchange)
{
if (pFun == nullptr || pApi == nullptr)
return;
((fnOnRespone)pFun)(RequestType::ReqQryInstrument, pApi, nullptr, 0, 0, szInstrument, 0, szExchange, 0, nullptr, 0);
}
void X_ReqQryInvestorPosition(void* pFun, void* pApi, char* szInstrument, char* szExchange)
{
if (pFun == nullptr || pApi == nullptr)
return;
((fnOnRespone)pFun)(RequestType::ReqQryInvestorPosition, pApi, nullptr, 0, 0, szInstrument, 0, szExchange, 0, nullptr, 0);
}
void X_ReqQryTradingAccount(void* pFun, void* pApi)
{
if (pFun == nullptr || pApi == nullptr)
return;
((fnOnRespone)pFun)(RequestType::ReqQryTradingAccount, pApi, nullptr, 0, 0, nullptr, 0, nullptr, 0, nullptr, 0);
}
void X_SendOrder(void* pFun, void* pApi, OrderField* pOrder, OrderIDType* pInOut, int count)
{
if (pFun == nullptr || pApi == nullptr)
return;
((fnOnRespone)pFun)(RequestType::ReqOrderInsert, pApi, nullptr, 0, 0, pOrder, count, pInOut, 0, nullptr, 0);
}
void X_CancelOrder(void* pFun, void* pApi, OrderIDType* pIn, OrderIDType* pOut, int count)
{
if (pFun == nullptr || pApi == nullptr)
return;
((fnOnRespone)pFun)(RequestType::ReqOrderAction, pApi, nullptr, 0, 0, pIn, count, pOut, 0, nullptr, 0);
}
void X_SendQuote(void* pFun, void* pApi, QuoteField* pQuote, OrderIDType* pAskOut, OrderIDType* pBidOut, int count)
{
if (pFun == nullptr || pApi == nullptr)
return;
((fnOnRespone)pFun)(RequestType::ReqQuoteInsert, pApi, nullptr, 0, 0, pQuote, count, pAskOut, 0, pBidOut, 0);
}
void X_CancelQuote(void* pFun, void* pApi, OrderIDType* pIn, OrderIDType* pOut, int count)
{
if (pFun == nullptr || pApi == nullptr)
return;
((fnOnRespone)pFun)(RequestType::ReqQuoteAction, pApi, nullptr, 0, 0, pIn, count, pOut, 0, nullptr, 0);
}