Codex skill for writing and reviewing PTrade strategy code with strict order, position, price-basis, logging, and static-check rules.
- PTrade order submission rules:
- use
order(stock, amount, limit_price=price) - avoid liquidation through
order_target_value(stock, 0)ororder_target(stock, 0) - use negative
amountfor sells - round quantities to board lots
- validate price, quantity, cash, and sellable/current position before submitting
- use
- Price-basis rules:
- signal calculations may use adjusted prices
- PTrade execution and position cost use raw trading price basis
- never compare adjusted
close/high/atrdirectly with real position cost - cost-based stop loss, trailing drawdown, return, and ATR stop width must use one consistent price basis
- Logging rules:
- use
提交买入/提交卖出for submitted orders - avoid filled wording unless fill is confirmed
- distinguish
refsignal/reference price fromcostactual position cost
- use
- PTrade environment rules:
- keep strategy code single-file unless the environment supports imports
- avoid local filesystem, network, and unsupported packages
- treat
get_snapshot()as live/simulation-only unless a backtest probe proves support - keep unstable fields such as turnover and circulating market cap optional unless freshly probed
Clone this repository into a Codex skills directory:
cd C:\Users\<you>\.codex\skills
git clone https://github.com/mnsgdhr/ptrade-code-standards.gitThen invoke it in Codex:
Use $ptrade-code-standards to write or review PTrade strategy code before delivery.
ptrade-code-standards/
├── SKILL.md
├── README.md
├── agents/
│ └── openai.yaml
└── scripts/
└── ptrade_static_check.py
Run the checker against a PTrade strategy file:
python .\scripts\ptrade_static_check.py --file <strategy.py>Block warnings as well:
python .\scripts\ptrade_static_check.py --file <strategy.py> --fail-on-warnAlso run Python syntax validation:
python -m py_compile <strategy.py>scripts/ptrade_static_check.py detects:
- forbidden imports such as
os,requests,subprocess,socket,pathlib,shutil,glob, andimportlib - old or suspicious
run_dailycall shape get_snapshot()usage warning for backtests- risky
order_target_valueusage in live/simulation code without pending-order guards - enabled turnover and circulating market-cap fields that may be unstable in PTrade
- logs that say
买入/卖出before order fill is confirmed - market-order style code without STAR board exclusion warning
- adjusted
row["close"],row["high"], orrow["atr20"]mixed with real position cost in return, stop loss, or drawdown logic
Bad pattern:
cost = get_position_cost(pos)
row = calc_indicators(get_daily_history(stock, 60, fields))
ret = row["close"] / cost - 1.0
high_price = max(info["high_price"], row["high"])Better pattern:
cost = get_position_cost(pos)
signal_row = calc_indicators(get_adjusted_daily_history(stock, 60, fields))
raw_row = calc_indicators(get_raw_daily_history(stock, 60, fields))
ret = raw_row["close"] / cost - 1.0
high_price = max(info["high_price"], raw_row["high"], raw_row["close"])
dif = signal_row["dif"]Current package validation:
quick_validate: pass
ptrade_static_check.py py_compile: pass
bad price-basis fixture: blocked with errors