hikyuu 2.3.0__py3-none-win_amd64.whl → 2.5.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 (179) hide show
  1. hikyuu/__init__.py +438 -6
  2. hikyuu/__init__.pyi +791 -0
  3. hikyuu/analysis/__init__.pyi +487 -0
  4. hikyuu/analysis/analysis.pyi +517 -0
  5. hikyuu/core.pyi +482 -0
  6. hikyuu/cpp/__init__.pyi +3 -0
  7. hikyuu/cpp/boost_date_time-mt.dll +0 -0
  8. hikyuu/cpp/boost_serialization-mt.dll +0 -0
  9. hikyuu/cpp/boost_wserialization-mt.dll +0 -0
  10. hikyuu/cpp/core310.pyd +0 -0
  11. hikyuu/cpp/core311.pyd +0 -0
  12. hikyuu/cpp/core312.pyd +0 -0
  13. hikyuu/cpp/core312.pyi +12867 -0
  14. hikyuu/cpp/core313.pyd +0 -0
  15. hikyuu/cpp/core38.pyd +0 -0
  16. hikyuu/cpp/core39.pyd +0 -0
  17. hikyuu/cpp/hikyuu.dll +0 -0
  18. hikyuu/cpp/hikyuu.lib +0 -0
  19. hikyuu/cpp/sqlite3.dll +0 -0
  20. hikyuu/data/common_mysql.py +24 -7
  21. hikyuu/data/common_pytdx.py +17 -1
  22. hikyuu/data/em_block_to_mysql.py +3 -2
  23. hikyuu/data/em_block_to_sqlite.py +8 -3
  24. hikyuu/data/mysql_upgrade/0025.sql +61 -0
  25. hikyuu/data/mysql_upgrade/0026.sql +9 -0
  26. hikyuu/data/sqlite_upgrade/0025.sql +63 -0
  27. hikyuu/data/sqlite_upgrade/0026.sql +10 -0
  28. hikyuu/draw/__init__.pyi +35 -0
  29. hikyuu/draw/drawplot/__init__.py +3 -0
  30. hikyuu/draw/drawplot/__init__.pyi +134 -0
  31. hikyuu/draw/drawplot/bokeh_draw.pyi +796 -0
  32. hikyuu/draw/drawplot/common.pyi +10 -0
  33. hikyuu/draw/drawplot/echarts_draw.py +219 -24
  34. hikyuu/draw/drawplot/echarts_draw.pyi +682 -0
  35. hikyuu/draw/drawplot/matplotlib_draw.py +18 -3
  36. hikyuu/draw/drawplot/matplotlib_draw.pyi +1101 -0
  37. hikyuu/draw/elder.pyi +44 -0
  38. hikyuu/draw/kaufman.pyi +38 -0
  39. hikyuu/draw/volume.pyi +31 -0
  40. hikyuu/examples/notebook/Demo/Demo2.ipynb +1 -1
  41. hikyuu/extend.py +9 -3
  42. hikyuu/extend.pyi +636 -0
  43. hikyuu/fetcher/stock/zh_block_em.py +118 -51
  44. hikyuu/gui/data/EscapetimeThread.py +4 -4
  45. hikyuu/gui/data/ImportBlockInfoTask.py +3 -2
  46. hikyuu/gui/data/ImportHistoryFinanceTask.py +2 -0
  47. hikyuu/gui/data/MainWindow.py +48 -42
  48. hikyuu/gui/importdata.py +13 -26
  49. hikyuu/hub.py +2 -4
  50. hikyuu/hub.pyi +254 -0
  51. hikyuu/include/hikyuu/DataType.h +5 -0
  52. hikyuu/include/hikyuu/Stock.h +7 -0
  53. hikyuu/include/hikyuu/indicator/Indicator.h +8 -1
  54. hikyuu/include/hikyuu/indicator/Indicator2InImp.h +65 -0
  55. hikyuu/include/hikyuu/indicator/IndicatorImp.h +4 -3
  56. hikyuu/include/hikyuu/indicator/build_in.h +12 -0
  57. hikyuu/include/hikyuu/indicator/crt/ADVANCE.h +3 -1
  58. hikyuu/include/hikyuu/indicator/crt/CONTEXT.h +2 -2
  59. hikyuu/include/hikyuu/indicator/crt/CORR.h +4 -2
  60. hikyuu/include/hikyuu/indicator/crt/COST.h +3 -0
  61. hikyuu/include/hikyuu/indicator/crt/CYCLE.h +24 -0
  62. hikyuu/include/hikyuu/indicator/crt/DECLINE.h +3 -1
  63. hikyuu/include/hikyuu/indicator/crt/DISCARD.h +27 -0
  64. hikyuu/include/hikyuu/indicator/crt/DMA.h +2 -1
  65. hikyuu/include/hikyuu/indicator/crt/HSL.h +1 -13
  66. hikyuu/include/hikyuu/indicator/crt/INBLOCK.h +31 -0
  67. hikyuu/include/hikyuu/indicator/crt/INDEX.h +60 -0
  68. hikyuu/include/hikyuu/indicator/crt/INSUM.h +5 -2
  69. hikyuu/include/hikyuu/indicator/crt/ISINF.h +28 -0
  70. hikyuu/include/hikyuu/indicator/crt/ISINFA.h +28 -0
  71. hikyuu/include/hikyuu/indicator/crt/ISNA.h +29 -0
  72. hikyuu/include/hikyuu/indicator/crt/JUMPDOWN.h +24 -0
  73. hikyuu/include/hikyuu/indicator/crt/JUMPUP.h +24 -0
  74. hikyuu/include/hikyuu/indicator/crt/LASTVALUE.h +29 -0
  75. hikyuu/include/hikyuu/indicator/crt/LIUTONGPAN.h +1 -0
  76. hikyuu/include/hikyuu/indicator/crt/REPLACE.h +29 -0
  77. hikyuu/include/hikyuu/indicator/crt/SPEARMAN.h +3 -2
  78. hikyuu/include/hikyuu/indicator/crt/WINNER.h +38 -0
  79. hikyuu/include/hikyuu/indicator/imp/IContext.h +1 -1
  80. hikyuu/include/hikyuu/indicator/imp/ICorr.h +7 -22
  81. hikyuu/include/hikyuu/indicator/imp/ICost.h +31 -0
  82. hikyuu/include/hikyuu/indicator/imp/ICycle.h +30 -0
  83. hikyuu/include/hikyuu/indicator/imp/IDiscard.h +28 -0
  84. hikyuu/include/hikyuu/indicator/imp/IDma.h +7 -24
  85. hikyuu/include/hikyuu/indicator/imp/IHsl.h +30 -0
  86. hikyuu/include/hikyuu/indicator/imp/IInBlock.h +30 -0
  87. hikyuu/include/hikyuu/indicator/imp/IIndex.h +26 -0
  88. hikyuu/include/hikyuu/indicator/imp/IIsInf.h +26 -0
  89. hikyuu/include/hikyuu/indicator/imp/IIsInfa.h +26 -0
  90. hikyuu/include/hikyuu/indicator/imp/IIsNa.h +26 -0
  91. hikyuu/include/hikyuu/indicator/imp/IJumpDown.h +24 -0
  92. hikyuu/include/hikyuu/indicator/imp/IJumpUp.h +24 -0
  93. hikyuu/include/hikyuu/indicator/imp/ILastValue.h +26 -0
  94. hikyuu/include/hikyuu/indicator/imp/IReplace.h +26 -0
  95. hikyuu/include/hikyuu/indicator/imp/ISpearman.h +6 -21
  96. hikyuu/include/hikyuu/indicator/imp/IWinner.h +26 -0
  97. hikyuu/include/hikyuu/indicator_talib/imp/TaMavp.h +6 -20
  98. hikyuu/include/hikyuu/indicator_talib/imp/ta_defines.h +14 -65
  99. hikyuu/include/hikyuu/indicator_talib/imp/ta_imp.h +54 -90
  100. hikyuu/include/hikyuu/indicator_talib/ta_crt.h +11 -9
  101. hikyuu/include/hikyuu/strategy/RunPortfolioInStrategy.h +3 -4
  102. hikyuu/include/hikyuu/strategy/Strategy.h +4 -5
  103. hikyuu/include/hikyuu/trade_manage/TradeRecord.h +5 -1
  104. hikyuu/include/hikyuu/trade_sys/allocatefunds/build_in.h +1 -0
  105. hikyuu/include/hikyuu/trade_sys/allocatefunds/crt/AF_FixedWeightList.h +22 -0
  106. hikyuu/include/hikyuu/trade_sys/allocatefunds/imp/FixedWeightListAllocateFunds.h +25 -0
  107. hikyuu/include/hikyuu/trade_sys/moneymanager/MoneyManagerBase.h +17 -4
  108. hikyuu/include/hikyuu/trade_sys/moneymanager/build_in.h +2 -0
  109. hikyuu/include/hikyuu/trade_sys/moneymanager/crt/MM_FixedCapital.h +6 -0
  110. hikyuu/include/hikyuu/trade_sys/moneymanager/crt/MM_FixedCapitalFunds.h +26 -0
  111. hikyuu/include/hikyuu/trade_sys/moneymanager/crt/MM_FixedCountTps.h +27 -0
  112. hikyuu/include/hikyuu/trade_sys/moneymanager/crt/MM_FixedRisk.h +6 -0
  113. hikyuu/include/hikyuu/trade_sys/moneymanager/crt/MM_FixedUnits.h +6 -0
  114. hikyuu/include/hikyuu/trade_sys/moneymanager/crt/MM_WilliamsFixedRisk.h +7 -0
  115. hikyuu/include/hikyuu/trade_sys/moneymanager/imp/FixedCapitalFundsMM.h +28 -0
  116. hikyuu/include/hikyuu/trade_sys/moneymanager/imp/FixedCountTpsMM.h +44 -0
  117. hikyuu/include/hikyuu/trade_sys/multifactor/build_in.h +1 -0
  118. hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_Weight.h +30 -0
  119. hikyuu/include/hikyuu/trade_sys/multifactor/imp/WeightMultiFactor.h +41 -0
  120. hikyuu/include/hikyuu/trade_sys/portfolio/Portfolio.h +38 -37
  121. hikyuu/include/hikyuu/trade_sys/portfolio/build_in.h +1 -0
  122. hikyuu/include/hikyuu/trade_sys/portfolio/crt/PF_Simple.h +25 -1
  123. hikyuu/include/hikyuu/trade_sys/portfolio/crt/PF_WithoutAF.h +50 -0
  124. hikyuu/include/hikyuu/trade_sys/portfolio/imp/SimplePortfolio.h +53 -0
  125. hikyuu/include/hikyuu/trade_sys/portfolio/imp/WithoutAFPortfolio.h +57 -0
  126. hikyuu/include/hikyuu/trade_sys/selector/imp/MultiFactorSelector.h +7 -0
  127. hikyuu/include/hikyuu/trade_sys/signal/SignalBase.h +51 -5
  128. hikyuu/include/hikyuu/trade_sys/signal/build_in.h +2 -0
  129. hikyuu/include/hikyuu/trade_sys/signal/crt/SG_Bool.h +2 -1
  130. hikyuu/include/hikyuu/trade_sys/signal/crt/SG_Logic.h +37 -0
  131. hikyuu/include/hikyuu/trade_sys/signal/crt/SG_OneSide.h +28 -0
  132. hikyuu/include/hikyuu/trade_sys/signal/imp/OneSideSignal.h +46 -0
  133. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/AddSignal.h +19 -0
  134. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/AddValueSignal.h +19 -0
  135. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/DivSignal.h +19 -0
  136. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/DivValueSignal.h +22 -0
  137. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/MulSignal.h +19 -0
  138. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/MulValueSignal.h +19 -0
  139. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/OperatorSignal.h +68 -0
  140. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/OperatorValueSignal.h +67 -0
  141. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/SubSignal.h +19 -0
  142. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/SubValueSignal.h +22 -0
  143. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/__init__.py +1 -0
  144. hikyuu/include/hikyuu/trade_sys/stoploss/crt/ST_Indicator.h +1 -1
  145. hikyuu/include/hikyuu/trade_sys/stoploss/imp/IndicatorStoploss.h +3 -4
  146. hikyuu/include/hikyuu/utilities/FilterNode.h +2 -2
  147. hikyuu/include/hikyuu/utilities/Log.h +42 -15
  148. hikyuu/include/hikyuu/utilities/datetime/Datetime.h +1 -1
  149. hikyuu/include/hikyuu/utilities/datetime/TimeDelta.h +2 -2
  150. hikyuu/include/hikyuu/utilities/db_connect/DBCondition.h +4 -0
  151. hikyuu/include/hikyuu/utilities/db_connect/SQLResultSet.h +2 -2
  152. hikyuu/include/hikyuu/utilities/db_connect/mysql/MySQLConnect.h +5 -1
  153. hikyuu/include/hikyuu/utilities/node/NodeServer.h +4 -4
  154. hikyuu/include/hikyuu/utilities/thread/MQStealThreadPool.h +2 -2
  155. hikyuu/include/hikyuu/utilities/thread/MQThreadPool.h +2 -2
  156. hikyuu/include/hikyuu/utilities/thread/StealThreadPool.h +5 -5
  157. hikyuu/include/hikyuu/utilities/thread/ThreadPool.h +2 -2
  158. hikyuu/include/hikyuu/utilities/thread/algorithm.h +16 -10
  159. hikyuu/include/hikyuu/version.h +4 -4
  160. hikyuu/indicator/indicator.py +1 -0
  161. hikyuu/interactive.py +3 -266
  162. hikyuu/trade_manage/__init__.pyi +584 -0
  163. hikyuu/trade_manage/broker.pyi +54 -0
  164. hikyuu/trade_manage/broker_easytrader.pyi +21 -0
  165. hikyuu/trade_manage/broker_mail.pyi +55 -0
  166. hikyuu/trade_manage/trade.pyi +590 -0
  167. hikyuu/util/__init__.pyi +55 -0
  168. hikyuu/util/check.pyi +59 -0
  169. hikyuu/util/mylog.pyi +70 -0
  170. hikyuu/util/notebook.pyi +23 -0
  171. hikyuu/util/singleton.pyi +18 -0
  172. hikyuu/util/slice.pyi +8 -0
  173. {hikyuu-2.3.0.dist-info → hikyuu-2.5.0.dist-info}/METADATA +3 -2
  174. {hikyuu-2.3.0.dist-info → hikyuu-2.5.0.dist-info}/RECORD +178 -95
  175. {hikyuu-2.3.0.dist-info → hikyuu-2.5.0.dist-info}/top_level.txt +1 -0
  176. hikyuu/deprecated.py +0 -651
  177. {hikyuu-2.3.0.dist-info → hikyuu-2.5.0.dist-info}/LICENSE +0 -0
  178. {hikyuu-2.3.0.dist-info → hikyuu-2.5.0.dist-info}/WHEEL +0 -0
  179. {hikyuu-2.3.0.dist-info → hikyuu-2.5.0.dist-info}/entry_points.txt +0 -0
hikyuu/interactive.py CHANGED
@@ -24,308 +24,45 @@
24
24
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
25
  # SOFTWARE.
26
26
 
27
- from hikyuu.data.hku_config_template import generate_default_config
28
- from .draw import *
29
- __copyright__ = """
30
- MIT License
31
-
32
- Copyright (c) 2010-2017 fasiondog
33
-
34
- Permission is hereby granted, free of charge, to any person obtaining a copy
35
- of this software and associated documentation files (the "Software"), to deal
36
- in the Software without restriction, including without limitation the rights
37
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
38
- copies of the Software, and to permit persons to whom the Software is
39
- furnished to do so, subject to the following conditions:
40
-
41
- The above copyright notice and this permission notice shall be included in all
42
- copies or substantial portions of the Software.
43
-
44
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
47
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
48
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
49
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
50
- SOFTWARE.
51
- """
52
-
53
- import os
54
- import configparser
55
-
56
- from hikyuu.data.hku_config_template import generate_default_config
57
27
  from hikyuu import *
58
28
 
29
+ load_hikyuu()
59
30
 
60
- # ==============================================================================
61
- #
62
- # 读取配置信息,并初始化
63
- #
64
- # ==============================================================================
65
- config_file = os.path.expanduser('~') + "/.hikyuu/hikyuu.ini"
66
- if not os.path.exists(config_file):
67
- # 创建默认配置
68
- hku_info("创建默认配置文件")
69
- generate_default_config()
70
-
71
- ini = configparser.ConfigParser()
72
- ini.read(config_file, encoding='utf-8')
73
- hku_param = Parameter()
74
- hku_param["tmpdir"] = ini.get('hikyuu', 'tmpdir')
75
- hku_param["datadir"] = ini.get('hikyuu', 'datadir')
76
- if ini.has_option('hikyuu', 'quotation_server'):
77
- hku_param["quotation_server"] = ini['hikyuu']['quotation_server']
78
-
79
- base_param = Parameter()
80
- base_info_config = ini.options('baseinfo')
81
- for p in base_info_config:
82
- base_param[p] = ini.get('baseinfo', p)
83
-
84
- block_param = Parameter()
85
- block_config = ini.options('block')
86
- for p in block_config:
87
- block_param[p] = ini.get('block', p)
88
-
89
- preload_param = Parameter()
90
- preload_config = ini.options('preload')
91
- for p in preload_config:
92
- if p in ('day', 'week', 'month', 'quarter', 'halfyear', 'year', 'min', 'min5', 'min15', 'min30', 'min60', 'hour2'):
93
- preload_param[p] = ini.getboolean('preload', p)
94
- else:
95
- preload_param[p] = ini.getint('preload', p)
96
-
97
- kdata_param = Parameter()
98
- kdata_config = ini.options('kdata')
99
- for p in kdata_config:
100
- if p == "convert":
101
- kdata_param[p] = ini.getboolean('kdata', p)
102
- continue
103
- kdata_param[p] = ini.get('kdata', p)
104
-
105
- context = StrategyContext(["all"])
106
- if 'HKU_STOCK_LIST' in os.environ:
107
- context.stock_list = os.environ['HKU_STOCK_LIST'].split(";")
108
- if 'HKU_KTYPE_LIST' in os.environ:
109
- context.ktype_list = os.environ['HKU_KTYPE_LIST'].split(";")
110
- if 'HKU_LOAD_HISTORY_FINANCE' in os.environ:
111
- load_str = os.environ['HKU_LOAD_HISTORY_FINANCE'].upper()
112
- load_finance = load_str in ("1", "TRUE")
113
- hku_param.set("load_history_finance", load_finance)
114
- if 'HKU_LOAD_STOCK_WEIGHT' in os.environ:
115
- load_str = os.environ['HKU_LOAD_STOCK_WEIGHT'].upper()
116
- load_stk_weight = load_str in ("1", "TRUE")
117
- hku_param.set("load_stock_weight", load_stk_weight)
118
-
119
- sm.init(base_param, block_param, kdata_param, preload_param, hku_param, context)
120
- # set_log_level(LOG_LEVEL.INFO)
121
-
122
- start_spot = False
123
- if 'HKU_START_SPOT' in os.environ:
124
- spot_str = os.environ['HKU_START_SPOT'].upper()
125
- start_spot = spot_str in ('1', 'TRUE')
126
- spot_worker_num = 1
127
- if 'HKU_SPOT_WORKER_NUM' in os.environ:
128
- spot_worker_num = int(os.environ['HKU_SPOT_WORKER_NUM'])
129
-
130
- # 启动行情接收代理
131
- start_spot_agent(False, spot_worker_num)
132
-
133
- # ==============================================================================
134
- #
135
- # 引入blocka、blocksh、blocksz、blockg全局变量,便于交互式环境下使用
136
- #
137
- # ==============================================================================
138
31
  blocka = Block("A", "ALL")
139
32
  for s in sm:
140
33
  if s.type in (constant.STOCKTYPE_A, constant.STOCKTYPE_A_BJ):
141
34
  blocka.add(s)
142
35
  zsbk_a = blocka
143
-
144
36
  blocksh = Block("A", "SH")
145
37
  for s in blocka:
146
38
  if s.market == "SH":
147
39
  blocksh.add(s)
148
40
  zsbk_sh = blocksh
149
-
150
41
  blocksz = Block("A", "SZ")
151
42
  for s in blocka:
152
43
  if s.market == "SZ":
153
44
  blocksz.add(s)
154
45
  zsbk_sz = blocksz
155
-
156
46
  blockbj = Block("A", "BJ")
157
47
  for s in blocka:
158
48
  if s.market == "BJ":
159
49
  blockbj.add(s)
160
50
  zsbk_bj = blockbj
161
-
162
51
  blockg = Block("G", "创业板")
163
52
  for s in sm:
164
53
  if s.type == constant.STOCKTYPE_GEM:
165
54
  blockg.add(s)
166
55
  zsbk_cyb = blockg
167
-
168
56
  blockstart = Block("START", "科创板")
169
57
  for s in sm:
170
58
  if s.type == constant.STOCKTYPE_START:
171
59
  blockstart.add(s)
172
-
173
60
  blockzxb = Block("A", "中小板")
174
61
  for s in blocksz:
175
62
  if s.code[:3] == "002":
176
63
  blockzxb.add(s)
177
64
  zsbk_zxb = blockzxb
178
-
179
- zsbk_sz50 = sm.get_block("指数板块", "上证50")
180
- zsbk_sz180 = sm.get_block("指数板块", "上证180")
65
+ zsbk_sh50 = sm.get_block("指数板块", "上证50")
66
+ zsbk_sh180 = sm.get_block("指数板块", "上证180")
181
67
  zsbk_hs300 = sm.get_block("指数板块", "沪深300")
182
68
  zsbk_zz100 = sm.get_block("指数板块", "中证100")
183
-
184
-
185
- def set_global_context(stk, query):
186
- """设置全局的 context
187
-
188
- :param Stock stk: 指定的全局Stock
189
- :param Query query: 指定的查询条件
190
- """
191
- global K, O, C, H, L, A, V
192
- K = stk.get_kdata(query)
193
- O.set_context(K)
194
- C.set_context(K)
195
- H.set_context(K)
196
- L.set_context(K)
197
- A.set_context(K)
198
- V.set_context(K)
199
-
200
-
201
- def get_global_context():
202
- """获取当前的全局上下文
203
-
204
- :rtype: KData
205
- """
206
- return C.getContext()
207
-
208
-
209
- set_global_context(sm['sh000001'], Query(-150))
210
-
211
- # ==============================================================================
212
- #
213
- # 设置默认绘图引擎
214
- #
215
- # ==============================================================================
216
-
217
- use_draw_engine('matplotlib')
218
-
219
- # ==============================================================================
220
- #
221
- # 粗略的选股函数
222
- #
223
- # ==============================================================================
224
-
225
-
226
- def select(cond, start=Datetime(201801010000), end=Datetime.now(), print_out=True):
227
- """
228
- 示例:
229
- #选出涨停股
230
- C = CLOSE()
231
- x = select(C / REF(C, 1) - 1 >= 0.0995))
232
-
233
- :param Indicator cond: 条件指标
234
- :param Datetime start: 起始日期
235
- :param Datetime end: 结束日期
236
- :param bool print_out: 打印选中的股票
237
- :rtype: 选中的股票列表
238
- """
239
- q = Query(start, end)
240
- d = sm.get_trading_calendar(q, 'SH')
241
- if len(d) == 0:
242
- return
243
-
244
- result = []
245
- for s in blocka:
246
- if not s.valid:
247
- continue
248
-
249
- q = Query(start, end)
250
- k = s.get_kdata(q)
251
- cond.set_context(k)
252
- if len(cond) > 0 and cond[-1] != constant.null_price and cond[-1] > 0 and len(k
253
- ) > 0 and k[-1].datetime == d[-1]:
254
- result.append(s)
255
- if print_out:
256
- print(d[-1], s)
257
-
258
- return result
259
-
260
-
261
- # ==============================================================================
262
- #
263
- # 增加临时的实时数据更新函数 realtime_update
264
- #
265
- # ==============================================================================
266
-
267
-
268
- def realtime_update_inner(source='qq', stk_list=None):
269
- if stk_list is None:
270
- if source == 'qmt':
271
- stk_list = [s for s in sm if s.valid and s.type in (
272
- constant.STOCKTYPE_A, constant.STOCKTYPE_INDEX, constant.STOCKTYPE_ETF,
273
- constant.STOCKTYPE_GEM, constant.STOCKTYPE_START, constant.STOCKTYPE_A_BJ)]
274
- else:
275
- stk_list = [
276
- stk.market_code.lower() for stk in sm if stk.valid and stk.type in
277
- (constant.STOCKTYPE_A, constant.STOCKTYPE_INDEX, constant.STOCKTYPE_GEM,
278
- constant.STOCKTYPE_START, constant.STOCKTYPE_A_BJ)
279
- ]
280
-
281
- if source == 'qq':
282
- from hikyuu.fetcher.stock.zh_stock_a_sina_qq import get_spot
283
- stk_list = [s.market_code.lower() for s in stk_list]
284
- records = get_spot(stk_list, 'qq')
285
- elif source == 'qmt':
286
- from hikyuu.fetcher.stock.zh_stock_a_qmt import get_spot
287
- records = get_spot(stk_list)
288
- else:
289
- hku_error(f'Not support website source: {source}!')
290
- return
291
-
292
- for r in records:
293
- stk = sm[f'{r["market"]}{r["code"]}']
294
- if stk.is_null():
295
- continue
296
- k = KRecord()
297
- k.datetime = Datetime(r['datetime']).start_of_day()
298
- k.open = r['open']
299
- k.high = r['high']
300
- k.low = r['low']
301
- k.close = r['close']
302
- k.volume = r['volume']
303
- k.amount = r['amount']
304
- stk.realtime_update(k)
305
-
306
-
307
- def realtime_update_wrap():
308
- pre_update_time = None
309
-
310
- def realtime_update_closure(source='qq', delta=60, stk_list=None):
311
- """
312
- 更新实时日线数据
313
- :param str source: 数据源 ('qq' | 'qmt')
314
- :param int delta: 最小更新间隔时间, 防止更新过于频繁
315
- :param sequence stk_list: 待更新的stock列表, 如为 None 则更新全部
316
- """
317
- from datetime import timedelta, datetime
318
- nonlocal pre_update_time
319
- now_update_time = datetime.now()
320
- if (source == 'qmt') or (pre_update_time is None) or (now_update_time - pre_update_time) > timedelta(0, delta, 0):
321
- realtime_update_inner(source, stk_list)
322
- pre_update_time = datetime.now()
323
- print(f"更新完毕!更新时间: {pre_update_time}")
324
- else:
325
- print(f"更新间隔小于 {str(delta)} 秒,未更新")
326
- print(f"上次更新时间: {pre_update_time}")
327
-
328
- return realtime_update_closure
329
-
330
-
331
- realtime_update = realtime_update_wrap()