hikyuu 2.7.1__py3-none-win_amd64.whl → 2.7.2__py3-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.
Files changed (90) hide show
  1. hikyuu/__init__.py +4 -1
  2. hikyuu/__init__.pyi +23 -11
  3. hikyuu/analysis/__init__.pyi +5 -1
  4. hikyuu/analysis/analysis.pyi +6 -2
  5. hikyuu/core.pyi +7 -3
  6. hikyuu/cpp/core310.pyd +0 -0
  7. hikyuu/cpp/core310.pyi +55 -6
  8. hikyuu/cpp/core311.pyd +0 -0
  9. hikyuu/cpp/core311.pyi +55 -6
  10. hikyuu/cpp/core312.pyd +0 -0
  11. hikyuu/cpp/core312.pyi +55 -6
  12. hikyuu/cpp/core313.pyd +0 -0
  13. hikyuu/cpp/core313.pyi +55 -6
  14. hikyuu/cpp/hikyuu.dll +0 -0
  15. hikyuu/cpp/hikyuu.lib +0 -0
  16. hikyuu/cpp/i18n/zh_CN/hikyuu.mo +0 -0
  17. hikyuu/cpp/i18n/zh_CN/hikyuu_plugin.mo +0 -0
  18. hikyuu/data/clickhouse_upgrade/0001.sql +2 -0
  19. hikyuu/data/common_clickhouse.py +1 -3
  20. hikyuu/data/hku_config_template.py +6 -0
  21. hikyuu/data/mysql_upgrade/0029.sql +2 -0
  22. hikyuu/data/pytdx_to_clickhouse.py +85 -31
  23. hikyuu/data/pytdx_to_h5.py +73 -28
  24. hikyuu/data/pytdx_to_mysql.py +65 -21
  25. hikyuu/data/pytdx_weight_to_clickhouse.py +2 -0
  26. hikyuu/data/pytdx_weight_to_mysql.py +2 -0
  27. hikyuu/data/pytdx_weight_to_sqlite.py +2 -0
  28. hikyuu/data/sqlite_upgrade/0029.sql +4 -0
  29. hikyuu/draw/drawplot/bokeh_draw.pyi +10 -6
  30. hikyuu/draw/drawplot/echarts_draw.pyi +10 -6
  31. hikyuu/draw/drawplot/matplotlib_draw.py +8 -2
  32. hikyuu/draw/drawplot/matplotlib_draw.pyi +10 -6
  33. hikyuu/extend.pyi +8 -4
  34. hikyuu/gui/HikyuuTDX.py +12 -2
  35. hikyuu/gui/data/MainWindow.py +166 -142
  36. hikyuu/hub.pyi +6 -6
  37. hikyuu/include/hikyuu/StockManager.h +4 -0
  38. hikyuu/include/hikyuu/StrategyContext.h +4 -4
  39. hikyuu/include/hikyuu/global/sysinfo.h +24 -5
  40. hikyuu/include/hikyuu/indicator/IndicatorImp.h +1 -1
  41. hikyuu/include/hikyuu/plugin/KDataToClickHouseImporter.h +40 -0
  42. hikyuu/include/hikyuu/plugin/KDataToMySQLImporter.h +40 -0
  43. hikyuu/include/hikyuu/plugin/checkdata.h +20 -0
  44. hikyuu/include/hikyuu/plugin/hkuextra.h +2 -0
  45. hikyuu/include/hikyuu/plugin/interface/CheckDataPluginInterface.h +25 -0
  46. hikyuu/include/hikyuu/plugin/interface/HkuExtraPluginInterface.h +2 -0
  47. hikyuu/include/hikyuu/plugin/interface/ImportKDataToClickHousePluginInterface.h +44 -0
  48. hikyuu/include/hikyuu/plugin/interface/ImportKDataToMySQLPluginInterface.h +42 -0
  49. hikyuu/include/hikyuu/plugin/interface/plugins.h +6 -0
  50. hikyuu/include/hikyuu/python/convert_any.h +9 -6
  51. hikyuu/include/hikyuu/strategy/Strategy.h +1 -1
  52. hikyuu/include/hikyuu/trade_manage/TradeRecord.h +2 -1
  53. hikyuu/include/hikyuu/trade_sys/allocatefunds/build_in.h +1 -0
  54. hikyuu/include/hikyuu/trade_sys/allocatefunds/crt/AF_FixedAmount.h +26 -0
  55. hikyuu/include/hikyuu/trade_sys/allocatefunds/imp/FixAmountFunds.h +18 -0
  56. hikyuu/include/hikyuu/utilities/Log.h +6 -7
  57. hikyuu/include/hikyuu/utilities/Parameter.h +17 -0
  58. hikyuu/include/hikyuu/utilities/config.h +28 -0
  59. hikyuu/include/hikyuu/utilities/plugin/PluginBase.h +17 -2
  60. hikyuu/include/hikyuu/utilities/plugin/PluginManager.h +41 -22
  61. hikyuu/include/hikyuu/utilities/thread/GlobalStealThreadPool.h +1 -2
  62. hikyuu/include/hikyuu/utilities/thread/GlobalThreadPool.h +1 -1
  63. hikyuu/include/hikyuu/utilities/thread/MQStealThreadPool.h +285 -0
  64. hikyuu/include/hikyuu/utilities/thread/StealThreadPool.h +296 -0
  65. hikyuu/include/hikyuu/utilities/thread/WorkStealQueue.h +9 -8
  66. hikyuu/include/hikyuu/utilities/thread/algorithm.h +64 -14
  67. hikyuu/include/hikyuu/version.h +4 -4
  68. hikyuu/plugin/backtest.dll +0 -0
  69. hikyuu/plugin/checkdata.dll +0 -0
  70. hikyuu/plugin/clickhousedriver.dll +0 -0
  71. hikyuu/plugin/dataserver.dll +0 -0
  72. hikyuu/plugin/dataserver_parquet.dll +0 -0
  73. hikyuu/plugin/device.dll +0 -0
  74. hikyuu/plugin/extind.dll +0 -0
  75. hikyuu/plugin/hkuextra.dll +0 -0
  76. hikyuu/plugin/import2ch.dll +0 -0
  77. hikyuu/plugin/import2hdf5.dll +0 -0
  78. hikyuu/plugin/import2mysql.dll +0 -0
  79. hikyuu/plugin/tmreport.dll +0 -0
  80. hikyuu/trade_manage/__init__.pyi +10 -6
  81. hikyuu/trade_manage/trade.pyi +10 -6
  82. hikyuu/trade_sys/trade_sys.py +3 -1
  83. hikyuu/util/__init__.pyi +1 -1
  84. hikyuu/util/singleton.pyi +1 -1
  85. {hikyuu-2.7.1.dist-info → hikyuu-2.7.2.dist-info}/METADATA +5 -1
  86. {hikyuu-2.7.1.dist-info → hikyuu-2.7.2.dist-info}/RECORD +89 -73
  87. hikyuu/data/pytdx_to_taos.py +0 -736
  88. {hikyuu-2.7.1.dist-info → hikyuu-2.7.2.dist-info}/WHEEL +0 -0
  89. {hikyuu-2.7.1.dist-info → hikyuu-2.7.2.dist-info}/entry_points.txt +0 -0
  90. {hikyuu-2.7.1.dist-info → hikyuu-2.7.2.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,40 @@
1
+ /*
2
+ * Copyright (c) 2025 hikyuu.org
3
+ *
4
+ * Created on: 2025-05-06
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include "hikyuu/DataType.h"
11
+ #include "interface/ImportKDataToMySQLPluginInterface.h"
12
+
13
+ namespace hku {
14
+
15
+ class HKU_API KDataToMySQLImporter {
16
+ public:
17
+ KDataToMySQLImporter();
18
+ virtual ~KDataToMySQLImporter();
19
+
20
+ bool setConfig(const string& host, int port, const string& user, const string& pwd);
21
+
22
+ Datetime getLastDatetime(const string& market, const string& code, const KQuery::KType& ktype);
23
+
24
+ void addKRecordList(const string& market, const string& code, const vector<KRecord>& krecords,
25
+ const KQuery::KType& ktype);
26
+
27
+ void addTimeLineList(const string& market, const string& code, const TimeLineList& timeline);
28
+
29
+ void addTransList(const string& market, const string& code, const TransRecordList& translist);
30
+
31
+ void updateIndex(const string& market, const string& code, const KQuery::KType& ktype);
32
+
33
+ void remove(const string& market, const string& code, const KQuery::KType& ktype,
34
+ Datetime start);
35
+
36
+ private:
37
+ ImportKDataToMySQLPluginInterface* m_plugin{nullptr};
38
+ };
39
+
40
+ } // namespace hku
@@ -0,0 +1,20 @@
1
+ /*
2
+ * Copyright (c) 2025 hikyuu.org
3
+ *
4
+ * Created on: 2025-12-20
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include "hikyuu/DataType.h"
11
+ #include "interface/CheckDataPluginInterface.h"
12
+
13
+ namespace hku {
14
+
15
+ std::pair<std::string, vector<std::string>> HKU_API checkData(const StockList& stock_list,
16
+ const Datetime& start_date,
17
+ const Datetime& end_date,
18
+ const KQuery::KType& check_ktype);
19
+
20
+ }
@@ -56,4 +56,6 @@ bool getStockExtraIndexRange(const Stock& stk, const KQuery& query, size_t& out_
56
56
 
57
57
  KDataImpPtr getKDataImp(const Stock& stk, const KQuery& query);
58
58
 
59
+ bool canLazyLoad(const KQuery::KType& ktype);
60
+
59
61
  } // namespace hku
@@ -0,0 +1,25 @@
1
+ /*
2
+ * Copyright (c) 2025 hikyuu.org
3
+ *
4
+ * Created on: 2025-05-19
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include "hikyuu/Stock.h"
11
+ #include "hikyuu/utilities/plugin/PluginBase.h"
12
+
13
+ namespace hku {
14
+
15
+ class CheckDataPluginInterface : public PluginBase {
16
+ public:
17
+ CheckDataPluginInterface() = default;
18
+ virtual ~CheckDataPluginInterface() = default;
19
+
20
+ virtual std::pair<std::string, vector<std::string>> checkData(
21
+ const StockList& stock_list, const Datetime& start_date, const Datetime& end_date,
22
+ const KQuery::KType& check_ktype) = 0;
23
+ };
24
+
25
+ } // namespace hku
@@ -35,6 +35,8 @@ public:
35
35
  size_t& out_end) = 0;
36
36
 
37
37
  virtual KDataImpPtr getKDataImp(const Stock& stk, const KQuery& query) = 0;
38
+
39
+ virtual bool canLazyLoad(const KQuery::KType& ktype) = 0;
38
40
  };
39
41
 
40
42
  } // namespace hku
@@ -0,0 +1,44 @@
1
+ /*
2
+ * Copyright (c) 2025 hikyuu.org
3
+ *
4
+ * Created on: 2025-04-08
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include "hikyuu/KRecord.h"
11
+ #include "hikyuu/KQuery.h"
12
+ #include "hikyuu/TimeLineRecord.h"
13
+ #include "hikyuu/TransRecord.h"
14
+ #include "hikyuu/utilities/plugin/PluginBase.h"
15
+
16
+ namespace hku {
17
+
18
+ class ImportKDataToClickHousePluginInterface : public PluginBase {
19
+ public:
20
+ ImportKDataToClickHousePluginInterface() = default;
21
+ virtual ~ImportKDataToClickHousePluginInterface() = default;
22
+
23
+ virtual bool setConfig(const string& host, int port, const string& user, const string& pwd) = 0;
24
+
25
+ virtual Datetime getLastDatetime(const string& market, const string& code,
26
+ const KQuery::KType& ktype) = 0;
27
+
28
+ virtual void addKRecordList(const string& market, const string& code,
29
+ const vector<KRecord>& krecords, const KQuery::KType& ktype) = 0;
30
+
31
+ virtual void addTimeLineList(const string& market, const string& code,
32
+ const TimeLineList& timeline) = 0;
33
+
34
+ virtual void addTransList(const string& market, const string& code,
35
+ const TransRecordList& translist) = 0;
36
+
37
+ virtual void updateIndex(const string& market, const string& code,
38
+ const KQuery::KType& ktype) = 0;
39
+
40
+ virtual void remove(const string& market, const string& code, const KQuery::KType& ktype,
41
+ Datetime start) = 0;
42
+ };
43
+
44
+ } // namespace hku
@@ -0,0 +1,42 @@
1
+ /*
2
+ * Copyright (c) 2025 hikyuu.org
3
+ *
4
+ * Created on: 2025-04-08
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include "hikyuu/KRecord.h"
11
+ #include "hikyuu/KQuery.h"
12
+ #include "hikyuu/utilities/plugin/PluginBase.h"
13
+
14
+ namespace hku {
15
+
16
+ class ImportKDataToMySQLPluginInterface : public PluginBase {
17
+ public:
18
+ ImportKDataToMySQLPluginInterface() = default;
19
+ virtual ~ImportKDataToMySQLPluginInterface() = default;
20
+
21
+ virtual bool setConfig(const string& host, int port, const string& user, const string& pwd) = 0;
22
+
23
+ virtual Datetime getLastDatetime(const string& market, const string& code,
24
+ const KQuery::KType& ktype) = 0;
25
+
26
+ virtual void addKRecordList(const string& market, const string& code,
27
+ const vector<KRecord>& krecords, const KQuery::KType& ktype) = 0;
28
+
29
+ virtual void updateIndex(const string& market, const string& code,
30
+ const KQuery::KType& ktype) = 0;
31
+
32
+ virtual void addTimeLineList(const string& market, const string& code,
33
+ const TimeLineList& timeline) = 0;
34
+
35
+ virtual void addTransList(const string& market, const string& code,
36
+ const TransRecordList& translist) = 0;
37
+
38
+ virtual void remove(const string& market, const string& code, const KQuery::KType& ktype,
39
+ Datetime start) = 0;
40
+ };
41
+
42
+ } // namespace hku
@@ -13,10 +13,13 @@
13
13
  #include "DevicePluginInterface.h"
14
14
  #include "DataServerPluginInterface.h"
15
15
  #include "ImportKDataToHdf5PluginInterface.h"
16
+ #include "ImportKDataToClickHousePluginInterface.h"
17
+ #include "ImportKDataToMySQLPluginInterface.h"
16
18
  #include "ExtendIndicatorsPluginInterface.h"
17
19
  #include "TMReportPluginInterface.h"
18
20
  #include "DataDriverPluginInterface.h"
19
21
  #include "HkuExtraPluginInterface.h"
22
+ #include "CheckDataPluginInterface.h"
20
23
 
21
24
  namespace hku {
22
25
 
@@ -24,9 +27,12 @@ namespace hku {
24
27
  #define HKU_PLUGIN_DEVICE "device"
25
28
  #define HKU_PLUGIN_DATASERVER "dataserver"
26
29
  #define HKU_PLUGIN_IMPORTKDATATOHDF5 "import2hdf5"
30
+ #define HKU_PLUGIN_IMPORTKDATATOCLICKHOUSE "import2ch"
31
+ #define HKU_PLUGIN_IMPORTKDATATOMYSQL "import2mysql"
27
32
  #define HKU_PLUGIN_EXTEND_INDICATOR "extind"
28
33
  #define HKU_PLUGIN_TMREPORT "tmreport"
29
34
  #define HKU_PLUGIN_CLICKHOUSE_DRIVER "clickhousedriver"
30
35
  #define HKU_PLUGIN_HKU_EXTRA "hkuextra"
36
+ #define HKU_PLUGIN_CHECK_DATA "checkdata"
31
37
 
32
38
  } // namespace hku
@@ -104,12 +104,12 @@ public:
104
104
  }
105
105
 
106
106
  if (PyLong_Check(src)) {
107
- int overflow;
108
- long tmp = PyLong_AsLongAndOverflow(src, &overflow);
109
- if (overflow == 0) {
110
- value = static_cast<int>(tmp);
107
+ long long ll_val = PyLong_AsLongLong(src);
108
+ if (ll_val < std::numeric_limits<int>::min() ||
109
+ ll_val > std::numeric_limits<int>::max()) {
110
+ value = static_cast<int64_t>(ll_val);
111
111
  } else {
112
- value = PyLong_AsLongLong(src);
112
+ value = static_cast<int>(ll_val);
113
113
  }
114
114
  return true;
115
115
  }
@@ -192,8 +192,11 @@ public:
192
192
  } else {
193
193
  Py_RETURN_FALSE;
194
194
  }
195
+ } else if (x.type() == typeid(int64_t)) {
196
+ long long ll_val = (long long)boost::any_cast<int64_t>(x);
197
+ return PyLong_FromLongLong(ll_val);
195
198
  } else if (x.type() == typeid(int)) {
196
- return Py_BuildValue("n", boost::any_cast<int>(x));
199
+ return Py_BuildValue("i", boost::any_cast<int>(x));
197
200
  } else if (x.type() == typeid(double)) {
198
201
  return Py_BuildValue("d", boost::any_cast<double>(x));
199
202
  } else if (x.type() == typeid(std::string)) {
@@ -35,7 +35,7 @@ public:
35
35
  Strategy();
36
36
  explicit Strategy(const string& name, const string& config_file = "");
37
37
  Strategy(const vector<string>& codeList, const vector<KQuery::KType>& ktypeList,
38
- const unordered_map<string, int>& preloadNum = {}, const string& name = "Strategy",
38
+ const unordered_map<string, int64_t>& preloadNum = {}, const string& name = "Strategy",
39
39
  const string& config_file = "");
40
40
  explicit Strategy(const StrategyContext& context, const string& name = "Strategy",
41
41
  const string& config_file = "");
@@ -38,7 +38,8 @@ enum BUSINESS {
38
38
  BUSINESS_RETURN_STOCK = 12, /**< 归还股票资产 */
39
39
  BUSINESS_SELL_SHORT = 13, /**< 卖空 */
40
40
  BUSINESS_BUY_SHORT = 14, /**< 卖空后回补 */
41
- BUSINESS_INVALID = 15 /**< 无效类型 */
41
+ BUSINESS_SUOGU = 15, /**< 缩扩股 */
42
+ BUSINESS_INVALID = 16 /**< 无效类型 */
42
43
  };
