While testing the code for PR #119 an error was discovered that may affect both fiat_market_buy() and fiat_market_sell()
The following exception was raised when attempting a fiat_limit_buy() with the code from PR #119:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/app-root/lib64/python3.12/site-packages/coinbase_advancedtrade_python-0.4.0-py3.12.egg/coinbase_advanced_trader/enhanced_rest_client.py", line 164, in fiat_limit_buy
File "/opt/app-root/lib64/python3.12/site-packages/coinbase_advancedtrade_python-0.4.0-py3.12.egg/coinbase_advanced_trader/services/order_service.py", line 146, in fiat_limit_buy
File "/opt/app-root/lib64/python3.12/site-packages/coinbase_advancedtrade_python-0.4.0-py3.12.egg/coinbase_advanced_trader/services/order_service.py", line 213, in _place_limit_order
AttributeError: 'CreateOrderResponse' object has no attribute 'get'
Since the edits in #119 originally used the code from fiat_market_buy() as a basis, it is assumed that fiat_market_buy() and fiat_market_sell() will probably throw similar exceptions.
Possible cause: maybe Coinbase changed the return type of their order methods. Reference:
https://github.com/coinbase/coinbase-advanced-py/blob/master/coinbase/rest/orders.py
https://github.com/coinbase/coinbase-advanced-py/blob/master/coinbase/rest/types/orders_types.py
Potential Fix
A simple fix would be similar to what was added for #119 by using the to_dict() method to change order_response to a dictionary:
diff --git a/coinbase_advanced_trader/services/order_service.py b/coinbase_advanced_trader/services/order_service.py
index e3f5b5e..1e106b4 100644
--- a/coinbase_advanced_trader/services/order_service.py
+++ b/coinbase_advanced_trader/services/order_service.py
@@ -52,7 +52,7 @@ class OrderService:
self._generate_client_order_id(), product_id, fiat_amount
)
if not order_response['success']:
- error_response = order_response.get('error_response', {})
+ error_response = order_response.to_dict().get('error_response', {})
error_message = error_response.get('message', 'Unknown error')
preview_failure_reason = error_response.get('preview_failure_reason', 'Unknown')
error_log = (f"Failed to place a market buy order. "
@@ -103,7 +103,7 @@ class OrderService:
self._generate_client_order_id(), product_id, str(base_size)
)
if not order_response['success']:
- error_response = order_response.get('error_response', {})
+ error_response = order_response.to_dict().get('error_response', {})
error_message = error_response.get('message', 'Unknown error')
preview_failure_reason = error_response.get('preview_failure_reason', 'Unknown')
error_log = (f"Failed to place a market sell order. "
While testing the code for PR #119 an error was discovered that may affect both
fiat_market_buy()andfiat_market_sell()The following exception was raised when attempting a
fiat_limit_buy()with the code from PR #119:Since the edits in #119 originally used the code from
fiat_market_buy()as a basis, it is assumed thatfiat_market_buy()andfiat_market_sell()will probably throw similar exceptions.Possible cause: maybe Coinbase changed the return type of their order methods. Reference:
https://github.com/coinbase/coinbase-advanced-py/blob/master/coinbase/rest/orders.py
https://github.com/coinbase/coinbase-advanced-py/blob/master/coinbase/rest/types/orders_types.py
Potential Fix
A simple fix would be similar to what was added for #119 by using the
to_dict()method to changeorder_responseto a dictionary: