Skip to content

Commit 56ee084

Browse files
authored
Merge pull request #50 from QuantStrategyLab/codex/fractional-step-precision
Use four-decimal fractional quantity steps
2 parents 05103e0 + c148cb5 commit 56ee084

5 files changed

Lines changed: 9 additions & 8 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ The selected `ACCOUNT_GROUP` is now the runtime identity. Keep broker-specific i
104104
| `ACCOUNT_GROUP` | Yes | Account-group selector. Set explicitly for each deployment. |
105105
| `IBKR_FEATURE_SNAPSHOT_PATH` | Conditionally required | Required for snapshot-backed profiles such as `russell_1000_multi_factor_defensive`, `tech_communication_pullback_enhancement`, and `mega_cap_leader_rotation_top50_balanced`. Path to the latest feature snapshot file (`.csv`, `.json`, `.jsonl`, `.parquet`). |
106106
| `IBKR_FRACTIONAL_SHARES_ENABLED` | No | Defaults to `false`; set `true` only after verifying fractional order support for this account/API path. |
107-
| `IBKR_ORDER_QUANTITY_STEP` | No | Explicit order quantity step override; e.g. `1` for whole shares or `0.000001` for fractional sizing. Takes precedence over `IBKR_FRACTIONAL_SHARES_ENABLED`. |
107+
| `IBKR_ORDER_QUANTITY_STEP` | No | Explicit order quantity step override; e.g. `1` for whole shares or `0.0001` for fractional sizing. Takes precedence over `IBKR_FRACTIONAL_SHARES_ENABLED`. |
108108
| `IBKR_MIN_ORDER_NOTIONAL_USD` | No | Minimum buy notional for fractional sizing; defaults to `50.0`. |
109109
| `IB_ACCOUNT_GROUP_CONFIG_SECRET_NAME` | Yes for Cloud Run | Secret Manager secret name for account-group config JSON. Recommended production source. |
110110
| `IB_ACCOUNT_GROUP_CONFIG_JSON` | No | Local/dev JSON fallback for account-group config. Not recommended for production Cloud Run. |
@@ -162,7 +162,7 @@ IBKR_FEATURE_SNAPSHOT_MANIFEST_PATH=/var/manifests/tech_communication_pullback_e
162162
IBKR_DRY_RUN_ONLY=true
163163
# Keep whole-share sizing unless fractional API support has been verified for this account/API path.
164164
# IBKR_FRACTIONAL_SHARES_ENABLED=true
165-
# IBKR_ORDER_QUANTITY_STEP=0.000001
165+
# IBKR_ORDER_QUANTITY_STEP=0.0001
166166
GLOBAL_TELEGRAM_CHAT_ID=<telegram-chat-id>
167167
NOTIFY_LANG=zh
168168
```
@@ -351,7 +351,7 @@ IBKR 账户
351351
| `ACCOUNT_GROUP` || 账号组选择器,每个部署都要显式设置。 |
352352
| `IBKR_FEATURE_SNAPSHOT_PATH` | 条件必填 | `russell_1000_multi_factor_defensive``tech_communication_pullback_enhancement``mega_cap_leader_rotation_top50_balanced` 等快照策略需要。指向最新特征快照文件(`.csv``.json``.jsonl``.parquet`)。 |
353353
| `IBKR_FRACTIONAL_SHARES_ENABLED` || 默认 `false`;只有确认当前账户/API 路径支持碎股单后再设为 `true`|
354-
| `IBKR_ORDER_QUANTITY_STEP` || 显式覆盖下单数量步进;如 `1` 表示整数股,`0.000001` 表示碎股数量步进。优先级高于 `IBKR_FRACTIONAL_SHARES_ENABLED`|
354+
| `IBKR_ORDER_QUANTITY_STEP` || 显式覆盖下单数量步进;如 `1` 表示整数股,`0.0001` 表示碎股数量步进。优先级高于 `IBKR_FRACTIONAL_SHARES_ENABLED`|
355355
| `IBKR_MIN_ORDER_NOTIONAL_USD` || 碎股买入的最小名义金额;默认 `50.0`|
356356
| `IB_ACCOUNT_GROUP_CONFIG_SECRET_NAME` | Cloud Run 建议必填 | 账号组配置 JSON 在 Secret Manager 里的密钥名。生产环境推荐使用。 |
357357
| `IB_ACCOUNT_GROUP_CONFIG_JSON` || 本地开发用的账号组配置 JSON fallback。不建议在生产 Cloud Run 直接使用。 |

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
flask
22
gunicorn
3-
quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@08ed04ae9796f54a2218ffb700f97e0e33bf312f
4-
us-equity-strategies @ git+https://github.com/QuantStrategyLab/UsEquityStrategies.git@c9ec484c9a12cdffedf7d87c8906b93b21f50b1c
3+
quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@268171a74a1b522f03940af399f71c37e9a32c70
4+
us-equity-strategies @ git+https://github.com/QuantStrategyLab/UsEquityStrategies.git@47685bce6187b5e7d3f93bab72b72a7fc0d119d7
55
pandas
66
numpy
77
requests

runtime_config_support.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ def load_platform_runtime_settings(
144144
step_env="IBKR_ORDER_QUANTITY_STEP",
145145
fractional_env="IBKR_FRACTIONAL_SHARES_ENABLED",
146146
fractional_default=False,
147+
fractional_step=0.0001,
147148
),
148149
min_order_notional=resolve_float_env(
149150
os.environ,

tests/test_execution_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def fake_fetch_quote_snapshots(_ib, symbols):
168168
cash_reserve_ratio=0.0,
169169
rebalance_threshold_ratio=0.02,
170170
limit_buy_premium=1.005,
171-
quantity_step=0.000001,
171+
quantity_step=0.0001,
172172
min_order_notional=50.0,
173173
sell_settle_delay_sec=0,
174174
execution_lock_dir=tmp_path,
@@ -177,7 +177,7 @@ def fake_fetch_quote_snapshots(_ib, symbols):
177177

178178
assert summary["execution_status"] == "executed"
179179
assert len(submitted) == 1
180-
assert math.isclose(submitted[0].quantity, 0.298507, rel_tol=0.0, abs_tol=0.000001)
180+
assert math.isclose(submitted[0].quantity, 0.2985, rel_tol=0.0, abs_tol=1e-9)
181181

182182

183183
def test_execute_rebalance_zero_target_sell_uses_position_quantity(monkeypatch, tmp_path):

tests/test_runtime_config_support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def test_load_platform_runtime_settings_supports_fractional_quantity_step(monkey
148148

149149
settings = load_platform_runtime_settings(project_id_resolver=lambda: "project-1")
150150

151-
assert settings.quantity_step == 0.000001
151+
assert settings.quantity_step == 0.0001
152152
assert settings.min_order_notional == 5.0
153153

154154

0 commit comments

Comments
 (0)