danpaquin / coinbasepro-python

The unofficial Python client for the Coinbase Pro API
MIT License
1.83k stars 731 forks source link

Time limited order does not work #349

Open Menox10 opened 5 years ago

Menox10 commented 5 years ago

command: b=auth_client.place_order(product_id='ETC-EUR', order_type='limit', side='buy', price='4.23', size='1', time_in_force='GTT', cancel_after='1min')

*** response


ValueError Traceback (most recent call last)

in () 5 size='1', 6 time_in_force='GTT', ----> 7 cancel_after='1min') /usr/local/lib/python2.7/dist-packages/cbpro-1.1.1-py2.7.egg/cbpro/authenticated _client.pyc in place_order(self, product_id, side, order_type, **kwargs) 236 if kwargs.get('cancel_after') is not None and \ 237 kwargs.get('tif') != 'GTT': --> 238 raise ValueError('May only specify a cancel period when time ' 239 'in_force is `GTT`') 240 if kwargs.get('post_only') is not None and kwargs.get('tif') in \ **ValueError: May only specify a cancel period when time in_force is `GTT`**
noah222 commented 5 years ago

The correct use is: time_in_force='GTT', cancel_after='min'

To cancel after 2 or 3 minutes use a timer in your loop and then send a cancel message after the elapsed time. If you are getting into the fine details of time and candles then it can be helpful to use public_client.get_time() in order to get the most accurate coinbase time and build a stopwatch from that.

Also I would highly recommend using a more recent version of python!

Menox10 commented 5 years ago

Thanks noah222 for your prompt reply and advise. I tried it with your suggestion but still it fails. Maybe my python version is too old. I will use my self timed cancel order function. This is also more flexible in the time you would like to wait.

Traceback (most recent call last): File "cbpro-basis.py", line 95, in order_id = limit_buy(coin,price,size) File "cbpro-basis.py", line 24, in limit_buy b=auth_client.place_order(product_id=coin,order_type='limit',side='buy',price=price,size=size,time_in_force='GTT',cancel_after='min') File "build/bdist.linux-armv7l/egg/cbpro/authenticated_client.py", line 238, in place_order ValueError: May only specify a cancel period when time in_force is GTT

mcardillo55 commented 3 years ago

This is very odd. You basically only get this error if you provide the cancel_after kwarg without also providing time_in_force='GTT'

I was not able to reproduce this on my end. I copied and pasted your call and it works on my end. Are you still seeing this issue?