Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PTrade Code Standards Skill

Codex skill for writing and reviewing PTrade strategy code with strict order, position, price-basis, logging, and static-check rules.

What This Skill Covers

  • PTrade order submission rules:
    • use order(stock, amount, limit_price=price)
    • avoid liquidation through order_target_value(stock, 0) or order_target(stock, 0)
    • use negative amount for sells
    • round quantities to board lots
    • validate price, quantity, cash, and sellable/current position before submitting
  • Price-basis rules:
    • signal calculations may use adjusted prices
    • PTrade execution and position cost use raw trading price basis
    • never compare adjusted close/high/atr directly 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 ref signal/reference price from cost actual position cost
  • 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

Install

Clone this repository into a Codex skills directory:

cd C:\Users\<you>\.codex\skills
git clone https://github.com/mnsgdhr/ptrade-code-standards.git

Then invoke it in Codex:

Use $ptrade-code-standards to write or review PTrade strategy code before delivery.

Files

ptrade-code-standards/
├── SKILL.md
├── README.md
├── agents/
│   └── openai.yaml
└── scripts/
    └── ptrade_static_check.py

Static Check

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-warn

Also run Python syntax validation:

python -m py_compile <strategy.py>

Checks Implemented

scripts/ptrade_static_check.py detects:

  • forbidden imports such as os, requests, subprocess, socket, pathlib, shutil, glob, and importlib
  • old or suspicious run_daily call shape
  • get_snapshot() usage warning for backtests
  • risky order_target_value usage 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"], or row["atr20"] mixed with real position cost in return, stop loss, or drawdown logic

Price-Basis Example

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"]

Validation

Current package validation:

quick_validate: pass
ptrade_static_check.py py_compile: pass
bad price-basis fixture: blocked with errors

About

Codex skill for writing and reviewing PTrade strategy code with static checks

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages