hikyuu 2.6.8.5__py3-none-win_amd64.whl → 2.6.9__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 (176) hide show
  1. hikyuu/__init__.py +5 -11
  2. hikyuu/__init__.pyi +37 -12
  3. hikyuu/analysis/__init__.pyi +26 -0
  4. hikyuu/analysis/analysis.pyi +27 -1
  5. hikyuu/core.py +2 -0
  6. hikyuu/core.pyi +28 -2
  7. hikyuu/cpp/arrow.dll +0 -0
  8. hikyuu/cpp/boost_date_time-mt.dll +0 -0
  9. hikyuu/cpp/boost_serialization-mt.dll +0 -0
  10. hikyuu/cpp/boost_system-mt.dll +0 -0
  11. hikyuu/cpp/boost_wserialization-mt.dll +0 -0
  12. hikyuu/cpp/core310.pyd +0 -0
  13. hikyuu/cpp/core310.pyi +446 -9
  14. hikyuu/cpp/core311.pyd +0 -0
  15. hikyuu/cpp/core311.pyi +446 -9
  16. hikyuu/cpp/core312.pyd +0 -0
  17. hikyuu/cpp/core312.pyi +446 -9
  18. hikyuu/cpp/core313.pyd +0 -0
  19. hikyuu/cpp/core313.pyi +446 -9
  20. hikyuu/cpp/core39.pyd +0 -0
  21. hikyuu/cpp/core39.pyi +446 -9
  22. hikyuu/cpp/hikyuu.dll +0 -0
  23. hikyuu/cpp/hikyuu.lib +0 -0
  24. hikyuu/cpp/i18n/zh_CN/hikyuu.mo +0 -0
  25. hikyuu/cpp/msvcp140-a118642f3ae8774fb9dc223e15c4a52e.dll +0 -0
  26. hikyuu/cpp/parquet.dll +0 -0
  27. hikyuu/cpp/sqlite3.dll +0 -0
  28. hikyuu/data/clickhouse_upgrade/createdb.sql +105 -105
  29. hikyuu/data/common.py +3 -3
  30. hikyuu/data/common_clickhouse.py +1 -1
  31. hikyuu/data/download_block.py +318 -0
  32. hikyuu/data/em_block_to_clickhouse.py +26 -74
  33. hikyuu/data/em_block_to_mysql.py +25 -75
  34. hikyuu/data/em_block_to_sqlite.py +26 -78
  35. hikyuu/data/hku_config_template.py +3 -3
  36. hikyuu/data/pytdx_to_clickhouse.py +15 -11
  37. hikyuu/data/pytdx_to_h5.py +6 -2
  38. hikyuu/data/pytdx_to_mysql.py +5 -1
  39. hikyuu/data/pytdx_weight_to_clickhouse.py +1 -1
  40. hikyuu/data/pytdx_weight_to_mysql.py +1 -1
  41. hikyuu/data/pytdx_weight_to_sqlite.py +1 -1
  42. hikyuu/data/zh_bond10_to_clickhouse.py +1 -1
  43. hikyuu/draw/drawplot/bokeh_draw.pyi +33 -8
  44. hikyuu/draw/drawplot/echarts_draw.pyi +33 -8
  45. hikyuu/draw/drawplot/matplotlib_draw.py +4 -74
  46. hikyuu/draw/drawplot/matplotlib_draw.pyi +33 -8
  47. hikyuu/examples/notebook/Demo/Demo1.ipynb +48 -33
  48. hikyuu/extend.py +0 -1
  49. hikyuu/extend.pyi +30 -5
  50. hikyuu/fetcher/stock/zh_block_em.py +50 -18
  51. hikyuu/gui/HikyuuTDX.py +81 -30
  52. hikyuu/gui/data/CollectSpotThread.py +1 -1
  53. hikyuu/gui/data/EscapetimeThread.py +8 -14
  54. hikyuu/gui/data/ImportBlockInfoTask.py +3 -10
  55. hikyuu/gui/data/MainWindow.py +1168 -715
  56. hikyuu/gui/data/SchedImportThread.py +2 -2
  57. hikyuu/gui/data/UsePytdxImportToH5Thread.py +3 -3
  58. hikyuu/gui/data/UseQmtImportToH5Thread.py +2 -2
  59. hikyuu/gui/data/UseTdxImportToH5Thread.py +3 -3
  60. hikyuu/gui/data/tool.py +32 -25
  61. hikyuu/gui/dataserver.py +5 -3
  62. hikyuu/hub.pyi +6 -6
  63. hikyuu/include/hikyuu/DataType.h +4 -16
  64. hikyuu/include/hikyuu/KData.h +6 -3
  65. hikyuu/include/hikyuu/KDataPrivatedBufferImp.h +1 -1
  66. hikyuu/include/hikyuu/KDataSharedBufferImp.h +1 -1
  67. hikyuu/include/hikyuu/KQuery.h +2 -2
  68. hikyuu/include/hikyuu/Stock.h +3 -0
  69. hikyuu/include/hikyuu/StockManager.h +13 -3
  70. hikyuu/include/hikyuu/data_driver/BaseInfoDriver.h +8 -0
  71. hikyuu/include/hikyuu/data_driver/BlockInfoDriver.h +6 -0
  72. hikyuu/include/hikyuu/data_driver/KDataDriver.h +26 -1
  73. hikyuu/include/hikyuu/data_driver/base_info/mysql/MySQLBaseInfoDriver.h +1 -1
  74. hikyuu/include/hikyuu/data_driver/base_info/sqlite/SQLiteBaseInfoDriver.h +1 -1
  75. hikyuu/include/hikyuu/data_driver/block_info/mysql/MySQLBlockInfoDriver.h +2 -1
  76. hikyuu/include/hikyuu/data_driver/block_info/qianlong/QLBlockInfoDriver.h +2 -1
  77. hikyuu/include/hikyuu/data_driver/block_info/sqlite/SQLiteBlockInfoDriver.h +2 -1
  78. hikyuu/include/hikyuu/data_driver/kdata/DoNothingKDataDriver.h +1 -1
  79. hikyuu/include/hikyuu/data_driver/kdata/cvs/KDataTempCsvDriver.h +1 -1
  80. hikyuu/include/hikyuu/data_driver/kdata/hdf5/H5KDataDriver.h +1 -1
  81. hikyuu/include/hikyuu/data_driver/kdata/mysql/MySQLKDataDriver.h +1 -1
  82. hikyuu/include/hikyuu/data_driver/kdata/sqlite/SQLiteKDataDriver.h +1 -1
  83. hikyuu/include/hikyuu/data_driver/kdata/tdx/TdxKDataDriver.h +1 -1
  84. hikyuu/include/hikyuu/hikyuu.h +1 -1
  85. hikyuu/include/hikyuu/indicator/build_in.h +1 -0
  86. hikyuu/include/hikyuu/indicator/crt/CYCLE.h +4 -4
  87. hikyuu/include/hikyuu/indicator/crt/HSL.h +2 -2
  88. hikyuu/include/hikyuu/indicator/crt/QUANTILE_TRUNC.h +30 -0
  89. hikyuu/include/hikyuu/indicator/crt/TURNOVER.h +1 -0
  90. hikyuu/include/hikyuu/indicator/crt/ZSCORE.h +2 -2
  91. hikyuu/include/hikyuu/indicator/imp/IQuantileTrunc.h +25 -0
  92. hikyuu/include/hikyuu/misc.h +38 -0
  93. hikyuu/include/hikyuu/plugin/dataserver.h +2 -1
  94. hikyuu/include/hikyuu/plugin/extind.h +37 -0
  95. hikyuu/include/hikyuu/plugin/interface/DataServerPluginInterface.h +2 -2
  96. hikyuu/include/hikyuu/plugin/interface/ExtendIndicatorsPluginInterface.h +12 -0
  97. hikyuu/include/hikyuu/strategy/RunSystemInStrategy.h +3 -0
  98. hikyuu/include/hikyuu/trade_manage/Performance.h +4 -4
  99. hikyuu/include/hikyuu/trade_manage/TradeManagerBase.h +10 -1
  100. hikyuu/include/hikyuu/trade_sys/moneymanager/imp/FixedCapitalFundsMM.h +0 -4
  101. hikyuu/include/hikyuu/trade_sys/multifactor/MultiFactorBase.h +36 -3
  102. hikyuu/include/hikyuu/trade_sys/multifactor/NormalizeBase.h +125 -0
  103. hikyuu/include/hikyuu/trade_sys/multifactor/ScoresFilterBase.h +125 -0
  104. hikyuu/include/hikyuu/trade_sys/multifactor/build_in.h +3 -0
  105. hikyuu/include/hikyuu/trade_sys/multifactor/buildin_norm.h +36 -0
  106. hikyuu/include/hikyuu/trade_sys/multifactor/buildin_scfilter.h +51 -0
  107. hikyuu/include/hikyuu/trade_sys/multifactor/filter/GroupSCFilter.h +24 -0
  108. hikyuu/include/hikyuu/trade_sys/multifactor/filter/IgnoreLessOrEqualValueSCFilter.h +24 -0
  109. hikyuu/include/hikyuu/trade_sys/multifactor/filter/IgnoreNanSCFilter.h +24 -0
  110. hikyuu/include/hikyuu/trade_sys/multifactor/filter/MinAmountPercentSCFilter.h +25 -0
  111. hikyuu/include/hikyuu/trade_sys/multifactor/filter/PriceSCFilter.h +24 -0
  112. hikyuu/include/hikyuu/trade_sys/multifactor/filter/TopNSCFilter.h +24 -0
  113. hikyuu/include/hikyuu/trade_sys/multifactor/filter/__init__.py +1 -0
  114. hikyuu/include/hikyuu/trade_sys/multifactor/imp/EqualWeightMultiFactor.h +1 -1
  115. hikyuu/include/hikyuu/trade_sys/multifactor/imp/ICIRMultiFactor.h +1 -1
  116. hikyuu/include/hikyuu/trade_sys/multifactor/imp/ICMultiFactor.h +1 -1
  117. hikyuu/include/hikyuu/trade_sys/multifactor/imp/WeightMultiFactor.h +1 -1
  118. hikyuu/include/hikyuu/trade_sys/multifactor/normalize/NormMinMax.h +23 -0
  119. hikyuu/include/hikyuu/trade_sys/multifactor/normalize/NormQuantile.h +28 -0
  120. hikyuu/include/hikyuu/trade_sys/multifactor/normalize/NormQuantileUniform.h +28 -0
  121. hikyuu/include/hikyuu/trade_sys/multifactor/normalize/NormZScore.h +25 -0
  122. hikyuu/include/hikyuu/trade_sys/multifactor/normalize/__init__.py +1 -0
  123. hikyuu/include/hikyuu/trade_sys/multifactor/normalize/quantile_trunc.h +16 -0
  124. hikyuu/include/hikyuu/trade_sys/portfolio/Portfolio.h +7 -0
  125. hikyuu/include/hikyuu/trade_sys/portfolio/imp/SimplePortfolio.h +7 -0
  126. hikyuu/include/hikyuu/trade_sys/portfolio/imp/WithoutAFPortfolio.h +7 -0
  127. hikyuu/include/hikyuu/trade_sys/selector/SelectorBase.h +49 -0
  128. hikyuu/include/hikyuu/trade_sys/selector/build_in.h +1 -0
  129. hikyuu/include/hikyuu/trade_sys/selector/crt/SE_MultiFactor2.h +40 -0
  130. hikyuu/include/hikyuu/trade_sys/selector/imp/MultiFactorSelector.h +0 -3
  131. hikyuu/include/hikyuu/trade_sys/selector/imp/MultiFactorSelector2.h +49 -0
  132. hikyuu/include/hikyuu/trade_sys/selector/imp/logic/OperatorSelector.h +1 -1
  133. hikyuu/include/hikyuu/trade_sys/selector/imp/logic/OperatorValueSelector.h +1 -1
  134. hikyuu/include/hikyuu/trade_sys/signal/imp/BandSignal2.h +0 -4
  135. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/AddValueSignal.h +2 -2
  136. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/DivValueSignal.h +2 -2
  137. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/MulValueSignal.h +2 -2
  138. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/OperatorSignal.h +1 -1
  139. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/OperatorValueSignal.h +4 -4
  140. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/SubValueSignal.h +2 -2
  141. hikyuu/include/hikyuu/trade_sys/system/System.h +14 -1
  142. hikyuu/include/hikyuu/utilities/SpendTimer.h +17 -7
  143. hikyuu/include/hikyuu/utilities/arithmetic.h +45 -0
  144. hikyuu/include/hikyuu/utilities/db_connect/mysql/MySQLConnect.h +1 -1
  145. hikyuu/include/hikyuu/utilities/db_connect/mysql/MySQLStatement.h +1 -1
  146. hikyuu/include/hikyuu/utilities/db_connect/sqlite/SQLiteConnect.h +1 -1
  147. hikyuu/include/hikyuu/utilities/db_connect/sqlite/SQLiteStatement.h +1 -1
  148. hikyuu/include/hikyuu/utilities/plugin/PluginLoader.h +4 -1
  149. hikyuu/include/hikyuu/version.h +4 -4
  150. hikyuu/plugin/backtest.dll +0 -0
  151. hikyuu/plugin/clickhousedriver.dll +0 -0
  152. hikyuu/plugin/dataserver.dll +0 -0
  153. hikyuu/plugin/device.dll +0 -0
  154. hikyuu/plugin/extind.dll +0 -0
  155. hikyuu/plugin/hkuextra.dll +0 -0
  156. hikyuu/plugin/hkuviews.dll +0 -0
  157. hikyuu/plugin/import2hdf5.dll +0 -0
  158. hikyuu/plugin/tmreport.dll +0 -0
  159. hikyuu/trade_manage/__init__.pyi +33 -8
  160. hikyuu/trade_manage/trade.pyi +33 -8
  161. hikyuu/util/__init__.pyi +2 -2
  162. hikyuu/util/singleton.pyi +1 -1
  163. {hikyuu-2.6.8.5.dist-info → hikyuu-2.6.9.dist-info}/METADATA +13 -14
  164. {hikyuu-2.6.8.5.dist-info → hikyuu-2.6.9.dist-info}/RECORD +167 -149
  165. {hikyuu-2.6.8.5.dist-info → hikyuu-2.6.9.dist-info}/top_level.txt +2 -1
  166. hikyuu/data_driver/__init__.py +0 -49
  167. hikyuu/data_driver/jqdata_data_driver.py +0 -277
  168. hikyuu/data_driver/pytdx_data_driver.py +0 -292
  169. hikyuu/fetcher/stock/zh_stock_a_huatai.py +0 -51
  170. hikyuu/fetcher/stock/zh_stock_a_pytdx.py +0 -129
  171. hikyuu/gui/data/CollectToMemThread.py +0 -123
  172. hikyuu/gui/data/CollectToMySQLThread.py +0 -178
  173. hikyuu/gui/start_huatai_insight.py +0 -510
  174. hikyuu/tools/update_block_info.py +0 -168
  175. {hikyuu-2.6.8.5.dist-info → hikyuu-2.6.9.dist-info}/WHEEL +0 -0
  176. {hikyuu-2.6.8.5.dist-info → hikyuu-2.6.9.dist-info}/entry_points.txt +0 -0
@@ -4,85 +4,32 @@
4
4
  # Create on: 20240102
5
5
  # Author: fasiondog
6
6
 
7
- from concurrent.futures import ThreadPoolExecutor
8
- from hikyuu.data.common import MARKET, get_stk_code_name_list
9
7
  from hikyuu.util import *
10
8
  from hikyuu.fetcher.stock.zh_block_em import *
9
+ from hikyuu.data.download_block import *
11
10
 
12
11
 
13
- def em_import_block_to_clickhouse(connect, code_market_dict, categorys=('行业板块', '指数板块')):
14
- all_block_info = {}
15
-
16
- with ThreadPoolExecutor(4) as executor:
17
- if '行业板块' in categorys:
18
- t1 = executor.submit(get_all_hybk_info, code_market_dict)
19
-
20
- if '概念板块' in categorys:
21
- t2 = executor.submit(get_all_gnbk_info, code_market_dict)
22
-
23
- if '地域板块' in categorys:
24
- t3 = executor.submit(get_all_dybk_info, code_market_dict)
25
-
26
- if '指数板块' in categorys:
27
- t4 = executor.submit(get_all_zsbk_info, code_market_dict)
28
-
29
- success_fetch_hy = False
30
- if '行业板块' in categorys:
31
- x = t1.result()
32
- hku_info("获取行业板块信息完毕")
33
- if x:
34
- all_block_info["行业板块"] = x
35
- success_fetch_hy = True
36
-
37
- success_fetch_gn = False
38
- if '概念板块' in categorys:
39
- x = t2.result()
40
- hku_info("获取概念板块信息完毕")
41
- if x:
42
- all_block_info["概念板块"] = x
43
- success_fetch_gn = True
44
-
45
- success_fetch_dy = False
46
- if '地域板块' in categorys:
47
- x = t3.result()
48
- hku_info("获取地域板块信息完毕")
49
- if x:
50
- all_block_info["地域板块"] = x
51
- success_fetch_dy = True
52
-
53
- success_fetch_zs = False
54
- if '指数板块' in categorys:
55
- x = t4.result()
56
- hku_info("获取指数板块信息完毕")
57
- if x:
58
- all_block_info["指数板块"] = x
59
- success_fetch_zs = True
60
-
61
- blks = []
62
- if success_fetch_hy:
63
- blks.append('行业板块')
64
- if success_fetch_gn:
65
- blks.append('概念板块')
66
- if success_fetch_dy:
67
- blks.append('地域板块')
68
- if success_fetch_zs:
69
- blks.append('指数板块')
12
+ def em_import_block_to_clickhouse(connect):
13
+ download_block_info()
14
+
15
+ blocks_info = read_block_from_path()
16
+ blks = blocks_info['block']
17
+ blks_info = blocks_info['block_info']
70
18
 
