tickplus 0.1.0__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.
- tickplus/SKILL.md +484 -0
- tickplus/__init__.py +0 -0
- tickplus/references/apidoc.md +1228 -0
- tickplus/references/websocket.md +722 -0
- tickplus/scripts/CompleteExampleClient.py +139 -0
- tickplus/scripts/Config.py +3 -0
- tickplus/scripts/StockApiClient.py +121 -0
- tickplus/scripts/StockWebSocketClient.py +197 -0
- tickplus/scripts/__init__.py +0 -0
- tickplus/scripts/api/BasicApi.py +152 -0
- tickplus/scripts/api/ExpertApi.py +78 -0
- tickplus/scripts/api/ProApi.py +110 -0
- tickplus/scripts/generate_apidoc.py +112 -0
- tickplus/scripts/util/DataUtil.py +67 -0
- tickplus-0.1.0.dist-info/METADATA +443 -0
- tickplus-0.1.0.dist-info/RECORD +18 -0
- tickplus-0.1.0.dist-info/WHEEL +5 -0
- tickplus-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
from tickplus.scripts.Config import Config
|
|
4
|
+
from tickplus.scripts.util import DataUtil
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def getTransaction(code: str, tradeDate: str, token: str, method: str = "get") -> str:
|
|
8
|
+
"""
|
|
9
|
+
逐笔交易数据。
|
|
10
|
+
|
|
11
|
+
:param code: 股票代码,仅支持单个股票获取,不支持批量参数
|
|
12
|
+
:param tradeDate: 交易日期
|
|
13
|
+
:param token: 激活Token参考 http://www.tickplus.org/
|
|
14
|
+
:param method: 请求方法,默认get
|
|
15
|
+
:return: JSON格式的字符串数据
|
|
16
|
+
"""
|
|
17
|
+
url = Config.SERVER_URL + "/plus/expert/transaction"
|
|
18
|
+
params = {"code": code, "tradeDate": tradeDate, "token": token}
|
|
19
|
+
result = DataUtil.request(url, method, params)
|
|
20
|
+
data = json.loads(result)
|
|
21
|
+
DataUtil.printLog("/plus/expert/transaction", params, data)
|
|
22
|
+
return data
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def getFullBid(token: str, code: str = "", method: str = "get") -> str:
|
|
26
|
+
"""
|
|
27
|
+
获取沪深A股实时竞价数据,竞价时间段:09:15-09:25。
|
|
28
|
+
|
|
29
|
+
:param code: 股票代码。code取值为空,则表示全推全市场数据;code取值为000001,000002,则表示批量获取,股票数量最大为100个;code取值为000001,则表示获取单个股票数据。
|
|
30
|
+
:param token: 激活Token参考 http://www.tickplus.org/
|
|
31
|
+
:param method: 请求方法,默认get
|
|
32
|
+
:return: JSON格式的字符串数据
|
|
33
|
+
"""
|
|
34
|
+
url = Config.SERVER_URL + "/plus/expert/fullbid"
|
|
35
|
+
params = {"token": token}
|
|
36
|
+
if code:
|
|
37
|
+
params["code"] = code
|
|
38
|
+
result = DataUtil.request(url, method, params)
|
|
39
|
+
data = json.loads(result)
|
|
40
|
+
DataUtil.printLog("/plus/expert/fullbid", params, data)
|
|
41
|
+
return data
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def getFiveLevel(symbol: str, token: str, code: str = "", method: str = "get") -> str:
|
|
45
|
+
"""
|
|
46
|
+
买卖五档实时数据全推。
|
|
47
|
+
|
|
48
|
+
:param symbol: stock-沪深京A股,etf-ETF基金,bond-沪深可转债,index-指数
|
|
49
|
+
:param code: 股票代码;逗号分隔代码表示批量获取,最多100个
|
|
50
|
+
:param token: 激活Token参考 http://www.tickplus.org/
|
|
51
|
+
:param method: 请求方法,默认get
|
|
52
|
+
:return: JSON格式的字符串数据
|
|
53
|
+
"""
|
|
54
|
+
url = Config.SERVER_URL + "/plus/expert/fivelevel"
|
|
55
|
+
params = {"symbol": symbol, "token": token}
|
|
56
|
+
if code:
|
|
57
|
+
params["code"] = code
|
|
58
|
+
result = DataUtil.request(url, method, params)
|
|
59
|
+
data = json.loads(result)
|
|
60
|
+
DataUtil.printLog("/plus/expert/fivelevel", params, data)
|
|
61
|
+
return data
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def getFluctuation(tradeDate: str, token: str, method: str = "get") -> str:
|
|
65
|
+
"""
|
|
66
|
+
获取涨停板异动数据,包含首板股池、一进二、二进三、三进四等数据。
|
|
67
|
+
|
|
68
|
+
:param tradeDate: 交易日期。如果为交易日当天
|
|
69
|
+
:param token: 激活Token参考 http://www.tickplus.org/
|
|
70
|
+
:param method: 请求方法,默认get
|
|
71
|
+
:return: JSON格式的字符串数据
|
|
72
|
+
"""
|
|
73
|
+
url = Config.SERVER_URL + "/plus/expert/fluctuation"
|
|
74
|
+
params = {"tradeDate": tradeDate, "token": token}
|
|
75
|
+
result = DataUtil.request(url, method, params)
|
|
76
|
+
data = json.loads(result)
|
|
77
|
+
DataUtil.printLog("/plus/expert/fluctuation", params, data)
|
|
78
|
+
return data
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
from tickplus.scripts.Config import Config
|
|
4
|
+
from tickplus.scripts.util import DataUtil
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def getFullMinute(symbol: str, token: str, code: str = "", method: str = "get") -> str:
|
|
8
|
+
"""
|
|
9
|
+
实时分钟数据全推。
|
|
10
|
+
|
|
11
|
+
:param symbol: stock-沪深京A股,etf-ETF基金,bond-沪深可转债,index-指数
|
|
12
|
+
:param code: 股票代码。code取值为空,则表示全推全市场数据;code取值为000001,000002,则表示批量获取,股票数量最大为100个;code取值为000001,则表示获取单个股票数据。
|
|
13
|
+
:param token: 激活Token参考 http://www.tickplus.org/
|
|
14
|
+
:param method: 请求方法,默认get
|
|
15
|
+
:return: JSON格式的字符串数据
|
|
16
|
+
"""
|
|
17
|
+
url = Config.SERVER_URL + "/plus/pro/fullminute"
|
|
18
|
+
params = {"symbol": symbol, "token": token}
|
|
19
|
+
if code:
|
|
20
|
+
params["code"] = code
|
|
21
|
+
result = DataUtil.request(url, method, params)
|
|
22
|
+
data = json.loads(result)
|
|
23
|
+
DataUtil.printLog("/plus/pro/fullminute", params, data)
|
|
24
|
+
return data
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def getFullMinuteSnapshot(symbol: str, token: str, code: str = "", method: str = "get") -> str:
|
|
28
|
+
"""
|
|
29
|
+
获取盘中分钟快照数据全推,盘中秒级实时更新。
|
|
30
|
+
|
|
31
|
+
:param symbol: stock-沪深京A股,etf-ETF基金,bond-沪深可转债,index-指数
|
|
32
|
+
:param code: 股票代码;为空表示全市场,逗号分隔代码表示批量获取,最多100个
|
|
33
|
+
:param token: 激活Token参考 http://www.tickplus.org/
|
|
34
|
+
:param method: 请求方法,默认get
|
|
35
|
+
:return: JSON格式的字符串数据
|
|
36
|
+
"""
|
|
37
|
+
url = Config.SERVER_URL + "/plus/pro/fullminutesnapshot"
|
|
38
|
+
params = {"symbol": symbol, "token": token}
|
|
39
|
+
if code:
|
|
40
|
+
params["code"] = code
|
|
41
|
+
result = DataUtil.request(url, method, params)
|
|
42
|
+
data = json.loads(result)
|
|
43
|
+
DataUtil.printLog("/plus/pro/fullminutesnapshot", params, data)
|
|
44
|
+
return data
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def getMinuteKline(symbol: str, code: str, period: str, dividend: str,
|
|
48
|
+
startDate: str, endDate: str, token: str, method: str = "get") -> str:
|
|
49
|
+
"""
|
|
50
|
+
实时分钟K线数据。
|
|
51
|
+
|
|
52
|
+
:param symbol: stock-沪深京A股,etf-ETF基金,bond-沪深可转债,index-指数
|
|
53
|
+
:param code: 股票代码,仅支持单个股票获取
|
|
54
|
+
:param period: K线周期,1m-1分钟线,5m-5分钟线,15m-15分钟线,30m-30分钟线,1h-1小时线
|
|
55
|
+
:param dividend: 复权类型,1-不复权,2-前复权,3-后复权
|
|
56
|
+
:param startDate: 开始日期
|
|
57
|
+
:param endDate: 结束日期
|
|
58
|
+
:param token: 激活Token参考 http://www.tickplus.org/
|
|
59
|
+
:param method: 请求方法,默认get
|
|
60
|
+
:return: JSON格式的字符串数据
|
|
61
|
+
"""
|
|
62
|
+
url = Config.SERVER_URL + "/plus/pro/minutekline"
|
|
63
|
+
params = {
|
|
64
|
+
"symbol": symbol,
|
|
65
|
+
"code": code,
|
|
66
|
+
"period": period,
|
|
67
|
+
"dividend": dividend,
|
|
68
|
+
"token": token
|
|
69
|
+
}
|
|
70
|
+
params["startDate"] = startDate
|
|
71
|
+
params["endDate"] = endDate
|
|
72
|
+
result = DataUtil.request(url, method, params)
|
|
73
|
+
data = json.loads(result)
|
|
74
|
+
DataUtil.printLog("/plus/pro/minutekline", params, data)
|
|
75
|
+
return data
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def getTimeKline(symbol: str, code: str, token: str, method: str = "get") -> str:
|
|
79
|
+
"""
|
|
80
|
+
日内分时数据。
|
|
81
|
+
|
|
82
|
+
:param symbol: stock-沪深京A股,etf-ETF基金,bond-沪深可转债,index-指数
|
|
83
|
+
:param code: 股票代码,仅支持单个股票获取
|
|
84
|
+
:param token: 激活Token参考 http://www.tickplus.org/
|
|
85
|
+
:param method: 请求方法,默认get
|
|
86
|
+
:return: JSON格式的字符串数据
|
|
87
|
+
"""
|
|
88
|
+
url = Config.SERVER_URL + "/plus/pro/timekline"
|
|
89
|
+
params = {"symbol": symbol, "code": code, "token": token}
|
|
90
|
+
result = DataUtil.request(url, method, params)
|
|
91
|
+
data = json.loads(result)
|
|
92
|
+
DataUtil.printLog("/plus/pro/timekline", params, data)
|
|
93
|
+
return data
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def getGncgf(symbol: str, token: str, method: str = "get") -> str:
|
|
97
|
+
"""
|
|
98
|
+
获取行业板块、概念板块、特色板块下的成分股数据。
|
|
99
|
+
|
|
100
|
+
:param symbol: hy-行业板块,gn-概念板块,ts-特色板块
|
|
101
|
+
:param token: 激活Token参考 http://www.tickplus.org/
|
|
102
|
+
:param method: 请求方法,默认get
|
|
103
|
+
:return: JSON格式的字符串数据
|
|
104
|
+
"""
|
|
105
|
+
url = Config.SERVER_URL + "/plus/pro/gncgf"
|
|
106
|
+
params = {"symbol": symbol, "token": token}
|
|
107
|
+
result = DataUtil.request(url, method, params)
|
|
108
|
+
data = json.loads(result)
|
|
109
|
+
DataUtil.printLog("/plus/pro/gncgf", params, data)
|
|
110
|
+
return data
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""Generate the Markdown API reference from TickPlus apidoc.json."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
AUTH_NAMES = {1: "基础版", 2: "高级版", 3: "专业版"}
|
|
9
|
+
SDK_METHODS = {
|
|
10
|
+
"/plus/basic/list": "BasicApi.getStockList",
|
|
11
|
+
"/plus/basic/fullquotes": "BasicApi.getFullQuotes",
|
|
12
|
+
"/plus/basic/daykline": "BasicApi.getDayKline",
|
|
13
|
+
"/plus/basic/fullmetric": "BasicApi.getFullMetric",
|
|
14
|
+
"/plus/basic/financecore": "BasicApi.getFinanceCore",
|
|
15
|
+
"/plus/basic/capital": "BasicApi.getCapital",
|
|
16
|
+
"/plus/basic/updatedaykline": "BasicApi.getUpdateDayKline",
|
|
17
|
+
"/plus/pro/timekline": "ProApi.getTimeKline",
|
|
18
|
+
"/plus/pro/gncgf": "ProApi.getGncgf",
|
|
19
|
+
"/plus/pro/minutekline": "ProApi.getMinuteKline",
|
|
20
|
+
"/plus/pro/fullminute": "ProApi.getFullMinute",
|
|
21
|
+
"/plus/pro/fullminutesnapshot": "ProApi.getFullMinuteSnapshot",
|
|
22
|
+
"/plus/expert/transaction": "ExpertApi.getTransaction",
|
|
23
|
+
"/plus/expert/fivelevel": "ExpertApi.getFiveLevel",
|
|
24
|
+
"/plus/expert/fullbid": "ExpertApi.getFullBid",
|
|
25
|
+
"/plus/expert/fluctuation": "ExpertApi.getFluctuation",
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def markdown_table(headers, rows):
|
|
30
|
+
lines = ["| " + " | ".join(headers) + " |", "| " + " | ".join("---" for _ in headers) + " |"]
|
|
31
|
+
for row in rows:
|
|
32
|
+
cells = [str(value or "").replace("|", "|").replace("\n", "<br>") for value in row]
|
|
33
|
+
lines.append("| " + " | ".join(cells) + " |")
|
|
34
|
+
return "\n".join(lines)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def format_api(api, index):
|
|
38
|
+
auth = "、".join(
|
|
39
|
+
f"{AUTH_NAMES.get(level, f'权限{level}')} ({level})" for level in api.get("apiAuth", [])
|
|
40
|
+
)
|
|
41
|
+
lines = [
|
|
42
|
+
f"### {index}. {api['name']}",
|
|
43
|
+
"",
|
|
44
|
+
api.get("description", ""),
|
|
45
|
+
"",
|
|
46
|
+
f"- **路径**:`{api['url']}`",
|
|
47
|
+
f"- **权限**:{auth}",
|
|
48
|
+
]
|
|
49
|
+
tags = api.get("tags", [])
|
|
50
|
+
if tags:
|
|
51
|
+
lines.append(f"- **标签**:{'、'.join(tags)}")
|
|
52
|
+
lines.extend(["", "**请求参数**", ""])
|
|
53
|
+
inputs = [
|
|
54
|
+
[p.get("name"), p.get("type"), "是" if p.get("required") else "否", p.get("range"), p.get("description")]
|
|
55
|
+
for p in api.get("inputParas", [])
|
|
56
|
+
]
|
|
57
|
+
lines.extend(markdown_table(["参数名", "类型", "必填", "取值范围", "说明"], inputs).splitlines())
|
|
58
|
+
lines.extend(["", "**返回字段**", ""])
|
|
59
|
+
outputs = [[p.get("name"), p.get("type"), p.get("description")] for p in api.get("outputParas", [])]
|
|
60
|
+
lines.extend(markdown_table(["字段名", "类型", "说明"], outputs).splitlines())
|
|
61
|
+
|
|
62
|
+
demo = api.get("demo")
|
|
63
|
+
if demo:
|
|
64
|
+
lines.extend(["", "**请求示例**", "", "```text", demo, "```"])
|
|
65
|
+
data = api.get("data")
|
|
66
|
+
if data:
|
|
67
|
+
try:
|
|
68
|
+
sample = json.dumps(json.loads(data), ensure_ascii=False, indent=2)
|
|
69
|
+
except (TypeError, json.JSONDecodeError):
|
|
70
|
+
sample = str(data)
|
|
71
|
+
lines.extend(["", "**响应示例**", "", "```json", sample, "```"])
|
|
72
|
+
return "\n".join(lines)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def render(document):
|
|
76
|
+
sections = [
|
|
77
|
+
"# TickPlus API 接口文档",
|
|
78
|
+
"",
|
|
79
|
+
"本文由 TickPlus `apidoc.json` 生成,接口名称、参数、返回字段、示例和权限以该文件为准。",
|
|
80
|
+
"",
|
|
81
|
+
"- **官方网站**:http://www.tickplus.org",
|
|
82
|
+
"- **API 基址**:http://api.tickplus.org",
|
|
83
|
+
"- **请求方式**:GET",
|
|
84
|
+
"",
|
|
85
|
+
"权限代码:1 基础版,2 高级版,3 专业版。",
|
|
86
|
+
]
|
|
87
|
+
index = 1
|
|
88
|
+
for group in document:
|
|
89
|
+
sections.extend(["", f"## {group['name']}", ""])
|
|
90
|
+
for api in group.get("docApis", []):
|
|
91
|
+
sections.extend([format_api(api, index), ""])
|
|
92
|
+
index += 1
|
|
93
|
+
sections.extend(["", "## Python SDK 方法", "", "| 接口路径 | SDK 方法 |", "| --- | --- |"])
|
|
94
|
+
for group in document:
|
|
95
|
+
for api in group.get("docApis", []):
|
|
96
|
+
method = SDK_METHODS.get(api["url"], "")
|
|
97
|
+
sections.append(f"| `{api['url']}` | `{method}` |")
|
|
98
|
+
return "\n".join(sections).rstrip() + "\n"
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def main():
|
|
102
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
103
|
+
parser.add_argument("apidoc_json", type=Path, help="TickPlus apidoc.json path")
|
|
104
|
+
parser.add_argument("output_markdown", type=Path, help="Markdown output path")
|
|
105
|
+
args = parser.parse_args()
|
|
106
|
+
|
|
107
|
+
document = json.loads(args.apidoc_json.read_text(encoding="utf-8-sig"))
|
|
108
|
+
args.output_markdown.write_text(render(document), encoding="utf-8", newline="\n")
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
if __name__ == "__main__":
|
|
112
|
+
main()
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import gzip
|
|
2
|
+
import json
|
|
3
|
+
import zipfile
|
|
4
|
+
from io import BytesIO
|
|
5
|
+
|
|
6
|
+
import requests
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def detect_compression_format(data: bytes) -> str:
|
|
10
|
+
if len(data) >= 4 and (data[0] & 0xFF) == 0x50 and (data[1] & 0xFF) == 0x4B and (
|
|
11
|
+
((data[2] & 0xFF) == 0x03 and (data[3] & 0xFF) == 0x04) or
|
|
12
|
+
((data[2] & 0xFF) == 0x05 and (data[3] & 0xFF) == 0x06) or
|
|
13
|
+
((data[2] & 0xFF) == 0x07 and (data[3] & 0xFF) == 0x08)
|
|
14
|
+
):
|
|
15
|
+
return "zip"
|
|
16
|
+
elif len(data) >= 2 and (data[0] & 0xFF) == 0x1F and (data[1] & 0xFF) == 0x8B:
|
|
17
|
+
return "gzip"
|
|
18
|
+
return "unknown"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def process_zip_data(data: bytes):
|
|
22
|
+
try:
|
|
23
|
+
with zipfile.ZipFile(BytesIO(data)) as zip_file:
|
|
24
|
+
for file_info in zip_file.filelist:
|
|
25
|
+
if file_info.filename.endswith('.json'):
|
|
26
|
+
content = zip_file.read(file_info).decode('utf-8')
|
|
27
|
+
packet = json.loads(content)
|
|
28
|
+
return packet
|
|
29
|
+
except Exception as e:
|
|
30
|
+
print(f"解析ZIP数据失败: {e}")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def process_gzip_data(data: bytes):
|
|
34
|
+
try:
|
|
35
|
+
with gzip.GzipFile(fileobj=BytesIO(data)) as gzip_file:
|
|
36
|
+
content = gzip_file.read().decode('utf-8')
|
|
37
|
+
packet = json.loads(content)
|
|
38
|
+
return packet
|
|
39
|
+
except Exception as e:
|
|
40
|
+
print(f"解析GZIP数据失败: {e}")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def process_data(data: bytes):
|
|
44
|
+
compression_format = detect_compression_format(data)
|
|
45
|
+
if compression_format == "gzip":
|
|
46
|
+
return process_gzip_data(data)
|
|
47
|
+
elif compression_format == "zip":
|
|
48
|
+
return process_zip_data(data)
|
|
49
|
+
else:
|
|
50
|
+
return data.decode('utf-8')
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def request(url: str, method: str = "get", params=None):
|
|
54
|
+
if method == 'post':
|
|
55
|
+
response = requests.post(url, params=params)
|
|
56
|
+
return response.content.decode('utf-8')
|
|
57
|
+
else:
|
|
58
|
+
response = requests.get(url, params=params)
|
|
59
|
+
return response.content.decode('utf-8')
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def printLog(apiName: str, params: dict, data: json):
|
|
63
|
+
if isinstance(data, list):
|
|
64
|
+
print(f"{apiName},返回 {len(data)} 条记录,参数{params},数据样例:{data[0] if len(data) > 0 else {} }")
|
|
65
|
+
else:
|
|
66
|
+
print(f"{apiName},返回异常信息,参数{params},异常详情:{data}")
|
|
67
|
+
return data
|