43
44
 
44
45
  /**
@@ -13,5 +13,6 @@
13
13
  #include "crt/AF_FixedWeight.h"
14
14
  #include "crt/AF_FixedWeightList.h"
15
15
  #include "crt/AF_MultiFactor.h"
16
+ #include "crt/AF_FixedAmount.h"
16
17
 
17
18
  #endif /* TRADE_SYS_ALLOCATEFUNDS_BUILD_IN_H_ */
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Copyright (c) 2019 hikyuu.org
3
+ *
4
+ * Created on: 2025年12月9日
5
+ * Author: stone
6
+ */
7
+
8
+ #pragma once
9
+ #ifndef TRADE_SYS_ALLOCATEFUNDS_CRT_AF_FIXEDAMOUNT_H_
10
+ #define TRADE_SYS_ALLOCATEFUNDS_CRT_AF_FIXEDAMOUNT_H_
11
+
12
+ #include "../AllocateFundsBase.h"
13
+
14
+ namespace hku {
15
+
16
+ /**
17
+ * @brief 固定金额分配,每个选中的资产都不能超过此金额交易
18
+ * @param amount 指定的固定交易金额
19
+ * @return AFPtr
20
+ * @ingroup AllocateFunds
21
+ */
22
+ AFPtr HKU_API AF_FixedAmount(double amount = 20000.0);
23
+
24
+ } /* namespace hku */
25
+
26
+ #endif /* TRADE_SYS_ALLOCATEFUNDS_CRT_AF_FIXEDAMOUNT_H_ */
@@ -0,0 +1,18 @@
1
+ #pragma once
2
+ #include "../AllocateFundsBase.h"
3
+
4
+ namespace hku {
5
+
6
+ class FixedAmountFunds : public AllocateFundsBase {
7
+ ALLOCATEFUNDS_IMP(FixedAmountFunds)
8
+ ALLOCATEFUNDS_NO_PRIVATE_MEMBER_SERIALIZATION
9
+
10
+ public:
11
+ FixedAmountFunds();
12
+ virtual ~FixedAmountFunds();
13
+ virtual void _checkParam(const string& name) const override;
14
+ };
15
+
16
+ } /* namespace hku */
17
+
18
+
@@ -343,13 +343,12 @@ std::shared_ptr<spdlog::logger> HKU_UTILS_API getHikyuuLogger();
343
343
  }
344
344
 
345
345
  /** 用于 catch (...) 中打印,减少编译后代码大小 */
346
- extern std::string g_unknown_error_msg;
347
- #define HKU_THROW_UNKNOWN HKU_THROW("{}", g_unknown_error_msg);
348
- #define HKU_TRACE_UNKNOWN HKU_TRACE("{}", g_unknown_error_msg)
349
- #define HKU_DEBUG_UNKNOWN HKU_DEBUG("{}", g_unknown_error_msg)
350
- #define HKU_INFO_UNKNOWN HKU_INFO("{}", g_unknown_error_msg)
351
- #define HKU_ERROR_UNKNOWN HKU_ERROR("{}", g_unknown_error_msg)
352
- #define HKU_FATAL_UNKNOWN HKU_FATAL("{}", g_unknown_error_msg)
346
+ #define HKU_THROW_UNKNOWN HKU_THROW("Unknown error!")
347
+ #define HKU_TRACE_UNKNOWN HKU_TRACE("Unknown error!")
348
+ #define HKU_DEBUG_UNKNOWN HKU_DEBUG("Unknown error!")
349
+ #define HKU_INFO_UNKNOWN HKU_INFO("Unknown error!");
350
+ #define HKU_ERROR_UNKNOWN HKU_ERROR("Unknown error!");
351
+ #define HKU_FATAL_UNKNOWN HKU_FATAL("Unknown error!");
353
352
 
354
353
  #if CPP_STANDARD >= CPP_STANDARD_20
355
354
  #define CLASS_LOGGER_IMP(cls) \
@@ -503,6 +503,23 @@ inline void Parameter::set(const string& name, const boost::any& value) {
503
503
  m_params[name] = value;
504
504
  }
505
505
 
506
+ template <>
507
+ inline int64_t Parameter::get(const string& name) const {
508
+ param_map_t::const_iterator iter;
509
+ iter = m_params.find(name);
510
+ if (iter == m_params.end()) {
511
+ throw std::out_of_range("out_of_range in Parameter::get : " + name);
512
+ }
513
+ try {
514
+ if (iter->second.type() == typeid(int)) {
515
+ return boost::any_cast<int>(iter->second);
516
+ }
517
+ return boost::any_cast<int64_t>(iter->second);
518
+ } catch (...) {
519
+ throw std::runtime_error("failed conversion param: " + name);
520
+ }
521
+ }
522
+
506
523
  HKU_API bool operator==(const Parameter&, const Parameter&);
507
524
  HKU_API bool operator!=(const Parameter&, const Parameter&);
508
525
  HKU_API bool operator<(const Parameter&, const Parameter&);
@@ -6,33 +6,61 @@
6
6
 
7
7
  // clang-format off
8
8
 
9
+ #ifndef HKU_ENABLE_MYSQL
9
10
  #define HKU_ENABLE_MYSQL 1
10
11
  #if HKU_ENABLE_MYSQL && HKU_OS_WINDOWS
11
12
  #ifndef NOMINMAX
12
13
  #define NOMINMAX
13
14
  #endif
14
15
  #endif
16
+ #endif
15
17
 
18
+ #ifndef HKU_ENABLE_SQLITE
16
19
  #define HKU_ENABLE_SQLITE 1
20
+ #endif
21
+ #ifndef HKU_ENABLE_SQLCIPHER
17
22
  #define HKU_ENABLE_SQLCIPHER 0
23
+ #endif
24
+ #ifndef HKU_SQL_TRACE
18
25
  /* #define HKU_SQL_TRACE 0 */
26
+ #endif
19
27
 
28
+ #ifndef HKU_SUPPORT_DATETIME
20
29
  #define HKU_SUPPORT_DATETIME 1
30
+ #endif
21
31
 
32
+ #ifndef HKU_ENABLE_INI_PARSER
22
33
  #define HKU_ENABLE_INI_PARSER 1
34
+ #endif
23
35
 
36
+ #ifndef HKU_ENABLE_STACK_TRACE
24
37
  #define HKU_ENABLE_STACK_TRACE 0
38
+ #endif
25
39
 
40
+ #ifndef HKU_CLOSE_SPEND_TIME
26
41
  #define HKU_CLOSE_SPEND_TIME 0
42
+ #endif
27
43
 
44
+ #ifndef HKU_USE_SPDLOG_ASYNC_LOGGER
28
45
  #define HKU_USE_SPDLOG_ASYNC_LOGGER 0
46
+ #endif
47
+ #ifndef HKU_LOG_ACTIVE_LEVEL
29
48
  #define HKU_LOG_ACTIVE_LEVEL 2
49
+ #endif
30
50
 
51
+ #ifndef HKU_ENABLE_HTTP_CLIENT
31
52
  #define HKU_ENABLE_HTTP_CLIENT 1
53
+ #endif
54
+ #ifndef HKU_ENABLE_HTTP_CLIENT_SSL
32
55
  #define HKU_ENABLE_HTTP_CLIENT_SSL 0
56
+ #endif
57
+ #ifndef HKU_ENABLE_HTTP_CLIENT_ZIP
33
58
  #define HKU_ENABLE_HTTP_CLIENT_ZIP 0
59
+ #endif
34
60
 
61
+ #ifndef HKU_ENABLE_NODE
35
62
  #define HKU_ENABLE_NODE 1
63
+ #endif
36
64
 
