tgtc-sdk 0.1.0__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.
- tgtc_sdk-0.1.0/LICENSE +21 -0
- tgtc_sdk-0.1.0/PKG-INFO +100 -0
- tgtc_sdk-0.1.0/README.md +87 -0
- tgtc_sdk-0.1.0/pyproject.toml +19 -0
- tgtc_sdk-0.1.0/setup.cfg +4 -0
- tgtc_sdk-0.1.0/tgtc/__init__.py +18 -0
- tgtc_sdk-0.1.0/tgtc/client.py +97 -0
- tgtc_sdk-0.1.0/tgtc/errors.py +41 -0
- tgtc_sdk-0.1.0/tgtc/models.py +74 -0
- tgtc_sdk-0.1.0/tgtc_sdk.egg-info/PKG-INFO +100 -0
- tgtc_sdk-0.1.0/tgtc_sdk.egg-info/SOURCES.txt +12 -0
- tgtc_sdk-0.1.0/tgtc_sdk.egg-info/dependency_links.txt +1 -0
- tgtc_sdk-0.1.0/tgtc_sdk.egg-info/requires.txt +1 -0
- tgtc_sdk-0.1.0/tgtc_sdk.egg-info/top_level.txt +1 -0
tgtc_sdk-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TGTC-Suiyoung
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
tgtc_sdk-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tgtc-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: TGTC BSC 代币数据 API 的 Python 客户端(计费透明:每次返回剩余次数与扣次明细)
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://www.tgtcbot.com
|
|
7
|
+
Project-URL: Documentation, https://github.com/TGTC-Suiyoung/tgtc-api-docs
|
|
8
|
+
Requires-Python: >=3.9
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: requests>=2.25
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# tgtc-sdk (Python)
|
|
15
|
+
|
|
16
|
+
TGTC 数据 API 的 Python 客户端。一行代码接入 BSC 代币数据:基本行情、持仓结构、安全审计、持有人、社交信息、聪明钱动向。
|
|
17
|
+
|
|
18
|
+
**计费透明**:每次调用都会返回剩余次数与本次扣次明细,余额一眼可见。
|
|
19
|
+
|
|
20
|
+
## 安装
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install tgtc-sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
需要先创建 API Key(TGTC Bot 个人中心 → 我的 API)。
|
|
27
|
+
|
|
28
|
+
## 快速开始
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from tgtc import TGTC
|
|
32
|
+
|
|
33
|
+
client = TGTC(api_key="你的 API Key")
|
|
34
|
+
|
|
35
|
+
# 代币聚合查询(默认返回完整产品类别)
|
|
36
|
+
res = client.token("0x...合约地址")
|
|
37
|
+
|
|
38
|
+
print(res.symbol) # 代币符号
|
|
39
|
+
print(res.price) # 当前价格
|
|
40
|
+
print(res.remaining) # 剩余调用次数
|
|
41
|
+
print(res.used) # 本次扣次
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 按类别/字段查询
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
# 只要行情 + 安全审计,扣次更少
|
|
48
|
+
res = client.token(ca, categories=["basic", "security"])
|
|
49
|
+
|
|
50
|
+
# 精确字段裁剪(与 categories 二选一)
|
|
51
|
+
res = client.token(ca, fields=["symbol", "price", "honeypot", "buy_tax"])
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
可选类别:`basic`(基本行情)/ `structure`(持仓结构)/ `holders`(持有人)/ `security`(安全审计)/ `social`(社交信息)/ `traders`(聪明钱动向)。
|
|
55
|
+
|
|
56
|
+
## 计费明细
|
|
57
|
+
|
|
58
|
+
| 字段 | 说明 |
|
|
59
|
+
| --- | --- |
|
|
60
|
+
| `remaining` | 剩余调用次数 |
|
|
61
|
+
| `used` | 本次扣次(缓存命中为 0) |
|
|
62
|
+
| `cache_hit` | 是否命中缓存(命中不扣次) |
|
|
63
|
+
| `delay_sec` | 数据新鲜度(0 = 实时) |
|
|
64
|
+
|
|
65
|
+
## 错误处理
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from tgtc import TGTCError, TGTCQuotaError, TGTCAuthError
|
|
69
|
+
|
|
70
|
+
try:
|
|
71
|
+
res = client.token(ca)
|
|
72
|
+
except TGTCAuthError:
|
|
73
|
+
print("API Key 无效")
|
|
74
|
+
except TGTCQuotaError:
|
|
75
|
+
print("调用次数不足,请充值")
|
|
76
|
+
except TGTCError as e:
|
|
77
|
+
print("请求失败:", e)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
| 异常 | 触发条件 |
|
|
81
|
+
| --- | --- |
|
|
82
|
+
| `TGTCAuthError` | API Key 缺失或无效 |
|
|
83
|
+
| `TGTCParamError` | 参数错误(CA 格式/类别组合) |
|
|
84
|
+
| `TGTCNotFoundError` | 代币数据不存在 |
|
|
85
|
+
| `TGTCQuotaError` | 调用次数不足 |
|
|
86
|
+
| `TGTCUnavailableError` | 服务初始化或维护中 |
|
|
87
|
+
|
|
88
|
+
## 路线图
|
|
89
|
+
|
|
90
|
+
- [x] token:代币聚合查询
|
|
91
|
+
- [ ] token/trending + token/hot:榜单
|
|
92
|
+
- [ ] twitter:推特检测/舆情
|
|
93
|
+
- [ ] track:交易流
|
|
94
|
+
- [ ] market:信号流
|
|
95
|
+
- [ ] wallet:钱包分析
|
|
96
|
+
- [ ] translate:翻译
|
|
97
|
+
|
|
98
|
+
## 文档
|
|
99
|
+
|
|
100
|
+
完整接口文档见 [TGTC API Docs](https://github.com/TGTC-Suiyoung/tgtc-api-docs)。
|
tgtc_sdk-0.1.0/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# tgtc-sdk (Python)
|
|
2
|
+
|
|
3
|
+
TGTC 数据 API 的 Python 客户端。一行代码接入 BSC 代币数据:基本行情、持仓结构、安全审计、持有人、社交信息、聪明钱动向。
|
|
4
|
+
|
|
5
|
+
**计费透明**:每次调用都会返回剩余次数与本次扣次明细,余额一眼可见。
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install tgtc-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
需要先创建 API Key(TGTC Bot 个人中心 → 我的 API)。
|
|
14
|
+
|
|
15
|
+
## 快速开始
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from tgtc import TGTC
|
|
19
|
+
|
|
20
|
+
client = TGTC(api_key="你的 API Key")
|
|
21
|
+
|
|
22
|
+
# 代币聚合查询(默认返回完整产品类别)
|
|
23
|
+
res = client.token("0x...合约地址")
|
|
24
|
+
|
|
25
|
+
print(res.symbol) # 代币符号
|
|
26
|
+
print(res.price) # 当前价格
|
|
27
|
+
print(res.remaining) # 剩余调用次数
|
|
28
|
+
print(res.used) # 本次扣次
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## 按类别/字段查询
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
# 只要行情 + 安全审计,扣次更少
|
|
35
|
+
res = client.token(ca, categories=["basic", "security"])
|
|
36
|
+
|
|
37
|
+
# 精确字段裁剪(与 categories 二选一)
|
|
38
|
+
res = client.token(ca, fields=["symbol", "price", "honeypot", "buy_tax"])
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
可选类别:`basic`(基本行情)/ `structure`(持仓结构)/ `holders`(持有人)/ `security`(安全审计)/ `social`(社交信息)/ `traders`(聪明钱动向)。
|
|
42
|
+
|
|
43
|
+
## 计费明细
|
|
44
|
+
|
|
45
|
+
| 字段 | 说明 |
|
|
46
|
+
| --- | --- |
|
|
47
|
+
| `remaining` | 剩余调用次数 |
|
|
48
|
+
| `used` | 本次扣次(缓存命中为 0) |
|
|
49
|
+
| `cache_hit` | 是否命中缓存(命中不扣次) |
|
|
50
|
+
| `delay_sec` | 数据新鲜度(0 = 实时) |
|
|
51
|
+
|
|
52
|
+
## 错误处理
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from tgtc import TGTCError, TGTCQuotaError, TGTCAuthError
|
|
56
|
+
|
|
57
|
+
try:
|
|
58
|
+
res = client.token(ca)
|
|
59
|
+
except TGTCAuthError:
|
|
60
|
+
print("API Key 无效")
|
|
61
|
+
except TGTCQuotaError:
|
|
62
|
+
print("调用次数不足,请充值")
|
|
63
|
+
except TGTCError as e:
|
|
64
|
+
print("请求失败:", e)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
| 异常 | 触发条件 |
|
|
68
|
+
| --- | --- |
|
|
69
|
+
| `TGTCAuthError` | API Key 缺失或无效 |
|
|
70
|
+
| `TGTCParamError` | 参数错误(CA 格式/类别组合) |
|
|
71
|
+
| `TGTCNotFoundError` | 代币数据不存在 |
|
|
72
|
+
| `TGTCQuotaError` | 调用次数不足 |
|
|
73
|
+
| `TGTCUnavailableError` | 服务初始化或维护中 |
|
|
74
|
+
|
|
75
|
+
## 路线图
|
|
76
|
+
|
|
77
|
+
- [x] token:代币聚合查询
|
|
78
|
+
- [ ] token/trending + token/hot:榜单
|
|
79
|
+
- [ ] twitter:推特检测/舆情
|
|
80
|
+
- [ ] track:交易流
|
|
81
|
+
- [ ] market:信号流
|
|
82
|
+
- [ ] wallet:钱包分析
|
|
83
|
+
- [ ] translate:翻译
|
|
84
|
+
|
|
85
|
+
## 文档
|
|
86
|
+
|
|
87
|
+
完整接口文档见 [TGTC API Docs](https://github.com/TGTC-Suiyoung/tgtc-api-docs)。
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tgtc-sdk"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "TGTC BSC 代币数据 API 的 Python 客户端(计费透明:每次返回剩余次数与扣次明细)"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
dependencies = ["requests>=2.25"]
|
|
13
|
+
|
|
14
|
+
[project.urls]
|
|
15
|
+
Homepage = "https://www.tgtcbot.com"
|
|
16
|
+
Documentation = "https://github.com/TGTC-Suiyoung/tgtc-api-docs"
|
|
17
|
+
|
|
18
|
+
[tool.setuptools.packages.find]
|
|
19
|
+
include = ["tgtc*"]
|
tgtc_sdk-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""tgtc-sdk:TGTC 数据 API 的 Python 客户端。
|
|
3
|
+
|
|
4
|
+
v0.1 覆盖 token(代币聚合)端点,计费透明(每次返回剩余次数与扣次明细)。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .client import CATEGORIES, DEFAULT_BASE_URL, TGTC
|
|
8
|
+
from .errors import (TGTCError, TGTCAuthError, TGTCParamError, TGTCNotFoundError,
|
|
9
|
+
TGTCQuotaError, TGTCUnavailableError)
|
|
10
|
+
from .models import TokenResult
|
|
11
|
+
|
|
12
|
+
__version__ = "0.1.0"
|
|
13
|
+
__all__ = [
|
|
14
|
+
"TGTC", "TokenResult",
|
|
15
|
+
"TGTCError", "TGTCAuthError", "TGTCParamError", "TGTCNotFoundError",
|
|
16
|
+
"TGTCQuotaError", "TGTCUnavailableError",
|
|
17
|
+
"CATEGORIES", "DEFAULT_BASE_URL",
|
|
18
|
+
]
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""TGTC 客户端:X-API-Key 鉴权 + token 端点封装。
|
|
3
|
+
|
|
4
|
+
v0.1 只覆盖 token(代币聚合)端点;后续端点按同样模式追加方法即可。
|
|
5
|
+
架构要点:
|
|
6
|
+
· 计费透明——每次调用返回剩余次数(remaining)与本次扣次(used)
|
|
7
|
+
· 错误映射——HTTP 状态码转明确异常(见 errors.py)
|
|
8
|
+
· 零侵入——SDK 只面向 /api/v1 产品接口,不直连任何数据源
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from typing import List, Optional
|
|
14
|
+
|
|
15
|
+
import requests
|
|
16
|
+
|
|
17
|
+
from .errors import TGTCError, _map_error
|
|
18
|
+
from .models import TokenResult
|
|
19
|
+
|
|
20
|
+
DEFAULT_BASE_URL = "https://www.tgtcbot.com"
|
|
21
|
+
TOKEN_PATH = "/api/v1/aggregation/token"
|
|
22
|
+
|
|
23
|
+
# 可选类别(缺省由服务端按产品默认执行)
|
|
24
|
+
CATEGORIES = ("basic", "structure", "holders", "security", "social", "traders")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class TGTC:
|
|
28
|
+
"""TGTC 数据 API 客户端。
|
|
29
|
+
|
|
30
|
+
用法::
|
|
31
|
+
|
|
32
|
+
from tgtc import TGTC
|
|
33
|
+
client = TGTC(api_key="你的 API Key")
|
|
34
|
+
res = client.token("0x...")
|
|
35
|
+
print(res.symbol, res.remaining) # 符号 + 剩余次数
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
def __init__(self, api_key: Optional[str] = None,
|
|
39
|
+
base_url: str = DEFAULT_BASE_URL,
|
|
40
|
+
timeout: float = 30.0) -> None:
|
|
41
|
+
if not api_key:
|
|
42
|
+
raise TGTCError("缺少 API Key:请在个人中心创建 Key 后传入 api_key")
|
|
43
|
+
self._base_url = (base_url or DEFAULT_BASE_URL).rstrip("/")
|
|
44
|
+
self._timeout = timeout
|
|
45
|
+
self._session = requests.Session()
|
|
46
|
+
self._session.headers["X-API-Key"] = api_key
|
|
47
|
+
|
|
48
|
+
# ── 内部请求管道 ──────────────────────────────────────────
|
|
49
|
+
def _post(self, path: str, payload: dict) -> tuple[dict, dict]:
|
|
50
|
+
"""POST JSON 到产品接口;返回 (响应体, 计费明细)。异常已映射为明确类型。"""
|
|
51
|
+
try:
|
|
52
|
+
resp = self._session.post(self._base_url + path,
|
|
53
|
+
json=payload, timeout=self._timeout)
|
|
54
|
+
except requests.RequestException as e:
|
|
55
|
+
raise TGTCError(f"网络请求失败:{e}") from e
|
|
56
|
+
meta = {
|
|
57
|
+
"remaining": resp.headers.get("X-RateLimit-Remaining"),
|
|
58
|
+
"used": resp.headers.get("X-RateLimit-Used"),
|
|
59
|
+
"cache_hit": resp.headers.get("X-Cache") == "HIT",
|
|
60
|
+
}
|
|
61
|
+
try:
|
|
62
|
+
body = resp.json() if resp.content else {}
|
|
63
|
+
except ValueError:
|
|
64
|
+
body = {}
|
|
65
|
+
if resp.status_code >= 400:
|
|
66
|
+
raise _map_error(resp.status_code, str(body.get("detail") or body or resp.reason))
|
|
67
|
+
if not isinstance(body, dict):
|
|
68
|
+
raise TGTCError(f"响应格式异常:{body!r}")
|
|
69
|
+
return body, meta
|
|
70
|
+
|
|
71
|
+
# ── 产品端点 ─────────────────────────────────────────────
|
|
72
|
+
def token(self, ca: str, chain: str = "bsc",
|
|
73
|
+
categories: Optional[List[str]] = None,
|
|
74
|
+
fields: Optional[List[str]] = None) -> TokenResult:
|
|
75
|
+
"""代币聚合查询(基本行情/持仓结构/安全审计/持有人/社交/聪明钱,按类别计费)。
|
|
76
|
+
|
|
77
|
+
参数:
|
|
78
|
+
ca: 合约地址(0x 开头 40 位十六进制)
|
|
79
|
+
chain: 链名,当前仅支持 bsc
|
|
80
|
+
categories: 可选类别子集;缺省由服务端按产品默认返回
|
|
81
|
+
fields: 可选字段裁剪(与 categories 互斥,二选一)
|
|
82
|
+
|
|
83
|
+
返回:
|
|
84
|
+
TokenResult:data 为完整响应体,remaining/used 为本次计费明细
|
|
85
|
+
"""
|
|
86
|
+
payload = {"ca": ca, "chain": chain}
|
|
87
|
+
if categories:
|
|
88
|
+
payload["categories"] = [str(c) for c in categories]
|
|
89
|
+
if fields:
|
|
90
|
+
payload["fields"] = [str(f) for f in fields]
|
|
91
|
+
body, meta = self._post(TOKEN_PATH, payload)
|
|
92
|
+
return TokenResult(data=body,
|
|
93
|
+
remaining=meta["remaining"],
|
|
94
|
+
used=meta["used"],
|
|
95
|
+
cache_hit=meta["cache_hit"],
|
|
96
|
+
delay_sec=body.get("data_delay_sec"),
|
|
97
|
+
degraded=body.get("degraded_sources"))
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""tgtc-sdk 异常体系:错误码 → 明确异常,开发者不用猜响应结构。"""
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class TGTCError(Exception):
|
|
6
|
+
"""SDK 基类异常。所有异常均继承此类的 message 为服务端返回的中文说明。"""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class TGTCAuthError(TGTCError):
|
|
10
|
+
"""鉴权失败(401):API Key 缺失或无效。"""
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class TGTCParamError(TGTCError):
|
|
14
|
+
"""请求参数错误(400/422):CA 格式、链名或字段/类别组合不合法。"""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class TGTCNotFoundError(TGTCError):
|
|
18
|
+
"""数据不存在(404):代币数据缺失或暂不可用。"""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class TGTCQuotaError(TGTCError):
|
|
22
|
+
"""调用次数不足(429):本次调用所需扣次超过剩余次数。"""
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class TGTCUnavailableError(TGTCError):
|
|
26
|
+
"""服务暂不可用(503):服务初始化中或维护中。"""
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _map_error(status_code: int, detail: str) -> TGTCError:
|
|
30
|
+
"""HTTP 状态码 → 异常实例。未知状态码归入 TGTCError。"""
|
|
31
|
+
if status_code == 401:
|
|
32
|
+
return TGTCAuthError(detail)
|
|
33
|
+
if status_code in (400, 422):
|
|
34
|
+
return TGTCParamError(detail)
|
|
35
|
+
if status_code == 404:
|
|
36
|
+
return TGTCNotFoundError(detail)
|
|
37
|
+
if status_code == 429:
|
|
38
|
+
return TGTCQuotaError(detail)
|
|
39
|
+
if status_code == 503:
|
|
40
|
+
return TGTCUnavailableError(detail)
|
|
41
|
+
return TGTCError(f"服务返回异常状态码 {status_code}:{detail}")
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""tgtc-sdk 结构化返回。v0.1 覆盖 token 端点;其余端点复用 Result 基类扩展。"""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import Any, Dict, Optional
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class Result:
|
|
12
|
+
"""通用响应信封:数据 + 计费明细(来自响应头,与服务端扣次一致)。"""
|
|
13
|
+
|
|
14
|
+
data: Dict[str, Any]
|
|
15
|
+
remaining: Optional[int] = None # 剩余次数(X-RateLimit-Remaining)
|
|
16
|
+
used: Optional[int] = None # 本次扣次(X-RateLimit-Used)
|
|
17
|
+
cache_hit: bool = False # 命中缓存 = 本次免费(X-Cache: HIT)
|
|
18
|
+
delay_sec: Optional[int] = None # 数据新鲜度(data_delay_sec,0 = 实时)
|
|
19
|
+
degraded: Optional[list] = None # 数据源降级标记(degraded_sources,空 = 全量正常)
|
|
20
|
+
|
|
21
|
+
def __post_init__(self) -> None:
|
|
22
|
+
self.remaining = int(self.remaining) if self.remaining is not None else None
|
|
23
|
+
self.used = int(self.used) if self.used is not None else None
|
|
24
|
+
self.delay_sec = int(self.delay_sec) if self.delay_sec is not None else None
|
|
25
|
+
|
|
26
|
+
@property
|
|
27
|
+
def ok(self) -> bool:
|
|
28
|
+
"""请求是否成功(非异常返回即为成功)。"""
|
|
29
|
+
return True
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@dataclass
|
|
33
|
+
class TokenResult(Result):
|
|
34
|
+
"""token 端点结构化返回。常用字段提供 property 快捷访问,其余字段走 data 字典。"""
|
|
35
|
+
|
|
36
|
+
@property
|
|
37
|
+
def ca(self) -> Optional[str]:
|
|
38
|
+
return self.data.get("ca")
|
|
39
|
+
|
|
40
|
+
@property
|
|
41
|
+
def symbol(self) -> Optional[str]:
|
|
42
|
+
return self.data.get("symbol")
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
def name(self) -> Optional[str]:
|
|
46
|
+
return self.data.get("name")
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
def price(self) -> Optional[float]:
|
|
50
|
+
return self.data.get("price")
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def mcap(self) -> Optional[float]:
|
|
54
|
+
return self.data.get("mcap")
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def liquidity(self) -> Optional[float]:
|
|
58
|
+
return self.data.get("liquidity")
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def volume_24h(self) -> Optional[float]:
|
|
62
|
+
return self.data.get("volume_24h")
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def holder_count(self) -> Optional[int]:
|
|
66
|
+
return self.data.get("holder_count")
|
|
67
|
+
|
|
68
|
+
@property
|
|
69
|
+
def categories(self) -> list:
|
|
70
|
+
return list(self.data.get("categories") or [])
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
def disclaimer(self) -> Optional[str]:
|
|
74
|
+
return self.data.get("disclaimer")
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tgtc-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: TGTC BSC 代币数据 API 的 Python 客户端(计费透明:每次返回剩余次数与扣次明细)
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://www.tgtcbot.com
|
|
7
|
+
Project-URL: Documentation, https://github.com/TGTC-Suiyoung/tgtc-api-docs
|
|
8
|
+
Requires-Python: >=3.9
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: requests>=2.25
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# tgtc-sdk (Python)
|
|
15
|
+
|
|
16
|
+
TGTC 数据 API 的 Python 客户端。一行代码接入 BSC 代币数据:基本行情、持仓结构、安全审计、持有人、社交信息、聪明钱动向。
|
|
17
|
+
|
|
18
|
+
**计费透明**:每次调用都会返回剩余次数与本次扣次明细,余额一眼可见。
|
|
19
|
+
|
|
20
|
+
## 安装
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install tgtc-sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
需要先创建 API Key(TGTC Bot 个人中心 → 我的 API)。
|
|
27
|
+
|
|
28
|
+
## 快速开始
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from tgtc import TGTC
|
|
32
|
+
|
|
33
|
+
client = TGTC(api_key="你的 API Key")
|
|
34
|
+
|
|
35
|
+
# 代币聚合查询(默认返回完整产品类别)
|
|
36
|
+
res = client.token("0x...合约地址")
|
|
37
|
+
|
|
38
|
+
print(res.symbol) # 代币符号
|
|
39
|
+
print(res.price) # 当前价格
|
|
40
|
+
print(res.remaining) # 剩余调用次数
|
|
41
|
+
print(res.used) # 本次扣次
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 按类别/字段查询
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
# 只要行情 + 安全审计,扣次更少
|
|
48
|
+
res = client.token(ca, categories=["basic", "security"])
|
|
49
|
+
|
|
50
|
+
# 精确字段裁剪(与 categories 二选一)
|
|
51
|
+
res = client.token(ca, fields=["symbol", "price", "honeypot", "buy_tax"])
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
可选类别:`basic`(基本行情)/ `structure`(持仓结构)/ `holders`(持有人)/ `security`(安全审计)/ `social`(社交信息)/ `traders`(聪明钱动向)。
|
|
55
|
+
|
|
56
|
+
## 计费明细
|
|
57
|
+
|
|
58
|
+
| 字段 | 说明 |
|
|
59
|
+
| --- | --- |
|
|
60
|
+
| `remaining` | 剩余调用次数 |
|
|
61
|
+
| `used` | 本次扣次(缓存命中为 0) |
|
|
62
|
+
| `cache_hit` | 是否命中缓存(命中不扣次) |
|
|
63
|
+
| `delay_sec` | 数据新鲜度(0 = 实时) |
|
|
64
|
+
|
|
65
|
+
## 错误处理
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from tgtc import TGTCError, TGTCQuotaError, TGTCAuthError
|
|
69
|
+
|
|
70
|
+
try:
|
|
71
|
+
res = client.token(ca)
|
|
72
|
+
except TGTCAuthError:
|
|
73
|
+
print("API Key 无效")
|
|
74
|
+
except TGTCQuotaError:
|
|
75
|
+
print("调用次数不足,请充值")
|
|
76
|
+
except TGTCError as e:
|
|
77
|
+
print("请求失败:", e)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
| 异常 | 触发条件 |
|
|
81
|
+
| --- | --- |
|
|
82
|
+
| `TGTCAuthError` | API Key 缺失或无效 |
|
|
83
|
+
| `TGTCParamError` | 参数错误(CA 格式/类别组合) |
|
|
84
|
+
| `TGTCNotFoundError` | 代币数据不存在 |
|
|
85
|
+
| `TGTCQuotaError` | 调用次数不足 |
|
|
86
|
+
| `TGTCUnavailableError` | 服务初始化或维护中 |
|
|
87
|
+
|
|
88
|
+
## 路线图
|
|
89
|
+
|
|
90
|
+
- [x] token:代币聚合查询
|
|
91
|
+
- [ ] token/trending + token/hot:榜单
|
|
92
|
+
- [ ] twitter:推特检测/舆情
|
|
93
|
+
- [ ] track:交易流
|
|
94
|
+
- [ ] market:信号流
|
|
95
|
+
- [ ] wallet:钱包分析
|
|
96
|
+
- [ ] translate:翻译
|
|
97
|
+
|
|
98
|
+
## 文档
|
|
99
|
+
|
|
100
|
+
完整接口文档见 [TGTC API Docs](https://github.com/TGTC-Suiyoung/tgtc-api-docs)。
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
tgtc/__init__.py
|
|
5
|
+
tgtc/client.py
|
|
6
|
+
tgtc/errors.py
|
|
7
|
+
tgtc/models.py
|
|
8
|
+
tgtc_sdk.egg-info/PKG-INFO
|
|
9
|
+
tgtc_sdk.egg-info/SOURCES.txt
|
|
10
|
+
tgtc_sdk.egg-info/dependency_links.txt
|
|
11
|
+
tgtc_sdk.egg-info/requires.txt
|
|
12
|
+
tgtc_sdk.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests>=2.25
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tgtc
|