Uniqueness of ClientOrderID seems broken (causing bad retry behavior)

Hi,

Coinbase API used to ensure that ClientOrderID to OrderID mapping is unique, that is to say, if CreateOrder request is retried with the same ClientOrderID value, Coinbase used to return the same (previously created) OrderID.

This behavior now seems to be broken. I have the following data-point for verification in (ETH-USD):

$ tradebot exchange get-order 69c85a06-6fe1-4dd6-bd45-5af583563ddf
{
  "Error": "",
  "Order": {
    "ServerOrderID": "69c85a06-6fe1-4dd6-bd45-5af583563ddf",
    "ClientOrderID": "3146ad92-435a-fa77-6639-5fbcd48542d7",
    "CreateTime": "2023-12-06T20:53:57.554988Z",
    "Side": "BUY",
    "Status": "FILLED",
    "FilledFee": "1.6875",
    "FilledSize": "0.5",
    "FilledPrice": "2250",
    "Done": true,
    "DoneReason": ""
  }
}
$ tradebot exchange get-order "cd894693-0b3f-43be-94dc-8b530c165dde"
{
  "Error": "",
  "Order": {
    "ServerOrderID": "cd894693-0b3f-43be-94dc-8b530c165dde",
    "ClientOrderID": "3146ad92-435a-fa77-6639-5fbcd48542d7",
    "CreateTime": "2023-12-09T16:38:42.389748Z",
    "Side": "BUY",
    "Status": "CANCELLED",
    "FilledFee": "0",
    "FilledSize": "0",
    "FilledPrice": "0",
    "Done": true,
    "DoneReason": "CANCELLED"
  }
}

Notice that both orders have same ClientOrderID, but different server/coinbase order-ids. Can anyone from Coinbase please verify?

Thanks

1 Like

Your second order shows cancelled, did you manually cancel or it was canceled because of duplicated client order id?

1 Like

My bot most likely have cancelled the second order after the order is created.

However, 2nd order-id should not even be created in the first place. Coinbase used to return older order-id when client-order-id is reused.

1 Like

Is that guess or that actually did happen?

I understand that, but… You placed new order, so there is new order on other side (assuming you/bot did not cancel it). I think that would make more sense then returning existing order.

Anyway any change in behavior is not acceptable without some notice before actual change. So I do agree that it is problem… Basically all Advanced Trade API users are beta/alpha/preview testers… This API is simply not ready!

1 Like

Is that guess or that actually did happen?

Unfortunately, I don’t have the corresponding log to confirm, so it is a guess at this point.

When recovering from unexpected crashes, my bot does rely on retrying with previous client-order-ids and expecting Coinbase to return the same order-id associated for the client-order-id. I have tested and confirmed this behavior before – otherwise, we can’t guarantee exactly-once semantics anyway.

Since we have the two order-ids, coinbase should be able to confirm what is wrong.

1 Like

Here is another data point from BTC-USD product. Now I have two FILLED orders with same client-order-id:

$ tradebot exchange get-order 2f56fda1-2dbd-4c3b-a8de-42482b17ced7
{
  "Error": "",
  "Order": {
    "ServerOrderID": "2f56fda1-2dbd-4c3b-a8de-42482b17ced7",
    "ClientOrderID": "1c78822c-15ca-c4f2-4dac-7bd465733315",
    "CreateTime": "2023-12-05T18:42:09.917698Z",
    "Side": "BUY",
    "Status": "FILLED",
    "FilledFee": "2.1998195",
    "FilledSize": "0.02",
    "FilledPrice": "43996.39",
    "Done": true,
    "DoneReason": ""
  }
}
$ tradebot exchange get-order 291181c5-8062-4706-9c25-fdf81c5a3f6d
{
  "Error": "",
  "Order": {
    "ServerOrderID": "291181c5-8062-4706-9c25-fdf81c5a3f6d",
    "ClientOrderID": "1c78822c-15ca-c4f2-4dac-7bd465733315",
    "CreateTime": "2023-12-09T15:34:25.159989Z",
    "Side": "BUY",
    "Status": "FILLED",
    "FilledFee": "2.199247",
    "FilledSize": "0.02",
    "FilledPrice": "43984.94",
    "Done": true,
    "DoneReason": ""
  }
}
$

This effectively means, support for retries is completely broken.

2 Likes

Looks like they have updated description for client_order_id:

A unique ID provided by the client for their own identification purposes. This ID differs from the order_id generated for the order. If the ID provided is not unique, the order fails to be created and the order corresponding to that ID is returned.

This is clearly regression… @Loop_11 and/or @rishabh Is this already know problem?

1 Like

Thank you for the report. Our teams are investigating this.

1 Like

Great. Please let us know when the issue is fixed. I did shutdown my bot for ETH-USD and BTC-USD products – cause risk is too high. Thank you.

@bjeavons-cb Any update on this?

Hello @chai, I heard back from the team and learned that our documentation is incorrect about the purpose of client order ID. The purpose is to prevent accidental “double click” orders. We cache client order IDs for 24 hours but after then we do not guarantee uniqueness. There hasn’t been any change in this logic recently so I’m not sure why this was observed in error. We will update our documentation to make this clear. We still recommend unique client order IDs for all orders but please take the 24 hour window into account.

2 Likes

Then why is this field required? Make it optional…

1 Like

Thank you @bjeavons-cb

24h window makes sense. One cannot expect client order id unique-ness to hold forever. Please consider mentioning this 24h time-window-limit in the documentation. Thanks again.

1 Like