With the advanced trade api, I’m getting an error with these parameters with the endpoint /api/v3/brokerage/orders:

With the advanced trade api, I’m getting an error with these parameters with the endpoint /api/v3/brokerage/orders:

uuid = str(uuid.uuid1())

{‘client_order_id’: uuid, ‘product_id’: ‘BTC-USDT’, ‘side’: ‘BUY’, ‘order_configuration’: {‘market_market_ioc’: {‘quote_size’: 43524}}}

or even this:

{‘client_order_id’: uuid, ‘product_id’: ‘BTC-USDT’, ‘side’: ‘SELL’, ‘order_configuration’: {‘market_market_ioc’: {‘base_size’: 1}}}

This is the result I’m getting:

{‘error’: ‘INVALID_ARGUMENT’, ‘error_details’: ‘Invalid product_id’, ‘message’: ‘Invalid product_id’}

I can get my balances and there is no issue. But I cannot place any orders.

I checked my API permissions and both create orders and read wallets are checked, and I tried different product IDs and still got the same response. I’m stumped.

1 Like

I’m getting the same error with the api/v3/brokerage/orders/preview endpoint as well. It’s driving me nuts, because I can only find one thread on it from last year here, and that fix did not work for me.

2 Likes

Here is what I use to generate a simple market order. I get an “unauthorized” error, no errors about the payload syntax. Pipe the output to a script and run the script. I pass three variables: the coin symbol (XLM-USD), the quantity to buy (44) and the client order ID (T5-test).

from coinbase import jwt_generator
import sys

symbol = sys.argv[1]
entryQ = sys.argv[2]
clientOID = sys.argv[3]
print(f":: symbol: {symbol} entryq: {entryQ} clientOID: {clientOID} ")
print()

data00 = ‘–data-raw ‘+"’"+’{“client_order_id”:“‘+clientOID+’”,“product_id”:“‘+symbol+’”,“side”:“BUY”,“order_configuration”:{“market_market_ioc”:{“quote_size”:“‘+entryQ+’”}}}‘+"’"
#print(f"raw data: {data00}")

#new trade key 2024-02-27
api_key = “something”
api_secret = “something secret”

request_method = “POST”
request_path = “/api/v3/brokerage/orders”

def main():
jwt_uri = jwt_generator.format_jwt_uri(request_method, request_path)
jwt_token = jwt_generator.build_rest_jwt(jwt_uri, api_key, api_secret)
print(f"set JWT={jwt_token}")
print(f’curl -X POST -H “Authorization: Bearer %JWT%” -H “Content-Type: application/json” https://api.coinbase.com/api/v3/brokerage/orders {data00} -o TestOrder.json’)

if name == “main”:
main()

In Windows 10 Pro here is the ouput from the Python

:: symbol: XLM-USD entryq: 44 clientOID: T5-test
set JWT=the generated JWT (too long for here)
curl -X POST -H “Authorization: Bearer %JWT%” -H “Content-Type: application/json” https://api.coinbase.com/api/v3/brokerage/orders --data-raw ‘{“client_order_id”:“T5-test”,“product_id”:“XLM-USD”,“side”:“BUY”,“order_configuration”:{“market_market_ioc”:{“quote_size”:“44”}}}’ -o TestOrder.json

and TestOrder.json is just
Unauthorized

I have generated multiple keys, tried many things, but can’t get an order to work. Getting open positions and open orders work with this same method, but have no payload.

You are already importing from coinbase, why don’t you use python to post your order?

P.S. Use Preformatted text option for code you are pasting!

I only used the Python code snippets to begin to translate to another language that I strongly prefer, Perl. The output in curl format gives me all the necessary elements and json format. That leaves only generating the JWT.

No idea if that could be problem but maybe use --json not --data-raw?

Also try --verbose option? Check if request is really sent as POST…

EDIT: are you really generating JWT for POST request as you have shown?

Here is the curl code, copied directly from Coinbase Cloud (without the authentication header and expanding the variables to literals since the site doesn’t work correctly). --data-raw is how it is presented.

But it never even gets to that point since the session is rejected as unauthorized.

curl -L -X POST ‘https://api.coinbase.com/api/v3/brokerage/orders’ -H ‘Content-Type: application/json’ --data-raw ‘{“client_order_id”:“T5-test”,“product_id”:“XLM-USD”,“side”:“BUY”,“order_configuration”:{“market_market_ioc”:{“quote_size”:“15”}}}’

Here’s the Python that generates the curl code. I only use data00 as a convenience to keep the curl line shorter.

from coinbase import jwt_generator

symbol = ‘XLM-USD’
entryQ = ‘15’
clientOID = ‘T5-test’

data00 = ‘–data-raw ‘+"’"+’{“client_order_id”:“‘+clientOID+’”,“product_id”:“‘+symbol+’”,“side”:“BUY”,“order_configuration”:{“market_market_ioc”:{“quote_size”:“‘+entryQ+’”}}}‘+"’"

api_key = ‘organizations/mysecret’
api_secret = ‘-----BEGIN EC PRIVATE KEY-----\nmysecret\n-----END EC PRIVATE KEY-----\n’

request_method = “POST”
request_path = “/api/v3/brokerage/orders”

def main():
jwt_uri = jwt_generator.format_jwt_uri(request_method, request_path)
jwt_token = jwt_generator.build_rest_jwt(jwt_uri, api_key, api_secret)
print(f"set JWT={jwt_token}")
print(f’curl -X POST -H “Authorization: Bearer %JWT%” -H “Content-Type: application/json” https://api.coinbase.com/api/v3/brokerage/orders {data00} -o TestOrder.json’)
if name == “main”:
main()

First - use Preformatted text option for code!

You told that other things works, can you post also code for working case?

It does not work. Returns
RESTClient - ERROR - HTTP Error: 400 Client Error: Bad Request {“error”:“INVALID_ARGUMENT”,“error_details”:“Invalid product_id”,“message”:“Invalid product_id”}
for XLM-USD

Post code and use Preformatted text for it!!! Also post generated json message that you are trying to send/post.