Dev
June 29, 2023, 5:55pm
1
import time
import http.client
import json
import uuid
import hashlib
import hmac
import base64
import os
api_key = ‘MY_API_KEY’
api_secret = ‘MY_SECRET_KEY’
timestamp = str(int(time.time()))
request_method = ‘POST’
request_path = ‘/api/v3/brokerage/orders’
order_uuid = str(uuid.uuid4())
conn = http.client.HTTPSConnection(“api.coinbase.com ”)
payload = json.dumps({
“client_order_id”: “000000003245”,
“side”: “BUY”,
“product_id”: “BTC-USD”
})
message = timestamp + request_method + request_path + payload
signature = hmac.new(api_secret.encode(‘utf-8’), message.encode(‘utf-8’), digestmod=hashlib.sha256).digest()
headers = {
‘Content-Type’: ‘application/json’,
‘CB-ACCESS-KEY’: api_key,
‘CB-ACCESS-SIGN’: signature.hex(),
‘CB-ACCESS-TIMESTAMP’: timestamp,
}
conn.request(request_method, request_path, payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode(“utf-8”))
Dev
June 29, 2023, 6:13pm
2
this code response is {“error”:“INVALID_ARGUMENT”,“error_details”:“account is not available”,“message”:“account is not available”}, please help me to fix this issue.
Any luck with this? I’m having the same issue.
Justin
July 2, 2023, 12:18pm
4
It looks like the Payload is missing the order configuration.
Example Below:
import uuid
payload = json.dumps({
'order_configuration':{
"limit_limit_gtc": {
"limit_price": "0.45",
"base_size": "3.5"
},
},
'client_order_id': str(uuid.uuid1()),
'side': "SELL",
'product_id': "ADA-USD"
})
See the following post to setup a Request Body:
I am in the process of migrating from the Exchange Pro to Advanced Trading API.
Could someone please provide an example of how the request body should look to create an order? The code builder in the API documentation doesn’t seem to be working properly. It shows us how the client ID, product ID, and side should look, but not the order configuration objects.
I would also like to verify that this request body should be included in the request signature as it was with Exchange Pro. I thank y…
Thx for the response! Yes that seems to be the problem with OP, didn’t notice.
I had a different issue, was using “ETH-USD” as product_id, switching to “ETH-USDC” solved the problem. I was earlier testing the wss channels and there the id had to be the opposite (“ETH-USD” instead of “ETH-USDC”) which confused me.