hikyuu 2.5.6__py3-none-win_amd64.whl → 2.6.0__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 (72) hide show
  1. hikyuu/__init__.py +15 -0
  2. hikyuu/__init__.pyi +16 -7
  3. hikyuu/analysis/__init__.pyi +7 -0
  4. hikyuu/analysis/analysis.pyi +8 -1
  5. hikyuu/core.pyi +9 -2
  6. hikyuu/cpp/core310.pyd +0 -0
  7. hikyuu/cpp/core310.pyi +150 -19
  8. hikyuu/cpp/core311.pyd +0 -0
  9. hikyuu/cpp/core311.pyi +150 -19
  10. hikyuu/cpp/core312.pyd +0 -0
  11. hikyuu/cpp/core312.pyi +150 -19
  12. hikyuu/cpp/core313.pyd +0 -0
  13. hikyuu/cpp/core313.pyi +149 -19
  14. hikyuu/cpp/core39.pyd +0 -0
  15. hikyuu/cpp/core39.pyi +150 -19
  16. hikyuu/cpp/hikyuu.dll +0 -0
  17. hikyuu/cpp/hikyuu.lib +0 -0
  18. hikyuu/draw/drawplot/__init__.py +2 -0
  19. hikyuu/draw/drawplot/__init__.pyi +1 -0
  20. hikyuu/draw/drawplot/bokeh_draw.pyi +12 -4
  21. hikyuu/draw/drawplot/echarts_draw.pyi +12 -4
  22. hikyuu/draw/drawplot/matplotlib_draw.py +80 -0
  23. hikyuu/draw/drawplot/matplotlib_draw.pyi +22 -4
  24. hikyuu/examples/notebook/002-HowToGetStock.ipynb +1 -1
  25. hikyuu/examples/notebook/004-IndicatorOverview.ipynb +117 -52
  26. hikyuu/extend.pyi +9 -2
  27. hikyuu/gui/HikyuuTDX.py +19 -3
  28. hikyuu/gui/data/MainWindow.py +87 -24
  29. hikyuu/gui/dataserver.py +25 -0
  30. hikyuu/gui/images/star.png +0 -0
  31. hikyuu/hub.pyi +6 -6
  32. hikyuu/include/hikyuu/StockManager.h +23 -0
  33. hikyuu/include/hikyuu/global/agent/spot_generated.h +3 -3
  34. hikyuu/include/hikyuu/plugin/__init__.py +1 -0
  35. hikyuu/include/hikyuu/plugin/backtest.h +37 -0
  36. hikyuu/include/hikyuu/plugin/dataserver.h +18 -0
  37. hikyuu/include/hikyuu/plugin/device.h +29 -0
  38. hikyuu/include/hikyuu/plugin/interface/BackTestPluginInterface.h +26 -0
  39. hikyuu/include/hikyuu/plugin/interface/DataServerPluginInterface.h +23 -0
  40. hikyuu/include/hikyuu/plugin/interface/DevicePluginInterface.h +25 -0
  41. hikyuu/include/hikyuu/plugin/interface/__init__.py +1 -0
  42. hikyuu/include/hikyuu/plugin/interface/plugins.h +20 -0
  43. hikyuu/include/hikyuu/python/pybind_utils.h +8 -0
  44. hikyuu/include/hikyuu/strategy/BrokerTradeManager.h +2 -1
  45. hikyuu/include/hikyuu/strategy/RunPortfolioInStrategy.h +1 -0
  46. hikyuu/include/hikyuu/strategy/Strategy.h +96 -16
  47. hikyuu/include/hikyuu/trade_manage/TradeManagerBase.h +4 -2
  48. hikyuu/include/hikyuu/trade_sys/system/imp/WalkForwardTradeManager.h +3 -2
  49. hikyuu/include/hikyuu/utilities/plugin/PluginClient.h +2 -2
  50. hikyuu/include/hikyuu/utilities/plugin/PluginLoader.h +66 -13
  51. hikyuu/include/hikyuu/utilities/plugin/PluginManager.h +72 -0
  52. hikyuu/include/hikyuu/version.h +5 -5
  53. hikyuu/plugin/__init__.py +1 -0
  54. hikyuu/plugin/backtest.dll +0 -0
  55. hikyuu/plugin/dataserver.dll +0 -0
  56. hikyuu/plugin/device.dll +0 -0
  57. hikyuu/strategy/strategy_demo1.py +7 -8
  58. hikyuu/strategy/strategy_demo2.py +1 -1
  59. hikyuu/trade_manage/__init__.pyi +11 -3
  60. hikyuu/trade_manage/trade.pyi +11 -3
  61. hikyuu/util/__init__.pyi +1 -1
  62. hikyuu/util/singleton.pyi +1 -1
  63. {hikyuu-2.5.6.dist-info → hikyuu-2.6.0.dist-info}/METADATA +6 -2
  64. {hikyuu-2.5.6.dist-info → hikyuu-2.6.0.dist-info}/RECORD +69 -56
  65. {hikyuu-2.5.6.dist-info → hikyuu-2.6.0.dist-info}/entry_points.txt +1 -0
  66. {hikyuu-2.5.6.dist-info → hikyuu-2.6.0.dist-info}/top_level.txt +4 -0
  67. hikyuu/cpp/core38.pyd +0 -0
  68. hikyuu/cpp/core38.pyi +0 -13173
  69. hikyuu/examples/notebook/011-PyechartsDrawplot.ipynb +0 -21821
  70. /hikyuu/gui/{hikyuu_small.png → images/hikyuu_small.png} +0 -0
  71. {hikyuu-2.5.6.dist-info → hikyuu-2.6.0.dist-info}/LICENSE +0 -0
  72. {hikyuu-2.5.6.dist-info → hikyuu-2.6.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,20 @@
1
+ /*
2
+ * Copyright (c) 2025 hikyuu.org
3
+ *
4
+ * Created on: 2025-04-10
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include "BackTestPluginInterface.h"
11
+ #include "DevicePluginInterface.h"
12
+ #include "DataServerPluginInterface.h"
13
+
14
+ namespace hku {
15
+
16
+ #define HKU_PLUGIN_BACKTEST "backtest"
17
+ #define HKU_PLUGIN_DEVICE "device"
18
+ #define HKU_PLUGIN_DATASERVER "dataserver"
19
+
20
+ }
@@ -98,6 +98,14 @@ public: \
98
98
  return std::shared_ptr<classname>(keep_python_state_alive, ptr); \
99
99
  }
100
100
 
101
+ // 用于检查已 py::object 方式传递的函数参数个数是否符合预期
102
+ inline bool check_pyfunction_arg_num(py::object& func, size_t arg_num) {
103
+ py::module_ inspect = py::module_::import("inspect");
104
+ py::object sig = inspect.attr("signature")(func);
105
+ py::object params = sig.attr("parameters");
106
+ return len(params) == arg_num;
107
+ }
108
+
101
109
  } // namespace hku
102
110
 
103
111
  #endif // HIKYUU_PYTHON_BIND_UTILS_H
@@ -23,7 +23,8 @@ public:
23
23
 
24
24
  virtual shared_ptr<TradeManagerBase> _clone() override;
25
25
 
26
- virtual void fetchAssetInfoFromBroker(const OrderBrokerPtr& broker) override;
26
+ virtual void fetchAssetInfoFromBroker(const OrderBrokerPtr& broker,
27
+ const Datetime& datetime = Null<Datetime>()) override;
27
28
 
28
29
  /**
29
30
  * 根据权息信息更新当前持仓与交易情况
@@ -25,6 +25,7 @@ private:
25
25
  PFPtr m_pf;
26
26
  OrderBrokerPtr m_broker;
27
27
  KQuery m_query;
28
+ std::unordered_set<Stock> m_stocks;
28
29
  };
29
30
 
30
31
  StrategyPtr HKU_API crtPFStrategy(const PFPtr& pf, const KQuery& query,
@@ -8,6 +8,7 @@
8
8
  #pragma once
9
9
 
10
10
  #include <future>
11
+ #include <forward_list>
11
12
  #include "hikyuu/DataType.h"
12
13
  #include "hikyuu/StrategyContext.h"
13
14
  #include "hikyuu/global/SpotRecord.h"
@@ -34,7 +35,8 @@ public:
34
35
  Strategy();
35
36
  explicit Strategy(const string& name, const string& config_file = "");
36
37
  Strategy(const vector<string>& codeList, const vector<KQuery::KType>& ktypeList,
37
- const string& name = "Strategy", const string& config_file = "");
38
+ const unordered_map<string, int>& preloadNum = {}, const string& name = "Strategy",
39
+ const string& config_file = "");
38
40
  explicit Strategy(const StrategyContext& context, const string& name = "Strategy",
39
41
  const string& config_file = "");
40
42
 
@@ -55,14 +57,16 @@ public:
55
57
  return m_context;
56
58
  }
57
59
 
60
+ bool running() const;
61
+
58
62
  /**
59
63
  * 每日开盘时间内,以 delta 为周期循环定时执行指定任务
60
64
  * @param func 待执行的任务
61
65
  * @param delta 间隔时间
62
- * @param market 指定的市场
66
+ * @param market 指定的市场, 用于获取开/收盘时间
63
67
  * @param ignoreMarket 是否忽略市场时间限制,如为 true,则为定时循环不受开闭市时间限制
64
68
  */
65
- void runDaily(std::function<void()>&& func, const TimeDelta& delta,
69
+ void runDaily(const std::function<void(Strategy*)>& func, const TimeDelta& delta,
66
70
  const std::string& market = "SH", bool ignoreMarket = false);
67
71
 
68
72
  /**
@@ -71,7 +75,7 @@ public:
71
75
  * @param delta 指定时刻
72
76
  * @param ignoreHoliday 忽略节假日,即节假日不执行
73
77
  */
74
- void runDailyAt(std::function<void()>&& func, const TimeDelta& delta,
78
+ void runDailyAt(const std::function<void(Strategy*)>& func, const TimeDelta& delta,
75
79
  bool ignoreHoliday = true);
76
80
 
77
81
  /**
@@ -79,7 +83,8 @@ public:
79
83
  * @note 通常用于调试。且只要收到行情采集消息就会触发,不受开、闭市时间限制
80
84
  * @param changeFunc 回调函数
81
85
  */
82
- void onChange(std::function<void(const Stock&, const SpotRecord& spot)>&& changeFunc);
86
+ void onChange(
87
+ const std::function<void(Strategy*, const Stock&, const SpotRecord& spot)>& changeFunc);
83
88
 
84
89
  /**
85
90
  * 一批行情数据接受完毕后通知
@@ -87,36 +92,111 @@ public:
87
92
  * 且只要收到行情采集消息就会触发,不受开、闭市时间限制。
88
93
  * @param recievedFucn 回调函数
89
94
  */
90
- void onReceivedSpot(std::function<void(const Datetime&)>&& recievedFucn);
95
+ void onReceivedSpot(const std::function<void(Strategy*, const Datetime&)>& recievedFucn);
91
96
 
92
97
  /**
93
98
  * 启动策略执行,必须在已注册相关处理函数后执行
94
99
  */
95
100
  void start(bool autoRecieveSpot = true);
96
101
 
97
- private:
102
+ //==========================================================================
103
+ // 以下为策略运行时对外接口,建议使用这些接口代替同名其他功能函数,已保证回测和实盘一致
104
+ //==========================================================================
105
+
106
+ TradeManagerPtr getTM() const noexcept {
107
+ return m_tm;
108
+ }
109
+
110
+ void setTM(const TradeManagerPtr& tm) noexcept {
111
+ m_tm = tm;
112
+ }
113
+
114
+ /** 仅在回测状态下使用 */
115
+ SlippagePtr getSP() const noexcept {
116
+ return m_sp;
117
+ }
118
+
119
+ void setSP(const SlippagePtr& slippage) noexcept {
120
+ m_sp = slippage;
121
+ }
122
+
123
+ KData getKData(const Stock& stk, const Datetime& start_date, const Datetime& end_date,
124
+ const KQuery::KType& ktype,
125
+ KQuery::RecoverType recover_type = KQuery::NO_RECOVER) const {
126
+ return stk.getKData(KQueryByDate(start_date, end_date, ktype, recover_type));
127
+ }
128
+
129
+ KData getLastKData(const Stock& stk, const Datetime& start_date, const KQuery::KType& ktype,
130
+ KQuery::RecoverType recover_type = KQuery::NO_RECOVER) const {
131
+ return getKData(stk, start_date, Null<Datetime>(), ktype, recover_type);
132
+ }
133
+
134
+ KData getLastKData(const Stock& stk, size_t lastnum, const KQuery::KType& ktype,
135
+ KQuery::RecoverType recover_type = KQuery::NO_RECOVER) const;
136
+
137
+ virtual Datetime today() const {
138
+ return Datetime::today();
139
+ }
140
+
141
+ virtual Datetime now() const {
142
+ return Datetime::now();
143
+ }
144
+
145
+ virtual Datetime nextDatetime() const {
146
+ return Null<Datetime>();
147
+ }
148
+
149
+ virtual TradeRecord buy(const Stock& stk, price_t price, double num, double stoploss = 0.0,
150
+ double goal_price = 0.0,
151
+ SystemPart part_from = SystemPart::PART_SIGNAL) {
152
+ HKU_ASSERT(m_tm);
153
+ return m_tm->buy(Datetime::now(), stk, price, num, stoploss, goal_price, price, part_from);
154
+ }
155
+
156
+ virtual TradeRecord sell(const Stock& stk, price_t price, double num, price_t stoploss = 0.0,
157
+ price_t goal_price = 0.0,
158
+ SystemPart part_from = SystemPart::PART_SIGNAL) {
159
+ HKU_ASSERT(m_tm);
160
+ return m_tm->sell(Datetime::now(), stk, price, num, stoploss, goal_price, price, part_from);
161
+ }
162
+
163
+ virtual bool isBacktesting() const {
164
+ return false;
165
+ }
166
+
167
+ protected:
98
168
  string m_name;
99
169
  string m_config_file;
100
170
  StrategyContext m_context;
101
- std::function<void(const Datetime&)> m_on_recieved_spot;
102
- std::function<void(const Stock&, const SpotRecord& spot)> m_on_change;
171
+ TradeManagerPtr m_tm;
172
+ SlippagePtr m_sp;
173
+
174
+ std::function<void(Strategy*, const Datetime&)> m_on_recieved_spot;
175
+ std::function<void(Strategy*, const Stock&, const SpotRecord& spot)> m_on_change;
176
+
177
+ struct RunDailyAt {
178
+ std::function<void()> func;
179
+ TimeDelta delta;
180
+ string market;
181
+ bool ignoreMarket{false};
182
+ };
183
+ std::forward_list<RunDailyAt> m_run_daily_at_list;
184
+
185
+ std::unordered_map<TimeDelta, std::function<void()>> m_run_daily_at_funcs;
103
186
 
104
- std::function<void()> m_run_daily_func;
105
- TimeDelta m_run_daily_delta;
106
- string m_run_daily_market;
107
- bool m_ignoreMarket{false};
187
+ protected:
188
+ static std::atomic_bool ms_keep_running;
108
189
 
109
- std::map<TimeDelta, std::function<void()>> m_run_daily_at_funcs;
190
+ protected:
191
+ void _init();
110
192
 
111
193
  private:
112
194
  void _initParam();
113
- void _init();
114
195
  void _receivedSpot(const SpotRecord& spot);
115
196
  void _runDaily();
116
197
  void _runDailyAt();
117
198
 
118
199
  private:
119
- static std::atomic_bool ms_keep_running;
120
200
  static void sig_handler(int sig);
121
201
 
122
202
  typedef FuncWrapper event_type;
@@ -697,8 +697,10 @@ public:
697
697
  /**
698
698
  * 从订单代理实例同步当前账户资产信息(包含资金、持仓等)
699
699
  * @param broker 订单代理实例
700
+ * @param datetime 同步时,通常为当前时间(Null),也可以强制为指定的时间点
700
701
  */
701
- virtual void fetchAssetInfoFromBroker(const OrderBrokerPtr& broker) {
702
+ virtual void fetchAssetInfoFromBroker(const OrderBrokerPtr& broker,
703
+ const Datetime& datetime = Null<Datetime>()) {
702
704
  HKU_WARN("The subclass does not implement this method");
703
705
  }
704
706
 
@@ -706,7 +708,7 @@ protected:
706
708
  string m_name; // 账户名称
707
709
  TradeCostPtr m_costfunc; // 成本算法
708
710
 
709
- Datetime m_broker_last_datetime; // 订单代理最近一次执行操作的时刻,当前启动运行时间
711
+ Datetime m_broker_last_datetime; // 订单代理最近一次执行操作的时刻,当前启动运行时间
710
712
  list<OrderBrokerPtr> m_broker_list; // 订单代理列表
711
713
 
712
714
  //============================================
@@ -437,8 +437,9 @@ public:
437
437
  * 从订单代理实例同步当前账户资产信息(包含资金、持仓等)
438
438
  * @param broker 订单代理实例
439
439
  */
440
- virtual void fetchAssetInfoFromBroker(const OrderBrokerPtr& broker) override {
441
- m_tm->fetchAssetInfoFromBroker(broker);
440
+ virtual void fetchAssetInfoFromBroker(const OrderBrokerPtr& broker,
441
+ const Datetime& datetime = Null<Datetime>()) override {
442
+ m_tm->fetchAssetInfoFromBroker(broker, datetime);
442
443
  }
443
444
 
444
445
  private:
@@ -17,7 +17,7 @@ public:
17
17
  PluginClient() = delete;
18
18
  PluginClient(const std::string &path, const std::string &filename) {
19
19
  m_loader = std::make_unique<PluginLoader>(path);
20
- m_loader->load(filename);
20
+ HKU_CHECK(m_loader->load(filename), "load plugin failed! {}/{}", path, filename);
21
21
  m_impl = m_loader->instance<InterfaceT>();
22
22
  }
23
23
  virtual ~PluginClient() = default;
@@ -46,7 +46,7 @@ public:
46
46
  }
47
47
 
48
48
  protected:
49
- InterfaceT *m_impl;
49
+ InterfaceT *m_impl{nullptr};
50
50
 
51
51
  protected:
52
52
  std::unique_ptr<PluginLoader> m_loader;
@@ -14,29 +14,29 @@
14
14
  #include <memory>
15
15
  #include "hikyuu/utilities/config.h"
16
16
  #include "hikyuu/utilities/osdef.h"
17
+ #include "hikyuu/utilities/os.h"
17
18
  #include "hikyuu/utilities/Log.h"
18
19
  #include "PluginBase.h"
19
20
 
20
21
  #if HKU_OS_WINDOWS
21
22
  #include <windows.h>
22
- #endif
23
-
24
- #ifndef HKU_UTILS_API
25
- #define HKU_UTILS_API
23
+ #else
24
+ #include <dlfcn.h>
26
25
  #endif
27
26
 
28
27
  namespace hku {
29
28
 
30
- class HKU_UTILS_API PluginLoader final {
29
+ class PluginLoader final {
31
30
  public:
32
- PluginLoader();
33
- explicit PluginLoader(const std::string& path);
31
+ PluginLoader() : PluginLoader(".") {}
32
+ explicit PluginLoader(const std::string& path) : m_path(path) {}
33
+
34
34
  PluginLoader(const PluginLoader&) = delete;
35
35
  PluginLoader(PluginLoader&&) = delete;
36
36
 
37
- ~PluginLoader();
38
-
39
- bool load(const std::string& pluginname) noexcept;
37
+ ~PluginLoader() {
38
+ unload();
39
+ }
40
40
 
41
41
  template <typename T>
42
42
  T* instance() const noexcept {
@@ -44,10 +44,63 @@ public:
44
44
  return dynamic_cast<T*>(m_plugin.get());
45
45
  }
46
46
 
47
+ bool load(const std::string& pluginname) noexcept {
48
+ std::string filename = getFileName(pluginname);
49
+ HKU_WARN_IF_RETURN(!existFile(filename), false, "file({}) not exist!", filename);
50
+
51
+ #if HKU_OS_WINDOWS
52
+ m_handle = LoadLibrary(HKU_PATH(filename).c_str());
53
+ #else
54
+ m_handle = dlopen(filename.c_str(), RTLD_LAZY);
55
+ #endif
56
+ HKU_WARN_IF_RETURN(!m_handle, false, "load plugin({}) failed!", filename);
57
+
58
+ typedef PluginBase* (*CreateFunction)();
59
+ CreateFunction createFunction =
60
+ reinterpret_cast<CreateFunction>(getFunciton("createPlugin"));
61
+ HKU_WARN_IF_RETURN(!createFunction, false, "Failed to get plugin({}) handle!", filename);
62
+
63
+ m_plugin.reset(createFunction());
64
+ if (!m_plugin) {
65
+ HKU_ERROR("Failed to create plugin ({})!", filename);
66
+ unload();
67
+ m_plugin.reset();
68
+ return false;
69
+ }
70
+
71
+ return true;
72
+ }
73
+
47
74
  private:
48
- void unload() noexcept;
49
- void* getFunciton(const char* symbol) noexcept;
50
- std::string getFileName(const std::string& pluginname) const noexcept;
75
+ void unload() noexcept {
76
+ m_plugin.reset();
77
+ if (m_handle) {
78
+ #if HKU_OS_WINDOWS
79
+ FreeLibrary(m_handle);
80
+ #else
81
+ dlclose(m_handle);
82
+ #endif
83
+ }
84
+ }
85
+
86
+ void* getFunciton(const char* symbol) noexcept {
87
+ #if HKU_OS_WINDOWS
88
+ void* func = GetProcAddress(m_handle, symbol);
89
+ #else
90
+ void* func = dlsym(m_handle, symbol);
91
+ #endif
92
+ return func;
93
+ }
94
+
95
+ std::string getFileName(const std::string& pluginname) const noexcept {
96
+ #if HKU_OS_WINDOWS
97
+ return fmt::format("{}/{}.dll", m_path, pluginname);
98
+ #elif HKU_OS_LINUX
99
+ return fmt::format("{}/lib{}.so", m_path, pluginname);
100
+ #elif HKU_OS_OSX
101
+ return fmt::format("{}/lib{}.dylib", m_path, pluginname);
102
+ #endif
103
+ }
51
104
 
52
105
  private:
53
106
  #if HKU_OS_WINDOWS
@@ -0,0 +1,72 @@
1
+ /*
2
+ * Copyright (c) 2025 hikyuu.org
3
+ *
4
+ * Created on: 2025-04-10
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include <string>
11
+ #include <memory>
12
+ #include <unordered_map>
13
+ #include <mutex>
14
+ #include "hikyuu/utilities/Log.h"
15
+ #include "hikyuu/utilities/plugin/PluginLoader.h"
16
+
17
+ namespace hku {
18
+
19
+ class PluginManager final {
20
+ public:
21
+ PluginManager() : m_plugin_path(".") {};
22
+ explicit PluginManager(const std::string& plugin_path) : m_plugin_path(plugin_path) {}
23
+
24
+ ~PluginManager() = default;
25
+ PluginManager(const PluginManager&) = delete;
26
+ PluginManager(PluginManager&&) = delete;
27
+ PluginManager& operator=(const PluginManager&) = delete;
28
+ PluginManager& operator=(PluginManager&&) = delete;
29
+
30
+ const std::string& pluginPath() const noexcept {
31
+ return m_plugin_path;
32
+ }
33
+
34
+ void pluginPath(const std::string& plugin_path) noexcept {
35
+ HKU_TRACE_IF_RETURN(!m_plugins.empty(), void(),
36
+ "Existing loaded plugins, Ignore set plugin path: {}, ", plugin_path);
37
+ m_plugin_path = plugin_path;
38
+ }
39
+
40
+ template <typename PluginInterfaceT>
41
+ PluginInterfaceT* getPlugin(const std::string& pluginname) noexcept;
42
+
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;
52
+ }
53
+ }
54
+ return m_plugins.end();
55
+ }
56
+
57
+ private:
58
+ std::string m_plugin_path;
59
+ std::unordered_map<std::string, std::unique_ptr<PluginLoader>> m_plugins;
60
+ std::mutex m_mutex;
61
+ };
62
+
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
+ } // namespace hku
@@ -12,13 +12,13 @@
12
12
  #define HKU_VERSION_H
13
13
 
14
14
  // clang-format off
15
- #define HKU_VERSION "2.5.6"
15
+ #define HKU_VERSION "2.6.0"
16
16
  #define HKU_VERSION_MAJOR 2
17
- #define HKU_VERSION_MINOR 5
18
- #define HKU_VERSION_ALTER 6
19
- #define HKU_VERSION_BUILD 202504131513
17
+ #define HKU_VERSION_MINOR 6
18
+ #define HKU_VERSION_ALTER 0
19
+ #define HKU_VERSION_BUILD 202504301710
20
20
  #define HKU_VERSION_MODE "RELEASE"
21
- #define HKU_VERSION_GIT "2.5.6 release.2e933ae9 (RELEASE)"
21
+ #define HKU_VERSION_GIT "2.6.0 release.3bd470a3 (RELEASE)"
22
22
  // clang-format on
23
23
 
24
24
  #endif /* HKU_VERSION_H */
@@ -0,0 +1 @@
1
+
Binary file
Binary file
Binary file
@@ -7,24 +7,23 @@
7
7
  # 供自行实现程序化交易时参考,请自行负责程序化交易可能造成的损失。
8
8
  #
9
9
 
10
- from hikyuu import Strategy, Query, Datetime, Seconds, Minutes
11
- from hikyuu import sm
10
+ from hikyuu import *
12
11
 
13
12
 
14
- def on_change(stk, spot):
13
+ def on_change(stg: Strategy, stk: Stock, spot: SpotRecord):
15
14
  print("[on_change]:", stk.market_code, stk.name, spot.close, spot.bid1, spot.ask1)
16
15
 
17
16
 
18
- def on_spot(rev_time):
17
+ def on_spot(stg: Strategy, rev_time: Datetime):
19
18
  print("[on_received_spot] rev_time:", rev_time)
20
19
 
21
20
 
22
- def my_func1():
23
- print("[my_func1]", str(Datetime.now()))
21
+ def my_func1(stg: Strategy):
22
+ print("[my_func1]", str(stg.now()))
24
23
 
25
24
 
26
- def my_func2():
27
- print("[my_func2] calculate:", Datetime.now())
25
+ def my_func2(stg: Strategy):
26
+ print("[my_func2] calculate:", stg.now())
28
27
  for s in sm:
29
28
  print(s)
30
29
 
@@ -24,7 +24,7 @@ sys.set_param("sell_delay", False)
24
24
 
25
25
 
26
26
  # 执行策略主体
27
- def my_func():
27
+ def my_func(stg: Strategy):
28
28
  # 这里示例使用的是 TC_Zero() 零成本算法,但实际建议使用接近实际的成本算法
29
29
  # 因为 sys 不依赖于成交单中的实际成本,而是使用成本算法预算需要买入的数量
30
30
  run_in_strategy(sys, sm['sz000001'], Query(Datetime(20240101)), broker, TC_Zero())