We’re happy to help and we understand that you are encountering a 502 Bad Gateway error response when trying to push a buy order using the Create Order endpoint.
Upon checking the code snippet you have shared with us, what we can suggest to you is to utilize the order_configuration parameter and this is shown in the documentation which have several possible options such as: market_market_ioc, limit_limit_gtc, limit_limit_gtd, stop_limit_stop_limit_gtc, and stop_limit_stop_limit_gtd. Each order_configuration object corresponds to the order_type and time_in_force parameters that are in use for Coinbase Pro. For example, market_market_ioc corresponds to market order with Immediate or Cancel (ioc) policy for the lifetime of the order. Meaning, should your order fall under this category of market_market_ioc, your request body must only contain the parameters under this order_configuration: quote_size (required for BUY orders) and base_size (required for SELL orders).
Additionally, here is a forum post that is related to your concern. You might want to check it out. Aside from the forum post, you may visit this link to know more about order_configurations.
We hope this helps. If the issue still persists after utilizing the order_configuration objects, please don’t hesitate to reach back to us.
Hi @Shinyzack123! We understand that you are still having issues placing a BUY order. We are working with our team to check on this but we would like to ask if this is your first time placing an order using the Create Order endpoint? If not, were you able to successfully place an order before?
Once you send us the information requested above, we’ll work to quickly address your concern. We appreciate your patience and understanding. Have a nice day!
Hi @Shinyzack123! Thank you for your patience as we look into this. Based on the inputs we got from the relevant teams, we suggest that you try running your code again, but this time, please set a value to the parameter client_order_id (unique uuid for this order) instead of default. In addition, please note that we also found a forum post that could be helpful with your case scenario. We highly suggest that you try looking into this for reference, since the user provided a random client_order_id generator which you could also embed in your code.
Please do not hesitate to reply back to this thread if you still have queries/concerns. Thank you and have a great day!
Thank you so much for all the help, it works now, last question, for some reason this line
order_id = np.random.randint(2**63)
gives me an error when i run it in visual studio code, when i run it in google colab, it works fine. despite this my vsc is 64 bit so i shouldn’t be seeing an error.
Then i tried
order_id = np.random.randint(2**31)
and it ran telling me that i had insufficient funds which is true but i don’t know if that would give me the same result from the order api as the first sample of code (64 bit), can you confirm that it is okay if i use the second sample of code.
The client_order_id can be pretty much anything you want. Could use a random word generator if you wanted to. The important part is that the id is truly random. If you use an id that you’ve already used in the past, Coinbase will return the order that you placed in the past, and won’t create a new order.
With a 32 bit integer, you have 4,294,967,295 possible random numbers. With 64 bit you have 9,223,372,036,854,775,807. Both of these are very large, but technically using 64 bit would have a lower chance of generating the same number twice. If you want to be extra safe you could generate multiple integers and concatenate them together as strings. You could also look into UUIDs. UUIDv4 is generally pretty easy to implement and will give you a 128 bit id, which is practically impossible to accidentally duplicate.
At the end of the day, there’s no security risk here or anything. The client id is mostly for your own organizational purposes. Using 32 bit ints is totally okay. You will get the same results as with 64 bit ints.