danpaquin / coinbasepro-python

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

Fix creation of stop orders #370

Closed JonasSteur closed 3 years ago

JonasSteur commented 4 years ago

Related issue: https://github.com/danpaquin/coinbasepro-python/issues/368

A 'stop' isn't an actual order type but is actually a special flavour of a limit order. The 'stop' and 'stop_price' params need to be set.

There are 2 stop types:

  1. loss (triggers at or below the stop price) -> this has to be a sell order to be valid (the Coinbase Pro will respond with an error otherwise)
  2. entry (trigger at or above the stop price) -> has to be a buy

Modified existing test and added new test to check for invalid combinations.

jacov commented 3 years ago

i was able to work around this using the regular .sell with limit function and adding the stop and stop_price args as follows:

    response = auth_client.sell(price=str(LIMIT_PRICE),
                    size=str(QTY),
                    order_type='limit',
                    stop='loss',
                    stop_price=str(LIMIT_PRICE),
                    product_id=str(SYMBOLUSD))
mcardillo55 commented 3 years ago

This looks great! Just one minor thing - in the assert r['stop_price]' line in the test, I'm getting '100' back from the sandbox, not '100.00000000'. Perhaps this behavior has changed since your PR? Is this what you get now as well? I'd like to merge this with a passing test. Thanks!

bryanminorphd commented 3 years ago

@jacov - So you set the 'price' and 'stop_price' to the desired Stop loss price? Since the Stop_Loss prices is typically below the current price, this will not be a problem with this Limit price?

Since you used the 'LIMIT_PRICE' for both 'price and 'stop_price' I was concerned.

mcardillo55 commented 3 years ago

Made a few minor changes to get the merge in. Thanks again.