37
65
  // clang-format on
38
66
 
@@ -12,6 +12,7 @@
12
12
  #include <string>
13
13
  #include "hikyuu/utilities/config.h"
14
14
  #include "hikyuu/utilities/osdef.h"
15
+ #include "hikyuu/utilities/Log.h"
15
16
 
16
17
  namespace hku {
17
18
 
@@ -35,12 +36,26 @@ public:
35
36
  #if HKU_OS_WINDOWS
36
37
  #define HKU_PLUGIN_DEFINE(plugin) \
37
38
  extern "C" __declspec(dllexport) hku::PluginBase* createPlugin() { \
38
- return new plugin(); \
39
+ try { \
40
+ return new plugin(); \
41
+ } catch (const std::exception& e) { \
42
+ HKU_ERROR("{}", e.what()); \
43
+ return nullptr; \
44
+ } catch (...) { \
45
+ return nullptr; \
46
+ } \
39
47
  }
40
48
  #else
41
49
  #define HKU_PLUGIN_DEFINE(plugin) \
42
50
  extern "C" hku::PluginBase* createPlugin() { \
43
- return new plugin(); \
51
+ try { \
52
+ return new plugin(); \
53
+ } catch (const std::exception& e) { \
54
+ HKU_ERROR("{}", e.what()); \
55
+ return nullptr; \
56
+ } catch (...) { \
57
+ return nullptr; \
58
+ } \
44
59
  }
45
60
  #endif
46
61
 
@@ -10,7 +10,7 @@
10
10
  #include <string>
11
11
  #include <memory>
12
12
  #include <unordered_map>
13
- #include <mutex>
13
+ #include <shared_mutex>
14
14
  #include "hikyuu/utilities/Log.h"
15
15
  #include "hikyuu/utilities/plugin/PluginLoader.h"
16
16
 
@@ -38,35 +38,54 @@ public:
38
38
  }
39
39
 
40
40
  template <typename PluginInterfaceT>
41
- PluginInterfaceT* getPlugin(const std::string& pluginname) noexcept;
41
+ PluginInterfaceT* getPlugin(const std::string& pluginname) noexcept {
42
+ PluginInterfaceT* ret{nullptr};
43
+ try {
44
+ {
45
+ std::shared_lock<std::shared_mutex> read_lock(m_mutex);
46
+ auto it = m_plugins.find(pluginname);
47
+ if (it != m_plugins.end()) {
48
+ ret = it->second->instance<PluginInterfaceT>();
49
+ return ret;
50
+ }
51
+ }
42
52
 
43
- private:
44
- std::unordered_map<std::string, std::unique_ptr<PluginLoader>>::iterator load(
45
- const std::string& pluginname) noexcept {
46
- std::lock_guard<std::mutex> lock(m_mutex);
47
- std::unique_ptr<PluginLoader> loader = std::make_unique<PluginLoader>(m_plugin_path);
48
- if (loader->load(pluginname)) {
49
- auto [it, success] = m_plugins.insert(std::make_pair(pluginname, std::move(loader)));
50
- if (success) {
51
- return it;
53
+ std::unique_ptr<PluginLoader> loader = std::make_unique<PluginLoader>(m_plugin_path);
54
+ if (!loader->load(pluginname)) {
55
+ HKU_DEBUG("Load plugin {} failed: {}", pluginname, loader->getFileName(pluginname));
56
+ return ret;
57
+ }
58
+
59
+ {
60
+ std::unique_lock<std::shared_mutex> write_lock(m_mutex);
61
+ auto it = m_plugins.find(pluginname);
62
+ if (it != m_plugins.end()) {
63
+ // 复用已插入的插件实例
64
+ ret = it->second->instance<PluginInterfaceT>();
65
+ } else {
66
+ // 插入新加载的插件
67
+ auto [it, success] =
68
+ m_plugins.insert(std::make_pair(pluginname, std::move(loader)));
69
+ if (success) {
70
+ ret = it->second->instance<PluginInterfaceT>();
71
+ }
72
+ }
73
+ return ret;
52
74
  }
75
+ } catch (const std::exception& e) {
76
+ HKU_ERROR("Load plugin {} failed: {}", pluginname, e.what());
77
+ ret = nullptr;
78
+ } catch (...) {
79
+ HKU_ERROR("Load plugin {} failed: unknown exception", pluginname);
80
+ ret = nullptr;
53
81
  }
54
- return m_plugins.end();
82
+ return ret;
55
83
  }
56
84
 
57
85
  private:
58
86
  std::string m_plugin_path;
59
87
  std::unordered_map<std::string, std::unique_ptr<PluginLoader>> m_plugins;
60
- std::mutex m_mutex;
88
+ std::shared_mutex m_mutex;
61
89
  };
62
90
 
63
- template <typename PluginInterfaceT>
64
- PluginInterfaceT* PluginManager::getPlugin(const std::string& pluginname) noexcept {
65
- auto it = m_plugins.find(pluginname);
66
- if (it == m_plugins.end()) {
67
- it = load(pluginname);
68
- }
69
- return it != m_plugins.end() ? it->second->instance<PluginInterfaceT>() : nullptr;
70
- }
71
-
72
91
  } // namespace hku
@@ -218,12 +218,11 @@ public:
218
218
  }
219
219
  }
220
220
 
221
+ m_done = true;
221
222
  m_master_work_queue.clear();
222
223
  for (size_t i = 0; i < m_worker_num; i++) {
223
224
  m_queues[i]->clear();
224
225
  }
225
-
226
- m_done = true;
227
226
  }
228
227
 
229
228
  private:
@@ -174,8 +174,8 @@ public:
174
174
  }
175
175
  }
176
176
 
177
- m_master_work_queue.clear();
178
177
  m_done = true;
178
+ m_master_work_queue.clear();
179
179
  }
180
180
 
181
181
  private: