mirror of
https://ghfast.top/https://github.com/aeroxw/easy-tdx.git
synced 2026-09-12 15:44:15 +08:00
feat: merge datetime fields in DataFrame output, hide MinuteBar internal fields
- K-line: daily+ periods output 'date' only, minute periods output 'datetime' - Transactions (tick-by-tick): combine date param + hour/minute into 'datetime' - XdxrRecord, HistoricalFundFlow: year/month/day merged to 'date' - MinuteBar: rename unknown_1 to _unknown_1 (hidden from DataFrame) - MinuteBar: add datetime column computed from bar index (A-share 240-bar pattern) - get_minute_time_data: use history endpoint only (current-day endpoint broken in pytdx too) - Update all examples to reflect new DataFrame column names
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
"""演示:获取公司信息目录与各个分类的详细内容。"""
|
||||
|
||||
import pandas as pd
|
||||
from easy_tdx import TdxClient, Market
|
||||
from easy_tdx import Market, TdxClient
|
||||
|
||||
CODE = "600519"
|
||||
NAME = "贵州茅台"
|
||||
@@ -28,51 +27,36 @@ SHOW_CATEGORIES = [
|
||||
]
|
||||
|
||||
|
||||
def show_categories(categories):
|
||||
"""显示公司信息目录。"""
|
||||
df = pd.DataFrame([{
|
||||
"目录名": cat.name,
|
||||
"文件名": cat.filename,
|
||||
"起始偏移": cat.start,
|
||||
"内容长度": cat.length,
|
||||
} for cat in categories])
|
||||
print(f"{NAME} 公司信息目录:")
|
||||
print(df.to_string(index=False))
|
||||
|
||||
|
||||
def show_category_content(client, categories, category_name, max_chars=500):
|
||||
"""获取并展示指定分类的内容。"""
|
||||
cat = next((c for c in categories if c.name == category_name), None)
|
||||
if not cat:
|
||||
row = categories[categories["name"] == category_name]
|
||||
if row.empty:
|
||||
print(f" 未找到分类: {category_name}")
|
||||
return
|
||||
|
||||
r = row.iloc[0]
|
||||
content = client.get_company_info_content(
|
||||
MARKET, CODE, cat.filename, cat.start, cat.length
|
||||
MARKET, CODE, r["filename"], int(r["start"]), int(r["length"])
|
||||
)
|
||||
text = content.strip()
|
||||
if len(text) > max_chars:
|
||||
text = text[:max_chars] + f"\n... (共 {len(content.strip())} 字,仅显示前 {max_chars} 字)"
|
||||
print(f"\n{'='*60}")
|
||||
print(f"【{cat.name}】 (共 {cat.length} 字节)")
|
||||
print(f"{'='*60}")
|
||||
print(f"\n{'=' * 60}")
|
||||
print(f"【{r['name']}】 (共 {r['length']} 字节)")
|
||||
print(f"{'=' * 60}")
|
||||
print(text)
|
||||
|
||||
|
||||
def show_all_categories(client, categories):
|
||||
"""依次展示所有 SHOW_CATEGORIES 中列出的分类内容。"""
|
||||
for name in SHOW_CATEGORIES:
|
||||
show_category_content(client, categories, name)
|
||||
|
||||
|
||||
with TdxClient.from_best_host() as c:
|
||||
categories = c.get_company_info_category(MARKET, CODE)
|
||||
|
||||
# 1. 显示目录
|
||||
show_categories(categories)
|
||||
print(f"{NAME} 公司信息目录:")
|
||||
print(categories.to_string(index=False))
|
||||
|
||||
# 2. 显示所有分类内容(每个分类默认只显示前500字)
|
||||
show_all_categories(c, categories)
|
||||
for name in SHOW_CATEGORIES:
|
||||
show_category_content(c, categories, name)
|
||||
|
||||
# 3. 也可以单独获取某个分类的完整内容,例如:
|
||||
# show_category_content(c, categories, "公司概况", max_chars=99999)
|
||||
|
||||
@@ -1,21 +1,8 @@
|
||||
"""演示:获取最新财务数据。"""
|
||||
|
||||
import pandas as pd
|
||||
from easy_tdx import TdxClient, Market
|
||||
from easy_tdx import Market, TdxClient
|
||||
|
||||
with TdxClient.from_best_host() as c:
|
||||
info = c.get_finance_info(Market.SH, "600519")
|
||||
df = pd.DataFrame([
|
||||
{"项目": "总股本(万股)", "数值": info.zong_guben},
|
||||
{"项目": "流通股本(万股)", "数值": info.liutong_guben},
|
||||
{"项目": "每股净资产", "数值": info.meigujing_zichan},
|
||||
{"项目": "净利润(元)", "数值": info.jing_lirun},
|
||||
{"项目": "主营收入(元)", "数值": info.zhuying_shouru},
|
||||
{"项目": "主营利润(元)", "数值": info.zhuying_lirun},
|
||||
{"项目": "净资产(元)", "数值": info.jing_zichan},
|
||||
{"项目": "总资产(元)", "数值": info.zong_zichan},
|
||||
{"项目": "股东人数", "数值": info.gudong_renshu},
|
||||
{"项目": "上市日期", "数值": info.ipo_date},
|
||||
])
|
||||
print("贵州茅台 最新财务数据:")
|
||||
print(df.to_string(index=False, formatters={"数值": lambda x: f"{x:,.0f}"}))
|
||||
print(info.T.to_string(header=False))
|
||||
|
||||
@@ -1,23 +1,16 @@
|
||||
"""演示:计算个股涨跌停价格。"""
|
||||
|
||||
import pandas as pd
|
||||
from easy_tdx import TdxClient, Market
|
||||
from easy_tdx import Market, TdxClient
|
||||
|
||||
CODE = "600519"
|
||||
NAME = "贵州茅台"
|
||||
|
||||
with TdxClient.from_best_host() as c:
|
||||
quotes = c.get_security_quotes([(Market.SH, CODE)])
|
||||
if quotes:
|
||||
q = quotes[0]
|
||||
limit_up, limit_down = c.get_price_limits(
|
||||
Market.SH, CODE, NAME, q.pre_close
|
||||
)
|
||||
df = pd.DataFrame([{
|
||||
"代码": CODE,
|
||||
"名称": NAME,
|
||||
"昨收": q.pre_close,
|
||||
"涨停价": limit_up,
|
||||
"跌停价": limit_down,
|
||||
}])
|
||||
print(df.to_string(index=False))
|
||||
if not quotes.empty:
|
||||
q = quotes.iloc[0]
|
||||
limit_up, limit_down = c.get_price_limits(Market.SH, CODE, NAME, q["pre_close"])
|
||||
print(f"代码: {CODE} 名称: {NAME}")
|
||||
print(f"昨收: {q['pre_close']}")
|
||||
print(f"涨停价: {limit_up}")
|
||||
print(f"跌停价: {limit_down}")
|
||||
|
||||
@@ -1,17 +1,8 @@
|
||||
"""演示:获取除权除息历史记录。"""
|
||||
|
||||
import pandas as pd
|
||||
from easy_tdx import TdxClient, Market, XDXR_CATEGORY_NAMES
|
||||
from easy_tdx import Market, TdxClient
|
||||
|
||||
with TdxClient.from_best_host() as c:
|
||||
records = c.get_xdxr_info(Market.SH, "600519")
|
||||
df = pd.DataFrame([{
|
||||
"日期": f"{r.year}-{r.month:02d}-{r.day:02d}",
|
||||
"类型": XDXR_CATEGORY_NAMES.get(r.category, f"未知({r.category})"),
|
||||
"每股分红(元)": r.fenhong,
|
||||
"送转股比例": r.songzhuangu,
|
||||
"配股价": r.peigujia,
|
||||
"配股比例": r.peigu,
|
||||
} for r in records])
|
||||
df = c.get_xdxr_info(Market.SH, "600519")
|
||||
print(f"贵州茅台 除权除息记录,共 {len(df)} 条:")
|
||||
print(df.tail(10).to_string(index=False))
|
||||
|
||||
Reference in New Issue
Block a user