hikyuu 2.6.2__py3-none-win_amd64.whl → 2.6.5__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 (136) hide show
  1. hikyuu/__init__.py +1 -1
  2. hikyuu/__init__.pyi +28 -13
  3. hikyuu/analysis/__init__.pyi +20 -0
  4. hikyuu/analysis/analysis.pyi +21 -1
  5. hikyuu/core.pyi +22 -2
  6. hikyuu/cpp/core310.pyd +0 -0
  7. hikyuu/cpp/core310.pyi +499 -50
  8. hikyuu/cpp/core311.pyd +0 -0
  9. hikyuu/cpp/core311.pyi +499 -50
  10. hikyuu/cpp/core312.pyd +0 -0
  11. hikyuu/cpp/core312.pyi +499 -50
  12. hikyuu/cpp/core313.pyd +0 -0
  13. hikyuu/cpp/core313.pyi +499 -50
  14. hikyuu/cpp/core39.pyd +0 -0
  15. hikyuu/cpp/core39.pyi +499 -50
  16. hikyuu/cpp/hikyuu.dll +0 -0
  17. hikyuu/cpp/hikyuu.lib +0 -0
  18. hikyuu/data/common.py +1 -1
  19. hikyuu/data/common_mysql.py +19 -0
  20. hikyuu/data/common_pytdx.py +2 -0
  21. hikyuu/data/common_sqlite3.py +1 -0
  22. hikyuu/data/hku_config_template.py +14 -0
  23. hikyuu/data/mysql_upgrade/0028.sql +95 -0
  24. hikyuu/data/pytdx_to_h5.py +53 -13
  25. hikyuu/data/pytdx_to_mysql.py +42 -9
  26. hikyuu/data/pytdx_to_taos.py +736 -0
  27. hikyuu/data/sqlite_upgrade/0028.sql +97 -0
  28. hikyuu/draw/__init__.pyi +1 -1
  29. hikyuu/draw/drawplot/__init__.pyi +1 -1
  30. hikyuu/draw/drawplot/bokeh_draw.pyi +24 -9
  31. hikyuu/draw/drawplot/echarts_draw.pyi +24 -9
  32. hikyuu/draw/drawplot/matplotlib_draw.py +26 -4
  33. hikyuu/draw/drawplot/matplotlib_draw.pyi +24 -9
  34. hikyuu/draw/kaufman.py +2 -2
  35. hikyuu/draw/kaufman.pyi +2 -2
  36. hikyuu/examples/notebook/001-overview.ipynb +65 -100
  37. hikyuu/examples/notebook/004-IndicatorOverview.ipynb +34 -32
  38. hikyuu/examples/notebook/007-SystemDetails.ipynb +64 -50
  39. hikyuu/examples/notebook/010-Portfolio.ipynb +120 -124
  40. hikyuu/extend.py +1 -1
  41. hikyuu/extend.pyi +24 -9
  42. hikyuu/fetcher/stock/zh_block_em.py +349 -5
  43. hikyuu/fetcher/stock/zh_stock_a_pytdx.py +2 -1
  44. hikyuu/gui/HikyuuTDX.py +47 -24
  45. hikyuu/gui/data/ImportBlockInfoTask.py +1 -1
  46. hikyuu/gui/data/ImportHistoryFinanceTask.py +48 -44
  47. hikyuu/gui/data/ImportPytdxTimeToH5Task.py +3 -1
  48. hikyuu/gui/data/ImportPytdxToH5Task.py +4 -2
  49. hikyuu/gui/data/ImportPytdxTransToH5Task.py +3 -1
  50. hikyuu/gui/data/ImportWeightToSqliteTask.py +2 -1
  51. hikyuu/gui/data/ImportZhBond10Task.py +1 -1
  52. hikyuu/gui/data/MainWindow.py +123 -106
  53. hikyuu/gui/data/UsePytdxImportToH5Thread.py +7 -3
  54. hikyuu/gui/data/UseQmtImportToH5Thread.py +1 -0
  55. hikyuu/gui/data/UseTdxImportToH5Thread.py +2 -1
  56. hikyuu/hub.pyi +6 -6
  57. hikyuu/include/hikyuu/Block.h +20 -0
  58. hikyuu/include/hikyuu/KQuery.h +8 -0
  59. hikyuu/include/hikyuu/MarketInfo.h +6 -0
  60. hikyuu/include/hikyuu/Stock.h +1 -1
  61. hikyuu/include/hikyuu/StockManager.h +6 -0
  62. hikyuu/include/hikyuu/data_driver/BaseInfoDriver.h +35 -0
  63. hikyuu/include/hikyuu/indicator/Indicator.h +5 -0
  64. hikyuu/include/hikyuu/indicator/IndicatorImp.h +8 -3
  65. hikyuu/include/hikyuu/indicator/build_in.h +1 -0
  66. hikyuu/include/hikyuu/indicator/crt/BARSLASTCOUNT.h +33 -0
  67. hikyuu/include/hikyuu/indicator/crt/INSUM.h +5 -10
  68. hikyuu/include/hikyuu/indicator/crt/RSI.h +2 -18
  69. hikyuu/include/hikyuu/indicator/imp/IBarsLastCount.h +27 -0
  70. hikyuu/include/hikyuu/plugin/backtest.h +3 -2
  71. hikyuu/include/hikyuu/plugin/device.h +6 -3
  72. hikyuu/include/hikyuu/plugin/extind.h +150 -0
  73. hikyuu/include/hikyuu/plugin/interface/BackTestPluginInterface.h +2 -1
  74. hikyuu/include/hikyuu/plugin/interface/DevicePluginInterface.h +1 -0
  75. hikyuu/include/hikyuu/plugin/interface/ExtendIndicatorsPluginInterface.h +26 -0
  76. hikyuu/include/hikyuu/plugin/interface/TMReportPluginInterface.h +80 -0
  77. hikyuu/include/hikyuu/plugin/interface/plugins.h +4 -0
  78. hikyuu/include/hikyuu/strategy/BrokerTradeManager.h +7 -5
  79. hikyuu/include/hikyuu/strategy/Strategy.h +22 -9
  80. hikyuu/include/hikyuu/trade_manage/OrderBrokerBase.h +11 -4
  81. hikyuu/include/hikyuu/trade_manage/Performance.h +17 -9
  82. hikyuu/include/hikyuu/trade_manage/PositionExtInfo.h +92 -0
  83. hikyuu/include/hikyuu/trade_manage/PositionRecord.h +7 -1
  84. hikyuu/include/hikyuu/trade_manage/TradeManager.h +8 -5
  85. hikyuu/include/hikyuu/trade_manage/TradeManagerBase.h +66 -5
  86. hikyuu/include/hikyuu/trade_manage/TradeRecord.h +9 -1
  87. hikyuu/include/hikyuu/trade_sys/multifactor/MultiFactorBase.h +8 -5
  88. hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_EqualWeight.h +4 -1
  89. hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_ICIRWeight.h +4 -1
  90. hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_ICWeight.h +4 -1
  91. hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_Weight.h +4 -1
  92. hikyuu/include/hikyuu/trade_sys/multifactor/imp/EqualWeightMultiFactor.h +2 -1
  93. hikyuu/include/hikyuu/trade_sys/multifactor/imp/ICIRMultiFactor.h +2 -1
  94. hikyuu/include/hikyuu/trade_sys/multifactor/imp/ICMultiFactor.h +2 -1
  95. hikyuu/include/hikyuu/trade_sys/multifactor/imp/WeightMultiFactor.h +1 -1
  96. hikyuu/include/hikyuu/trade_sys/selector/crt/SE_Optimal.h +8 -0
  97. hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/OptimalEvaluateSelector.h +28 -0
  98. hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/OptimalSelectorBase.h +1 -0
  99. hikyuu/include/hikyuu/trade_sys/system/TradeRequest.h +7 -4
  100. hikyuu/include/hikyuu/trade_sys/system/imp/WalkForwardTradeManager.h +17 -13
  101. hikyuu/include/hikyuu/utilities/DllLoader.h +226 -0
  102. hikyuu/include/hikyuu/utilities/datetime/Datetime.h +20 -0
  103. hikyuu/include/hikyuu/utilities/datetime/TimeDelta.h +6 -0
  104. hikyuu/include/hikyuu/utilities/plugin/PluginLoader.h +10 -10
  105. hikyuu/include/hikyuu/utilities/thread/{MQStealThreadPool.h → GlobalMQStealThreadPool.h} +12 -12
  106. hikyuu/include/hikyuu/utilities/thread/GlobalMQThreadPool.h +271 -0
  107. hikyuu/include/hikyuu/utilities/thread/{StealThreadPool.h → GlobalStealThreadPool.h} +11 -10
  108. hikyuu/include/hikyuu/utilities/thread/GlobalThreadPool.h +224 -0
  109. hikyuu/include/hikyuu/utilities/thread/InterruptFlag.h +16 -0
  110. hikyuu/include/hikyuu/utilities/thread/MQThreadPool.h +40 -77
  111. hikyuu/include/hikyuu/utilities/thread/ThreadPool.h +31 -59
  112. hikyuu/include/hikyuu/utilities/thread/ThreadSafeQueue.h +4 -0
  113. hikyuu/include/hikyuu/utilities/thread/algorithm.h +9 -9
  114. hikyuu/include/hikyuu/utilities/thread/thread.h +4 -0
  115. hikyuu/include/hikyuu/version.h +4 -4
  116. hikyuu/plugin/backtest.dll +0 -0
  117. hikyuu/plugin/dataserver.dll +0 -0
  118. hikyuu/plugin/device.dll +0 -0
  119. hikyuu/plugin/extind.dll +0 -0
  120. hikyuu/plugin/import2hdf5.dll +0 -0
  121. hikyuu/plugin/tmreport.dll +0 -0
  122. hikyuu/trade_manage/__init__.pyi +23 -8
  123. hikyuu/trade_manage/broker.py +8 -8
  124. hikyuu/trade_manage/broker.pyi +4 -4
  125. hikyuu/trade_manage/broker_easytrader.py +3 -3
  126. hikyuu/trade_manage/broker_easytrader.pyi +2 -2
  127. hikyuu/trade_manage/broker_mail.py +2 -2
  128. hikyuu/trade_manage/broker_mail.pyi +2 -2
  129. hikyuu/trade_manage/trade.pyi +23 -8
  130. hikyuu/util/singleton.pyi +1 -1
  131. {hikyuu-2.6.2.dist-info → hikyuu-2.6.5.dist-info}/METADATA +4 -3
  132. {hikyuu-2.6.2.dist-info → hikyuu-2.6.5.dist-info}/RECORD +136 -121
  133. {hikyuu-2.6.2.dist-info → hikyuu-2.6.5.dist-info}/LICENSE +0 -0
  134. {hikyuu-2.6.2.dist-info → hikyuu-2.6.5.dist-info}/WHEEL +0 -0
  135. {hikyuu-2.6.2.dist-info → hikyuu-2.6.5.dist-info}/entry_points.txt +0 -0
  136. {hikyuu-2.6.2.dist-info → hikyuu-2.6.5.dist-info}/top_level.txt +0 -0
