Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix position_intent for mleg order #557

Merged
merged 2 commits into from
Feb 4, 2025

Conversation

hiohiohio
Copy link
Contributor

Context:

  • TradingStream.subscribe_trade_updates() causes a validation error for MLeg(multi-leg) orders
  • position_intent of order in trade_updates is empty string ("")
ERROR:alpaca.trading.stream:error during websocket communication: 1 validation error for TradeUpdate
order.position_intent
  Input should be 'buy_to_open', 'buy_to_close', 'sell_to_open' or 'sell_to_close' [type=enum, input_value='', input_type=str]
    For further information visit https://errors.pydantic.dev/2.10/v/enum
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/dist-packages/alpaca/trading/stream.py", line 173, in _run_forever
    await self._consume()
  File "/usr/local/lib/python3.11/dist-packages/alpaca/trading/stream.py", line 146, in _consume
    await self._dispatch(msg)
  File "/usr/local/lib/python3.11/dist-packages/alpaca/trading/stream.py", line 90, in _dispatch
    await self._trade_updates_handler(self._cast(msg))
                                      ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/alpaca/trading/stream.py", line 104, in _cast
    result = TradeUpdate(**msg.get("data"))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/pydantic/main.py", line 214, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for TradeUpdate
order.position_intent
  Input should be 'buy_to_open', 'buy_to_close', 'sell_to_open' or 'sell_to_close' [type=enum, input_value='', input_type=str]
    For further information visit https://errors.pydantic.dev/2.10/v/enum

Changes:

  • allow position_intent to be empty string

Copy link
Contributor

@matebudai matebudai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@hiohiohio hiohiohio merged commit 644c5de into master Feb 4, 2025
12 checks passed
@hiohiohio hiohiohio deleted the fix-mleg-order-position-intent branch February 4, 2025 11:12
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