Skip to content

enable different response format #123#124

Open
FrenchCommando wants to merge 1 commit into
jessecooper:masterfrom
FrenchCommando:order-resp-format-123
Open

enable different response format #123#124
FrenchCommando wants to merge 1 commit into
jessecooper:masterfrom
FrenchCommando:order-resp-format-123

Conversation

@FrenchCommando
Copy link
Copy Markdown

Summary

  • preview_equity_order, change_preview_equity_order, place_equity_order, and place_changed_equity_order hardcoded "xml" in their perform_request calls, ignoring the resp_format kwarg passed by
    the caller
  • Replaced the hardcoded "xml" with kwargs.get("resp_format", "xml") so the parameter is properly forwarded
  • place_option_order and place_changed_option_order also inherit the fix since they delegate via **kwargs

Test plan

  • Added 4 new tests that call each fixed method with resp_format="json", mock the session to return JSON, and assert the response is parsed as JSON (not piped through xmltodict)
  • All 11 tests pass

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 with kwargs.get("resp_format", "xml").
  • Added new unit tests asserting JSON responses are handled as JSON (not parsed through xmltodict) when resp_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 thread pyetrade/order.py
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 thread pyetrade/order.py
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 thread pyetrade/order.py
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 thread pyetrade/order.py
Comment on lines +678 to 679
return self.perform_request(self.session.put, api_url, payload, kwargs.get("resp_format", "xml"))

Comment thread tests/test_order.py
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)
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