feat(orders): add configurable per-symbol option price strategy#684
Open
junyuanz1 wants to merge 1 commit into
Open
feat(orders): add configurable per-symbol option price strategy#684junyuanz1 wants to merge 1 commit into
junyuanz1 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an opt-in, per-symbol configurable option order price strategy (midpoint/latest/bid/ask) with optional per-side adjustments, wiring it into the options engine’s limit-price creation while preserving existing fallback behavior when unset.
Changes:
- Introduces
sell_price/buy_priceand*_price_adjustmentat both global ([runtime.orders]) and per-symbol ([portfolio.symbols.<SYMBOL>]) levels. - Adds a centralized resolver (
Config.get_order_limit_price) and routes option order sites through it. - Updates documentation (
README.md,thetagang.toml) and adds a new unit test module for pricing resolution.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| thetagang/strategies/options_engine.py | Routes option limit-price calculation through the new config-driven resolver. |
| thetagang/config.py | Implements order limit price resolution logic and adds display of configured strategies. |
| thetagang/config_models.py | Extends config schema with global + per-symbol price strategy and adjustments. |
| thetagang.toml | Documents new runtime order pricing configuration options. |
| tests/test_order_pricing.py | Adds unit tests for price strategy resolution and adjustment floor behavior. |
| README.md | Documents global and per-symbol configuration examples and fallback behavior. |
Comment on lines
+611
to
+612
| if ib_util.isNan(price) or price < 0: | ||
| return fallback_price |
Comment on lines
+126
to
+129
| def test_global_price_adjustment_applies() -> None: | ||
| config = _config(orders={"sell_price": "ask", "sell_price_adjustment": -0.10}) | ||
| ticker = FakeTicker(ask=3.00) | ||
| assert config.get_order_limit_price("AAA", ticker, "SELL", 2.0) == 2.90 |
Add sell_price/buy_price (midpoint|latest|bid|ask) plus optional sell/buy price adjustments, configurable globally under [runtime.orders] and overridable per symbol under [portfolio.symbols.<SYMBOL>]. When unset, order pricing falls back to the existing midpoint/model-price behavior, so the feature is fully opt-in and backward compatible. This lets users quote less-liquid options off the bid/ask to capture more of the spread, at the cost of slower or missed fills. Wired into the options engine order sites (write puts/calls and close positions). Includes config display, TOML/README docs, and unit tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
junyuanz1
force-pushed
the
feat/per-symbol-price-strategy
branch
from
June 23, 2026 02:15
ea2ffc2 to
eb794c3
Compare
brndnmtthws
requested changes
Jun 24, 2026
| else: # pragma: no cover - guarded by the Literal type | ||
| return fallback_price | ||
|
|
||
| if ib_util.isNan(price) or price < 0: |
Owner
There was a problem hiding this comment.
One edge case: sell_price = "bid" can sneak under minimum_credit.
Example: midpoint 0.08 passes a 0.05 floor, but bid 0.01 becomes the submitted limit. Could we clamp opening sells to minimum_credit or fall back when the resolved price is below it?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in, per-symbol option price strategy so users can quote orders off the
midpoint,latest,bid, oraskinstead of the default midpoint/model price. Quoting off the bid/ask captures more of the spread on less-liquid options, at the cost of slower or missed fills.[runtime.orders]and overridable per symbol under[portfolio.symbols.<SYMBOL>].sell_price/buy_price(midpoint|latest|bid|ask) plus optionalsell_price_adjustment/buy_price_adjustmentoffsets.Backward compatibility
Fully backward compatible. When
sell_price/buy_priceare unset, each order site computes today's price (get_higher_price/get_lower_price) and passes it as a fallback; the resolver only overrides it when a strategy is explicitly configured and the chosen bid/ask/last is valid. If the chosen price is unavailable (NaN/negative), it falls back to the existing price. So existing configs behave exactly as before.Behavioral impact
write_calls,write_puts, and both branches ofclose_positions(buy-to-close / sell-to-close).post_engine.py) is intentionally left unchanged.MINIMUM_PRICE(0.01) floor prevents a negative adjustment from pushing the limit price to zero/negative.Config example
Tests / validation
uv run pytest→ 289 passed (incl. 11 new tests intests/test_order_pricing.pycovering bid/ask/midpoint/latest, adjustments, the MINIMUM_PRICE floor, NaN fallback, global default, and symbol-overrides-global).uv run ty check→ cleanuv run ruff check ./ruff format --check→ clean🤖 Generated with Claude Code