Fize/mmtickerlab / sim-trade
sim-trade
VerifiedA 股专用的确定性模拟交易系统。具备严格的数据真实性门禁、五档盘口真实撮合、T+1 规则、持仓盈亏计算及 SQLite 可审计流水账本。当用户需要进行模拟交易下单、模拟买入/卖出、查询模拟盘持仓、账户资产或重置模拟盘时触发(包含触发词:模拟买入, 模拟卖出, 模拟交易, 查持仓, 模拟盘, 交易账本, sim trade, paper trading)。
| File | Kind | Size |
|---|---|---|
| .clawhubignore | other | 63 B |
| SKILL.md | skill md | 2.5 KB |
| agents/openai.yaml | config | 258 B |
| references/command_reference.md | markdown | 1.4 KB |
| references/data_contract.md | markdown | 2.9 KB |
| references/trading_rules.md | markdown | 2.3 KB |
| requirements.txt | manifest | 101 B |
| scripts/akshare_patch.py | script | 2.9 KB |
| scripts/simtrade.py | script | 10.0 KB |
| scripts/simtrade_core/__init__.py | script | 105 B |
| scripts/simtrade_core/database.py | script | 6.4 KB |
| scripts/simtrade_core/fees.py | script | 1.7 KB |
| scripts/simtrade_core/market_data.py | script | 9.5 KB |
| scripts/simtrade_core/models.py | script | 5.1 KB |
| scripts/simtrade_core/rules.py | script | 3.5 KB |
| scripts/simtrade_core/service.py | script | 39.4 KB |
| scripts/simtrade_core/trading_calendar.py | script | 4.1 KB |
| tests/test_live_data.py | script | 667 B |
| tests/test_simtrade.py | script | 10.4 KB |
scripts/simtrade_core/trading_calendar.py
View on GitHubfrom __future__ import annotations
import sqlite3
from datetime import date, datetime
from typing import Iterable, Protocol
from zoneinfo import ZoneInfo
from .database import Database
from .market_data import fetch_trade_dates
from .models import DataUnavailable
TZ = ZoneInfo("Asia/Shanghai")
class CalendarProvider(Protocol):
def is_trading_day(self, day: date) -> bool: ...
def next_trading_day(self, day: date) -> date: ...
def latest_trading_day(self, day: date) -> date: ...
class TradingCalendar:
def __init__(self, database: Database):
self.database = database
def refresh(self) -> int:
days = fetch_trade_dates()
fetched_at = datetime.now(TZ).isoformat()
with self.database.transaction() as connection:
connection.executemany(
"INSERT OR REPLACE INTO trading_calendar(trade_date,source,fetched_at) VALUES(?,?,?)",
((day.isoformat(), "AKShare.tool_trade_date_hist_sina", fetched_at) for day in days),
)
return len(days)
def _ensure(self, day: date, *, need_future: bool = False) -> None:
with self.database.connect() as connection:
exact = connection.execute("SELECT 1 FROM trading_calendar WHERE trade_date=?", (day.isoformat(),)).fetchone()
future = connection.execute(
"SELECT 1 FROM trading_calendar WHERE trade_date>? LIMIT 1", (day.isoformat(),)
).fetchone()
count = connection.execute("SELECT COUNT(*) AS n FROM trading_calendar").fetchone()["n"]
if count == 0 or (need_future and future is None):
self.refresh()
elif exact is None:
# A populated calendar can safely identify a closed day only when it spans both sides.
with self.database.connect() as connection:
before = connection.execute("SELECT 1 FROM trading_calendar WHERE trade_date<? LIMIT 1", (day.isoformat(),)).fetchone()
after = connection.execute("SELECT 1 FROM trading_calendar WHERE trade_date>? LIMIT 1", (day.isoformat(),)).fetchone()
if before is None or after is None:
self.refresh()
def is_trading_day(self, day: date) -> bool:
self._ensure(day)
with self.database.connect() as connection:
return connection.execute("SELECT 1 FROM trading_calendar WHERE trade_date=?", (day.isoformat(),)).fetchone() is not None
def next_trading_day(self, day: date) -> date:
self._ensure(day, need_future=True)
with self.database.connect() as connection:
row = connection.execute(
"SELECT trade_date FROM trading_calendar WHERE trade_date>? ORDER BY trade_date LIMIT 1",
(day.isoformat(),),
).fetchone()
if row is None:
raise DataUnavailable(f"交易日历无法确定 {day} 的下一交易日")
return date.fromisoformat(row["trade_date"])
def latest_trading_day(self, day: date) -> date:
self._ensure(day)
with self.database.connect() as connection:
row = connection.execute(
"SELECT trade_date FROM trading_calendar WHERE trade_date<=? ORDER BY trade_date DESC LIMIT 1",
(day.isoformat(),),
).fetchone()
if row is None:
raise DataUnavailable(f"交易日历无法确定 {day} 之前的最近交易日")
return date.fromisoformat(row["trade_date"])
class StaticCalendar:
"""Deterministic calendar for isolated tests."""
def __init__(self, days: Iterable[date]):
self.days = tuple(sorted(set(days)))
def is_trading_day(self, day: date) -> bool:
return day in self.days
def next_trading_day(self, day: date) -> date:
for candidate in self.days:
if candidate > day:
return candidate
raise DataUnavailable(f"测试日历缺少 {day} 的下一交易日")
def latest_trading_day(self, day: date) -> date:
candidates = [candidate for candidate in self.days if candidate <= day]
if not candidates:
raise DataUnavailable(f"测试日历缺少 {day} 之前的交易日")
return candidates[-1]
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| deprecation-and-migrationaddyosmani/agent-skillsManages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| performance-optimizationaddyosmani/agent-skillsOptimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |
| agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |