mns-scheduler 1.0.7.5__py3-none-any.whl → 1.0.7.7__py3-none-any.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.
Potentially problematic release.
This version of mns-scheduler might be problematic. Click here for more details.
- mns_scheduler/db/col_move_service.py +5 -1
- mns_scheduler/open/__init__.py +7 -0
- mns_scheduler/open/sync_one_day_open_data_to_db_service.py +86 -0
- mns_scheduler/zt/connected_boards/__init__.py +8 -0
- mns_scheduler/zt/export/__init__.py +8 -0
- mns_scheduler/zt/{export_open_data_to_excel.py → export/export_kcx_high_chg_open_data_to_excel.py} +2 -0
- mns_scheduler/zt/high_chg/__init__.py +7 -0
- mns_scheduler/zt/high_chg/sync_high_chg_pool_service.py +283 -0
- mns_scheduler/zt/high_chg/sync_high_chg_real_time_quotes_service.py +141 -0
- mns_scheduler/zt/open_data/__init__.py +8 -0
- mns_scheduler/zt/{realtime_quotes_now_zt_kc_sync.py → open_data/kcx_high_chg_open_data_sync.py} +9 -142
- mns_scheduler/zt/script/__init__.py +7 -0
- mns_scheduler/zt/script/kcx_high_chg_open_his_data_handle.py +113 -0
- mns_scheduler/zt/script/sync_high_chg_pool_his_data.py +39 -0
- mns_scheduler/zt/zt_pool/__init__.py +8 -0
- mns_scheduler/zz_task/data_sync_task.py +16 -10
- {mns_scheduler-1.0.7.5.dist-info → mns_scheduler-1.0.7.7.dist-info}/METADATA +1 -1
- {mns_scheduler-1.0.7.5.dist-info → mns_scheduler-1.0.7.7.dist-info}/RECORD +22 -11
- mns_scheduler/zt/today_high_chg_pool_sync_api.py +0 -481
- /mns_scheduler/zt/{zt_five_boards_sync_api.py → connected_boards/zt_five_boards_sync_api.py} +0 -0
- /mns_scheduler/zt/{zt_pool_sync_api.py → zt_pool/zt_pool_sync_api.py} +0 -0
- {mns_scheduler-1.0.7.5.dist-info → mns_scheduler-1.0.7.7.dist-info}/WHEEL +0 -0
- {mns_scheduler-1.0.7.5.dist-info → mns_scheduler-1.0.7.7.dist-info}/top_level.txt +0 -0
|
@@ -109,4 +109,8 @@ def db_import_col(db, col):
|
|
|
109
109
|
|
|
110
110
|
# -u "username" -p "password"
|
|
111
111
|
if __name__ == '__main__':
|
|
112
|
-
sync_col_move('2024-05-
|
|
112
|
+
sync_col_move('2024-05-28')
|
|
113
|
+
sync_col_move('2024-05-30')
|
|
114
|
+
sync_col_move('2024-05-31')
|
|
115
|
+
sync_col_move('2024-06-03')
|
|
116
|
+
sync_col_move('2024-06-04')
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
file_path = os.path.abspath(__file__)
|
|
5
|
+
end = file_path.index('mns') + 16
|
|
6
|
+
project_path = file_path[0:end]
|
|
7
|
+
sys.path.append(project_path)
|
|
8
|
+
# 同步当天所有开盘数据
|
|
9
|
+
import mns_common.utils.date_handle_util as date_handle_util
|
|
10
|
+
from loguru import logger
|
|
11
|
+
from datetime import time
|
|
12
|
+
from mns_common.db.MongodbUtil import MongodbUtil
|
|
13
|
+
import mns_common.component.common_service_fun_api as common_service_fun_api
|
|
14
|
+
import mns_common.component.company.company_common_service_api as company_common_service_api
|
|
15
|
+
import mns_common.component.data.data_init_api as data_init_api
|
|
16
|
+
import pandas as pd
|
|
17
|
+
import mns_common.utils.db_util as db_util
|
|
18
|
+
|
|
19
|
+
mongodb_util = MongodbUtil('27017')
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def sync_one_day_open_data(str_day):
|
|
23
|
+
realtime_quotes_db_name = 'realtime_quotes_now_' + str_day
|
|
24
|
+
|
|
25
|
+
number = db_util.get_realtime_quotes_now_min_number(str_day, None, None)
|
|
26
|
+
|
|
27
|
+
query = {"number": number}
|
|
28
|
+
db = db_util.get_db(str_day)
|
|
29
|
+
realtime_quotes_now_list = db.find_query_data(realtime_quotes_db_name, query)
|
|
30
|
+
|
|
31
|
+
realtime_quotes_now_one = realtime_quotes_now_list.iloc[0]
|
|
32
|
+
str_now_date = realtime_quotes_now_one['_id']
|
|
33
|
+
str_now_date = str_now_date[7:26]
|
|
34
|
+
|
|
35
|
+
now_date = date_handle_util.str_to_date(str_now_date, "%Y-%m-%d %H:%M:%S")
|
|
36
|
+
now_date_time = now_date.time()
|
|
37
|
+
|
|
38
|
+
target_time_09_31 = time(9, 31)
|
|
39
|
+
if now_date_time >= target_time_09_31:
|
|
40
|
+
return
|
|
41
|
+
|
|
42
|
+
realtime_quotes_now_list['str_day'] = str_day
|
|
43
|
+
|
|
44
|
+
realtime_quotes_now_list = handle_init_real_time_quotes_data(
|
|
45
|
+
realtime_quotes_now_list.copy(),
|
|
46
|
+
str_now_date, number)
|
|
47
|
+
|
|
48
|
+
mongodb_util.insert_mongo(realtime_quotes_now_list, 'realtime_quotes_now_open')
|
|
49
|
+
|
|
50
|
+
logger.info("同步str_day:{}开盘数据", str_day)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def handle_init_real_time_quotes_data(real_time_quotes_now, str_now_date, number):
|
|
54
|
+
# exclude b symbol
|
|
55
|
+
real_time_quotes_now = common_service_fun_api.exclude_b_symbol(real_time_quotes_now.copy())
|
|
56
|
+
# classification symbol
|
|
57
|
+
real_time_quotes_now = common_service_fun_api.classify_symbol(real_time_quotes_now.copy())
|
|
58
|
+
# fix industry
|
|
59
|
+
real_time_quotes_now = fix_industry_data(real_time_quotes_now.copy())
|
|
60
|
+
# calculate parameter
|
|
61
|
+
real_time_quotes_now = data_init_api.calculate_parameter_factor(real_time_quotes_now.copy())
|
|
62
|
+
|
|
63
|
+
real_time_quotes_now = real_time_quotes_now.loc[real_time_quotes_now['amount'] != 0]
|
|
64
|
+
real_time_quotes_now['str_now_date'] = str_now_date
|
|
65
|
+
real_time_quotes_now['number'] = number
|
|
66
|
+
return real_time_quotes_now
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# fix 错杀数据 有成交量的数据
|
|
70
|
+
def fix_industry_data(real_time_quotes_now):
|
|
71
|
+
# fix industry
|
|
72
|
+
real_time_quotes_now_r = company_common_service_api.amendment_industry(real_time_quotes_now.copy())
|
|
73
|
+
|
|
74
|
+
symbol_list = list(real_time_quotes_now_r['symbol'])
|
|
75
|
+
|
|
76
|
+
na_real_now = real_time_quotes_now.loc[
|
|
77
|
+
~(real_time_quotes_now['symbol'].isin(symbol_list))]
|
|
78
|
+
|
|
79
|
+
na_real_now = na_real_now.loc[na_real_now['amount'] != 0]
|
|
80
|
+
|
|
81
|
+
real_time_quotes_now_result = pd.concat([real_time_quotes_now_r, na_real_now], axis=0)
|
|
82
|
+
return real_time_quotes_now_result
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
if __name__ == '__main__':
|
|
86
|
+
sync_one_day_open_data('2024-06-04')
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
file_path = os.path.abspath(__file__)
|
|
5
|
+
end = file_path.index('mns') + 17
|
|
6
|
+
project_path = file_path[0:end]
|
|
7
|
+
sys.path.append(project_path)
|
|
8
|
+
import pandas as pd
|
|
9
|
+
from loguru import logger
|
|
10
|
+
import mns_common.component.common_service_fun_api as common_service_fun_api
|
|
11
|
+
import mns_common.component.trade_date.trade_date_common_service_api as trade_date_common_service_api
|
|
12
|
+
import mns_common.api.em.east_money_stock_api as east_money_stock_api
|
|
13
|
+
import mns_common.utils.date_handle_util as date_handle_util
|
|
14
|
+
import mns_common.component.company.company_common_service_api as company_common_service_api
|
|
15
|
+
from mns_common.db.MongodbUtil import MongodbUtil
|
|
16
|
+
import mns_common.utils.data_frame_util as data_frame_util
|
|
17
|
+
import mns_common.component.zt.zt_common_service_api as zt_common_service_api
|
|
18
|
+
import mns_common.constant.db_name_constant as db_name_constant
|
|
19
|
+
from datetime import datetime
|
|
20
|
+
import mns_common.component.k_line.common.k_line_common_service_api as k_line_common_service_api
|
|
21
|
+
import mns_common.component.concept.ths_concept_common_service_api as ths_concept_common_service_api
|
|
22
|
+
|
|
23
|
+
mongodb_util = MongodbUtil('27017')
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# 保存高涨股票列表
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def sync_stock_high_chg_pool_list(str_day):
|
|
30
|
+
zt_pool_stocks = get_zt_pool(str_day)
|
|
31
|
+
k_line_high_chg_stocks = k_line_high_chg(str_day)
|
|
32
|
+
if data_frame_util.is_empty(zt_pool_stocks):
|
|
33
|
+
return None
|
|
34
|
+
# 涨停池中的股票
|
|
35
|
+
zt_pool_stocks_symbol_list = list(zt_pool_stocks['symbol'])
|
|
36
|
+
zt_pool_stocks = zt_pool_stocks[['symbol',
|
|
37
|
+
'name',
|
|
38
|
+
"chg",
|
|
39
|
+
'now_price',
|
|
40
|
+
"first_closure_time",
|
|
41
|
+
"last_closure_time",
|
|
42
|
+
"connected_boards_numbers",
|
|
43
|
+
"zt_reason",
|
|
44
|
+
"closure_funds",
|
|
45
|
+
"frying_plates_numbers",
|
|
46
|
+
"statistics",
|
|
47
|
+
"ths_concept_name",
|
|
48
|
+
"ths_concept_code",
|
|
49
|
+
"ths_concept_sync_day",
|
|
50
|
+
"amount",
|
|
51
|
+
"high",
|
|
52
|
+
"low",
|
|
53
|
+
"open",
|
|
54
|
+
|
|
55
|
+
"exchange",
|
|
56
|
+
"flow_mv",
|
|
57
|
+
"total_mv",
|
|
58
|
+
"classification",
|
|
59
|
+
"flow_mv_sp",
|
|
60
|
+
"total_mv_sp",
|
|
61
|
+
"flow_mv_level",
|
|
62
|
+
"amount_level",
|
|
63
|
+
"str_day"
|
|
64
|
+
]]
|
|
65
|
+
|
|
66
|
+
all_company_info_df = company_common_service_api.get_company_info_industry_list_date()
|
|
67
|
+
|
|
68
|
+
zt_pool_company_df = all_company_info_df[[
|
|
69
|
+
'_id',
|
|
70
|
+
'industry',
|
|
71
|
+
'company_type',
|
|
72
|
+
'list_date'
|
|
73
|
+
]]
|
|
74
|
+
|
|
75
|
+
zt_pool_company_df = zt_pool_company_df.loc[all_company_info_df['_id'].isin(zt_pool_stocks_symbol_list)]
|
|
76
|
+
zt_pool_company_df = zt_pool_company_df.set_index(['_id'], drop=True)
|
|
77
|
+
zt_pool_stocks = zt_pool_stocks.set_index(['symbol'], drop=False)
|
|
78
|
+
zt_pool_stocks = pd.merge(zt_pool_stocks, zt_pool_company_df, how='outer',
|
|
79
|
+
left_index=True, right_index=True)
|
|
80
|
+
|
|
81
|
+
# 高涨幅股票未涨停 wei_bi !=100
|
|
82
|
+
high_chg_no_zt_pool = k_line_high_chg_stocks.loc[
|
|
83
|
+
~(k_line_high_chg_stocks['symbol'].isin(zt_pool_stocks_symbol_list))]
|
|
84
|
+
|
|
85
|
+
high_chg_no_zt_pool = high_chg_no_zt_pool.rename(columns={
|
|
86
|
+
"close": "now_price"})
|
|
87
|
+
|
|
88
|
+
high_chg_no_zt_pool = high_chg_no_zt_pool[[
|
|
89
|
+
'symbol',
|
|
90
|
+
'name',
|
|
91
|
+
'chg',
|
|
92
|
+
'now_price',
|
|
93
|
+
"amount",
|
|
94
|
+
"high",
|
|
95
|
+
"low",
|
|
96
|
+
"open",
|
|
97
|
+
"exchange",
|
|
98
|
+
"classification",
|
|
99
|
+
"flow_mv",
|
|
100
|
+
"flow_mv_sp",
|
|
101
|
+
"amount_level"
|
|
102
|
+
]]
|
|
103
|
+
high_chg_no_zt_pool['first_closure_time'] = '无'
|
|
104
|
+
high_chg_no_zt_pool['last_closure_time'] = '无'
|
|
105
|
+
high_chg_no_zt_pool['connected_boards_numbers'] = 1
|
|
106
|
+
high_chg_no_zt_pool['zt_reason'] = '无'
|
|
107
|
+
high_chg_no_zt_pool['closure_funds'] = 0
|
|
108
|
+
high_chg_no_zt_pool['frying_plates_numbers'] = 0
|
|
109
|
+
high_chg_no_zt_pool['statistics'] = '1/1'
|
|
110
|
+
# 暂无
|
|
111
|
+
high_chg_no_zt_pool['total_mv'] = 0
|
|
112
|
+
high_chg_no_zt_pool['total_mv_sp'] = 0
|
|
113
|
+
high_chg_no_zt_pool['flow_mv_level'] = 0
|
|
114
|
+
|
|
115
|
+
high_chg_no_zt_pool['str_day'] = str_day
|
|
116
|
+
|
|
117
|
+
high_chg_no_zt_company_df = all_company_info_df[[
|
|
118
|
+
'_id',
|
|
119
|
+
'industry',
|
|
120
|
+
'company_type',
|
|
121
|
+
'list_date',
|
|
122
|
+
'ths_concept_name',
|
|
123
|
+
'ths_concept_code',
|
|
124
|
+
'ths_concept_sync_day'
|
|
125
|
+
]]
|
|
126
|
+
|
|
127
|
+
high_chg_no_zt_company_df = high_chg_no_zt_company_df.loc[
|
|
128
|
+
all_company_info_df['_id'].isin(list(high_chg_no_zt_pool['symbol']))]
|
|
129
|
+
|
|
130
|
+
high_chg_no_zt_company_df = high_chg_no_zt_company_df.set_index(['_id'], drop=True)
|
|
131
|
+
high_chg_no_zt_pool = high_chg_no_zt_pool.set_index(['symbol'], drop=False)
|
|
132
|
+
|
|
133
|
+
high_chg_no_zt_pool = pd.merge(high_chg_no_zt_pool, high_chg_no_zt_company_df, how='outer',
|
|
134
|
+
left_index=True, right_index=True)
|
|
135
|
+
|
|
136
|
+
high_chg_pool = pd.concat([zt_pool_stocks, high_chg_no_zt_pool])
|
|
137
|
+
|
|
138
|
+
now_date = datetime.now()
|
|
139
|
+
now_day = now_date.strftime('%Y-%m-%d')
|
|
140
|
+
|
|
141
|
+
real_time_quotes_now_init = east_money_stock_api.get_real_time_quotes_all_stocks()
|
|
142
|
+
|
|
143
|
+
last_trade_zt_pool = zt_common_service_api.get_last_trade_day_zt(str_day)
|
|
144
|
+
|
|
145
|
+
zt_symbol_connected_boards_numbers_list = last_trade_zt_pool.loc[
|
|
146
|
+
last_trade_zt_pool['symbol'].isin(high_chg_pool['symbol'])]
|
|
147
|
+
|
|
148
|
+
# 所有重置为1
|
|
149
|
+
high_chg_pool['connected_boards_numbers'] = 1
|
|
150
|
+
|
|
151
|
+
if zt_symbol_connected_boards_numbers_list is not None and zt_symbol_connected_boards_numbers_list.shape[0] != 0:
|
|
152
|
+
for yesterday_zt in zt_symbol_connected_boards_numbers_list.itertuples():
|
|
153
|
+
high_chg_pool.loc[
|
|
154
|
+
high_chg_pool["symbol"] == yesterday_zt.symbol, ['connected_boards_numbers']] \
|
|
155
|
+
= 1 + yesterday_zt.connected_boards_numbers
|
|
156
|
+
|
|
157
|
+
for stock_one in high_chg_pool.itertuples():
|
|
158
|
+
try:
|
|
159
|
+
|
|
160
|
+
symbol = stock_one.symbol
|
|
161
|
+
stock_one_df = high_chg_pool.loc[high_chg_pool['symbol'] == symbol]
|
|
162
|
+
|
|
163
|
+
classification = common_service_fun_api.classify_symbol_one(symbol)
|
|
164
|
+
stock_one_df['classification'] = classification
|
|
165
|
+
|
|
166
|
+
list_date = stock_one.list_date
|
|
167
|
+
if list_date is None or pd.isna(list_date):
|
|
168
|
+
list_date = '1989-07-29'
|
|
169
|
+
diff_days = 10000
|
|
170
|
+
else:
|
|
171
|
+
list_date = str(list_date)
|
|
172
|
+
list_date = list_date.replace(".0", "")
|
|
173
|
+
list_date = date_handle_util.lash_date(list_date)
|
|
174
|
+
|
|
175
|
+
list_date_time = date_handle_util.str_to_date(list_date, "%Y-%m-%d")
|
|
176
|
+
str_now_day_time = date_handle_util.str_to_date(str_day, "%Y-%m-%d")
|
|
177
|
+
|
|
178
|
+
diff_days = date_handle_util.days_diff(str_now_day_time, list_date_time)
|
|
179
|
+
# 上市新股
|
|
180
|
+
if diff_days == 0:
|
|
181
|
+
continue
|
|
182
|
+
|
|
183
|
+
stock_one_df['list_day'] = list_date
|
|
184
|
+
# 上市天数
|
|
185
|
+
stock_one_df['diff_days'] = diff_days
|
|
186
|
+
# 交易天数
|
|
187
|
+
deal_days = k_line_common_service_api.get_deal_days(str_day, symbol)
|
|
188
|
+
stock_one_df['deal_days'] = deal_days
|
|
189
|
+
|
|
190
|
+
last_trade_day = trade_date_common_service_api.get_last_trade_day(str_day)
|
|
191
|
+
|
|
192
|
+
# 上个交易日是否是高涨幅
|
|
193
|
+
last_day_high_chg = mongodb_util.exist_data_query(db_name_constant.STOCK_QFQ_DAILY,
|
|
194
|
+
query={"symbol": symbol, "date": last_trade_day,
|
|
195
|
+
"chg": {'$gte': common_service_fun_api.ZT_CHG}})
|
|
196
|
+
stock_one_df['last_day_high_chg'] = last_day_high_chg
|
|
197
|
+
|
|
198
|
+
open_price = stock_one.open
|
|
199
|
+
high = stock_one.high
|
|
200
|
+
close = stock_one.now_price
|
|
201
|
+
yi_zhi_ban = False
|
|
202
|
+
if open_price == high and open_price == close:
|
|
203
|
+
yi_zhi_ban = True
|
|
204
|
+
|
|
205
|
+
stock_one_df['yi_zhi_ban'] = yi_zhi_ban
|
|
206
|
+
|
|
207
|
+
if now_day == str_day:
|
|
208
|
+
real_time_quotes_now_one = real_time_quotes_now_init.loc[
|
|
209
|
+
real_time_quotes_now_init['symbol'] == symbol]
|
|
210
|
+
stock_one_df['total_mv'] = list(real_time_quotes_now_one['total_mv'])[0]
|
|
211
|
+
|
|
212
|
+
stock_one_df.loc[:, ['flow_mv_level']] \
|
|
213
|
+
= ((stock_one_df["flow_mv"] / common_service_fun_api.HUNDRED_MILLION) // 10) + 1
|
|
214
|
+
stock_one_df['total_mv_sp'] = round((stock_one_df['total_mv'] / common_service_fun_api.HUNDRED_MILLION), 2)
|
|
215
|
+
stock_one_df["_id"] = stock_one_df['symbol'] + "_" + str_day
|
|
216
|
+
stock_one_df['remark'] = ''
|
|
217
|
+
symbol_last_concept_df = get_symbol_last_concept(symbol, str_day)
|
|
218
|
+
if data_frame_util.is_not_empty(symbol_last_concept_df):
|
|
219
|
+
ths_concept_name = list(symbol_last_concept_df['concept_name'])[0]
|
|
220
|
+
ths_concept_sync_day = list(symbol_last_concept_df['str_day'])[0]
|
|
221
|
+
ths_concept_code = list(symbol_last_concept_df['concept_code'])[0]
|
|
222
|
+
stock_one_df['ths_concept_name'] = ths_concept_name
|
|
223
|
+
stock_one_df['ths_concept_code'] = ths_concept_code
|
|
224
|
+
stock_one_df['ths_concept_sync_day'] = ths_concept_sync_day
|
|
225
|
+
|
|
226
|
+
stock_one_df['ths_concept_name'].fillna('退市', inplace=True)
|
|
227
|
+
stock_one_df['ths_concept_code'].fillna(0, inplace=True)
|
|
228
|
+
stock_one_df['ths_concept_sync_day'].fillna('1989-07-29', inplace=True)
|
|
229
|
+
stock_one_df['industry'].fillna('退市', inplace=True)
|
|
230
|
+
stock_one_df['company_type'].fillna('', inplace=True)
|
|
231
|
+
stock_one_df['list_date'].fillna(19890729, inplace=True)
|
|
232
|
+
stock_one_df['chg'] = round(stock_one_df['chg'], 2)
|
|
233
|
+
|
|
234
|
+
mongodb_util.save_mongo(stock_one_df, db_name_constant.STOCK_HIGH_CHG_POOL)
|
|
235
|
+
logger.info("更新高涨幅数据成功{},{}", stock_one.symbol, str_day)
|
|
236
|
+
except Exception as e:
|
|
237
|
+
logger.error("更新高涨幅数据异常:{},{},{}", stock_one.symbol, str_day, e)
|
|
238
|
+
continue
|
|
239
|
+
|
|
240
|
+
return high_chg_no_zt_pool
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
# 通过k线获取高涨幅股票
|
|
244
|
+
def k_line_high_chg(str_day):
|
|
245
|
+
query = {"date": date_handle_util.no_slash_date(str_day), "chg": {'$gte': common_service_fun_api.ZT_CHG}}
|
|
246
|
+
# 今日高涨幅的list
|
|
247
|
+
return mongodb_util.find_query_data(db_name_constant.STOCK_QFQ_DAILY, query)
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
# 获取当日涨停池中股票
|
|
251
|
+
def get_zt_pool(str_day):
|
|
252
|
+
# 今日涨停股
|
|
253
|
+
query_zt = {'str_day': str_day}
|
|
254
|
+
zt_pool = mongodb_util.find_query_data(db_name_constant.STOCK_ZT_POOL, query_zt)
|
|
255
|
+
if data_frame_util.is_empty(zt_pool):
|
|
256
|
+
return pd.DataFrame()
|
|
257
|
+
if 'zt_reason' not in zt_pool.columns:
|
|
258
|
+
zt_pool['zt_reason'] = ''
|
|
259
|
+
if 'ths_concept_name' not in zt_pool.columns:
|
|
260
|
+
zt_pool['ths_concept_name'] = ''
|
|
261
|
+
if 'ths_concept_code' not in zt_pool.columns:
|
|
262
|
+
zt_pool['ths_concept_code'] = 0
|
|
263
|
+
if 'ths_concept_sync_day' not in zt_pool.columns:
|
|
264
|
+
zt_pool['ths_concept_sync_day'] = 0
|
|
265
|
+
if 'high' not in zt_pool.columns:
|
|
266
|
+
zt_pool['high'] = 0
|
|
267
|
+
if 'low' not in zt_pool.columns:
|
|
268
|
+
zt_pool['low'] = 0
|
|
269
|
+
if 'open' not in zt_pool.columns:
|
|
270
|
+
zt_pool['open'] = 0
|
|
271
|
+
zt_pool['amount_level'] = round(zt_pool['amount'] / common_service_fun_api.HUNDRED_MILLION, 2)
|
|
272
|
+
return zt_pool
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def get_symbol_last_concept(symbol, str_day):
|
|
276
|
+
ths_effective_concept_df = ths_concept_common_service_api.get_all_ths_effective_concept()
|
|
277
|
+
ths_effective_concept_code = list(ths_effective_concept_df['symbol'])
|
|
278
|
+
query = {"symbol": symbol, 'str_day': {"$lte": str_day}, 'concept_code': {"$in": ths_effective_concept_code}}
|
|
279
|
+
return mongodb_util.descend_query(query, db_name_constant.THS_STOCK_CONCEPT_DETAIL, 'str_day', 1)
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
if __name__ == '__main__':
|
|
283
|
+
sync_stock_high_chg_pool_list('2024-06-04')
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
file_path = os.path.abspath(__file__)
|
|
5
|
+
end = file_path.index('mns') + 17
|
|
6
|
+
project_path = file_path[0:end]
|
|
7
|
+
sys.path.append(project_path)
|
|
8
|
+
|
|
9
|
+
from loguru import logger
|
|
10
|
+
import mns_common.component.common_service_fun_api as common_service_fun_api
|
|
11
|
+
import mns_common.utils.date_handle_util as date_handle_util
|
|
12
|
+
import mns_common.component.company.company_common_service_api as company_common_service_api
|
|
13
|
+
import mns_common.component.data.data_init_api as data_init_api
|
|
14
|
+
from mns_common.db.MongodbUtil import MongodbUtil
|
|
15
|
+
import mns_common.utils.db_util as db_util
|
|
16
|
+
import mns_common.constant.db_name_constant as db_name_constant
|
|
17
|
+
|
|
18
|
+
mongodb_util = MongodbUtil('27017')
|
|
19
|
+
|
|
20
|
+
# 保存高涨股票当天实时行情数据
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
choose_field = ["_id",
|
|
24
|
+
"symbol",
|
|
25
|
+
"name",
|
|
26
|
+
"industry",
|
|
27
|
+
"now_price",
|
|
28
|
+
"chg",
|
|
29
|
+
"quantity_ratio",
|
|
30
|
+
"amount_level",
|
|
31
|
+
"disk_ratio",
|
|
32
|
+
"real_disk_diff_amount_exchange",
|
|
33
|
+
'max_real_main_inflow_multiple',
|
|
34
|
+
'sum_main_inflow_disk',
|
|
35
|
+
"real_main_inflow_multiple",
|
|
36
|
+
"real_super_main_inflow_multiple",
|
|
37
|
+
"super_main_inflow_multiple",
|
|
38
|
+
"main_inflow_multiple",
|
|
39
|
+
"disk_diff_amount_exchange",
|
|
40
|
+
"large_inflow_multiple",
|
|
41
|
+
"today_main_net_inflow",
|
|
42
|
+
"today_main_net_inflow_ratio",
|
|
43
|
+
"super_large_order_net_inflow",
|
|
44
|
+
"super_large_order_net_inflow_ratio",
|
|
45
|
+
"large_order_net_inflow",
|
|
46
|
+
"large_order_net_inflow_ratio",
|
|
47
|
+
"reference_main_inflow",
|
|
48
|
+
"disk_diff_amount",
|
|
49
|
+
"mv_circulation_ratio",
|
|
50
|
+
"real_exchange",
|
|
51
|
+
"exchange",
|
|
52
|
+
'real_exchange',
|
|
53
|
+
"total_mv",
|
|
54
|
+
"flow_mv",
|
|
55
|
+
"volume",
|
|
56
|
+
"high",
|
|
57
|
+
"low",
|
|
58
|
+
"open",
|
|
59
|
+
"yesterday_price",
|
|
60
|
+
"amount",
|
|
61
|
+
"total_mv_sp",
|
|
62
|
+
"flow_mv_sp",
|
|
63
|
+
"outer_disk",
|
|
64
|
+
"inner_disk",
|
|
65
|
+
"classification",
|
|
66
|
+
"number",
|
|
67
|
+
"str_day",
|
|
68
|
+
"str_now_date"
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# 同步高涨幅股票实时行情数据
|
|
73
|
+
def sync_high_chg_real_time_quotes(str_day):
|
|
74
|
+
mongo = db_util.get_db(str_day)
|
|
75
|
+
|
|
76
|
+
realtime_quotes_db_name = 'realtime_quotes_now_' + str_day
|
|
77
|
+
high_chg_list = get_high_chg_symbol(str_day)
|
|
78
|
+
if high_chg_list is None or len(high_chg_list) == 0:
|
|
79
|
+
return
|
|
80
|
+
|
|
81
|
+
for symbol in high_chg_list:
|
|
82
|
+
try:
|
|
83
|
+
query_all = {"symbol": symbol}
|
|
84
|
+
real_time_quotes_now_high_chg_all = mongo.find_query_data(realtime_quotes_db_name, query_all)
|
|
85
|
+
if real_time_quotes_now_high_chg_all.shape[0] == 0:
|
|
86
|
+
return
|
|
87
|
+
real_time_quotes_now_high_chg_all = company_common_service_api.amendment_industry_exist_na(
|
|
88
|
+
real_time_quotes_now_high_chg_all,
|
|
89
|
+
high_chg_list)
|
|
90
|
+
real_time_quotes_now_high_chg_all.dropna(subset=['symbol'], axis=0,
|
|
91
|
+
inplace=True)
|
|
92
|
+
real_time_quotes_now_high_chg_all = data_init_api.calculate_parameter_factor(
|
|
93
|
+
real_time_quotes_now_high_chg_all)
|
|
94
|
+
|
|
95
|
+
real_time_quotes_now_high_chg_all['amount_level'] = round(
|
|
96
|
+
(real_time_quotes_now_high_chg_all['amount'] / common_service_fun_api.HUNDRED_MILLION), 2) * 10
|
|
97
|
+
real_time_quotes_now_high_chg_all['flow_mv_sp'] = round(
|
|
98
|
+
(real_time_quotes_now_high_chg_all['flow_mv'] / common_service_fun_api.HUNDRED_MILLION), 2)
|
|
99
|
+
real_time_quotes_now_high_chg_all['total_mv_sp'] = round(
|
|
100
|
+
(real_time_quotes_now_high_chg_all['total_mv'] / common_service_fun_api.HUNDRED_MILLION), 2)
|
|
101
|
+
|
|
102
|
+
save_realtime_quotes_now_zt_data(real_time_quotes_now_high_chg_all, str_day, symbol)
|
|
103
|
+
logger.info("同步高涨幅股票实时行情数据信息:{},{}", str_day, symbol)
|
|
104
|
+
except BaseException as e:
|
|
105
|
+
logger.error("同步高涨幅股票实时行情数据发生异常:{}:{},{}", str_day, e, symbol)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
# 获取 str_day 高涨幅列表 k线和涨停池中
|
|
109
|
+
def get_high_chg_symbol(str_day):
|
|
110
|
+
query = {"date": date_handle_util.no_slash_date(str_day), "chg": {'$gte': common_service_fun_api.ZT_CHG}}
|
|
111
|
+
# 今日高涨幅的list
|
|
112
|
+
real_time_quotes_now_high_chg = mongodb_util.find_query_data(db_name_constant.STOCK_QFQ_DAILY, query)
|
|
113
|
+
if real_time_quotes_now_high_chg.shape[0] == 0:
|
|
114
|
+
return None
|
|
115
|
+
high_chg_list = list(real_time_quotes_now_high_chg['symbol'])
|
|
116
|
+
# 今日涨停股
|
|
117
|
+
query_zt = {'str_day': str_day}
|
|
118
|
+
zt_pool = mongodb_util.find_query_data(db_name_constant.STOCK_ZT_POOL, query_zt)
|
|
119
|
+
if zt_pool.shape[0] > 0:
|
|
120
|
+
zt_pool_list = list(zt_pool['symbol'])
|
|
121
|
+
high_chg_list.extend(zt_pool_list)
|
|
122
|
+
high_chg_list = list(set(high_chg_list))
|
|
123
|
+
return high_chg_list
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
# 保存high chg 股票实时行情数据
|
|
127
|
+
def save_realtime_quotes_now_zt_data(realtime_quotes_now_zt, str_day, symbol):
|
|
128
|
+
realtime_quotes_now_zt = common_service_fun_api.classify_symbol(realtime_quotes_now_zt.copy())
|
|
129
|
+
# create_index()
|
|
130
|
+
if 'wei_bi' in realtime_quotes_now_zt.columns and bool(1 - ("wei_bi" in choose_field)):
|
|
131
|
+
choose_field.append("wei_bi")
|
|
132
|
+
if 'up_speed' in realtime_quotes_now_zt.columns and bool(1 - ("up_speed" in choose_field)):
|
|
133
|
+
choose_field.append("up_speed")
|
|
134
|
+
if 'list_date' in realtime_quotes_now_zt.columns and bool(1 - ("list_date" in choose_field)):
|
|
135
|
+
choose_field.append("list_date")
|
|
136
|
+
realtime_quotes_now_zt.loc[:, 'str_day'] = str_day
|
|
137
|
+
realtime_quotes_now_zt = realtime_quotes_now_zt[choose_field]
|
|
138
|
+
remove_query = {"symbol": symbol, "str_day": str_day}
|
|
139
|
+
result = mongodb_util.remove_data(remove_query, db_name_constant.ZT_STOCK_REAL_TIME_QUOTES).acknowledged
|
|
140
|
+
if result:
|
|
141
|
+
mongodb_util.insert_mongo(realtime_quotes_now_zt, db_name_constant.ZT_STOCK_REAL_TIME_QUOTES)
|