enable different response format #123#124
Open
FrenchCommando wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes order-preview/place APIs in pyetrade.order.ETradeOrder so that the caller-provided resp_format (e.g., "json") is no longer ignored and is forwarded into the shared perform_request parsing/serialization path.
Changes:
- Replaced hardcoded
"xml"arguments in several order methods withkwargs.get("resp_format", "xml"). - Added new unit tests asserting JSON responses are handled as JSON (not parsed through
xmltodict) whenresp_format="json"is provided.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
pyetrade/order.py |
Forwards resp_format from **kwargs into perform_request for preview/place equity flows. |
tests/test_order.py |
Adds tests validating JSON handling for several order endpoints when resp_format="json" is passed. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
555
to
+557
| payload = self.build_order_payload("PreviewOrderRequest", **kwargs) | ||
|
|
||
| return self.perform_request(self.session.post, api_url, payload, "xml") | ||
| return self.perform_request(self.session.post, api_url, payload, kwargs.get("resp_format", "xml")) |
Comment on lines
581
to
+583
| payload = self.build_order_payload("PreviewOrderRequest", **kwargs) | ||
|
|
||
| return self.perform_request(self.session.put, api_url, payload, "xml") | ||
| return self.perform_request(self.session.put, api_url, payload, kwargs.get("resp_format", "xml")) |
Comment on lines
626
to
+628
| payload = self.build_order_payload("PlaceOrderRequest", **kwargs) | ||
|
|
||
| return self.perform_request(self.session.post, api_url, payload, "xml") | ||
| return self.perform_request(self.session.post, api_url, payload, kwargs.get("resp_format", "xml")) |
Comment on lines
+678
to
679
| return self.perform_request(self.session.put, api_url, payload, kwargs.get("resp_format", "xml")) | ||
|
|
Comment on lines
+363
to
+368
| @patch("pyetrade.order.OAuth1Session") | ||
| def test_preview_equity_order_resp_format_json(self, MockOAuthSession): | ||
| """Test that preview_equity_order forwards resp_format='json' to perform_request""" | ||
| json_response = {"PreviewOrderResponse": {"PreviewIds": {"previewId": "321"}}} | ||
| MockOAuthSession().post().json.return_value = json_response | ||
| MockOAuthSession().post().text = json.dumps(json_response) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
the caller
Test plan