jsppy 1.2.9__tar.gz

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.
jsppy-1.2.9/PKG-INFO ADDED
@@ -0,0 +1,24 @@
1
+ Metadata-Version: 2.4
2
+ Name: jsppy
3
+ Version: 1.2.9
4
+ Summary: jsppy数据接口
5
+ Author: jsppy数据接口
6
+ Requires-Dist: click
7
+ Requires-Dist: six
8
+ Requires-Dist: cryptography
9
+ Requires-Dist: beautifulsoup4>=4.9.1
10
+ Requires-Dist: lxml>=4.2.1
11
+ Requires-Dist: pandas>=0.25
12
+ Requires-Dist: requests>=2.22.0
13
+ Requires-Dist: pypinyin>=0.35.0
14
+ Requires-Dist: html5lib>=1.0.1
15
+ Requires-Dist: xlrd>=1.2.0
16
+ Requires-Dist: urllib3>=1.25.8
17
+ Requires-Dist: tqdm>=4.43.0
18
+ Requires-Dist: openpyxl>=3.0.3
19
+ Requires-Dist: jsonpath>=0.82
20
+ Requires-Dist: tabulate>=0.8.6
21
+ Requires-Dist: decorator>=4.4.2
22
+ Dynamic: author
23
+ Dynamic: requires-dist
24
+ Dynamic: summary
@@ -0,0 +1 @@
1
+ from jsppy.stock import *
@@ -0,0 +1,281 @@
1
+
2
+ import os
3
+ from datetime import datetime, timedelta
4
+ import pandas as pd
5
+ import traceback
6
+ debug = 0
7
+ if debug == 1:
8
+ from third.maths import Jsp_API
9
+ else:
10
+ from jsppy.third.maths import Jsp_API
11
+ print("期货、现货、股票、外汇数据(level2、逐笔、十档、五档、分钟、日)需要的,价格全网最低,请联系微信:a1312131417 或 xiaolouVS")
12
+ print("--------------------")
13
+
14
+ import requests
15
+
16
+ bTest = 0
17
+ bLogin = False
18
+ api = Jsp_API()
19
+ str_bg = "jsppy"
20
+ token = ""
21
+ last_login_time = None
22
+
23
+ def print_info():
24
+ if debug == 1:
25
+ traceback.print_exc()
26
+ print("入参格式错误,或时间超限,请检查!")
27
+
28
+
29
+ def get_time():
30
+ global bLogin
31
+ strt = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
32
+ if strt > str_bg:
33
+ bLogin = False
34
+ time_str= strt.split(' ')[1]
35
+ return strt, time_str
36
+
37
+ def login(token_str):
38
+ global token, str_bg, bLogin, last_login_time
39
+ now = datetime.now()
40
+ if last_login_time is not None and (now - last_login_time).total_seconds() < 60:
41
+ print("登录接口在程序启动后只需要调用一次,请不要频繁调用!")
42
+ return 1
43
+
44
+ token = token_str
45
+ # 将内容转换为字符串列表
46
+ if debug == 1:
47
+ url = f"http://127.0.0.1:5000/api/interface/auth"
48
+ else:
49
+ url = f"http://49.233.164.146:8090/api/interface/auth"
50
+ payload = {
51
+ "token": token ,
52
+ "type": "a_gu"
53
+ }
54
+
55
+ bLogin = False
56
+ str_token, str_tokens, str_bg = "", "", ""
57
+ response = requests.post(url, json=payload)
58
+ data = response.json()
59
+ if response.status_code == 200:
60
+ if data.get('success') == True and 'data' in data:
61
+ autu_token = data['data'].get('autu_token')
62
+ str_token = autu_token.split(':')[0]
63
+ str_tokens = autu_token.split(':')[1]
64
+ str_bg = data['data'].get('autu_url')
65
+ api.connect(str_token, int(str_tokens))
66
+ bLogin = True
67
+ last_login_time = now
68
+ return 1
69
+ else:
70
+ if data.get('error') == None:
71
+ print("连接失败,请稍后重试")
72
+ else:
73
+ print(data.get('error'))
74
+ return 0
75
+ else:
76
+ if data.get('error') == None:
77
+ print("连接失败,请稍后重试")
78
+ else:
79
+ print(data.get('error'))
80
+ return 0
81
+
82
+ def login_out():
83
+ global bLogin
84
+ bLogin = False
85
+ api.disconnect()
86
+
87
+ def Init():
88
+ if bLogin == False:
89
+ print("请先使用token登录")
90
+ return False
91
+ return bLogin
92
+
93
+ def __select_market_code(code):
94
+ code = str(code)
95
+ if '.' in code:
96
+ if code.split('.')[0] == 'SZ':
97
+ return 0
98
+ elif code.split('.')[0] == 'SH':
99
+ return 1
100
+ else:
101
+ return 2
102
+ else:
103
+ if code[0] in ['5', '6', '9'] or code[:3] in ["009", "126", "110", "201", "202", "203", "204"]:
104
+ return 1
105
+ if code[0] in ['8']:
106
+ return 2
107
+ return 0
108
+
109
+ def __select_code(code):
110
+ code = str(code)
111
+ if '.' in code:
112
+ return code.split('.')[1]
113
+ else:
114
+ return code
115
+
116
+ def get_code(market):
117
+ list_df = []
118
+ i = 0
119
+ if market == 1:
120
+ i = 1000
121
+ while 1:
122
+ df = api.to_df(api.get_security_list(market, i))
123
+ if len(df) <= 1 :
124
+ break
125
+
126
+ if len(df) > 0:
127
+ df00 = df[df['code'].str[:2] == '00']
128
+ df30 = df[df['code'].str[:2] == '30'] #300开头获取不到
129
+ df60 = df[df['code'].str[:2] == '60']
130
+ df68 = df[df['code'].str[:2] == '68']
131
+
132
+ list_df.append(df00)
133
+ list_df.append(df30)
134
+ list_df.append(df60)
135
+ list_df.append(df68)
136
+
137
+ i = i + 1000
138
+ df = ''
139
+ if len(list_df) > 0:
140
+ df = pd.concat(list_df)
141
+ df = df.drop(['volunit', 'decimal_point'], axis=1)
142
+ df = df.reset_index(drop=True)
143
+ return df
144
+
145
+ def get_history_data(code, start_date, end_date, period, index=False):
146
+ try:
147
+ if (not Init()):
148
+ return pd.DataFrame()
149
+ periodDic = {'1min' : 8, '5min': 0, '15min': 1, '30min': 2, '60min': 3, 'D': 4, 'W': 5, 'M': 6}
150
+
151
+ date1 = datetime.strptime(start_date, "%Y-%m-%d")
152
+ date2 = datetime.now()
153
+ # 计算日期差异
154
+ n = (date2 - date1).days + 1
155
+
156
+ date_list = []
157
+ for i in range(n):
158
+ if index == False:
159
+ df_tem = api.to_df(api.get_security_bars(periodDic[period], __select_market_code(code), __select_code(code), i * 800, 800))
160
+ else:
161
+ df_tem = api.to_df(api.get_index_bars(periodDic[period], __select_market_code(code), __select_code(code), i * 800, 800))
162
+ if df_tem.empty:
163
+ break
164
+ time_tem = df_tem.iloc[0].loc['datetime']
165
+ time2 = datetime.strptime(time_tem, "%Y-%m-%d %H:%M")
166
+
167
+ date_list.insert(0, df_tem)
168
+
169
+ if time2 < date1:
170
+ break
171
+
172
+ data = pd.concat(date_list)
173
+
174
+ if data.empty:
175
+ return data
176
+
177
+ end_date = datetime.strptime(end_date, '%Y-%m-%d')
178
+ new_time = end_date + timedelta(days=1)
179
+ end_date = new_time.strftime('%Y-%m-%d')
180
+
181
+ data = data[(data['datetime'] >= start_date) & (data['datetime'] <= end_date)]
182
+ data = data[['datetime', 'open', 'high', 'low', 'close', 'vol', 'amount']]
183
+ data['datetime'] = data['datetime'] + ':00'
184
+ data = data.reset_index(drop=True)
185
+ data.loc[data['vol'] < 0.1, 'vol'] = 0
186
+ data.loc[data['amount'] < 0.1, 'amount'] = 0
187
+ data.columns = ['时间', '开盘价', '最高价', '最低价', '收盘价', '成交量', '成交额']
188
+ return data
189
+ except:
190
+ print_info()
191
+ return pd.DataFrame()
192
+
193
+ def get_index_data(code, start_date, end_date, period):
194
+ return get_history_data(code, start_date, end_date, period, index=True)
195
+
196
+ def get_real_hq(all_stock):
197
+ try:
198
+ if len(all_stock) > 80 or not Init():
199
+ return pd.DataFrame()
200
+
201
+ list_all = []
202
+ for c in all_stock:
203
+ list_all.append((__select_market_code(c), __select_code(c)))
204
+ stocks = api.get_security_quotes(list_all)
205
+ if stocks == None:
206
+ print("传入参数中有代码错误或现在停盘的股票,请剔除")
207
+ return pd.DataFrame()
208
+ combined_df = pd.DataFrame(stocks)
209
+ combined_df = combined_df.drop(
210
+ ['market', 'active1', 'reversed_bytes0', 'reversed_bytes1',
211
+ 'cur_vol', 'reversed_bytes2', 'reversed_bytes3', 'reversed_bytes4', 'reversed_bytes5',
212
+ 'reversed_bytes6', 'reversed_bytes7', 'reversed_bytes8', 'reversed_bytes9',
213
+ 'active2'], axis=1)
214
+
215
+ time_str, time_str2 = get_time()
216
+ combined_df['servertime'] = time_str
217
+
218
+ if (time_str2 < "09:30:00" or time_str2 > "15:03:00") or (time_str2 > "11:33:00" and time_str2 < "13:00:00"):
219
+ return pd.DataFrame()
220
+ combined_df.columns = ['代码', '价格','昨收价','开盘价','最高价','最低价', '时间', '成交量', '成交额', '总卖', '总买', '买一价', '卖一价', '买一量',
221
+ '卖一量',
222
+ '买二价', '卖二价', '买二量', '卖二量', '买三价', '卖三价', '买三量', '卖三量', '买四价',
223
+ '卖四价', '买四量', '卖四量', '买五价', '卖五价', '买五量', '卖五量', ]
224
+ return combined_df
225
+ except:
226
+ print_info()
227
+ return pd.DataFrame()
228
+
229
+ def get_real_kzz(all_stock):
230
+ df = get_real_hq(all_stock)
231
+ if df.empty:
232
+ return df
233
+
234
+ df['价格'] = df['价格'] * 0.01
235
+ df['昨收价'] = df['昨收价'] * 0.01
236
+ df['开盘价'] = df['开盘价'] * 0.01
237
+ df['最高价'] = df['最高价'] * 0.01
238
+ df['最低价'] = df['最低价'] * 0.01
239
+ df['买一价'] = df['买一价'] * 0.01
240
+ df['买二价'] = df['买二价'] * 0.01
241
+ df['买三价'] = df['买三价'] * 0.01
242
+ df['买四价'] = df['买四价'] * 0.01
243
+ df['买五价'] = df['买五价'] * 0.01
244
+ df['卖一价'] = df['卖一价'] * 0.01
245
+ df['卖二价'] = df['卖二价'] * 0.01
246
+ df['卖三价'] = df['卖三价'] * 0.01
247
+ df['卖四价'] = df['卖四价'] * 0.01
248
+ df['卖五价'] = df['卖五价'] * 0.01
249
+ return df
250
+
251
+ def get_tick(code, date):
252
+ if not Init():
253
+ return pd.DataFrame()
254
+ try:
255
+ date = datetime.strptime(date, '%Y-%m-%d')
256
+ date = int(date.strftime("%Y%m%d"))
257
+ df1 = api.to_df(api.get_history_transaction_data(__select_market_code(code), __select_code(code), 0, 5000, date))
258
+ df2 = api.to_df(api.get_history_transaction_data(__select_market_code(code), __select_code(code), 2000, 5000, date))
259
+ df3 = api.to_df(api.get_history_transaction_data(__select_market_code(code), __select_code(code), 4000, 5000, date))
260
+ df = pd.concat([df3, df2, df1], ignore_index=True)
261
+ df.columns = ['时间', '价格', '成交量', '买卖方向']
262
+ return df
263
+ except:
264
+ print_info()
265
+ return pd.DataFrame()
266
+
267
+
268
+
269
+
270
+ #--------------------------
271
+
272
+
273
+
274
+ ###########
275
+
276
+
277
+
278
+
279
+
280
+
281
+
@@ -0,0 +1,3 @@
1
+ #期货、现货、股票、外汇数据(level2、逐笔、十档、五档、分钟、日)需要的,价格全网最低,请联系微信:a1312131417 或 xiaolouVS
2
+
3
+