tushare 1.3.6__tar.gz → 1.3.7__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {tushare-1.3.6 → tushare-1.3.7}/PKG-INFO +1 -1
- {tushare-1.3.6 → tushare-1.3.7}/setup.py +13 -10
- tushare-1.3.7/test/build_pyd/__init__.py +8 -0
- tushare-1.3.6/tushare/stock/rtq.py → tushare-1.3.7/test/build_pyd/rtqc.py +6 -6
- tushare-1.3.7/test/build_pyd/setup.py +15 -0
- tushare-1.3.7/test/test_query.py +16 -0
- tushare-1.3.7/test/test_sdk_event.py +21 -0
- tushare-1.3.7/test/test_stock_basic.py +16 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/__init__.py +2 -1
- {tushare-1.3.6 → tushare-1.3.7}/tushare/pro/data_pro.py +1 -1
- tushare-1.3.7/tushare/stock/rtq.py +617 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/util/format_stock_code.py +35 -1
- {tushare-1.3.6 → tushare-1.3.7}/tushare/util/verify_token.py +1 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare.egg-info/PKG-INFO +1 -1
- {tushare-1.3.6 → tushare-1.3.7}/tushare.egg-info/SOURCES.txt +6 -0
- {tushare-1.3.6 → tushare-1.3.7}/LICENSE +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/README.md +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/setup.cfg +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/test/__init__.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/test/bar_test.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/test/billboard_test.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/test/classifying_test.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/test/dateu_test.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/test/fund_test.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/test/indictor_test.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/test/macro_test.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/test/nav_test.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/test/news_test.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/test/pro_test.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/test/ref_test.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/test/shibor_test.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/test/storing_test.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/test/test_realtime.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/test/test_stk_mins.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/test/test_websocket.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/test/trading_test.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/bond/__init__.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/bond/bonds.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/coins/__init__.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/coins/market.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/data/__init__.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/fund/__init__.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/fund/cons.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/fund/nav.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/futures/__init__.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/futures/cons.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/futures/domestic.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/futures/domestic_cons.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/futures/intlfutures.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/internet/__init__.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/internet/boxoffice.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/internet/caixinnews.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/internet/indexes.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/pro/__init__.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/pro/client.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/stock/__init__.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/stock/billboard.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/stock/classifying.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/stock/cons.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/stock/fundamental.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/stock/globals.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/stock/histroy_divide.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/stock/indictor.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/stock/macro.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/stock/macro_vars.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/stock/minsdata.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/stock/news_vars.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/stock/newsevent.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/stock/ref_vars.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/stock/reference.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/stock/rtq_vars.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/stock/shibor.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/stock/trading.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/subs/__init__.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/subs/ht_subs/__init__.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/subs/ht_subs/service/__init__.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/subs/ht_subs/service/covert.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/subs/model/__init__.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/subs/model/min.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/subs/model/tick.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/subs/ts_subs.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/trader/__init__.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/trader/trader.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/trader/utils.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/trader/vars.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/util/__init__.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/util/common.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/util/conns.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/util/dateu.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/util/form_date.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/util/formula.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/util/mailmerge.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/util/netbase.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/util/protobuf/__init__.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/util/protobuf/funcs.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/util/protobuf/response_pb2.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/util/store.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/util/upass.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare/util/vars.py +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare.egg-info/dependency_links.txt +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare.egg-info/requires.txt +0 -0
- {tushare-1.3.6 → tushare-1.3.7}/tushare.egg-info/top_level.txt +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
from setuptools import setup, find_packages
|
1
|
+
from setuptools import setup, find_packages, Extension
|
2
2
|
import codecs
|
3
3
|
import os
|
4
4
|
import tushare
|
@@ -7,6 +7,7 @@ import tushare
|
|
7
7
|
def read(fname):
|
8
8
|
return codecs.open(os.path.join(os.path.dirname(__file__), fname)).read()
|
9
9
|
|
10
|
+
|
10
11
|
long_desc = """
|
11
12
|
TuShare
|
12
13
|
===============
|
@@ -68,6 +69,7 @@ Log
|
|
68
69
|
|
69
70
|
"""
|
70
71
|
|
72
|
+
|
71
73
|
def read_install_requires():
|
72
74
|
reqs = [
|
73
75
|
'pandas',
|
@@ -85,8 +87,8 @@ setup(
|
|
85
87
|
name='tushare',
|
86
88
|
version=tushare.__version__,
|
87
89
|
description='A utility for crawling historical and Real-time Quotes data of China stocks',
|
88
|
-
# long_description=read("READM.rst"),
|
89
|
-
long_description
|
90
|
+
# long_description=read("READM.rst"),
|
91
|
+
long_description=long_desc,
|
90
92
|
author='Jimmy Liu',
|
91
93
|
author_email='waditu@163.com',
|
92
94
|
license='BSD',
|
@@ -94,13 +96,14 @@ setup(
|
|
94
96
|
install_requires=read_install_requires(),
|
95
97
|
keywords='Global Financial Data',
|
96
98
|
classifiers=['Development Status :: 4 - Beta',
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
99
|
+
'Programming Language :: Python :: 3.6',
|
100
|
+
'Programming Language :: Python :: 3.7',
|
101
|
+
'Programming Language :: Python :: 3.8',
|
102
|
+
'Programming Language :: Python :: 3.9',
|
103
|
+
'Programming Language :: Python :: 3.10',
|
104
|
+
'License :: OSI Approved :: BSD License'],
|
103
105
|
packages=find_packages(),
|
104
106
|
include_package_data=True,
|
107
|
+
# ext_modules=[Extension('tushare.stock.rtqc', sources=['tushare/stock/rtqc.pyd'])],
|
105
108
|
package_data={'': ['*.csv', '*.txt']},
|
106
|
-
)
|
109
|
+
)
|
@@ -201,15 +201,15 @@ def realtime_list(src: Optional[str] = None, interval: Optional[int] = 3,
|
|
201
201
|
|
202
202
|
"""
|
203
203
|
if src == "dc":
|
204
|
-
return get_stock_all_a_dc(
|
204
|
+
return get_stock_all_a_dc(page_count, proxies)
|
205
205
|
elif src == "sina":
|
206
206
|
return get_stock_all_a_sina(interval, page_count, proxies)
|
207
207
|
else:
|
208
|
-
return get_stock_all_a_dc(
|
208
|
+
return get_stock_all_a_dc(page_count, proxies)
|
209
209
|
|
210
210
|
|
211
211
|
def get_stock_all_a_dc(page_count: Optional[int] = None,
|
212
|
-
|
212
|
+
proxies: Optional[dict] = {}) -> pd.DataFrame:
|
213
213
|
"""
|
214
214
|
东方财富网-沪深京 A 股-实时行情
|
215
215
|
https://quote.eastmoney.com/center/gridlist.html#hs_a_board
|
@@ -298,7 +298,7 @@ def get_stock_all_a_dc(page_count: Optional[int] = None,
|
|
298
298
|
# temp_df.rename(columns={"index": "序号"}, inplace=True)
|
299
299
|
temp_df = temp_df[
|
300
300
|
[
|
301
|
-
#"序号",
|
301
|
+
# "序号",
|
302
302
|
"代码",
|
303
303
|
"名称",
|
304
304
|
"最新价",
|
@@ -346,7 +346,7 @@ def get_stock_all_a_dc(page_count: Optional[int] = None,
|
|
346
346
|
temp_df["60日涨跌幅"] = pd.to_numeric(temp_df["60日涨跌幅"], errors="coerce")
|
347
347
|
temp_df["年初至今涨跌幅"] = pd.to_numeric(temp_df["年初至今涨跌幅"], errors="coerce")
|
348
348
|
temp_df.columns = [
|
349
|
-
#"RANK",
|
349
|
+
# "RANK",
|
350
350
|
"TS_CODE",
|
351
351
|
"NAME",
|
352
352
|
"PRICE",
|
@@ -607,6 +607,6 @@ def format_dc_str(x):
|
|
607
607
|
|
608
608
|
if __name__ == '__main__':
|
609
609
|
# df = realtime_quote(ts_code="000688.SH,000010.SH,000012.SH,399005.SZ", src="sina")
|
610
|
-
df = realtime_list(src="
|
610
|
+
df = realtime_list(src="dc", page_count=1)
|
611
611
|
# print(help(realtime_quote))
|
612
612
|
print(df)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""
|
3
|
+
Created on 2021-12-31 09:32:16
|
4
|
+
---------
|
5
|
+
@summary:
|
6
|
+
---------
|
7
|
+
@author: yangyx01
|
8
|
+
"""
|
9
|
+
# setup.py
|
10
|
+
from setuptools import setup
|
11
|
+
from Cython.Build import cythonize
|
12
|
+
|
13
|
+
setup(
|
14
|
+
ext_modules=cythonize("rtqc.py")
|
15
|
+
)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
"""
|
2
|
+
作 者:lidy
|
3
|
+
时 间:2023/8/22 22:00
|
4
|
+
项目名:tsdpsdk
|
5
|
+
"""
|
6
|
+
|
7
|
+
import tushare
|
8
|
+
|
9
|
+
def test_query():
|
10
|
+
api = tushare.pro_api('75e70c1ef4bd1a14e2301cbf20ec35e1045971c104ab02853e375284')
|
11
|
+
df = api.query('stock_basic', fields='ts_code,symbol')
|
12
|
+
print(df)
|
13
|
+
|
14
|
+
|
15
|
+
if __name__ == '__main__':
|
16
|
+
test_query()
|
@@ -0,0 +1,21 @@
|
|
1
|
+
"""
|
2
|
+
# 作 者:84028
|
3
|
+
# 时 间:2024/1/9 13:29
|
4
|
+
# tsdpsdk
|
5
|
+
"""
|
6
|
+
import time
|
7
|
+
|
8
|
+
import requests
|
9
|
+
|
10
|
+
if __name__ == '__main__':
|
11
|
+
for i in range(200):
|
12
|
+
start = time.time()
|
13
|
+
resp = requests.post(
|
14
|
+
'http://127.0.0.1:8081/dataapi/sdk-event',
|
15
|
+
json={
|
16
|
+
"user_token": "af4c3a76ff14972b3467d8950dd1587bb3d4b6b2dc9cd94093910795",
|
17
|
+
"event_name": "test",
|
18
|
+
"event_detail": "测试"
|
19
|
+
}
|
20
|
+
)
|
21
|
+
print(time.time()-start, resp)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
"""
|
2
|
+
作 者:lidy
|
3
|
+
时 间:2023/8/22 22:00
|
4
|
+
项目名:tsdpsdk
|
5
|
+
"""
|
6
|
+
|
7
|
+
import tushare
|
8
|
+
|
9
|
+
def test_stock_basic():
|
10
|
+
api = tushare.pro_api('75e70c1ef4bd1a14e2301cbf20ec35e1045971c104ab02853e375284')
|
11
|
+
df = api.stock_basic()
|
12
|
+
print(df)
|
13
|
+
|
14
|
+
|
15
|
+
if __name__ == '__main__':
|
16
|
+
test_stock_basic()
|
@@ -2,7 +2,7 @@
|
|
2
2
|
import codecs
|
3
3
|
import os
|
4
4
|
|
5
|
-
__version__ = '1.3.
|
5
|
+
__version__ = '1.3.7'
|
6
6
|
__author__ = 'Jimmy Liu'
|
7
7
|
|
8
8
|
"""
|
@@ -133,5 +133,6 @@ from tushare.util.upass import (get_token, set_token)
|
|
133
133
|
"""
|
134
134
|
for quotes API
|
135
135
|
"""
|
136
|
+
# from tushare.stock.rtqc import (realtime_quote, realtime_list)
|
136
137
|
from tushare.stock.rtq import (realtime_quote, realtime_list)
|
137
138
|
from tushare.stock.histroy_divide import (realtime_tick)
|
@@ -13,7 +13,7 @@ from tushare.util import upass
|
|
13
13
|
from tushare.util.formula import MA
|
14
14
|
from tushare.subs.ts_subs import Subs
|
15
15
|
|
16
|
-
PRICE_COLS = ['open', 'close', 'high', 'low'
|
16
|
+
PRICE_COLS = ['open', 'close', 'high', 'low']
|
17
17
|
FORMAT = lambda x: '%.4f' % x
|
18
18
|
FREQS = {'D': '1DAY',
|
19
19
|
'W': '1WEEK',
|
@@ -0,0 +1,617 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
# -*- coding:utf-8 -*-
|
3
|
+
"""
|
4
|
+
所有 A 股的实时行情数据
|
5
|
+
Created on 2023/12/06
|
6
|
+
@author: Monday
|
7
|
+
@group : waditu
|
8
|
+
@contact:
|
9
|
+
"""
|
10
|
+
import time
|
11
|
+
import pandas as pd
|
12
|
+
import requests
|
13
|
+
from tqdm import tqdm
|
14
|
+
from typing import Optional
|
15
|
+
import re
|
16
|
+
from tushare.util.format_stock_code import symbol_verify
|
17
|
+
from tushare.util.format_stock_code import format_stock_code,verify_stock_or_index
|
18
|
+
from tushare.util.form_date import timestemp_to_time
|
19
|
+
from tushare.stock import rtq_vars as rtqv
|
20
|
+
from tushare.util.verify_token import require_permission
|
21
|
+
from tushare.stock import cons as ct
|
22
|
+
from tushare.stock.rtq_vars import (
|
23
|
+
zh_sina_a_stock_payload,
|
24
|
+
zh_sina_a_stock_url,
|
25
|
+
zh_sina_a_stock_count_url,
|
26
|
+
zh_sina_a_stock_headers,
|
27
|
+
zh_sina_a_stock_cookies,
|
28
|
+
|
29
|
+
)
|
30
|
+
|
31
|
+
|
32
|
+
def _random(n=13):
|
33
|
+
from random import randint
|
34
|
+
start = 10 ** (n - 1)
|
35
|
+
end = (10 ** n) - 1
|
36
|
+
return str(randint(start, end))
|
37
|
+
|
38
|
+
|
39
|
+
def _get_current_timestamp():
|
40
|
+
return str(int(time.time() * 1000))
|
41
|
+
|
42
|
+
|
43
|
+
@require_permission(event_name="realtime_quote", event_detail="个股实时交易数据")
|
44
|
+
def realtime_quote(ts_code="688553.SH", src="sina", ):
|
45
|
+
"""
|
46
|
+
获取实时交易数据 getting real time quotes data
|
47
|
+
用于跟踪交易情况(本次执行的结果-上一次执行的数据)
|
48
|
+
Parameters
|
49
|
+
------
|
50
|
+
ts_code : string
|
51
|
+
src : sina ,dc
|
52
|
+
|
53
|
+
return
|
54
|
+
-------
|
55
|
+
DataFrame 实时交易数据
|
56
|
+
属性:0:name,股票名字
|
57
|
+
1:open,今日开盘价
|
58
|
+
2:pre_close,昨日收盘价
|
59
|
+
3:price,当前价格
|
60
|
+
4:high,今日最高价
|
61
|
+
5:low,今日最低价
|
62
|
+
6:bid,竞买价,即“买一”报价
|
63
|
+
7:ask,竞卖价,即“卖一”报价
|
64
|
+
8:volumn,成交量 maybe you need do volumn/100
|
65
|
+
9:amount,成交金额(元 CNY)
|
66
|
+
10:b1_v,委买一(笔数 bid volume)
|
67
|
+
11:b1_p,委买一(价格 bid price)
|
68
|
+
12:b2_v,“买二”
|
69
|
+
13:b2_p,“买二”
|
70
|
+
14:b3_v,“买三”
|
71
|
+
15:b3_p,“买三”
|
72
|
+
16:b4_v,“买四”
|
73
|
+
17:b4_p,“买四”
|
74
|
+
18:b5_v,“买五”
|
75
|
+
19:b5_p,“买五”
|
76
|
+
20:a1_v,委卖一(笔数 ask volume)
|
77
|
+
21:a1_p,委卖一(价格 ask price)
|
78
|
+
...
|
79
|
+
30:date,日期;
|
80
|
+
31:time,时间;
|
81
|
+
"""
|
82
|
+
symbols = symbol_verify(ts_code)
|
83
|
+
if src == "sina":
|
84
|
+
return get_realtime_quotes_sina(symbols)
|
85
|
+
else:
|
86
|
+
return get_realtime_quotes_dc(symbols)
|
87
|
+
|
88
|
+
|
89
|
+
sina_stock_code = {}
|
90
|
+
|
91
|
+
|
92
|
+
def get_realtime_quotes_sina(symbol="688553"): # "688553"
|
93
|
+
global sina_stock_code
|
94
|
+
symbols = []
|
95
|
+
syms = []
|
96
|
+
for i in [j for j in symbol.split(",")]:
|
97
|
+
s = i.split(".")
|
98
|
+
sina_stock_code[s[0]] = s[1].upper()
|
99
|
+
symbols.append(s[1].lower() + s[0])
|
100
|
+
syms.append(s[0])
|
101
|
+
# symbols = re.search(r"(\d+)", str(symbols), re.S | re.M).group(1)
|
102
|
+
symbols_list = ''
|
103
|
+
if isinstance(symbols, list) or isinstance(symbols, set) or \
|
104
|
+
isinstance(symbols, tuple) or isinstance(symbols, pd.Series):
|
105
|
+
for code in symbols:
|
106
|
+
symbols_list += code + ','
|
107
|
+
else:
|
108
|
+
symbols_list = symbols
|
109
|
+
symbols_list = symbols_list[:-1] if len(symbols_list) > 8 else symbols_list
|
110
|
+
root_url = ct.LIVE_DATA_URL % (ct.P_TYPE['http'], ct.DOMAINS['sinahq'], _get_current_timestamp(), symbols_list)
|
111
|
+
response = requests.get(root_url,
|
112
|
+
headers={
|
113
|
+
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0",
|
114
|
+
'host': 'hq.sinajs.cn',
|
115
|
+
'referer': 'https://finance.sina.com.cn/'
|
116
|
+
})
|
117
|
+
text = response.content.decode('GBK')
|
118
|
+
reg = re.compile(r'\="(.*?)\";')
|
119
|
+
data = reg.findall(text)
|
120
|
+
data_list = []
|
121
|
+
syms_list = []
|
122
|
+
for index, row in enumerate(data):
|
123
|
+
if len(row) > 1:
|
124
|
+
data_list.append([astr for astr in row.split(',')[:33]])
|
125
|
+
syms_list.append(syms[index])
|
126
|
+
if len(syms_list) == 0:
|
127
|
+
return None
|
128
|
+
df = pd.DataFrame(data_list, columns=ct.LIVE_DATA_COLS)
|
129
|
+
df = df.drop('s', axis=1)
|
130
|
+
df['code'] = syms_list
|
131
|
+
ls = [cls for cls in df.columns if '_v' in cls]
|
132
|
+
for txt in ls:
|
133
|
+
df[txt] = df[txt].map(lambda x: x[:-2])
|
134
|
+
df.columns = rtqv.LIVE_DATA_COLS
|
135
|
+
df["TS_CODE"] = df["TS_CODE"].apply(format_sina_stock_code)
|
136
|
+
df["DATE"] = df["DATE"].apply(format_date_str)
|
137
|
+
new_order = rtqv.LIVE_DATA_COLS_REINDEX
|
138
|
+
df = df[new_order]
|
139
|
+
return df
|
140
|
+
|
141
|
+
|
142
|
+
def format_sina_stock_code(x):
|
143
|
+
ts_code = f"{x}.{sina_stock_code[x]}"
|
144
|
+
return ts_code
|
145
|
+
|
146
|
+
|
147
|
+
def format_date_str(date_str):
|
148
|
+
return date_str.replace("-", "")
|
149
|
+
|
150
|
+
|
151
|
+
@require_permission(event_name="realtime_list", event_detail="A股所有实时交易数据")
|
152
|
+
def realtime_list(src: Optional[str] = None, interval: Optional[int] = 3,
|
153
|
+
page_count: Optional[int] = None, proxies: Optional[dict] = {}) -> pd.DataFrame:
|
154
|
+
"""
|
155
|
+
沪深京 A 股 all -实时行情
|
156
|
+
@param src: 数据源 新浪sina |东方财富 dc
|
157
|
+
@param interval: 分页采集时间间隔(默认3秒翻译一夜)
|
158
|
+
@param page_count: 限制抓取的页数(仅对新浪有效)
|
159
|
+
@param proxies: 设置代理 防止被封禁
|
160
|
+
@return: 按涨跌幅 倒序排序
|
161
|
+
-------
|
162
|
+
DataFrame 实时交易数据
|
163
|
+
东方财富:
|
164
|
+
2、代码:TS_CODE
|
165
|
+
3、名称:NAME
|
166
|
+
4、最新价:PRICE
|
167
|
+
5、涨跌幅:PCT_CHANGE
|
168
|
+
6、涨跌额:CHANGE
|
169
|
+
7、成交量:VOLUME
|
170
|
+
8、成交额:AMOUNT
|
171
|
+
9、振幅:SWING
|
172
|
+
10、最高:HIGH
|
173
|
+
11、最低:LOW
|
174
|
+
12、今开:OPEN
|
175
|
+
13、昨收:CLOSE
|
176
|
+
14、量比:VOL_RATIO
|
177
|
+
15、换手率:TURNOVER_RATE
|
178
|
+
16、市盈率-动态:PE
|
179
|
+
17、市净率:PB
|
180
|
+
18、总市值:TOTAL_MV
|
181
|
+
19、流通市值:FLOAT_MV
|
182
|
+
20、涨速:RISE
|
183
|
+
21、5分钟涨跌:5MIN
|
184
|
+
22、60日涨跌幅:60DAY
|
185
|
+
23、年初至今涨跌幅:1YEAR
|
186
|
+
新浪财经:
|
187
|
+
1、代码:TS_CODE
|
188
|
+
2、名称:NAME
|
189
|
+
3、最新价:PRICE
|
190
|
+
4、涨跌额:CHANGE
|
191
|
+
5、涨跌幅:PCT_CHANGE
|
192
|
+
6、买入:BUY
|
193
|
+
7、卖出:SALE
|
194
|
+
8、昨收:CLOSE
|
195
|
+
9、今开:OPEN
|
196
|
+
10、最高:HIGH
|
197
|
+
11、最低:LOW
|
198
|
+
12、成交量:VOLUME
|
199
|
+
13、成交额:AMOUNT
|
200
|
+
14、时间戳:TIME
|
201
|
+
|
202
|
+
"""
|
203
|
+
if src == "dc":
|
204
|
+
return get_stock_all_a_dc(page_count, proxies)
|
205
|
+
elif src == "sina":
|
206
|
+
return get_stock_all_a_sina(interval, page_count, proxies)
|
207
|
+
else:
|
208
|
+
return get_stock_all_a_dc(page_count, proxies)
|
209
|
+
|
210
|
+
|
211
|
+
def get_stock_all_a_dc(page_count: Optional[int] = None,
|
212
|
+
proxies: Optional[dict] = {}) -> pd.DataFrame:
|
213
|
+
"""
|
214
|
+
东方财富网-沪深京 A 股-实时行情
|
215
|
+
https://quote.eastmoney.com/center/gridlist.html#hs_a_board
|
216
|
+
:return: 实时行情
|
217
|
+
:rtype: pandas.DataFrame
|
218
|
+
1、序号:RANK
|
219
|
+
2、代码:TS_CODE
|
220
|
+
3、名称:NAME
|
221
|
+
4、最新价:PRICE
|
222
|
+
5、涨跌幅:PCT_CHANGE
|
223
|
+
6、涨跌额:CHANGE
|
224
|
+
7、成交量:VOLUME
|
225
|
+
8、成交额:AMOUNT
|
226
|
+
9、振幅:SWING
|
227
|
+
10、最高:HIGH
|
228
|
+
11、最低:LOW
|
229
|
+
12、今开:OPEN
|
230
|
+
13、昨收:CLOSE
|
231
|
+
14、量比:VOL_RATIO
|
232
|
+
15、换手率:TURNOVER_RATE
|
233
|
+
16、市盈率-动态:PE
|
234
|
+
17、市净率:PB
|
235
|
+
18、总市值:TOTAL_MV
|
236
|
+
19、流通市值:FLOAT_MV
|
237
|
+
20、涨速:RISE
|
238
|
+
21、5分钟涨跌:5MIN
|
239
|
+
22、60日涨跌幅:60DAY
|
240
|
+
23、年初至今涨跌幅:1YEAR
|
241
|
+
"""
|
242
|
+
url = "http://82.push2.eastmoney.com/api/qt/clist/get"
|
243
|
+
params = {
|
244
|
+
"pn": "1",
|
245
|
+
"pz": "50000",
|
246
|
+
"po": "1",
|
247
|
+
"np": "1",
|
248
|
+
"ut": "bd1d9ddb04089700cf9c27f6f7426281",
|
249
|
+
"fltt": "2",
|
250
|
+
"invt": "2",
|
251
|
+
"fid": "f3",
|
252
|
+
"fs": "m:0 t:6,m:0 t:80,m:1 t:2,m:1 t:23,m:0 t:81 s:2048",
|
253
|
+
"fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
|
254
|
+
"_": "1623833739532",
|
255
|
+
}
|
256
|
+
if page_count:
|
257
|
+
params["pz"] = 20
|
258
|
+
r = requests.get(url, params=params, proxies=proxies)
|
259
|
+
data_json = r.json()
|
260
|
+
if not data_json["data"]["diff"]:
|
261
|
+
return pd.DataFrame()
|
262
|
+
temp_df = pd.DataFrame(data_json["data"]["diff"])
|
263
|
+
temp_df.columns = [
|
264
|
+
"_",
|
265
|
+
"最新价",
|
266
|
+
"涨跌幅",
|
267
|
+
"涨跌额",
|
268
|
+
"成交量",
|
269
|
+
"成交额",
|
270
|
+
"振幅",
|
271
|
+
"换手率",
|
272
|
+
"市盈率-动态",
|
273
|
+
"量比",
|
274
|
+
"5分钟涨跌",
|
275
|
+
"代码",
|
276
|
+
"_",
|
277
|
+
"名称",
|
278
|
+
"最高",
|
279
|
+
"最低",
|
280
|
+
"今开",
|
281
|
+
"昨收",
|
282
|
+
"总市值",
|
283
|
+
"流通市值",
|
284
|
+
"涨速",
|
285
|
+
"市净率",
|
286
|
+
"60日涨跌幅",
|
287
|
+
"年初至今涨跌幅",
|
288
|
+
"-",
|
289
|
+
"-",
|
290
|
+
"-",
|
291
|
+
"-",
|
292
|
+
"-",
|
293
|
+
"-",
|
294
|
+
"-",
|
295
|
+
]
|
296
|
+
temp_df.reset_index(inplace=True)
|
297
|
+
# temp_df["index"] = temp_df.index + 1
|
298
|
+
# temp_df.rename(columns={"index": "序号"}, inplace=True)
|
299
|
+
temp_df = temp_df[
|
300
|
+
[
|
301
|
+
# "序号",
|
302
|
+
"代码",
|
303
|
+
"名称",
|
304
|
+
"最新价",
|
305
|
+
"涨跌幅",
|
306
|
+
"涨跌额",
|
307
|
+
"成交量",
|
308
|
+
"成交额",
|
309
|
+
"振幅",
|
310
|
+
"最高",
|
311
|
+
"最低",
|
312
|
+
"今开",
|
313
|
+
"昨收",
|
314
|
+
"量比",
|
315
|
+
"换手率",
|
316
|
+
"市盈率-动态",
|
317
|
+
"市净率",
|
318
|
+
"总市值",
|
319
|
+
"流通市值",
|
320
|
+
"涨速",
|
321
|
+
"5分钟涨跌",
|
322
|
+
"60日涨跌幅",
|
323
|
+
"年初至今涨跌幅",
|
324
|
+
]
|
325
|
+
]
|
326
|
+
|
327
|
+
temp_df["代码"] = temp_df["代码"].apply(format_stock_code)
|
328
|
+
temp_df["最新价"] = pd.to_numeric(temp_df["最新价"], errors="coerce")
|
329
|
+
temp_df["涨跌幅"] = pd.to_numeric(temp_df["涨跌幅"], errors="coerce")
|
330
|
+
temp_df["涨跌额"] = pd.to_numeric(temp_df["涨跌额"], errors="coerce")
|
331
|
+
temp_df["成交量"] = pd.to_numeric(temp_df["成交量"], errors="coerce")
|
332
|
+
temp_df["成交额"] = pd.to_numeric(temp_df["成交额"], errors="coerce")
|
333
|
+
temp_df["振幅"] = pd.to_numeric(temp_df["振幅"], errors="coerce")
|
334
|
+
temp_df["最高"] = pd.to_numeric(temp_df["最高"], errors="coerce")
|
335
|
+
temp_df["最低"] = pd.to_numeric(temp_df["最低"], errors="coerce")
|
336
|
+
temp_df["今开"] = pd.to_numeric(temp_df["今开"], errors="coerce")
|
337
|
+
temp_df["昨收"] = pd.to_numeric(temp_df["昨收"], errors="coerce")
|
338
|
+
temp_df["量比"] = pd.to_numeric(temp_df["量比"], errors="coerce")
|
339
|
+
temp_df["换手率"] = pd.to_numeric(temp_df["换手率"], errors="coerce")
|
340
|
+
temp_df["市盈率-动态"] = pd.to_numeric(temp_df["市盈率-动态"], errors="coerce")
|
341
|
+
temp_df["市净率"] = pd.to_numeric(temp_df["市净率"], errors="coerce")
|
342
|
+
temp_df["总市值"] = pd.to_numeric(temp_df["总市值"], errors="coerce")
|
343
|
+
temp_df["流通市值"] = pd.to_numeric(temp_df["流通市值"], errors="coerce")
|
344
|
+
temp_df["涨速"] = pd.to_numeric(temp_df["涨速"], errors="coerce")
|
345
|
+
temp_df["5分钟涨跌"] = pd.to_numeric(temp_df["5分钟涨跌"], errors="coerce")
|
346
|
+
temp_df["60日涨跌幅"] = pd.to_numeric(temp_df["60日涨跌幅"], errors="coerce")
|
347
|
+
temp_df["年初至今涨跌幅"] = pd.to_numeric(temp_df["年初至今涨跌幅"], errors="coerce")
|
348
|
+
temp_df.columns = [
|
349
|
+
# "RANK",
|
350
|
+
"TS_CODE",
|
351
|
+
"NAME",
|
352
|
+
"PRICE",
|
353
|
+
"PCT_CHANGE",
|
354
|
+
"CHANGE",
|
355
|
+
"VOLUME",
|
356
|
+
"AMOUNT",
|
357
|
+
"SWING",
|
358
|
+
"HIGH",
|
359
|
+
"LOW",
|
360
|
+
"OPEN",
|
361
|
+
"CLOSE",
|
362
|
+
"VOL_RATIO",
|
363
|
+
"TURNOVER_RATE",
|
364
|
+
"PE",
|
365
|
+
"PB",
|
366
|
+
"TOTAL_MV",
|
367
|
+
"FLOAT_MV",
|
368
|
+
"RISE",
|
369
|
+
"5MIN",
|
370
|
+
"60DAY",
|
371
|
+
"1YEAR",
|
372
|
+
]
|
373
|
+
df_sorted = temp_df.sort_values(by='PCT_CHANGE', ascending=False).reset_index(drop=True)
|
374
|
+
return df_sorted
|
375
|
+
|
376
|
+
|
377
|
+
def _get_zh_a_page_count() -> int:
|
378
|
+
"""
|
379
|
+
所有股票的总页数
|
380
|
+
https://vip.stock.finance.sina.com.cn/mkt/#hs_a
|
381
|
+
:return: 需要采集的股票总页数
|
382
|
+
:rtype: int
|
383
|
+
"""
|
384
|
+
res = requests.get(zh_sina_a_stock_count_url)
|
385
|
+
page_count = int(re.findall(re.compile(r"\d+"), res.text)[0]) / 80
|
386
|
+
if isinstance(page_count, int):
|
387
|
+
return page_count
|
388
|
+
else:
|
389
|
+
return int(page_count) + 1
|
390
|
+
|
391
|
+
|
392
|
+
def get_stock_all_a_sina(interval: Optional[int] = 3, page_count: Optional[int] = None,
|
393
|
+
proxies: Optional[dict] = {}) -> pd.DataFrame:
|
394
|
+
"""
|
395
|
+
新浪财经-所有 A 股的实时行情数据; 重复运行本函数会被新浪暂时封 IP
|
396
|
+
https://vip.stock.finance.sina.com.cn/mkt/#hs_a
|
397
|
+
:param interval:请求间隔时间
|
398
|
+
:param page_count:限制抓取页数
|
399
|
+
:param proxies: 代理ip {}
|
400
|
+
:return: 所有股票的实时行情数据
|
401
|
+
:rtype: pandas.DataFrame
|
402
|
+
1、代码:TS_CODE
|
403
|
+
2、名称:NAME
|
404
|
+
3、最新价:PRICE
|
405
|
+
4、涨跌额:CHANGE
|
406
|
+
5、涨跌幅:PCT_CHANGE
|
407
|
+
6、买入:BUY
|
408
|
+
7、卖出:SALE
|
409
|
+
8、昨收:CLOSE
|
410
|
+
9、今开:OPEN
|
411
|
+
10、最高:HIGH
|
412
|
+
11、最低:LOW
|
413
|
+
12、成交量:VOLUME
|
414
|
+
13、成交额:AMOUNT
|
415
|
+
14、时间戳:TIME
|
416
|
+
|
417
|
+
"""
|
418
|
+
big_df = pd.DataFrame()
|
419
|
+
if not page_count:
|
420
|
+
page_count = _get_zh_a_page_count()
|
421
|
+
zh_sina_stock_payload_copy = zh_sina_a_stock_payload.copy()
|
422
|
+
for page in tqdm(
|
423
|
+
range(1, page_count + 1), leave=False, desc="Please wait for a moment"
|
424
|
+
):
|
425
|
+
zh_sina_stock_payload_copy.update({"page": page})
|
426
|
+
r = requests.get(
|
427
|
+
zh_sina_a_stock_url, headers=zh_sina_a_stock_headers,
|
428
|
+
cookies=zh_sina_a_stock_cookies,
|
429
|
+
params=zh_sina_stock_payload_copy,
|
430
|
+
proxies=proxies,
|
431
|
+
)
|
432
|
+
data_json = r.json()
|
433
|
+
big_df = pd.concat(
|
434
|
+
[big_df, pd.DataFrame(data_json)], ignore_index=True
|
435
|
+
)
|
436
|
+
|
437
|
+
time.sleep(interval)
|
438
|
+
|
439
|
+
big_df = big_df.astype(
|
440
|
+
{
|
441
|
+
"trade": "float",
|
442
|
+
"pricechange": "float",
|
443
|
+
"changepercent": "float",
|
444
|
+
"buy": "float",
|
445
|
+
"sell": "float",
|
446
|
+
"settlement": "float",
|
447
|
+
"open": "float",
|
448
|
+
"high": "float",
|
449
|
+
"low": "float",
|
450
|
+
"volume": "float",
|
451
|
+
"amount": "float",
|
452
|
+
"per": "float",
|
453
|
+
"pb": "float",
|
454
|
+
"mktcap": "float",
|
455
|
+
"nmc": "float",
|
456
|
+
"turnoverratio": "float",
|
457
|
+
}
|
458
|
+
)
|
459
|
+
big_df.columns = [
|
460
|
+
"代码",
|
461
|
+
"_",
|
462
|
+
"名称",
|
463
|
+
"最新价",
|
464
|
+
"涨跌额",
|
465
|
+
"涨跌幅",
|
466
|
+
"买入",
|
467
|
+
"卖出",
|
468
|
+
"昨收",
|
469
|
+
"今开",
|
470
|
+
"最高",
|
471
|
+
"最低",
|
472
|
+
"成交量",
|
473
|
+
"成交额",
|
474
|
+
"时间戳",
|
475
|
+
"_",
|
476
|
+
"_",
|
477
|
+
"_",
|
478
|
+
"_",
|
479
|
+
"_",
|
480
|
+
]
|
481
|
+
big_df = big_df[
|
482
|
+
[
|
483
|
+
"代码",
|
484
|
+
"名称",
|
485
|
+
"最新价",
|
486
|
+
"涨跌额",
|
487
|
+
"涨跌幅",
|
488
|
+
"买入",
|
489
|
+
"卖出",
|
490
|
+
"昨收",
|
491
|
+
"今开",
|
492
|
+
"最高",
|
493
|
+
"最低",
|
494
|
+
"成交量",
|
495
|
+
"成交额",
|
496
|
+
"时间戳",
|
497
|
+
]
|
498
|
+
]
|
499
|
+
big_df["代码"] = big_df["代码"].apply(format_stock_code)
|
500
|
+
big_df.columns = [
|
501
|
+
"TS_CODE",
|
502
|
+
"NAME",
|
503
|
+
"PRICE",
|
504
|
+
"CHANGE",
|
505
|
+
"PCT_CHANGE",
|
506
|
+
"BUY",
|
507
|
+
"SALE",
|
508
|
+
"CLOSE",
|
509
|
+
"OPEN",
|
510
|
+
"HIGH",
|
511
|
+
"LOW",
|
512
|
+
"VOLUME",
|
513
|
+
"AMOUNT",
|
514
|
+
"TIME",
|
515
|
+
|
516
|
+
]
|
517
|
+
df_sorted = big_df.sort_values(by='PCT_CHANGE', ascending=False).reset_index(drop=True)
|
518
|
+
return df_sorted
|
519
|
+
|
520
|
+
|
521
|
+
def get_realtime_quotes_dc(symbols="688553"):
|
522
|
+
"""
|
523
|
+
https://quote.eastmoney.com/sh601096.html
|
524
|
+
"""
|
525
|
+
symbols = str(symbols).split(",")[0]
|
526
|
+
url = "https://push2.eastmoney.com/api/qt/stock/get"
|
527
|
+
symbol = re.search(r"(\d+)", symbols, re.S | re.M).group(1)
|
528
|
+
# print(symbol)
|
529
|
+
params = {
|
530
|
+
"invt": "2",
|
531
|
+
"fltt": "1",
|
532
|
+
# "cb": "jQuery35108939078769986013_1701853424476",
|
533
|
+
"fields": "f58,f734,f107,f57,f43,f59,f169,f301,f60,f170,f152,f177,f111,f46,f44,f45,f47,f260,f48,f261,f279,f277,f278,f288,f19,f17,f531,f15,f13,f11,f20,f18,f16,f14,f12,f39,f37,f35,f33,f31,f40,f38,f36,f34,f32,f211,f212,f213,f214,f215,f210,f209,f208,f207,f206,f161,f49,f171,f50,f86,f84,f85,f168,f108,f116,f167,f164,f162,f163,f92,f71,f117,f292,f51,f52,f191,f192,f262,f294,f295,f748,f747",
|
534
|
+
"secid": f"0.{symbol}",
|
535
|
+
"ut": "fa5fd1943c7b386f172d6893dbfba10b",
|
536
|
+
"wbp2u": "|0|0|0|web",
|
537
|
+
"_": _get_current_timestamp()
|
538
|
+
}
|
539
|
+
if not verify_stock_or_index(symbols):
|
540
|
+
params["secid"] = f"1.{symbol}"
|
541
|
+
response = requests.get(url, headers=rtqv.dc_cookies, cookies=rtqv.dc_headers, params=params)
|
542
|
+
data_info = response.json()["data"]
|
543
|
+
if not data_info:
|
544
|
+
return pd.DataFrame()
|
545
|
+
name = data_info["f58"]
|
546
|
+
open = data_info["f45"] # / 100
|
547
|
+
high = data_info["f44"] # / 100
|
548
|
+
pre_close = data_info["f60"] # / 100
|
549
|
+
low = data_info["f46"] # / 100
|
550
|
+
price = data_info["f43"] # / 100 if data_info["f43"] != "-" else ""
|
551
|
+
b5_v = data_info["f12"]
|
552
|
+
b5_p = data_info["f11"] # / 100 if data_info["f11"] != "-" else ""
|
553
|
+
b4_v = data_info["f14"]
|
554
|
+
b4_p = data_info["f13"] # / 100 if data_info["f13"] != "-" else ""
|
555
|
+
b3_v = data_info["f16"]
|
556
|
+
b3_p = data_info["f15"] # / 100 if data_info["f15"] != "-" else ""
|
557
|
+
b2_v = data_info["f18"]
|
558
|
+
b2_p = data_info["f17"] # / 100 if data_info["f17"] != "-" else ""
|
559
|
+
b1_v = data_info["f20"]
|
560
|
+
b1_p = data_info["f19"] # / 100 if data_info["f19"] != "-" else ""
|
561
|
+
a5_v = data_info["f32"]
|
562
|
+
a5_p = data_info["f31"] # / 100 if data_info["f31"] != "-" else ""
|
563
|
+
a4_v = data_info["f34"]
|
564
|
+
a4_p = data_info["f33"] # / 100 if data_info["f33"] != "-" else ""
|
565
|
+
a3_v = data_info["f36"]
|
566
|
+
a3_p = data_info["f35"] # / 100 if data_info["f35"] != "-" else ""
|
567
|
+
a2_v = data_info["f38"]
|
568
|
+
a2_p = data_info["f37"] # / 100 if data_info["f38"] != "-" else ""
|
569
|
+
a1_v = data_info["f40"]
|
570
|
+
a1_p = data_info["f39"] # / 100 if data_info["f39"] != "-" else ""
|
571
|
+
date_time = timestemp_to_time(data_info["f86"])
|
572
|
+
date = date_time[0:10]
|
573
|
+
times = date_time[10:]
|
574
|
+
volume = data_info["f47"]
|
575
|
+
amount = data_info["f48"]
|
576
|
+
bid = data_info["f19"]
|
577
|
+
ask = data_info["f39"]
|
578
|
+
code = symbols
|
579
|
+
data_list = [[name, open, pre_close, price, high, low, bid, ask, volume, amount,
|
580
|
+
b1_v, b1_p, b2_v, b2_p, b3_v, b3_p, b4_v, b4_p, b5_v, b5_p,
|
581
|
+
a1_v, a1_p, a2_v, a2_p, a3_v, a3_p, a4_v, a4_p, a5_v, a5_p, date, times, code]]
|
582
|
+
df = pd.DataFrame(data_list, columns=rtqv.LIVE_DATA_COLS)
|
583
|
+
df["DATE"] = df["DATE"].apply(format_date_str)
|
584
|
+
df["ASK"] = df["ASK"].apply(format_dc_str)
|
585
|
+
df["OPEN"] = df["OPEN"].apply(format_dc_str)
|
586
|
+
df["HIGH"] = df["HIGH"].apply(format_dc_str)
|
587
|
+
df["LOW"] = df["LOW"].apply(format_dc_str)
|
588
|
+
df["PRE_CLOSE"] = df["PRE_CLOSE"].apply(format_dc_str)
|
589
|
+
df["BID"] = df["BID"].apply(format_dc_str)
|
590
|
+
df["A1_P"] = df["A1_P"].apply(format_dc_str)
|
591
|
+
df["A2_P"] = df["A2_P"].apply(format_dc_str)
|
592
|
+
df["A3_P"] = df["A3_P"].apply(format_dc_str)
|
593
|
+
df["A4_P"] = df["A4_P"].apply(format_dc_str)
|
594
|
+
df["A5_P"] = df["A5_P"].apply(format_dc_str)
|
595
|
+
df["PRICE"] = df["PRICE"].apply(format_dc_str)
|
596
|
+
df["B1_P"] = df["B1_P"].apply(format_dc_str)
|
597
|
+
df["B2_P"] = df["B2_P"].apply(format_dc_str)
|
598
|
+
df["B3_P"] = df["B3_P"].apply(format_dc_str)
|
599
|
+
df["B4_P"] = df["B4_P"].apply(format_dc_str)
|
600
|
+
df["B5_P"] = df["B5_P"].apply(format_dc_str)
|
601
|
+
new_order = rtqv.LIVE_DATA_COLS_REINDEX
|
602
|
+
df = df[new_order]
|
603
|
+
return df
|
604
|
+
|
605
|
+
|
606
|
+
def format_dc_str(x):
|
607
|
+
return x / 100 if x != "-" else ""
|
608
|
+
|
609
|
+
|
610
|
+
if __name__ == '__main__':
|
611
|
+
# df = realtime_quote(ts_code="000688.SH,000010.SH,000012.SH,399005.SZ", src="sina")
|
612
|
+
# # df = realtime_list(src="dc", page_count=1)
|
613
|
+
# print(df)
|
614
|
+
ts_code = '399005.SZ'
|
615
|
+
ts_code = '000001.SZ'
|
616
|
+
df = realtime_quote(src="dc", ts_code=ts_code)
|
617
|
+
print(df)
|
@@ -10,6 +10,12 @@ import re
|
|
10
10
|
|
11
11
|
|
12
12
|
def format_stock_code(x, special=""):
|
13
|
+
"""
|
14
|
+
股票代码 code 格式化
|
15
|
+
@param x:
|
16
|
+
@param special:
|
17
|
+
@return:
|
18
|
+
"""
|
13
19
|
if special:
|
14
20
|
x = str(x)
|
15
21
|
if "行业" in special or "概念" in special:
|
@@ -78,11 +84,39 @@ def symbol_verify(x):
|
|
78
84
|
raise '请按照 "000001.SZ" 格式传入symbol'
|
79
85
|
|
80
86
|
|
87
|
+
def verify_stock_or_index(x):
|
88
|
+
"""
|
89
|
+
判断代码是否是 股票 True 指数 False
|
90
|
+
@param x:
|
91
|
+
@return:
|
92
|
+
"""
|
93
|
+
x = str(x).upper()
|
94
|
+
if x.startswith('39') and x.endswith('SZ'):
|
95
|
+
return True
|
96
|
+
elif x.startswith('30') and x.endswith('SZ'):
|
97
|
+
return True
|
98
|
+
elif x.startswith('0') and x.endswith('SH'):
|
99
|
+
return False
|
100
|
+
elif x.startswith('0') and x.endswith('SZ'):
|
101
|
+
return True
|
102
|
+
elif x.startswith('6') and x.endswith('SH'):
|
103
|
+
return True
|
104
|
+
elif x.startswith('8') and x.endswith('BJ'):
|
105
|
+
return True
|
106
|
+
elif x.startswith('4') and x.endswith('BJ'):
|
107
|
+
return True
|
108
|
+
elif x.startswith('9') and x.endswith('CSI'):
|
109
|
+
return False
|
110
|
+
else:
|
111
|
+
return True
|
112
|
+
|
113
|
+
|
114
|
+
|
81
115
|
if __name__ == '__main__':
|
82
116
|
# s = symbol_verify("13.SH")
|
83
117
|
# # s = symbol_verify("sh13")
|
84
118
|
# s = symbol_verify("sz000001")
|
85
119
|
# s = symbol_verify("000001.SZ")
|
86
120
|
# s = symbols_f("000001", special="港股")
|
87
|
-
s =
|
121
|
+
s = verify_stock_or_index(x="399005.SZ")
|
88
122
|
print(s)
|
@@ -15,10 +15,16 @@ test/pro_test.py
|
|
15
15
|
test/ref_test.py
|
16
16
|
test/shibor_test.py
|
17
17
|
test/storing_test.py
|
18
|
+
test/test_query.py
|
18
19
|
test/test_realtime.py
|
20
|
+
test/test_sdk_event.py
|
19
21
|
test/test_stk_mins.py
|
22
|
+
test/test_stock_basic.py
|
20
23
|
test/test_websocket.py
|
21
24
|
test/trading_test.py
|
25
|
+
test/build_pyd/__init__.py
|
26
|
+
test/build_pyd/rtqc.py
|
27
|
+
test/build_pyd/setup.py
|
22
28
|
tushare/__init__.py
|
23
29
|
tushare.egg-info/PKG-INFO
|
24
30
|
tushare.egg-info/SOURCES.txt
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|