Skip to content

fix: preserve gateway trade commissions & normalize trade response fields#87

Open
rupurt wants to merge 1 commit into
TexasCoding:mainfrom
rupurt:codex/normalize-trade-response-fields
Open

fix: preserve gateway trade commissions & normalize trade response fields#87
rupurt wants to merge 1 commit into
TexasCoding:mainfrom
rupurt:codex/normalize-trade-response-fields

Conversation

@rupurt

@rupurt rupurt commented Jun 26, 2026

Copy link
Copy Markdown

Summary

Makes search_trades() resilient to Gateway trade payload variants while preserving Gateway commission data.

Root Cause

Some Gateway trade search responses return commissions instead of fees, and may include additional fields not accepted by the SDK Trade model. Passing the raw payload directly to Trade(**trade) can raise TypeError, and mapping commissions only into fees would hide a Gateway field callers may need.

Changes

  • Adds optional Trade.commissions.
  • Adds optional commissions to TradeResponse.
  • Keeps existing fees compatibility by populating fees from commissions when fees is absent.
  • Ignores unknown future response fields that are not part of the Trade model.
  • Adds regression coverage for preserving Gateway commissions.

Scope

This PR is trade response normalization and model support only. It does not change the trade search endpoint or position response handling.

Related PRs:

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

@rupurt rupurt changed the title [codex] Normalize trade response fields Normalize trade response fields Jun 26, 2026
@rupurt rupurt marked this pull request as ready for review June 26, 2026 06:57
@rupurt rupurt force-pushed the codex/normalize-trade-response-fields branch from 757b1f0 to c467261 Compare June 26, 2026 17:08
@rupurt rupurt changed the title Normalize trade response fields fix: preserve gateway trade commissions & normalize trade response fields Jun 26, 2026
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.

1 participant