Skip to content

fix: handle position display fields#88

Open
rupurt wants to merge 1 commit into
TexasCoding:mainfrom
rupurt:fix/filter-position-response-fields
Open

fix: handle position display fields#88
rupurt wants to merge 1 commit into
TexasCoding:mainfrom
rupurt:fix/filter-position-response-fields

Conversation

@rupurt

@rupurt rupurt commented Jun 26, 2026

Copy link
Copy Markdown

Summary

Adds support for ProjectX Gateway position payloads that include contractDisplayName and other additive fields.

Root Cause

search_open_positions() passed raw Gateway position payloads directly to Position(**pos). Gateway responses can include contractDisplayName, which was not modeled by the SDK and caused construction to fail when present.

Changes

  • Adds contractDisplayName to the Position model.
  • Adds contractDisplayName to the PositionResponse TypedDict.
  • Parses position responses through the modeled Position fields so unknown future Gateway fields do not crash the SDK.
  • Adds regression coverage for preserving contractDisplayName while ignoring an unknown Gateway field.

Scope

This PR is intentionally independent from the trade endpoint and trade response normalization PRs. It contains one commit on top of main and only touches position response handling.

Validation

  • uv run pytest tests/client/test_trading.py tests/client/test_trading_legacy.py tests/types/test_models.py tests/types/test_api_responses.py -q
  • uv run ruff check src/project_x_py/client/trading.py src/project_x_py/models.py src/project_x_py/types/api_responses.py tests/client/test_trading_legacy.py tests/types/test_models.py tests/types/test_api_responses.py
  • uv run ruff format --check src/project_x_py/client/trading.py src/project_x_py/models.py src/project_x_py/types/api_responses.py tests/client/test_trading_legacy.py tests/types/test_models.py tests/types/test_api_responses.py
  • uv run mypy src/project_x_py/client/trading.py src/project_x_py/models.py src/project_x_py/types/api_responses.py

@blurxy

blurxy commented Jul 9, 2026

Copy link
Copy Markdown

We hit this exact bug independently on 3.5.9: the ProjectX gateway returns additive fields (e.g. contractDisplayName) in position payloads, and Position(**payload) raises TypeError: unexpected keyword argument — which in a trading integration silently strips the broker-side stop from every entry (the add_stop_loss/list_positions path dies). Routing payloads through the modeled fields + ignoring unknowns (as this PR does) is the right fix and hardens against the next additive field too. +1 to merge. (We're working around it downstream by wrapping Position.__init__ to tolerate unknown kwargs.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants