hikyuu 2.1.0__cp312-none-win_amd64.whl → 2.1.2__cp312-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hikyuu/cpp/boost_date_time-mt.dll +0 -0
- hikyuu/cpp/boost_serialization-mt.dll +0 -0
- hikyuu/cpp/boost_wserialization-mt.dll +0 -0
- hikyuu/cpp/core312.pyd +0 -0
- hikyuu/cpp/hikyuu.dll +0 -0
- hikyuu/cpp/sqlite3.dll +0 -0
- hikyuu/examples/notebook/006-TradeManager.ipynb +41 -39
- hikyuu/examples/notebook/008-Pickle.ipynb +27 -35
- hikyuu/extend.py +3 -1
- hikyuu/fetcher/stock/zh_stock_a_qmt.py +49 -0
- hikyuu/gui/HikyuuTDX.py +13 -7
- hikyuu/gui/data/MainWindow.py +126 -126
- hikyuu/gui/spot_server.py +16 -7
- hikyuu/gui/start_qmt.py +36 -0
- hikyuu/include/hikyuu/DataType.h +2 -1
- hikyuu/include/hikyuu/KRecord.h +1 -1
- hikyuu/include/hikyuu/Stock.h +1 -1
- hikyuu/include/hikyuu/StockManager.h +3 -0
- hikyuu/include/hikyuu/StrategyContext.h +7 -2
- hikyuu/include/hikyuu/analysis/combinate.h +1 -1
- hikyuu/include/hikyuu/config.h +0 -12
- hikyuu/include/hikyuu/data_driver/base_info/table/HistoryFinanceTable.h +2 -2
- hikyuu/include/hikyuu/doc.h +2 -2
- hikyuu/include/hikyuu/global/GlobalSpotAgent.h +1 -0
- hikyuu/include/hikyuu/global/GlobalTaskGroup.h +4 -2
- hikyuu/include/hikyuu/global/SpotRecord.h +52 -0
- hikyuu/include/hikyuu/global/agent/SpotAgent.h +14 -41
- hikyuu/include/hikyuu/hikyuu.h +1 -0
- hikyuu/include/hikyuu/strategy/{AccountTradeManager.h → BrokerTradeManager.h} +97 -95
- hikyuu/include/hikyuu/strategy/RunPortfolioInStrategy.h +36 -0
- hikyuu/include/hikyuu/strategy/RunSystemInStrategy.h +37 -0
- hikyuu/include/hikyuu/strategy/Strategy.h +174 -0
- hikyuu/include/hikyuu/trade_manage/FundsRecord.h +8 -8
- hikyuu/include/hikyuu/trade_manage/OrderBrokerBase.h +66 -14
- hikyuu/include/hikyuu/trade_manage/PositionRecord.h +12 -12
- hikyuu/include/hikyuu/trade_manage/TradeManager.h +9 -0
- hikyuu/include/hikyuu/trade_manage/TradeManagerBase.h +19 -0
- hikyuu/include/hikyuu/utilities/FilterNode.h +267 -0
- hikyuu/include/hikyuu/utilities/LRUCache11.h +230 -0
- hikyuu/include/hikyuu/{Log.h → utilities/Log.h} +91 -113
- hikyuu/include/hikyuu/utilities/Null.h +1 -0
- hikyuu/include/hikyuu/utilities/Parameter.h +2 -1
- hikyuu/include/hikyuu/utilities/ResourcePool.h +636 -0
- hikyuu/include/hikyuu/utilities/SpendTimer.h +10 -9
- hikyuu/include/hikyuu/utilities/TimerManager.h +25 -11
- hikyuu/include/hikyuu/utilities/any_to_string.h +142 -0
- hikyuu/include/hikyuu/utilities/arithmetic.h +71 -35
- hikyuu/include/hikyuu/utilities/base64.h +59 -0
- hikyuu/include/hikyuu/utilities/config.h +41 -0
- hikyuu/include/hikyuu/utilities/datetime/Datetime.h +42 -31
- hikyuu/include/hikyuu/utilities/datetime/TimeDelta.h +24 -13
- hikyuu/include/hikyuu/utilities/db_connect/DBCondition.h +48 -48
- hikyuu/include/hikyuu/utilities/db_connect/DBConnect.h +10 -0
- hikyuu/include/hikyuu/utilities/db_connect/DBConnectBase.h +5 -22
- hikyuu/include/hikyuu/utilities/db_connect/DBUpgrade.h +3 -3
- hikyuu/include/hikyuu/utilities/db_connect/SQLException.h +1 -1
- hikyuu/include/hikyuu/utilities/db_connect/SQLResultSet.h +1 -1
- hikyuu/include/hikyuu/utilities/db_connect/SQLStatementBase.h +7 -7
- hikyuu/include/hikyuu/utilities/db_connect/TableMacro.h +1 -2
- hikyuu/include/hikyuu/utilities/db_connect/mysql/MySQLConnect.h +9 -9
- hikyuu/include/hikyuu/utilities/db_connect/mysql/MySQLStatement.h +18 -18
- hikyuu/include/hikyuu/utilities/db_connect/sqlite/SQLiteConnect.h +3 -3
- hikyuu/include/hikyuu/utilities/db_connect/sqlite/SQLiteStatement.h +2 -2
- hikyuu/include/hikyuu/utilities/db_connect/sqlite/SQLiteUtil.h +6 -6
- hikyuu/include/hikyuu/{exception.h → utilities/exception.h} +15 -16
- hikyuu/include/hikyuu/utilities/http_client/HttpClient.h +229 -0
- hikyuu/include/hikyuu/utilities/http_client/nng_wrap.h +517 -0
- hikyuu/include/hikyuu/utilities/http_client/url.h +25 -0
- hikyuu/include/hikyuu/utilities/{IniParser.h → ini_parser/IniParser.h} +10 -5
- hikyuu/include/hikyuu/utilities/ini_parser/__init__.py +1 -0
- hikyuu/include/hikyuu/utilities/md5.h +41 -0
- hikyuu/include/hikyuu/utilities/mo/__init__.py +1 -0
- hikyuu/include/hikyuu/utilities/mo/mo.h +48 -0
- hikyuu/include/hikyuu/utilities/mo/moFileReader.h +836 -0
- hikyuu/include/hikyuu/{global → utilities}/node/NodeClient.h +25 -18
- hikyuu/include/hikyuu/{global → utilities}/node/NodeError.h +1 -1
- hikyuu/include/hikyuu/{global → utilities}/node/NodeMessage.h +3 -2
- hikyuu/include/hikyuu/utilities/node/NodeServer.h +246 -0
- hikyuu/include/hikyuu/utilities/node/__init__.py +1 -0
- hikyuu/include/hikyuu/utilities/os.h +16 -15
- hikyuu/include/hikyuu/utilities/snowflake.h +110 -0
- hikyuu/include/hikyuu/utilities/string_view.h +70 -0
- hikyuu/include/hikyuu/utilities/thread/MQStealThreadPool.h +3 -3
- hikyuu/include/hikyuu/utilities/thread/MQThreadPool.h +3 -3
- hikyuu/include/hikyuu/utilities/thread/StealThreadPool.h +3 -3
- hikyuu/include/hikyuu/utilities/thread/ThreadPool.h +3 -3
- hikyuu/include/hikyuu/version.h +4 -4
- hikyuu/interactive.py +42 -137
- hikyuu/sqlite3.dll +0 -0
- hikyuu/strategy/__init__.py +0 -1
- hikyuu/strategy/strategy_demo1.py +53 -0
- hikyuu/strategy/strategy_demo2.py +47 -0
- hikyuu/strategy/strategy_demo3.py +24 -0
- hikyuu/trade_manage/broker.py +27 -11
- hikyuu/trade_manage/broker_easytrader.py +52 -6
- hikyuu/trade_manage/broker_mail.py +17 -20
- hikyuu/vcruntime140.dll +0 -0
- hikyuu/vcruntime140_1.dll +0 -0
- hikyuu-2.1.2.dist-info/METADATA +115 -0
- {hikyuu-2.1.0.dist-info → hikyuu-2.1.2.dist-info}/RECORD +105 -79
- {hikyuu-2.1.0.dist-info → hikyuu-2.1.2.dist-info}/top_level.txt +4 -2
- hikyuu/README.rst +0 -79
- hikyuu/include/hikyuu/strategy/StrategyBase.h +0 -156
- hikyuu/strategy/demo/__init__.py +0 -3
- hikyuu/strategy/strategy.py +0 -27
- hikyuu-2.1.0.dist-info/METADATA +0 -126
- /hikyuu/include/hikyuu/{global/node → utilities/http_client}/__init__.py +0 -0
- {hikyuu-2.1.0.dist-info → hikyuu-2.1.2.dist-info}/LICENSE +0 -0
- {hikyuu-2.1.0.dist-info → hikyuu-2.1.2.dist-info}/WHEEL +0 -0
- {hikyuu-2.1.0.dist-info → hikyuu-2.1.2.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2024-07-26
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
#ifndef HKU_UTILS_NNG_WRAP_H
|
|
10
|
+
#define HKU_UTILS_NNG_WRAP_H
|
|
11
|
+
|
|
12
|
+
#include <string>
|
|
13
|
+
#include <nng/nng.h>
|
|
14
|
+
#include <nng/supplemental/http/http.h>
|
|
15
|
+
#include "hikyuu/utilities/Log.h"
|
|
16
|
+
|
|
17
|
+
#include "hikyuu/utilities/config.h"
|
|
18
|
+
#if HKU_ENABLE_HTTP_CLIENT_SSL
|
|
19
|
+
#include <nng/supplemental/tls/tls.h>
|
|
20
|
+
#endif
|
|
21
|
+
|
|
22
|
+
namespace hku {
|
|
23
|
+
|
|
24
|
+
struct HttpTimeoutException : hku::exception {
|
|
25
|
+
HttpTimeoutException() : hku::exception("Http timeout!") {}
|
|
26
|
+
virtual ~HttpTimeoutException() noexcept = default;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
using HttpHeaders = std::map<std::string, std::string>;
|
|
30
|
+
using HttpParams = std::map<std::string, std::string>;
|
|
31
|
+
|
|
32
|
+
} // namespace hku
|
|
33
|
+
|
|
34
|
+
namespace hku {
|
|
35
|
+
namespace nng {
|
|
36
|
+
|
|
37
|
+
#ifndef NNG_CHECK
|
|
38
|
+
#define NNG_CHECK(rv) \
|
|
39
|
+
{ \
|
|
40
|
+
if (rv != 0) { \
|
|
41
|
+
HKU_THROW("[NNG_ERROR] {} ", nng_strerror(rv)); \
|
|
42
|
+
} \
|
|
43
|
+
}
|
|
44
|
+
#endif
|
|
45
|
+
|
|
46
|
+
#ifndef NNG_CHECK_M
|
|
47
|
+
#define NNG_CHECK_M(rv, ...) \
|
|
48
|
+
{ \
|
|
49
|
+
if (rv != 0) { \
|
|
50
|
+
HKU_THROW("{} | [NNG_ERROR] {}", fmt::format(__VA_ARGS__), nng_strerror(rv)); \
|
|
51
|
+
} \
|
|
52
|
+
}
|
|
53
|
+
#endif
|
|
54
|
+
|
|
55
|
+
class url final {
|
|
56
|
+
public:
|
|
57
|
+
url() = default;
|
|
58
|
+
explicit url(const std::string& url_) noexcept : m_rawurl(url_) {
|
|
59
|
+
nng_url_parse(&m_url, m_rawurl.c_str());
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
url(const url&) = delete;
|
|
63
|
+
url(url&& rhs) noexcept : m_rawurl(std::move(rhs.m_rawurl)), m_url(rhs.m_url) {
|
|
64
|
+
rhs.m_url = nullptr;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
url& operator=(const url&) = delete;
|
|
68
|
+
url& operator=(url&& rhs) noexcept {
|
|
69
|
+
if (this != &rhs) {
|
|
70
|
+
if (m_url != nullptr) {
|
|
71
|
+
nng_url_free(m_url);
|
|
72
|
+
}
|
|
73
|
+
m_url = rhs.m_url;
|
|
74
|
+
m_rawurl = std::move(rhs.m_rawurl);
|
|
75
|
+
rhs.m_url = nullptr;
|
|
76
|
+
}
|
|
77
|
+
return *this;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
~url() {
|
|
81
|
+
if (m_url) {
|
|
82
|
+
nng_url_free(m_url);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const std::string& raw_url() const noexcept {
|
|
87
|
+
return m_rawurl;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
nng_url* get() const noexcept {
|
|
91
|
+
return m_url;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
nng_url* operator->() const noexcept {
|
|
95
|
+
return m_url;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
bool valid() const noexcept {
|
|
99
|
+
return m_url != nullptr;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
bool is_https() const noexcept {
|
|
103
|
+
return m_url == nullptr ? false : strcmp("https", m_url->u_scheme) == 0;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private:
|
|
107
|
+
std::string m_rawurl;
|
|
108
|
+
nng_url* m_url{nullptr};
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
class aio final {
|
|
112
|
+
public:
|
|
113
|
+
aio() = default;
|
|
114
|
+
aio(const aio&) = delete;
|
|
115
|
+
~aio() {
|
|
116
|
+
if (m_aio) {
|
|
117
|
+
nng_aio_free(m_aio);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
aio(aio&& rhs) : m_aio(rhs.m_aio), m_timeout(rhs.m_timeout) {
|
|
122
|
+
rhs.m_aio = nullptr;
|
|
123
|
+
rhs.m_timeout = NNG_DURATION_DEFAULT;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
aio& operator=(const aio&) = delete;
|
|
127
|
+
|
|
128
|
+
aio& operator=(aio&& rhs) {
|
|
129
|
+
if (this != &rhs) {
|
|
130
|
+
m_aio = rhs.m_aio;
|
|
131
|
+
m_timeout = rhs.m_timeout;
|
|
132
|
+
rhs.m_aio = nullptr;
|
|
133
|
+
rhs.m_timeout = NNG_DURATION_DEFAULT;
|
|
134
|
+
}
|
|
135
|
+
return *this;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
bool valid() const noexcept {
|
|
139
|
+
return m_aio != nullptr;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
nng_aio* get() const noexcept {
|
|
143
|
+
return m_aio;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
nng_aio* operator->() const noexcept {
|
|
147
|
+
return m_aio;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
void alloc(int32_t timeout_ms) {
|
|
151
|
+
if (m_aio == nullptr) {
|
|
152
|
+
NNG_CHECK(nng_aio_alloc(&m_aio, NULL, NULL));
|
|
153
|
+
}
|
|
154
|
+
set_timeout(timeout_ms);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
void release() {
|
|
158
|
+
if (m_aio) {
|
|
159
|
+
nng_aio_free(m_aio);
|
|
160
|
+
m_aio = nullptr;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
aio& wait() {
|
|
165
|
+
nng_aio_wait(m_aio);
|
|
166
|
+
return *this;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
int result() {
|
|
170
|
+
// 直接返回结果,在调用处判断异常,才知道是在具体哪里
|
|
171
|
+
return nng_aio_result(m_aio);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
void* get_output(unsigned index) {
|
|
175
|
+
return nng_aio_get_output(m_aio, index);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/*
|
|
179
|
+
* 0 - 恢复默认值
|
|
180
|
+
* <0 - 不限制
|
|
181
|
+
*/
|
|
182
|
+
void set_timeout(int32_t ms) {
|
|
183
|
+
if (ms != m_timeout) {
|
|
184
|
+
m_timeout = ms;
|
|
185
|
+
nng_aio_set_timeout(m_aio, ms);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
int32_t get_timeout() const noexcept {
|
|
190
|
+
return m_timeout;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
void set_iov(unsigned n, const nng_iov* iov) {
|
|
194
|
+
NNG_CHECK(nng_aio_set_iov(m_aio, n, iov));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
private:
|
|
198
|
+
nng_aio* m_aio{nullptr};
|
|
199
|
+
int32_t m_timeout{NNG_DURATION_DEFAULT};
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
#if HKU_ENABLE_HTTP_CLIENT_SSL
|
|
203
|
+
class tls_config final {
|
|
204
|
+
public:
|
|
205
|
+
tls_config() = default;
|
|
206
|
+
|
|
207
|
+
tls_config(const tls_config& th) : m_cfg(th.m_cfg) {
|
|
208
|
+
if (m_cfg) {
|
|
209
|
+
nng_tls_config_hold(th.m_cfg);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
tls_config(tls_config&& rhs) : m_cfg(rhs.m_cfg) {
|
|
214
|
+
rhs.m_cfg = nullptr;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
~tls_config() {
|
|
218
|
+
if (m_cfg) {
|
|
219
|
+
nng_tls_config_free(m_cfg);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
tls_config& operator=(const tls_config& th) {
|
|
224
|
+
if (this != &th) {
|
|
225
|
+
m_cfg = th.m_cfg;
|
|
226
|
+
if (m_cfg) {
|
|
227
|
+
nng_tls_config_hold(m_cfg);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return *this;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
tls_config& operator=(tls_config&& rhs) {
|
|
234
|
+
if (this != &rhs) {
|
|
235
|
+
m_cfg = rhs.m_cfg;
|
|
236
|
+
rhs.m_cfg = nullptr;
|
|
237
|
+
}
|
|
238
|
+
return *this;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
void release() {
|
|
242
|
+
if (m_cfg) {
|
|
243
|
+
nng_tls_config_free(m_cfg);
|
|
244
|
+
m_cfg = nullptr;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
nng_tls_config* get() const noexcept {
|
|
249
|
+
return m_cfg;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
tls_config& set_ca_file(const std::string& filename) {
|
|
253
|
+
NNG_CHECK(alloc());
|
|
254
|
+
NNG_CHECK(nng_tls_config_ca_file(m_cfg, filename.c_str()));
|
|
255
|
+
return *this;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
private:
|
|
259
|
+
int alloc() {
|
|
260
|
+
return m_cfg ? 0 : nng_tls_config_alloc(&m_cfg, NNG_TLS_MODE_CLIENT);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
private:
|
|
264
|
+
nng_tls_config* m_cfg{nullptr};
|
|
265
|
+
};
|
|
266
|
+
#endif // #if HKU_ENABLE_HTTP_CLIENT_SSL
|
|
267
|
+
|
|
268
|
+
class http_client final {
|
|
269
|
+
public:
|
|
270
|
+
http_client() = default;
|
|
271
|
+
~http_client() {
|
|
272
|
+
if (m_client) {
|
|
273
|
+
nng_http_client_free(m_client);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
http_client(const http_client&) = delete;
|
|
278
|
+
http_client& operator=(const http_client&) = delete;
|
|
279
|
+
|
|
280
|
+
http_client(http_client&& rhs)
|
|
281
|
+
: m_client(rhs.m_client), m_aio(rhs.m_aio), m_tls_cfg(rhs.m_tls_cfg) {
|
|
282
|
+
rhs.m_client = nullptr;
|
|
283
|
+
rhs.m_aio = nullptr;
|
|
284
|
+
rhs.m_tls_cfg = nullptr;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
http_client& operator=(http_client&& rhs) {
|
|
288
|
+
if (this != &rhs) {
|
|
289
|
+
m_client = rhs.m_client;
|
|
290
|
+
m_aio = rhs.m_aio;
|
|
291
|
+
m_tls_cfg = rhs.m_tls_cfg;
|
|
292
|
+
rhs.m_client = nullptr;
|
|
293
|
+
rhs.m_aio = nullptr;
|
|
294
|
+
rhs.m_tls_cfg = nullptr;
|
|
295
|
+
}
|
|
296
|
+
return *this;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
void set_url(const nng::url& url) {
|
|
300
|
+
#if !HKU_ENABLE_HTTP_CLIENT_SSL
|
|
301
|
+
if (url.is_https()) {
|
|
302
|
+
HKU_THROW("Not support https: ({})! Please compile with --http_client_ssl",
|
|
303
|
+
url.raw_url());
|
|
304
|
+
}
|
|
305
|
+
#endif
|
|
306
|
+
if (!m_client) {
|
|
307
|
+
NNG_CHECK(nng_http_client_alloc(&m_client, url.get()));
|
|
308
|
+
m_tls_cfg = nullptr;
|
|
309
|
+
m_aio = nullptr;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
void connect(const aio& aio) {
|
|
314
|
+
if (m_aio != aio.get()) {
|
|
315
|
+
nng_http_client_connect(m_client, aio.get());
|
|
316
|
+
m_aio = aio.get();
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
void set_tls_cfg(nng_tls_config* cfg) {
|
|
321
|
+
if (cfg != m_tls_cfg) {
|
|
322
|
+
NNG_CHECK(nng_http_client_set_tls(m_client, cfg));
|
|
323
|
+
m_tls_cfg = cfg;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
nng_tls_config* get_tls_cfg() const noexcept {
|
|
328
|
+
return m_tls_cfg;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
nng_http_client* get() const noexcept {
|
|
332
|
+
return m_client;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
nng_http_client* operator->() const noexcept {
|
|
336
|
+
return m_client;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
explicit operator bool() const noexcept {
|
|
340
|
+
return m_client != nullptr;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
void release() {
|
|
344
|
+
if (m_client) {
|
|
345
|
+
nng_http_client_free(m_client);
|
|
346
|
+
m_client = nullptr;
|
|
347
|
+
m_aio = nullptr;
|
|
348
|
+
m_tls_cfg = nullptr;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
private:
|
|
353
|
+
nng_http_client* m_client{nullptr};
|
|
354
|
+
nng_aio* m_aio{nullptr};
|
|
355
|
+
nng_tls_config* m_tls_cfg{nullptr};
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
class http_req final {
|
|
359
|
+
public:
|
|
360
|
+
http_req() = default;
|
|
361
|
+
explicit http_req(const url& url) {
|
|
362
|
+
NNG_CHECK(nng_http_req_alloc(&m_req, url.get()));
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
http_req(const http_req&) = delete;
|
|
366
|
+
http_req(http_req&& rhs) : m_req(rhs.m_req) {
|
|
367
|
+
rhs.m_req = nullptr;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
~http_req() {
|
|
371
|
+
if (m_req) {
|
|
372
|
+
nng_http_req_free(m_req);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
http_req& operator=(const http_req&) = delete;
|
|
377
|
+
http_req& operator=(http_req&& rhs) {
|
|
378
|
+
if (this != &rhs) {
|
|
379
|
+
if (m_req) {
|
|
380
|
+
nng_http_req_free(m_req);
|
|
381
|
+
}
|
|
382
|
+
m_req = rhs.m_req;
|
|
383
|
+
rhs.m_req = nullptr;
|
|
384
|
+
}
|
|
385
|
+
return *this;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
nng_http_req* get() const noexcept {
|
|
389
|
+
return m_req;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
http_req& set_method(const std::string& method) {
|
|
393
|
+
NNG_CHECK(nng_http_req_set_method(m_req, method.c_str()));
|
|
394
|
+
return *this;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
http_req& set_uri(const std::string& uri) {
|
|
398
|
+
NNG_CHECK(nng_http_req_set_uri(m_req, uri.c_str()));
|
|
399
|
+
return *this;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
http_req& add_header(const std::string& key, const std::string& val) {
|
|
403
|
+
NNG_CHECK_M(nng_http_req_add_header(m_req, key.c_str(), val.c_str()),
|
|
404
|
+
"Failed add head {}: {}", key, val);
|
|
405
|
+
return *this;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
http_req& add_headers(const HttpHeaders& headers) {
|
|
409
|
+
for (auto iter = headers.cbegin(); iter != headers.cend(); ++iter) {
|
|
410
|
+
NNG_CHECK_M(nng_http_req_add_header(m_req, iter->first.c_str(), iter->second.c_str()),
|
|
411
|
+
"Failed add header {}: {}", iter->first, iter->second);
|
|
412
|
+
}
|
|
413
|
+
return *this;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
std::string get_header(const std::string& key) {
|
|
417
|
+
const char* head = nng_http_req_get_header(m_req, key.c_str());
|
|
418
|
+
return head ? std::string(head) : std::string();
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
http_req& del_header(const std::string& key) {
|
|
422
|
+
nng_http_req_del_header(m_req, key.c_str());
|
|
423
|
+
return *this;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/* 注: data 需要自行管理且在 req 释放之前应该一直存在,主要避免拷贝 */
|
|
427
|
+
http_req& set_data(const char* data, size_t len) {
|
|
428
|
+
if (data != nullptr && len != 0) {
|
|
429
|
+
NNG_CHECK(nng_http_req_set_data(m_req, data, len));
|
|
430
|
+
}
|
|
431
|
+
return *this;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
http_req& copy_data(const char* data, size_t len) {
|
|
435
|
+
if (data != nullptr && len != 0) {
|
|
436
|
+
NNG_CHECK(nng_http_req_copy_data(m_req, data, len));
|
|
437
|
+
}
|
|
438
|
+
return *this;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
private:
|
|
442
|
+
nng_http_req* m_req{nullptr};
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
class http_conn final {
|
|
446
|
+
public:
|
|
447
|
+
http_conn() = default;
|
|
448
|
+
explicit http_conn(nng_http_conn* conn_) noexcept : m_conn(conn_) {}
|
|
449
|
+
|
|
450
|
+
http_conn(const http_conn&) = delete;
|
|
451
|
+
|
|
452
|
+
http_conn(http_conn&& rhs) noexcept : m_conn(rhs.m_conn) {
|
|
453
|
+
rhs.m_conn = nullptr;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
http_conn& operator=(const http_conn& rhs) = delete;
|
|
457
|
+
|
|
458
|
+
http_conn& operator=(http_conn&& rhs) noexcept {
|
|
459
|
+
if (this != &rhs) {
|
|
460
|
+
if (m_conn != nullptr) {
|
|
461
|
+
nng_http_conn_close(m_conn);
|
|
462
|
+
}
|
|
463
|
+
m_conn = rhs.m_conn;
|
|
464
|
+
rhs.m_conn = nullptr;
|
|
465
|
+
}
|
|
466
|
+
return *this;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
~http_conn() {
|
|
470
|
+
if (m_conn) {
|
|
471
|
+
nng_http_conn_close(m_conn);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
void close() {
|
|
476
|
+
if (m_conn) {
|
|
477
|
+
nng_http_conn_close(m_conn);
|
|
478
|
+
m_conn = nullptr;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
nng_http_conn* get() const noexcept {
|
|
483
|
+
return m_conn;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
nng_http_conn* operator->() const noexcept {
|
|
487
|
+
return m_conn;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
bool valid() const noexcept {
|
|
491
|
+
return m_conn != nullptr;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
void write_req(const http_req& req, const aio& aio) {
|
|
495
|
+
nng_http_conn_write_req(m_conn, req.get(), aio.get());
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
void read_res(nng_http_res* res, const aio& aio) {
|
|
499
|
+
nng_http_conn_read_res(m_conn, res, aio.get());
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
void read_all(const aio& aio) {
|
|
503
|
+
nng_http_conn_read_all(m_conn, aio.get());
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
void transact(nng_http_req* req, nng_http_res* res, const aio& aio) {
|
|
507
|
+
nng_http_conn_transact(m_conn, req, res, aio.get());
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
private:
|
|
511
|
+
nng_http_conn* m_conn{nullptr};
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
} // namespace nng
|
|
515
|
+
} // namespace hku
|
|
516
|
+
|
|
517
|
+
#endif
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright(C) 2021 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Create on: 2021-03-07
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
#ifndef HKU_UTILS_URL_H
|
|
10
|
+
#define HKU_UTILS_URL_H
|
|
11
|
+
|
|
12
|
+
#include <string>
|
|
13
|
+
|
|
14
|
+
#ifndef HKU_UTILS_API
|
|
15
|
+
#define HKU_UTILS_API
|
|
16
|
+
#endif
|
|
17
|
+
|
|
18
|
+
namespace hku {
|
|
19
|
+
|
|
20
|
+
std::string HKU_UTILS_API url_escape(const char* istr);
|
|
21
|
+
std::string HKU_UTILS_API url_unescape(const char* istr);
|
|
22
|
+
|
|
23
|
+
} // namespace hku
|
|
24
|
+
|
|
25
|
+
#endif
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
2
|
* IniFile.h
|
|
3
3
|
*
|
|
4
4
|
* Created on: 2010-5-19
|
|
@@ -9,6 +9,11 @@
|
|
|
9
9
|
#ifndef INIPARSER_H_
|
|
10
10
|
#define INIPARSER_H_
|
|
11
11
|
|
|
12
|
+
#include "hikyuu/utilities/config.h"
|
|
13
|
+
#if !HKU_ENABLE_INI_PARSER
|
|
14
|
+
#error "Don't enable ini_parser, please config with --ini_parser=y"
|
|
15
|
+
#endif
|
|
16
|
+
|
|
12
17
|
#include <stdexcept>
|
|
13
18
|
#include <string>
|
|
14
19
|
#include <list>
|
|
@@ -21,8 +26,8 @@
|
|
|
21
26
|
#pragma warning(disable : 4290)
|
|
22
27
|
#endif
|
|
23
28
|
|
|
24
|
-
#ifndef
|
|
25
|
-
#define
|
|
29
|
+
#ifndef HKU_UTILS_API
|
|
30
|
+
#define HKU_UTILS_API
|
|
26
31
|
#endif
|
|
27
32
|
|
|
28
33
|
namespace hku {
|
|
@@ -52,7 +57,7 @@ namespace hku {
|
|
|
52
57
|
* @ingroup Utilities
|
|
53
58
|
*/
|
|
54
59
|
|
|
55
|
-
class
|
|
60
|
+
class HKU_UTILS_API IniParser {
|
|
56
61
|
public:
|
|
57
62
|
typedef std::list<std::string> StringList;
|
|
58
63
|
typedef std::shared_ptr<std::list<std::string> > StringListPtr;
|
|
@@ -75,7 +80,7 @@ public:
|
|
|
75
80
|
std::string get(const std::string& section, const std::string& option,
|
|
76
81
|
const std::string& default_str = std::string()) const;
|
|
77
82
|
|
|
78
|
-
|
|
83
|
+
// 以下默认值类型使用string的原因是因为int/float/double/bool类型没有空对象
|
|
79
84
|
int getInt(const std::string& section, const std::string& option,
|
|
80
85
|
const std::string& default_str = std::string()) const;
|
|
81
86
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2019~2021, hikyuu
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2021/12/06
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
#ifndef HKU_UTILS_MD5_H
|
|
10
|
+
#define HKU_UTILS_MD5_H
|
|
11
|
+
|
|
12
|
+
#include <string>
|
|
13
|
+
|
|
14
|
+
#ifndef HKU_UTILS_API
|
|
15
|
+
#define HKU_UTILS_API
|
|
16
|
+
#endif
|
|
17
|
+
|
|
18
|
+
namespace hku {
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @brief 计算 md5 值
|
|
22
|
+
*
|
|
23
|
+
* @param input 待计算数据起始指针
|
|
24
|
+
* @param len 待计算数据字节长度
|
|
25
|
+
* @return std::string
|
|
26
|
+
*/
|
|
27
|
+
std::string HKU_UTILS_API md5(const unsigned char* input, size_t len);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @brief 计算字符串 md5
|
|
31
|
+
*
|
|
32
|
+
* @param src 待计算的字符串
|
|
33
|
+
* @return std::string
|
|
34
|
+
*/
|
|
35
|
+
inline std::string md5(const std::string& src) {
|
|
36
|
+
return md5((const unsigned char*)src.data(), src.size());
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
} // namespace hku
|
|
40
|
+
|
|
41
|
+
#endif // #define HKU_UTILS_MD5_H
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright(C) 2021 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Create on: 2021-05-01
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "hikyuu/utilities/config.h"
|
|
11
|
+
#if !HKU_ENABLE_MO
|
|
12
|
+
#error "Don't enable mo, please config with --mo=y"
|
|
13
|
+
#endif
|
|
14
|
+
|
|
15
|
+
#include <unordered_map>
|
|
16
|
+
#include "hikyuu/utilities/string_view.h"
|
|
17
|
+
#include "moFileReader.h"
|
|
18
|
+
|
|
19
|
+
#if defined(_MSC_VER)
|
|
20
|
+
// moFileReader.hpp 最后打开了4251告警,这里关闭
|
|
21
|
+
#pragma warning(disable : 4251)
|
|
22
|
+
#endif /* _MSC_VER */
|
|
23
|
+
|
|
24
|
+
#ifndef HKU_UTILS_API
|
|
25
|
+
#define HKU_UTILS_API
|
|
26
|
+
#endif
|
|
27
|
+
|
|
28
|
+
namespace hku {
|
|
29
|
+
|
|
30
|
+
class HKU_UTILS_API MOHelper {
|
|
31
|
+
public:
|
|
32
|
+
static void init();
|
|
33
|
+
|
|
34
|
+
static std::string translate(const std::string &lang, const char *id) {
|
|
35
|
+
auto iter = ms_dict.find(lang);
|
|
36
|
+
return iter != ms_dict.end() ? ms_dict[lang].Lookup(id) : std::string(id);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static std::string translate(const std::string &lang, const char *ctx, const char *id) {
|
|
40
|
+
auto iter = ms_dict.find(lang);
|
|
41
|
+
return iter != ms_dict.end() ? ms_dict[lang].LookupWithContext(ctx, id) : std::string(id);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private:
|
|
45
|
+
static std::unordered_map<std::string, moFileLib::moFileReader> ms_dict;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
} // namespace hku
|