71
19
  if not blks:
72
- return
20
+ return 0
73
21
 
74
22
  hku_info("更新数据库")
75
- if len(blks) == 1:
76
- sql = f"delete from hku_base.block where category in ('{blks[0]}')"
77
- else:
78
- sql = f"delete from hku_base.block where category in {tuple(blks)}"
23
+ sql = f"delete from hku_base.block where category in {tuple(blks.keys())}"
24
+ connect.command(sql)
25
+ sql = f"delete from hku_base.blockindex where category in {tuple(blks.keys())}"
79
26
  connect.command(sql)
80
27
 
81
28
  insert_records = []
82
29
 
83
- for category in all_block_info:
84
- for name in all_block_info[category]:
85
- for code in all_block_info[category][name]:
30
+ for category, blocks in blks.items():
31
+ for name, codes in blocks.items():
32
+ for code in codes:
86
33
  insert_records.append((category, name, code))
87
34
 
88
35
  if insert_records:
@@ -91,6 +38,17 @@ def em_import_block_to_clickhouse(connect, code_market_dict, categorys=('行业
91
38
  data=insert_records)
92
39
  connect.insert(context=ic)
93
40
 
41
+ index_records = []
42
+ for category, blocks in blks_info.items():
43
+ for name, index_code in blocks.items():
44
+ if len(index_code) == 8:
45
+ index_records.append((category, name, index_code))
46
+ if index_records:
47
+ ic = connect.create_insert_context(table='blockindex', database='hku_base',
48
+ column_names=['category', 'name', 'index_code'],
49
+ data=index_records)
50
+ connect.insert(context=ic)
51
+
94
52
  return len(insert_records)
95
53
 
96
54
 
@@ -109,12 +67,6 @@ if __name__ == "__main__":
109
67
  client = clickhouse_connect.get_client(
110
68
  host=host, username=user, password=password)
111
69
 
112
- x = get_stk_code_name_list(MARKET.SH)
113
- code_market_dict = {}
114
- for v in x:
115
- code_market_dict[v["code"]] = MARKET.SH
116
- # print(code_market_dict)
117
-
118
- em_import_block_to_clickhouse(client, code_market_dict, categorys=('行业板块', ))
70
+ em_import_block_to_clickhouse(client)
119
71
 
120
72
  client.close()
@@ -4,93 +4,49 @@
4
4
  # Create on: 20240102
5
5
  # Author: fasiondog
6
6
 
7
- from concurrent.futures import ThreadPoolExecutor
8
- from hikyuu.data.common import MARKET, get_stk_code_name_list
7
+
9
8
  from hikyuu.util import *
10
9
  from hikyuu.fetcher.stock.zh_block_em import *
10
+ from hikyuu.data.download_block import *
11
+
11
12
 
13
+ def em_import_block_to_mysql(connect):
14
+ download_block_info()
12
15
 
13
- def em_import_block_to_mysql(connect, code_market_dict, categorys=('行业板块', '概念板块', '地域板块', '指数板块')):
14
- all_block_info = {}
15
-
16
- with ThreadPoolExecutor(4) as executor:
17
- if '行业板块' in categorys:
18
- t1 = executor.submit(get_all_hybk_info, code_market_dict)
19
-
20
- if '概念板块' in categorys:
21
- t2 = executor.submit(get_all_gnbk_info, code_market_dict)
22
-
23
- if '地域板块' in categorys:
24
- t3 = executor.submit(get_all_dybk_info, code_market_dict)
25
-
26
- if '指数板块' in categorys:
27
- t4 = executor.submit(get_all_zsbk_info, code_market_dict)
28
-
29
- success_fetch_hy = False
30
- if '行业板块' in categorys:
31
- x = t1.result()
32
- hku_info("获取行业板块信息完毕")
33
- if x:
34
- all_block_info["行业板块"] = x
35
- success_fetch_hy = True
36
-
37
- success_fetch_gn = False
38
- if '概念板块' in categorys:
39
- x = t2.result()
40
- hku_info("获取概念板块信息完毕")
41
- if x:
42
- all_block_info["概念板块"] = x
43
- success_fetch_gn = True
44
-
45
- success_fetch_dy = False
46
- if '地域板块' in categorys:
47
- x = t3.result()
48
- hku_info("获取地域板块信息完毕")
49
- if x:
50
- all_block_info["地域板块"] = x
51
- success_fetch_dy = True
52
-
53
- success_fetch_zs = False
54
- if '指数板块' in categorys:
55
- x = t4.result()
56
- hku_info("获取指数板块信息完毕")
57
- if x:
58
- all_block_info["指数板块"] = x
59
- success_fetch_zs = True
60
-
61
- blks = []
62
- if success_fetch_hy:
63
- blks.append('行业板块')
64
- if success_fetch_gn:
65
- blks.append('概念板块')
66
- if success_fetch_dy:
67
- blks.append('地域板块')
68
- if success_fetch_zs:
69
- blks.append('指数板块')
16
+ blocks_info = read_block_from_path()
17
+ blks = blocks_info['block']
18
+ blks_info = blocks_info['block_info']
70
19
 
71
20
  if not blks:
72
- return
21
+ return 0
73
22
 
74
23
  hku_info("更新数据库")
75
24
  cur = connect.cursor()
76
- if len(blks) == 1:
77
- sql = f"delete from hku_base.block where category in ('{blks[0]}')"
78
- else:
79
- sql = f"delete from hku_base.block where category in {tuple(blks)}"
25
+ sql = f"delete from hku_base.block where category in {tuple(blks.keys())}"
26
+ cur.execute(sql)
27
+ sql = f"delete from hku_base.BlockIndex where category in {tuple(blks.keys())}"
80
28
  cur.execute(sql)
81
29
 
82
30
  insert_records = []
83
31
 
84
- for category in all_block_info:
85
- for name in all_block_info[category]:
86
- for code in all_block_info[category][name]:
32
+ for category, blocks in blks.items():
33
+ for name, codes in blocks.items():
34
+ for code in codes:
87
35
  insert_records.append((category, name, code))
88
36
 
89
37
  if insert_records:
90
38
  sql = "insert into hku_base.block (category, name, market_code) values (%s,%s,%s)"
91
- hku_info(f"insert block records: {len(insert_records)}")
92
39
  cur.executemany(sql, insert_records)
93
40
 
41
+ index_records = []
42
+ for category, blocks in blks_info.items():
43
+ for name, index_code in blocks.items():
44
+ if len(index_code) == 8:
45
+ index_records.append((category, name, index_code))
46
+ if index_records:
47
+ sql = "insert into hku_base.BlockIndex (category, name, market_code) values (%s,%s,%s)"
48
+ cur.executemany(sql, index_records)
49
+
94
50
  connect.commit()
95
51
  cur.close()
96
52
  return len(insert_records)
@@ -111,11 +67,5 @@ if __name__ == "__main__":
111
67
  connect = mysql.connector.connect(user=usr, password=pwd, host=host, port=port)
112
68
  create_database(connect)
113
69
 
114
- x = get_stk_code_name_list(MARKET.SH)
115
- code_market_dict = {}
116
- for v in x:
117
- code_market_dict[v["code"]] = MARKET.SH
118
- # print(code_market_dict)
119
-
120
- em_import_block_to_mysql(connect, code_market_dict)
70
+ em_import_block_to_mysql(connect)
121
71
  connect.close()
@@ -4,97 +4,51 @@
4
4
  # Create on: 20240102
5
5
  # Author: fasiondog
6
6
 
7
- from concurrent.futures import ThreadPoolExecutor
8
- from hikyuu.data.common import MARKET, get_stk_code_name_list
7
+
9
8
  from hikyuu.util import *
10
9
  from hikyuu.fetcher.stock.zh_block_em import *
10
+ from hikyuu.data.download_block import *
11
11
 
12
12
 
13
13
  @spend_time
14
- def em_import_block_to_sqlite(connect, code_market_dict, categorys=('行业板块', '概念板块', '地域板块', '指数板块')):
15
- all_block_info = {}
16
-
17
- with ThreadPoolExecutor(4) as executor:
18
- if '行业板块' in categorys:
19
- t1 = executor.submit(get_all_hybk_info, code_market_dict)
20
-
21
- if '概念板块' in categorys:
22
- t2 = executor.submit(get_all_gnbk_info, code_market_dict)
23
-
24
- if '地域板块' in categorys:
25
- t3 = executor.submit(get_all_dybk_info, code_market_dict)
26
-
27
- if '指数板块' in categorys:
28
- t4 = executor.submit(get_all_zsbk_info, code_market_dict)
29
-
30
- success_fetch_hy = False
31
- if '行业板块' in categorys:
32
- x = t1.result()
33
- hku_info("获取行业板块信息完毕")
34
- if x:
35
- all_block_info["行业板块"] = x
36
- success_fetch_hy = True
37
-
38
- success_fetch_gn = False
39
- if '概念板块' in categorys:
40
- x = t2.result()
41
- hku_info("获取概念板块信息完毕")
42
- if x:
43
- all_block_info["概念板块"] = x
44
- success_fetch_gn = True
45
-
46
- success_fetch_dy = False
47
- if '地域板块' in categorys:
48
- x = t3.result()
49
- hku_info("获取地域板块信息完毕")
50
- if x:
51
- all_block_info["地域板块"] = x
52
- success_fetch_dy = True
53
-
54
- success_fetch_zs = False
55
- if '指数板块' in categorys:
56
- x = t4.result()
57
- hku_info("获取指数板块信息完毕")
58
- if x:
59
- all_block_info["指数板块"] = x
60
- success_fetch_zs = True
61
-
62
- blks = []
63
- if success_fetch_hy:
64
- blks.append('行业板块')
65
- if success_fetch_gn:
66
- blks.append('概念板块')
67
- if success_fetch_dy:
68
- blks.append('地域板块')
69
- if success_fetch_zs:
70
- blks.append('指数板块')
71
-
72
- print(blks)
14
+ def em_import_block_to_sqlite(connect):
15
+ download_block_info()
16
+
17
+ blocks_info = read_block_from_path()
18
+ blks = blocks_info['block']
19
+ blks_info = blocks_info['block_info']
73
20
 
74
21
  if not blks:
75
- return
22
+ return 0
76
23
 
77
24
  hku_info("更新数据库")
78
25
  cur = connect.cursor()
79
- if len(blks) == 1:
80
- sql = f"delete from block where category in ('{blks[0]}')"
81
- else:
82
- sql = f"delete from block where category in {tuple(blks)}"
83
- hku_info(sql)
26
+ sql = f"delete from block where category in {tuple(blks.keys())}"
27
+ cur.execute(sql)
28
+ sql = f"delete from BlockIndex where category in {tuple(blks.keys())}"
84
29
  cur.execute(sql)
85
30
 
86
31
  insert_records = []
87
32
 
88
- for category in all_block_info:
89
- for name in all_block_info[category]:
90
- for code in all_block_info[category][name]:
33
+ for category, blocks in blks.items():
34
+ for name, codes in blocks.items():
35
+ for code in codes:
91
36
  insert_records.append((category, name, code))
92
37
 
93
38
  if insert_records:
94
39
  sql = "insert into block (category, name, market_code) values (?,?,?)"
95
- hku_info(f"insert block records: {len(insert_records)}")
96
40
  cur.executemany(sql, insert_records)
97
41
 
42
+ index_records = []
43
+ for category, blocks in blks_info.items():
44
+ for name, index_code in blocks.items():
45
+ if len(index_code) == 8:
46
+ index_records.append((category, name, index_code))
47
+ if index_records:
48
+ sql = "insert into BlockIndex (category, name, market_code) values (?,?,?)"
49
+ cur.executemany(sql, index_records)
50
+ hku_info(f"insert block index records: {len(index_records)}")
51
+
98
52
  connect.commit()
99
53
  cur.close()
100
54
  return len(insert_records)
@@ -111,12 +65,6 @@ if __name__ == "__main__":
111
65
  connect = sqlite3.connect(dest_dir + "/stock.db")
112
66
  create_database(connect)
113
67
 
114
- x = get_stk_code_name_list(MARKET.SH)
115
- code_market_dict = {}
116
- for v in x:
117
- code_market_dict[v["code"]] = MARKET.SH
118
- # print(code_market_dict)
119
-
120
- em_import_block_to_sqlite(connect, code_market_dict, categorys=('地域板块',))
68
+ em_import_block_to_sqlite(connect)
121
69
 
122
70
  connect.close()
@@ -210,8 +210,8 @@ future = False
210
210
  day = True
211
211
  min = True
212
212
  min5 = True
213
- trans = True
214
- time = True
213
+ trans = False
214
+ time = False
215
215
  day_start_date = 1990-12-19
216
216
  min_start_date = 2023-09-19
217
217
  min5_start_date = 2023-09-19
@@ -251,7 +251,7 @@ enable = False
251
251
  enable = False
252
252
  ;tmpdir = D:/stock
253
253
  ;host = 127.0.0.1
254
- :http_port = 8123
254
+ ;http_port = 8123
255
255
  ;port = 9000
256
256
  ;usr = root
257
257
  ;pwd =
@@ -29,7 +29,7 @@ from pytdx.hq import TDXParams
29
29
 
30
30
  from hikyuu.util import hku_error, hku_debug, hku_run_ignore_exception
31
31
 
32
- from hikyuu import Datetime
32
+ from hikyuu import Datetime, roundEx
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_clickhouse import (
@@ -304,6 +304,10 @@ def import_one_stock_data(
304
304
  hku_error("Failed translate datetime: {}, from {}! {}".format(bar, api.ip, e))
305
305
  continue
306
306
 
307
+ if 'open' not in bar or 'high' not in bar or 'low' not in bar or 'close' not in bar or 'vol' not in bar or 'amount' not in bar:
308
+ hku_warn(f"Ignore invalid bar: {bar_datetime}, missing fields!")
309
+ continue
310
+
307
311
  if last_krecord is not None and bar_datetime == last_datetime:
308
312
  if abs(last_krecord[1] - bar["open"]) / last_krecord[1] > 0.01:
309
313
  hku_error(
@@ -325,7 +329,7 @@ def import_one_stock_data(
325
329
  hku_error(
326
330
  f"fetch data from tdx error! {bar_datetime} {ktype} {market}{code} last_krecord amount: {last_krecord[5]}, bar: {bar['amount']*0.001}")
327
331
  return 0
328
- if ktype == 'DAY' and last_krecord[5] != 0.0 and abs(last_krecord[6] - bar["vol"]) / last_krecord[6] > 0.1:
332
+ if ktype == 'DAY' and last_krecord[6] != 0.0 and last_krecord[5] != 0.0 and abs(last_krecord[6] - bar["vol"]) / last_krecord[6] > 0.1:
329
333
  hku_error(
330
334
  f"fetch data from tdx error! {bar_datetime} {ktype} {market}{code} last_krecord count: {last_krecord[6]}, bar: {bar['vol']}")
331
335
  return 0
@@ -343,12 +347,12 @@ def import_one_stock_data(
343
347
  (
344
348
  table[1], table[2],
345
349
  Datetime(bar_datetime).timestamp_utc()//1000000,
346
- bar["open"],
347
- bar["high"],
348
- bar["low"],
349
- bar["close"],
350
- bar["amount"] * 0.001,
351
- bar["vol"]
350
+ int(roundEx(bar["open"], 3)*1000),
351
+ int(roundEx(bar["high"], 3)*1000),
352
+ int(roundEx(bar["low"], 3)*1000),
353
+ int(roundEx(bar["close"], 3)*1000),
354
+ int(roundEx(bar["amount"], 0)),
355
+ int(roundEx(bar["vol"], 3)*1000)
352
356
  # bar['vol'] if stktype == 2 else round(bar['vol'] * 0.01)
353
357
  )
354
358
  )
@@ -592,8 +596,8 @@ def import_on_stock_trans(connect, api, market, stock_record, max_days):
592
596
  (
593
597
  market, code,
594
598
  Datetime(cur_date * 1000000 + minute * 100 + second).timestamp_utc()//1000000,
595
- record["price"],
596
- record["vol"],
599
+ int(roundEx(record["price"], 3) * 1000.0),
600
+ int(record["vol"]),
597
601
  record["buyorsell"],
598
602
  )
599
603
  )
@@ -698,7 +702,7 @@ def import_on_stock_time(connect, api, market, stock_record, max_days):
698
702
  time = 1400
699
703
  try:
700
704
  time_buf.append((market, code, Datetime(this_date + time).timestamp_utc() //
701
- ticks, record['price'], record['vol']))
705
+ ticks, int(roundEx(record['price'], 3) * 1000.0), int(record['vol'])))
702
706
  time += 1
703
707
  except Exception as e:
704
708
  hku_error("Failed trans record {}! {}".format(record, e))
@@ -286,7 +286,7 @@ def import_one_stock_data(connect, api, h5file, market, ktype, stock_record, sta
286
286
  bar_list = get_bars(pytdx_kline_type, pytdx_market, code, n * 800, step)
287
287
  n -= 1
288
288
  if bar_list is None:
289
- print(code, "invalid!!")
289
+ # print(code, "invalid!!")
290
290
  continue
291
291
 
292
292
  for bar in bar_list:
@@ -302,6 +302,10 @@ def import_one_stock_data(connect, api, h5file, market, ktype, stock_record, sta
302
302
  hku_error("Failed translate datetime: {}, from {}! {}".format(bar, api.ip, e))
303
303
  continue
304
304
 
305
+ if 'open' not in bar or 'high' not in bar or 'low' not in bar or 'close' not in bar or 'vol' not in bar or 'amount' not in bar:
306
+ hku_warn(f"Ignore invalid bar: {bar_datetime}, missing fields!")
307
+ continue
308
+
305
309
  if need_check and bar_datetime == last_datetime:
306
310
  # print(f'{bar_datetime} {ktype} {market}{code}')
307
311
  if abs(last_krecord['openPrice']*0.001 - bar["open"]) / (last_krecord['openPrice']*0.001) > 0.02:
@@ -324,7 +328,7 @@ def import_one_stock_data(connect, api, h5file, market, ktype, stock_record, sta
324
328
  hku_error(
325
329
  f"fetch data from tdx error! {bar_datetime} {ktype} {market}{code} last_krecord amount: {last_krecord['transAmount']}, bar: {bar['amount']*0.001}")
326
330
  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:
331
+ if ktype == 'DAY' and last_krecord['transCount'] != 0.0 and abs(last_krecord['transCount'] - round(bar["vol"])) / last_krecord['transCount'] > 0.1:
328
332
  hku_error(
329
333
  f"fetch data from tdx error! {bar_datetime} {ktype} {market}{code} last_krecord count: {last_krecord['transCount']}, bar: {bar['vol']}")
330
334
  return 0
@@ -348,6 +348,10 @@ def import_one_stock_data(
348
348
  hku_error("Failed translate datetime: {}, from {}! {}".format(bar, api.ip, e))
349
349
  continue
350
350
 
351
+ if 'open' not in bar or 'high' not in bar or 'low' not in bar or 'close' not in bar or 'vol' not in bar or 'amount' not in bar:
352
+ hku_warn(f"Ignore invalid bar: {bar_datetime}, missing fields!")
353
+ continue
354
+
351
355
  if last_krecord is not None and bar_datetime == last_datetime:
352
356
  if abs(last_krecord[1] - bar["open"]) / last_krecord[1] > 0.01:
353
357
  hku_error(
@@ -369,7 +373,7 @@ def import_one_stock_data(
369
373
  hku_error(
370
374
  f"fetch data from tdx error! {bar_datetime} {ktype} {market}{code} last_krecord amount: {last_krecord[5]}, bar: {bar['amount']*0.001}")
371
375
  return 0
372
- if ktype == 'DAY' and last_krecord[5] != 0.0 and abs(last_krecord[6] - bar["vol"]) / last_krecord[6] > 0.1:
376
+ if ktype == 'DAY' and last_krecord[6] != 0.0 and abs(last_krecord[6] - bar["vol"]) / last_krecord[6] > 0.1:
373
377
  hku_error(
374
378
  f"fetch data from tdx error! {bar_datetime} {ktype} {market}{code} last_krecord count: {last_krecord[6]}, bar: {bar['vol']}")
375
379
  return 0
@@ -34,7 +34,7 @@ def pytdx_import_weight_to_clickhouse(pytdx_api, connect, market):
34
34
 
35
35
  total_count = 0
36
36
  update_count = 0
37
- stock_list = connect.query(f"select code from `hku_base`.`stock` where market='{market}' and valid=1")
37
+ stock_list = connect.query(f"select code from `hku_base`.`stock` where market='{market}'")
38
38
  stockid_list = stock_list.result_rows
39
39
 
40
40
  for stockrecord in stockid_list:
@@ -38,7 +38,7 @@ def pytdx_import_weight_to_mysql(pytdx_api, connect, market):
38
38
  pytdx_market = to_pytdx_market(market)
39
39
 
40
40
  total_count = 0
41
- cur.execute("select stockid, code from `hku_base`.`stock` where marketid=%s and valid=1" % (marketid))
41
+ cur.execute("select stockid, code from `hku_base`.`stock` where marketid=%s" % (marketid))
42
42
  stockid_list = [x for x in cur.fetchall()]
43
43
  cur.close()
44
44
 
@@ -35,7 +35,7 @@ def pytdx_import_weight_to_sqlite(pytdx_api, connect, market):
35
35
  pytdx_market = to_pytdx_market(market)
36
36
 
37
37
  total_count = 0
38
- stockid_list = cur.execute("select stockid, code from Stock where marketid=%s and valid=1" % (marketid))
38
+ stockid_list = cur.execute("select stockid, code from Stock where marketid=%s" % (marketid))
39
39
  stockid_list = [x for x in stockid_list]
40
40
  cur.close()
41
41
 
@@ -13,7 +13,7 @@ from hikyuu.util import *
13
13
  def import_zh_bond10_to_clickhouse(connect):
14
14
  sql = "select max(date) from hku_base.zh_bond10"
15
15
  start_date = connect.command(sql)
16
- if type(start_date) == int:
16
+ if start_date == 0:
17
17
  start_date = "19901219"
18
18
  else:
19
19
  last_date = start_date