feat: add examples (01-08), fix index bars parsing, add ruff hook

- Add example scripts for all API categories (connection, market info,
  kline, minute, transaction, finance, block, fund flow)
- Fix GetIndexBarsCmd: index bar records have 4 extra bytes (advance/
  decline counts) that were not consumed, causing pos drift and
  corrupted dates/volumes for all records after the first
- Fix price_limits.py example (SecurityQuote has no name attr)
- Fix finance_info.py display (scientific notation -> formatted numbers)
- Add PostToolUse ruff hook (scripts/ruff_hook.py)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
GitHub
2026-05-21 18:36:50 +08:00
co-authored by Claude Opus 4.7
parent ace1099ab0
commit 7fd6e610cf
27 changed files with 735 additions and 47 deletions
+43
View File
@@ -0,0 +1,43 @@
"""PostToolUse hook: 对 Edit/Write 修改的 .py 文件自动运行 ruff check + format。
stdin 接收 JSON: {"tool_name": "Edit"|"Write", "tool_input": {"file_path": "..."}}
"""
import json
import subprocess
import sys
def main():
try:
data = json.load(sys.stdin)
except (json.JSONDecodeError, EOFError):
return
file_path = data.get("tool_input", {}).get("file_path", "")
if not file_path.endswith(".py"):
return
# ruff check --fix(自动修复 lint 问题)
r = subprocess.run(
["ruff", "check", "--fix", file_path],
capture_output=True,
text=True,
timeout=15,
)
if r.returncode != 0 and r.stdout.strip():
print(f"[ruff check] {file_path}:\n{r.stdout.strip()}")
# ruff format
r = subprocess.run(
["ruff", "format", file_path],
capture_output=True,
text=True,
timeout=15,
)
if r.returncode != 0 and r.stdout.strip():
print(f"[ruff format] {file_path}:\n{r.stdout.strip()}")
if __name__ == "__main__":
main()