-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifylist.py
More file actions
executable file
·265 lines (239 loc) · 8.4 KB
/
notifylist.py
File metadata and controls
executable file
·265 lines (239 loc) · 8.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/usr/bin/python
import akshare as ak
import config
import dbutils
import os
print(os.getcwd())
def choose_action():
global id
while True:
action = input("1:添加 2:删除 3:列表 4:重置 5:放弃操作\n请选择操作:")
if action == "1":
choose_type()
continue
if action == "2":
while True:
try:
id = int(input("请输入要删除的任务ID:"))
except ValueError as e:
print("请输入整数!")
continue
break
dbutils.delete_task(id)
dbutils.list_task()
continue
if action == "3":
dbutils.list_task()
continue
if action == "4":
confirm_del = input("即将清空所有的任务并重置,是否继续(y/n)?")
if confirm_del == "y" or confirm_del == "Y":
dbutils.delete_task_table()
print("重置成功!")
continue
print("已放弃操作!")
continue
if action == "5":
break
def choose_type():
while True:
type = input("1:内盘期货 2:A股 3:CFD 4:外汇 5:放弃\n添加类型:")
if type == "1":
add_cn_future()
break
if type == '2':
add_cn_stocks()
break
if type == '3':
add_foreign_commodity_cfd()
break
if type == '4':
add_forex()
break
if type == '5':
print("放弃操作,退出")
break
continue
def compare_direction():
global direction
while True:
try:
direction = int(input("1:高于等于 2:低于等于\n请选择:"))
except ValueError as e:
print("请输入正确的数字")
continue
if direction == 1:
return '高于'
if direction == 2:
return '低于'
if direction != 1 and direction != 2:
print("请输入正确的数字")
continue
def get_price():
global price
while True:
try:
price = float(input("请输入价格:"))
except ValueError as e:
print("请输入数字")
continue
if price < 0:
print("请输入数字")
continue
break
return price
def add_cn_future():
global name, symbol
future_items = ak.futures_symbol_mark()
length = future_items.shape[0]
for j in future_items.index:
if (j + 1) % 10 == 0:
print(f"%2s:%2s" % (j, future_items.at[j, 'symbol']), end="\n\n")
else:
print(f"%2s:%2s" % (j, future_items.at[j, 'symbol']), end=" ")
while True:
try:
item = int(input("请选择期货品种:"))
except ValueError as e:
print("请正确输入数字")
continue
if item > length - 1 or item < 0:
print("请输入正确的数字")
continue
name = future_items.at[item, 'symbol']
contracts = ak.futures_zh_realtime(symbol=name)
print("%-8s%-8s%-8s" % ("序号", "合约", "现价"))
for c in contracts.index:
print("%-8s%-8s%-8s" % (c, contracts.at[c, 'symbol'], contracts.at[c, 'trade']))
while True:
try:
symbol_index = int(input("请选择合约序号:"))
except ValueError as e:
print("请正确输入数字")
continue
if symbol_index > contracts.shape[0] - 1 or item < 0:
print("请输入正确的数字")
continue
symbol = contracts.at[symbol_index, 'symbol']
print("已选择:%s ,合约:%s" % (name, symbol))
break
break
direction = compare_direction()
price = get_price()
num = get_num()
values = ['cn_future', name, symbol, direction, price, num]
sqlite_db = dbutils.get_db()
sqlite_db.insert(config.table_name, config.table_fields, values)
print("添加成功!")
dbutils.list_task()
def add_foreign_commodity_cfd():
global cfd_symbol, cfd_name
cfds = ak.futures_hq_subscribe_exchange_symbol()
length = cfds.shape[0]
for cfd in cfds.index:
if (cfd + 1) % 10 == 0:
print(f"%2s:%2s" % (cfd, cfds.at[cfd, 'symbol']), end="\n\n")
else:
print(f"%2s:%2s" % (cfd, cfds.at[cfd, 'symbol']), end=" ")
while True:
try:
item = int(input("请选择外盘商品CFD品种:"))
except ValueError as e:
print("请正确输入数字")
continue
if item > length - 1 or item < 0:
print("请输入正确的数字")
continue
cfd_name = cfds.at[item, 'symbol']
cfd_symbol = cfds.at[item, 'code']
cfd_price = get_current_cfd_price(cfd_symbol)
print("已选择:%s ,代码:%s, 当前价格:%s" % (cfd_name, cfd_symbol, cfd_price))
break
direction = compare_direction()
price = get_price()
num = get_num()
values = ['foreign_commodity_cfd', cfd_name, cfd_symbol, direction, price, num]
sqlite_db = dbutils.get_db()
sqlite_db.insert(config.table_name, config.table_fields, values)
print("添加成功!")
dbutils.list_task()
def add_cn_stocks():
while True:
try:
stock_symbol = input("请输入6位A股个股代码:")
if len(stock_symbol) > 6:
continue
stock_info = ak.stock_individual_info_em(symbol=stock_symbol)
stock_name = stock_info.at[5, 'value']
stock_prices = ak.stock_bid_ask_em(symbol=stock_symbol)
stock_current_price = stock_prices.at[8, 'value']
confirm = input("A股 %s %s 现价:%s ,是否添加(y/n)?" % (stock_symbol, stock_name, stock_current_price))
if confirm != "y" and confirm != "Y":
print("已放弃添加!")
break
direction = compare_direction()
price = get_price()
num = get_num()
values = ['cn_stock', stock_name, stock_symbol, direction, price, num]
sqlite_db = dbutils.get_db()
sqlite_db.insert(config.table_name, config.table_fields, values)
print("添加成功!")
dbutils.list_task()
break
except Exception as e:
print(e)
print("查询个股失败")
continue
def add_forex():
fx_pair_quote_df = ak.fx_pair_quote()
print(fx_pair_quote_df)
length = fx_pair_quote_df.shape[0]
while True:
try:
forex_index = int(input("请选择货币对:"))
except ValueError as e:
print("请正确输入数字")
continue
if forex_index > length - 1 or forex_index < 0:
print("请输入正确的数字")
continue
name = fx_pair_quote_df.at[forex_index, '货币对']
symbol = forex_index
current_price = fx_pair_quote_df.at[forex_index, '卖报价']
confirm_choice = input("已选择:%s ,现报价:%s, 缺定添加(y/n)?" % (name, current_price))
if confirm_choice != "y" and confirm_choice != "Y":
print("放弃操作!")
break
direction = compare_direction()
price = get_price()
num = get_num()
values = ['forex', name, symbol, direction, price, num]
sqlite_db = dbutils.get_db()
sqlite_db.insert(config.table_name, config.table_fields, values)
print("添加成功!")
dbutils.list_task()
break
def get_current_cfd_price(code: str):
list = ['CT', code]
try:
futures_foreign_commodity_realtime_df = ak.futures_foreign_commodity_realtime(subscribe_list=list)
current_price = futures_foreign_commodity_realtime_df.at[1, '最新价']
return current_price
except Exception as e:
print(e)
return "获取失败"
def get_num():
global num
while True:
try:
num = int(input("请输入通知次数:"))
except ValueError as e:
print("请输入数字")
continue
if num < 0:
print("请输入正确数字数字")
continue
break
return num
if __name__ == '__main__':
choose_action()