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

[Bug]: currency changes introduced a bug with orders #274

Closed
2 tasks done
gageorsburn opened this issue Apr 20, 2023 · 2 comments · Fixed by #275
Closed
2 tasks done

[Bug]: currency changes introduced a bug with orders #274

gageorsburn opened this issue Apr 20, 2023 · 2 comments · Fixed by #275

Comments

@gageorsburn
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

    @validator("type")
    def order_type_must_be_market_for_lct(cls, value: OrderType) -> OrderType:
        """
        Order type must always be market if currency is not USD.
        See https://alpaca.markets/docs/broker/integration/lct/#submit-stock-trade
        """

        if cls.currency and value != OrderType.MARKET:
            raise ValueError(
                "Order type must be OrderType.MARKET if the order is in a local currency."
            )
        return value

cls refers to the class, which since this is a pydantic class does not have currency on it

class OrderRequest(BaseOrderRequest):
...
    commission: Optional[float]
    currency: Optional[SupportedCurrencies] = None  # None = USD

if you try to instantiate any order you get:

OrderRequest.order_type_must_be_market_for_lct(cls, value)
    676 breakpoint()
    677 print()
--> 679 if cls.currency and value != OrderType.MARKET:
    680     raise ValueError(
    681         "Order type must be OrderType.MARKET if the order is in a local currency."
    682     )
    683 return value

AttributeError: type object 'OrderRequest' has no attribute 'currency'

we can see this here:

(Pdb) cls
<class 'alpaca.broker.requests.OrderRequest'>
(Pdb) l
672             Order type must always be market if currency is not USD.
673             See https://alpaca.markets/docs/broker/integration/lct/#submit-stock-trade
674             """
675
676             breakpoint()
677  ->         print()
678
679             if cls.currency and value != OrderType.MARKET:
680                 raise ValueError(
681                     "Order type must be OrderType.MARKET if the order is in a local currency."
682                 )
(Pdb) cls
<class 'alpaca.broker.requests.OrderRequest'>
(Pdb) dir(cls)
['Config', '__abstractmethods__', '__annotations__', '__class__', '__class_vars__', '__config__', '__custom_root_type__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__exclude_fields__', '__fields__', '__fields_set__', '__format__', '__ge__', '__get_validators__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__include_fields__', '__init__', '__init_subclass__', '__iter__', '__json_encoder__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__post_root_validators__', '__pre_root_validators__', '__pretty__', '__private_attributes__', '__reduce__', '__reduce_ex__', '__repr__', '__repr_args__', '__repr_name__', '__repr_str__', '__schema_cache__', '__setattr__', '__setstate__', '__signature__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', '__try_update_forward_refs__', '__validators__', '_abc_impl', '_calculate_keys', '_copy_and_set_values', '_decompose_class', '_enforce_dict_if_root', '_get_value', '_init_private_attributes', '_iter', 'construct', 'copy', 'dict', 'from_orm', 'json', 'order_type_must_be_market_for_lct', 'parse_file', 'parse_obj', 'parse_raw', 'root_validator', 'schema', 'schema_json', 'to_request_fields', 'update_forward_refs', 'validate']

Expected Behavior

order object to be created

SDK Version I encountered this issue in

0.8.1

Steps To Reproduce

just try and create any order

Filled out the Steps to Reproduce section?

  • I have entered valid steps to reproduce my issue or have attached a minimally reproducible case in code that shows my issue happening; and understand that without this my issue will be flagged as invalid and closed after 30 days.

Anything else?

No response

@gageorsburn
Copy link
Contributor Author

you actually want to follow this example if you want to validate one field based on another:
https://docs.pydantic.dev/usage/validators/

    @validator('password2')
    def passwords_match(cls, v, values, **kwargs):
        if 'password1' in values and v != values['password1']:
            raise ValueError('passwords do not match')
        return v

haxdds added a commit that referenced this issue Jul 18, 2023
…dator

fixes issue #274 - can this get a review???????????????????????????
@haxdds
Copy link
Contributor

haxdds commented Jul 18, 2023

Follow here
#316

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 a pull request may close this issue.

3 participants