hikyuu/cpp/hikyuu.dll CHANGED
Binary file
hikyuu/cpp/hikyuu.lib CHANGED
Binary file
hikyuu/data/common.py CHANGED
@@ -227,7 +227,7 @@ def historyfinancialreader(filepath):
227
227
  stock_header = struct.unpack(header_pack_format, data_header)
228
228
  max_count = stock_header[2]
229
229
  file_date = stock_header[1]
230
- print(file_date)
230
+ # print(file_date)
231
231
  report_size = stock_header[4]
232
232
  report_fields_count = int(report_size / 4)
233
233
  report_pack_format = '<{}f'.format(report_fields_count)
@@ -209,9 +209,28 @@ def get_lastdatetime(connect, tablename):
209
209
  cur = connect.cursor()
210
210
  cur.execute("select max(date) from {}".format(tablename))
211
211
  a = cur.fetchone()
212
+ cur.close()
212
213
  return a[0]
213
214
 
214
215
 
216
+ def get_last_krecord(connect, tablename):
217
+ """获取最后一条K线记录
218
+ 返回:(date, open, close, high, low, amount, volume)
219
+ """
220
+ try:
221
+ cur = connect.cursor()
222
+ cur.execute(
223
+ "select `date`, `open`, `high`, `low`, `close`, `amount`, `count` from {} order by date desc limit 1".format(tablename))
224
+ a = cur.fetchone()
225
+ cur.close()
226
+ # hku_info(f"{tablename} {a}")
227
+ if not a:
228
+ return None
229
+ return (a[0], a[1], a[2], a[3], a[4], a[5], a[6])
230
+ except:
231
+ return None
232
+
233
+
215
234
  def update_extern_data(connect, market, code, data_type):
216
235
  """更新周线、月线、15分钟线等扩展数据索引"""
217
236
  def getWeekDate(olddate):
@@ -61,6 +61,7 @@ def ping(ip, port=7709, multithread=False, timeout=1):
61
61
  x = api.get_security_bars(7, 0, '000001', 800, 100)
62
62
  if x:
63
63
  success = True
64
+ api.close()
64
65
  except Exception as e:
65
66
  print(e)
66
67
  pass
@@ -89,6 +90,7 @@ def search_best_tdx():
89
90
  values[x[0]['close']] = [host]
90
91
  else:
91
92
  values[x[0]['close']].append(host)
93
+ api.close()
92
94
  ret = []
93
95
  for _, host in values.items():
94
96
  if len(host) > len(ret):
@@ -27,6 +27,7 @@ import sqlite3
27
27
  from pathlib import Path
28
28
 
29
29
  from .common import MARKETID, get_stktype_list, get_new_holidays
30
+ from hikyuu.util import hku_info
30
31
 
31
32
 
32
33
  def is_exist_db(connect):
@@ -167,6 +167,12 @@ time_start_date = 2023-12-11
167
167
  [weight]
168
168
  enable = True
169
169
 
170
+ [finance]
171
+ enable = True
172
+
173
+ [block]
174
+ enable = True
175
+
170
176
  [tdx]
171
177
  enable = False
172
178
  ;dir = d:/TdxW_HuaTai
@@ -187,6 +193,14 @@ enable = False
187
193
  ;usr = root
188
194
  ;pwd =
189
195
 
196
+ [taos]
197
+ enable = False
198
+ ;tmpdir = D:/stock
199
+ ;host = 127.0.0.1
200
+ ;port = 6030
201
+ ;usr = root
202
+ ;pwd =
203
+
190
204
  [sched]
191
205
  time = 18:00:00
192
206
 
@@ -0,0 +1,95 @@
1
+ DELETE FROM `hku_base`.`holiday`;
2
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (1, 20210101);
3
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (2, 20210211);
4
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (3, 20210212);
5
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (4, 20210215);
6
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (5, 20210216);
7
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (6, 20210217);
8
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (7, 20210405);
9
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (8, 20210501);
10
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (9, 20210503);
11
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (10, 20210504);
12
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (11, 20210505);
13
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (12, 20210614);
14
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (13, 20210920);
15
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (14, 20210921);
16
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (15, 20211001);
17
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (16, 20211004);
18
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (17, 20211005);
19
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (18, 20211006);
20
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (19, 20211007);
21
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (20, 20220103);
22
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (21, 20220131);
23
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (22, 20220201);
24
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (23, 20220202);
25
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (24, 20220203);
26
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (25, 20220204);
27
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (26, 20220205);
28
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (27, 20220404);
29
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (28, 20220405);
30
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (29, 20220502);
31
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (30, 20220503);
32
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (31, 20220504);
33
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (32, 20220603);
34
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (33, 20220912);
35
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (34, 20221003);
36
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (35, 20221004);
37
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (36, 20221005);
38
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (37, 20221006);
39
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (38, 20221007);
40
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (39, 20230102);
41
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (40, 20230123);
42
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (41, 20230124);
43
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (42, 20230125);
44
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (43, 20230126);
45
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (44, 20230127);
46
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (45, 20230405);
47
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (46, 20230501);
48
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (47, 20230502);
49
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (48, 20230503);
50
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (49, 20230622);
51
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (50, 20230623);
52
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (51, 20230929);
53
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (52, 20231002);
54
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (53, 20231003);
55
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (54, 20231004);
56
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (55, 20231005);
57
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (56, 20231006);
58
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (57, 20240101);
59
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (58, 20240212);
60
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (59, 20240213);
61
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (60, 20240214);
62
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (61, 20240215);
63
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (62, 20240216);
64
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (63, 20240404);
65
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (64, 20240405);
66
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (65, 20240501);
67
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (66, 20240502);
68
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (67, 20240503);
69
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (68, 20240610);
70
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (69, 20240916);
71
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (70, 20240917);
72
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (71, 20241001);
73
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (72, 20241002);
74
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (73, 20241003);
75
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (74, 20241004);
76
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (75, 20241007);
77
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (76, 20250101);
78
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (77, 20250128);
79
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (78, 20250129);
80
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (79, 20250130);
81
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (80, 20250131);
82
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (81, 20250203);
83
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (82, 20250204);
84
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (83, 20250404);
85
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (84, 20250501);
86
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (85, 20250502);
87
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (86, 20250505);
88
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (87, 20250602);
89
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (88, 20251001);
90
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (89, 20251002);
91
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (90, 20251003);
92
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (91, 20251006);
93
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (92, 20251007);
94
+ INSERT INTO `hku_base`.`holiday` (`id`, `date`) VALUES (93, 20251008);
95
+ UPDATE `hku_base`.`version` set `version` = 28;
@@ -29,7 +29,7 @@ import sqlite3
29
29
  from pytdx.hq import TDXParams
30
30
 
31
31
  from hikyuu.util.mylog import get_default_logger, hku_error, hku_debug
32
-
32
+ from hikyuu import Datetime
33
33
  from hikyuu.data.common import *
34
34
  from hikyuu.data.common_pytdx import to_pytdx_market, pytdx_get_day_trans
35
35
  from hikyuu.data.common_sqlite3 import (
@@ -191,7 +191,10 @@ def guess_day_n_step(last_datetime):
191
191
  if n < 1:
192
192
  last_m = last_date // 100 - last_y * 100
193
193
  last_d = last_date - (last_y * 10000 + last_m * 100)
194
- step = (today - datetime.date(last_y, last_m, last_d)).days
194
+ step = (today - datetime.date(last_y, last_m, last_d)).days + 1
195
+ if step > 800:
196
+ n = 1
197
+ step = 800
195
198
 
196
199
  return (n, step)
197
200
 
@@ -204,10 +207,10 @@ def guess_1min_n_step(last_datetime):
204
207
  last_m = last_date // 100 - last_y * 100
205
208
  last_d = last_date - (last_y * 10000 + last_m * 100)
206
209
 
207
- n = int((today - datetime.date(last_y, last_m, last_d)).days * 240 // 800)
210
+ n = int(((today - datetime.date(last_y, last_m, last_d)).days * 240 + 1) // 800)
208
211
  step = 800
209
212
  if n < 1:
210
- step = (today - datetime.date(last_y, last_m, last_d)).days * 240
213
+ step = (today - datetime.date(last_y, last_m, last_d)).days * 240 + 1
211
214
  elif n > 99:
212
215
  n = 99
213
216
 
@@ -222,10 +225,10 @@ def guess_5min_n_step(last_datetime):
222
225
  last_m = last_date // 100 - last_y * 100
223
226
  last_d = last_date - (last_y * 10000 + last_m * 100)
224
227
 
225
- n = int((today - datetime.date(last_y, last_m, last_d)).days * 48 // 800)
228
+ n = int(((today - datetime.date(last_y, last_m, last_d)).days * 48 + 1) // 800)
226
229
  step = 800
227
230
  if n < 1:
228
- step = (today - datetime.date(last_y, last_m, last_d)).days * 48
231
+ step = (today - datetime.date(last_y, last_m, last_d)).days * 48 + 1
229
232
  elif n > 99:
230
233
  n = 99
231
234
 
@@ -270,6 +273,12 @@ def import_one_stock_data(connect, api, h5file, market, ktype, stock_record, sta
270
273
 
271
274
  get_bars = api.get_index_bars if stktype == STOCKTYPE.INDEX else api.get_security_bars
272
275
 
276
+ need_check = False
277
+ last_krecord = None
278
+ if table.nrows > 0:
279
+ need_check = True
280
+ last_krecord = table[-1]
281
+
273
282
  add_record_count = 0
274
283
 
275
284
  row = table.row
@@ -277,7 +286,7 @@ def import_one_stock_data(connect, api, h5file, market, ktype, stock_record, sta
277
286
  bar_list = get_bars(pytdx_kline_type, pytdx_market, code, n * 800, step)
278
287
  n -= 1
279
288
  if bar_list is None:
280
- # print(code, "invalid!!")
289
+ print(code, "invalid!!")
281
290
  continue
282
291
 
283
292
  for bar in bar_list:
@@ -293,6 +302,34 @@ def import_one_stock_data(connect, api, h5file, market, ktype, stock_record, sta
293
302
  hku_error("Failed translate datetime: {}, from {}! {}".format(bar, api.ip, e))
294
303
  continue
295
304
 
305
+ if need_check and bar_datetime == last_datetime:
306
+ # print(f'{bar_datetime} {ktype} {market}{code}')
307
+ if abs(last_krecord['openPrice']*0.001 - bar["open"]) / (last_krecord['openPrice']*0.001) > 0.02:
308
+ hku_error(
309
+ f"fetch data from tdx error! {bar_datetime} {ktype} {market}{code} last_krecord open: {last_krecord['openPrice']*0.001}, bar: {bar['open']}")
310
+ return 0
311
+ if abs(last_krecord['highPrice']*0.001 - bar["high"]) / (last_krecord['highPrice']*0.001) > 0.02:
312
+ hku_error(
313
+ f"fetch data from tdx error! {bar_datetime} {ktype} {market}{code} last_krecord high: {last_krecord['highPrice']*0.001}, bar: {bar['high']}")
314
+ return 0
315
+ if abs(last_krecord['lowPrice']*0.001 - bar["low"]) / (last_krecord['lowPrice']*0.001) > 0.02:
316
+ hku_error(
317
+ f"fetch data from tdx error! {bar_datetime} {ktype} {market}{code} last_krecord low: {last_krecord['lowPrice']*0.001}, bar: {bar['low']}")
318
+ return 0
319
+ if abs(last_krecord['closePrice']*0.001 - bar["close"]) / (last_krecord['closePrice']*0.001) > 0.02:
320
+ hku_error(
321
+ f"fetch data from tdx error! {bar_datetime} {ktype} {market}{code} last_krecord close: {last_krecord['closePrice']*0.001}, bar: {bar['close']}")
322
+ return 0
323
+ if ktype == 'DAY' and last_krecord['transAmount'] != 0.0 and abs(last_krecord['transAmount'] - round(bar["amount"]*0.001)) / last_krecord['transAmount'] > 0.1:
324
+ hku_error(
325
+ f"fetch data from tdx error! {bar_datetime} {ktype} {market}{code} last_krecord amount: {last_krecord['transAmount']}, bar: {bar['amount']*0.001}")
326
+ return 0
327
+ if ktype == 'DAY' and last_krecord['transAmount'] != 0.0 and abs(last_krecord['transCount'] - round(bar["vol"])) / last_krecord['transCount'] > 0.1:
328
+ hku_error(
329
+ f"fetch data from tdx error! {bar_datetime} {ktype} {market}{code} last_krecord count: {last_krecord['transCount']}, bar: {bar['vol']}")
330
+ return 0
331
+ continue
332
+
296
333
  if today_datetime >= bar_datetime > last_datetime \
297
334
  and bar['high'] >= bar['open'] >= bar['low'] > 0 \
298
335
  and bar['high'] >= bar['close'] >= bar['low'] > 0 \
@@ -584,7 +621,7 @@ if __name__ == '__main__':
584
621
  starttime = time.time()
585
622
 
586
623
  dest_dir = "d:\\stock"
587
- tdx_server = '119.147.212.81'
624
+ tdx_server = '180.101.48.170'
588
625
  tdx_port = 7709
589
626
  quotations = ['stock', 'fund']
590
627
 
@@ -601,10 +638,11 @@ if __name__ == '__main__':
601
638
  add_count = import_index_name(connect)
602
639
  print("指数个数:", add_count)
603
640
  """
604
- print("导入股票代码表")
605
- add_count = import_stock_name(connect, api, 'SH', quotations)
606
- # add_count += import_stock_name(connect, api, 'SZ', quotations)
607
- print("新增股票数:", add_count)
641
+ # print("导入股票代码表")
642
+ # add_count = import_stock_name(connect, api, 'SH', quotations)
643
+ # # add_count += import_stock_name(connect, api, 'SZ', quotations)
644
+ # print("新增股票数:", add_count)
645
+
608
646
  """
609
647
  print("\n导入上证日线数据")
610
648
  add_count = import_data(connect, 'SH', 'DAY', quotations, api, dest_dir, progress=ProgressBar)
@@ -613,11 +651,13 @@ if __name__ == '__main__':
613
651
  print("\n导入深证日线数据")
614
652
  add_count = import_data(connect, 'SZ', 'DAY', quotations, api, dest_dir, progress=ProgressBar)
615
653
  print("\n导入数量:", add_count)
654
+ """
616
655
 
617
656
  print("\n导入上证5分钟线数据")
618
- add_count = import_data(connect, 'SH', '5MIN', quotations, api, dest_dir, progress=ProgressBar)
657
+ add_count = import_data(connect, 'SH', 'DAY', quotations, api, dest_dir, progress=ProgressBar)
619
658
  print("\n导入数量:", add_count)
620
659
 
660
+ """
621
661
  print("\n导入深证5分钟线数据")
622
662
  add_count = import_data(connect, 'SZ', '5MIN', quotations, api, dest_dir, progress=ProgressBar)
623
663
  print("\n导入数量:", add_count)
@@ -31,6 +31,7 @@ from hikyuu.util.mylog import hku_error, hku_debug
31
31
 
32
32
  import mysql.connector
33
33
 
34
+ from hikyuu import Datetime
34
35
  from .common import *
35
36
  from .common_pytdx import to_pytdx_market, pytdx_get_day_trans
36
37
  from .common_mysql import (
@@ -40,6 +41,7 @@ from .common_mysql import (
40
41
  get_stock_list,
41
42
  get_table,
42
43
  get_lastdatetime,
44
+ get_last_krecord,
43
45
  update_extern_data,
44
46
  )
45
47
  from .weight_to_mysql import qianlong_import_weight
@@ -238,8 +240,10 @@ def guess_day_n_step(last_datetime):
238
240
  if n < 1:
239
241
  last_m = last_date // 100 - last_y * 100
240
242
  last_d = last_date - (last_y * 10000 + last_m * 100)
241
- step = (today - datetime.date(last_y, last_m, last_d)).days
242
-
243
+ step = (today - datetime.date(last_y, last_m, last_d)).days + 1
244
+ if step > 800:
245
+ n = 1
246
+ step = 800
243
247
  return (n, step)
244
248
 
245
249
 
@@ -251,10 +255,10 @@ def guess_1min_n_step(last_datetime):
251
255
  last_m = last_date // 100 - last_y * 100
252
256
  last_d = last_date - (last_y * 10000 + last_m * 100)
253
257
 
254
- n = int((today - datetime.date(last_y, last_m, last_d)).days * 240 // 800)
258
+ n = int(((today - datetime.date(last_y, last_m, last_d)).days * 240 + 1) // 800)
255
259
  step = 800
256
260
  if n < 1:
257
- step = (today - datetime.date(last_y, last_m, last_d)).days * 240
261
+ step = (today - datetime.date(last_y, last_m, last_d)).days * 240 + 1
258
262
  elif n > 99:
259
263
  n = 99
260
264
 
@@ -269,10 +273,10 @@ def guess_5min_n_step(last_datetime):
269
273
  last_m = last_date // 100 - last_y * 100
270
274
  last_d = last_date - (last_y * 10000 + last_m * 100)
271
275
 
272
- n = int((today - datetime.date(last_y, last_m, last_d)).days * 48 // 800)
276
+ n = int(((today - datetime.date(last_y, last_m, last_d)).days * 48 + 1) // 800)
273
277
  step = 800
274
278
  if n < 1:
275
- step = (today - datetime.date(last_y, last_m, last_d)).days * 48
279
+ step = (today - datetime.date(last_y, last_m, last_d)).days * 48 + 1
276
280
  elif n > 99:
277
281
  n = 99
278
282
 
@@ -288,9 +292,11 @@ def import_one_stock_data(
288
292
  stockid, marketid, code, valid, stktype = stock_record[:5]
289
293
  hku_debug("{}{}".format(market, code))
290
294
  table = get_table(connect, market, code, ktype)
291
- last_datetime = get_lastdatetime(connect, table)
292
- if last_datetime is None:
293
- last_datetime = startDate
295
+ last_krecord = get_last_krecord(connect, table)
296
+ last_datetime = startDate if last_krecord is None else last_krecord[0]
297
+ # last_datetime = get_lastdatetime(connect, table)
298
+ # if last_datetime is None:
299
+ # last_datetime = startDate
294
300
 
295
301
  today = datetime.date.today()
296
302
  if ktype == "DAY":
@@ -342,6 +348,33 @@ def import_one_stock_data(
342
348
  hku_error("Failed translate datetime: {}, from {}! {}".format(bar, api.ip, e))
343
349
  continue
344
350
 
351
+ if last_krecord is not None and bar_datetime == last_datetime:
352
+ if abs(last_krecord[1] - bar["open"]) / last_krecord[1] > 0.02:
353
+ hku_error(
354
+ f"fetch data from tdx error! {bar_datetime} {ktype} {market}{code} last_krecord open: {last_krecord[1]}, bar: {bar['open']}")
355
+ return 0
356
+ if abs(last_krecord[2] - bar["high"]) / last_krecord[2] > 0.02:
357
+ hku_error(
358
+ f"fetch data from tdx error! {bar_datetime} {ktype} {market}{code} last_krecord high: {last_krecord[2]}, bar: {bar['high']}")
359
+ return 0
360
+ if abs(last_krecord[3] - bar["low"]) / last_krecord[3] > 0.02:
361
+ hku_error(
362
+ f"fetch data from tdx error! {bar_datetime} {ktype} {market}{code} last_krecord low: {last_krecord[3]}, bar: {bar['low']}")
363
+ return 0
364
+ if abs(last_krecord[4] - bar["close"]) / last_krecord[4] > 0.02:
365
+ hku_error(
366
+ f"fetch data from tdx error! {bar_datetime} {ktype} {market}{code} last_krecord close: {last_krecord[4]}, bar: {bar['close']}")
367
+ return 0
368
+ if ktype == 'DAY' and last_krecord[5] != 0.0 and abs(last_krecord[5] - bar["amount"]*0.001) / last_krecord[5] > 0.1:
369
+ hku_error(
370
+ f"fetch data from tdx error! {bar_datetime} {ktype} {market}{code} last_krecord amount: {last_krecord[5]}, bar: {bar['amount']*0.001}")
371
+ return 0
372
+ if ktype == 'DAY' and last_krecord[5] != 0.0 and abs(last_krecord[6] - bar["vol"]) / last_krecord[6] > 0.1:
373
+ hku_error(
374
+ f"fetch data from tdx error! {bar_datetime} {ktype} {market}{code} last_krecord count: {last_krecord[6]}, bar: {bar['vol']}")
375
+ return 0
376
+ continue
377
+
345
378
  if (
346
379
  today_datetime >= bar_datetime > last_datetime
347
380
  and bar["high"] >= bar["open"] >= bar["low"] > 0