-
Notifications
You must be signed in to change notification settings - Fork 0
Add IBKR client helpers for bracket and OCA orders #6
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting
| def to_dict(self) -> Dict[str, Any]: | ||
| """Return a serializable payload of the ticket.""" | ||
|
|
||
| return { | ||
| "order_id": self.order_id, | ||
| "client_id": self.client_id, | ||
| "perm_id": self.perm_id, | ||
| "status": self.status, | ||
| "filled": self.filled, | ||
| "remaining": self.remaining, | ||
| "avg_fill_price": self.avg_fill_price, | ||
| "last_fill_price": self.last_fill_price, | ||
| "identifier": self.identifier, | ||
| "contract": self.contract.__dict__, | ||
| "order": self.order.__dict__, | ||
| "fills": [fill.__dict__ for fill in self.fills], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Serialize slotted models without relying on dict
OrderTicket.to_dict builds its payload with self.contract.__dict__, self.order.__dict__, and fill.__dict__, but every model in this module is declared with @dataclass(slots=True). Slotted dataclasses do not expose __dict__, so calling to_dict() raises AttributeError and the helper cannot be used. Consider using dataclasses.asdict or manually constructing dictionaries from the fields instead.
Useful? React with 👍 / 👎.
| contract_model = ( | ||
| ContractModel.from_ib(ticker.contract) | ||
| if getattr(ticker, "contract", None) | ||
| else ContractModel.from_ib(contract) | ||
| ) | ||
| return { | ||
| "contract": contract_model.__dict__, | ||
| "last": getattr(ticker, "last", None), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid dict when returning market-data contract payloads
In req_market_data the returned mapping uses contract_model.__dict__, but ContractModel was declared with slots=True so it lacks a __dict__ attribute. This call path will raise AttributeError before any market data is returned. Use dataclasses.asdict or construct the contract dictionary field by field to avoid the exception.
Useful? React with 👍 / 👎.
Summary
Testing
https://chatgpt.com/codex/tasks/task_e_68e7c68a59448321a395d92f930f4184