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