Skip to content

Fize/mmtickerlab / sim-trade

sim-trade

Verified

A 股专用的确定性模拟交易系统。具备严格的数据真实性门禁、五档盘口真实撮合、T+1 规则、持仓盈亏计算及 SQLite 可审计流水账本。当用户需要进行模拟交易下单、模拟买入/卖出、查询模拟盘持仓、账户资产或重置模拟盘时触发(包含触发词:模拟买入, 模拟卖出, 模拟交易, 查持仓, 模拟盘, 交易账本, sim trade, paper trading)。

scripts/simtrade_core/fees.py

View on GitHub
from __future__ import annotations

from dataclasses import dataclass
from decimal import Decimal, ROUND_HALF_UP


TRANSFER_RATE = Decimal("0.00001")
STAMP_TAX_RATE = Decimal("0.0005")


def _fee_cents(gross_cents: int, rate: Decimal) -> int:
    return int((Decimal(gross_cents) * rate).quantize(Decimal("1"), rounding=ROUND_HALF_UP))


@dataclass(frozen=True)
class FeeConfig:
    commission_rate: Decimal
    minimum_commission_cents: int


@dataclass(frozen=True)
class FillFees:
    commission_cents: int
    transfer_fee_cents: int
    stamp_tax_cents: int

    @property
    def total_cents(self) -> int:
        return self.commission_cents + self.transfer_fee_cents + self.stamp_tax_cents


def cumulative_commission_cents(gross_cents: int, config: FeeConfig) -> int:
    if gross_cents <= 0:
        return 0
    return max(config.minimum_commission_cents, _fee_cents(gross_cents, config.commission_rate))


def fees_for_fill(
    side: str,
    fill_gross_cents: int,
    cumulative_gross_after_cents: int,
    commission_already_cents: int,
    config: FeeConfig,
) -> FillFees:
    target_commission = cumulative_commission_cents(cumulative_gross_after_cents, config)
    commission = max(0, target_commission - commission_already_cents)
    transfer = _fee_cents(fill_gross_cents, TRANSFER_RATE)
    stamp = _fee_cents(fill_gross_cents, STAMP_TAX_RATE) if side == "SELL" else 0
    return FillFees(commission, transfer, stamp)


def maximum_buy_reserve_cents(gross_cents: int, config: FeeConfig, *, prior_gross_cents: int = 0, prior_commission_cents: int = 0) -> int:
    commission = cumulative_commission_cents(prior_gross_cents + gross_cents, config) - prior_commission_cents
    return gross_cents + max(0, commission) + _fee_cents(gross_cents, TRANSFER_RATE)
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: 119kUpdated Claude CodeCodexVerifiedInstall
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: 119kUpdated Claude CodeCodexVerifiedInstall
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: 118kUpdated Claude CodeCodexVerifiedInstall
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: 118kUpdated Claude CodeCodexVerifiedInstall