cryptofeed icon indicating copy to clipboard operation
cryptofeed copied to clipboard

Improve handling of coinbase order responses

Open AlgoTrader5 opened this issue 4 years ago • 5 comments

The exchange will reject an order for various reasons. This will break on the order status function because the exchange response doesn't contain status key.

We can improve this for coinbase by handling responses that have a message key and updating the order status to failed

AlgoTrader5 avatar Oct 09 '19 00:10 AlgoTrader5

Sorry @AlgoTrader5 , its been a while since I reviewed the issues. Can you elaborate? It seems like you're telling me that if the response json has a specific key, I can take some action, but I'm not sure what the action is, and I'm not sure what the key is. I'm not sure what the issue is either. If you don't recall, I apologize for taking nearly 10 months to respond :(

bmoscon avatar Aug 01 '20 00:08 bmoscon

@bmoscon will add some info this week

AlgoTrader5 avatar Aug 03 '20 03:08 AlgoTrader5

@bmoscon

I'm able to successfully query my balances from coinbase. But when I attempt to place a market buy order (body = {'product_id': 'BTC-USDC', 'side': 'buy', 'size': '0.01', 'type': 'market'}) I am met with the following cryptofeed exception:

Traceback (most recent call last): File "create_rest_order.py", line 22, in resp = r.coinbase.place_order(symbol, side, order_type, amount, price, client_order_id, options) File "/usr/local/lib/python3.7/dist-packages/cryptofeed-1.5.1-py3.7.egg/cryptofeed/rest/coinbase.py", line 272, in place_order return Coinbase._order_status(resp.json()) File "/usr/local/lib/python3.7/dist-packages/cryptofeed-1.5.1-py3.7.egg/cryptofeed/rest/coinbase.py", line 40, in _order_status status = data['status'] KeyError: 'status'

The response from coinbase is {'message': 'invalid signature'} before it's passed to Coinbase._order_status(resp.json()) which it expects a status key.

The "invalid signature" message is weird because I am able to query balances fine. I was expecting to see the message to say something to the effect I don't have a USDC balance.

I think Coinbase will send data with "message" key if the order failed but can test other scenarios after I get through this invalid signature error.

AlgoTrader5 avatar Aug 04 '20 00:08 AlgoTrader5

@AlgoTrader5 I tweaked the order message handling so if the message is missing a status it will raise a new exception type with the contents of the message. Let me know if this helps and what you get once you're passed your other error and we can improve this further

bmoscon avatar Aug 18 '20 23:08 bmoscon

Adding more info to this. Current issue is when placing an order to coinbase via REST I am getting invalid signature. I am able to query balances, orders and trade history just fine.

The API keys are set up to view/trade/transfer so I don't think its an issue of permissioning. Version 1.6.0

///////////////////////////////////////////////////////////////

response = r.coinbase.place_order(symbol="BTC-USD", side=BUY, order_type=LIMIT, amount=Decimal("0.01"), price=13000, client_order_id=None, options=None) print(response)

///////////////////////////////////////////////////////////////

:~/repos/source/testing$ python testCryptofeedRest.py Traceback (most recent call last): File "testCryptofeedRest.py", line 23, in options=None) File "/usr/local/lib/python3.7/dist-packages/cryptofeed-1.6.0-py3.7.egg/cryptofeed/rest/coinbase.py", line 272, in place_order return Coinbase._order_status(resp.json()) File "/usr/local/lib/python3.7/dist-packages/cryptofeed-1.6.0-py3.7.egg/cryptofeed/rest/coinbase.py", line 42, in _order_status raise UnexpectedMessage(f"Message from exchange: {data}") cryptofeed.rest.exceptions.UnexpectedMessage: Message from exchange: {'message': 'invalid signature'}

AlgoTrader5 avatar Nov 03 '20 16:11 AlgoTrader5