Trying to create limit_limit_gtd sell order

I am a novice coder. I am hoping someone can spot my coding mistake(s).

Error:

{“error”:“unknown”,“error_details”:“json: cannot unmarshal string into Go value of type bool”,“message”:“json: cannot unmarshal string into Go value of type bool”}

Code:

#!/usr/bin/env python3

import http.client
import hmac
import hashlib
import time
import json
import datetime
import base64


timestamp = str(int(time.time()))



secretKey='***************'
accessKey='***************'

conn = http.client.HTTPSConnection("api.coinbase.com")


method = "POST"
path = "/api/v3/brokerage/orders"

zulu_plus_3 = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(hours=3)
zulu_plus_3_iso = str(zulu_plus_3.isoformat())#order good for three hours

payload = "{\"client_order_id\":\"default\",\"product_id\":\"OXT-USD\",\"side\":\"SELL\",\"order_configuration\": {\"limit_limit_gtd\": {\"base_size\":\"178\",\"limit_price\":\"0.07\",\"end_time\":" + "\"" + zulu_plus_3_iso + "\"" + ",\"post_only\":\"False\"}}}"

message = timestamp + method + path.split('?')[0] + str(payload)
signature = hmac.new(secretKey.encode('utf-8'), message.encode('utf-8'), digestmod=hashlib.sha256).hexdigest()


headers={
'CB-ACCESS-KEY': accessKey,
'CB-ACCESS-TIMESTAMP': timestamp,
'CB-ACCESS-SIGN': signature,
'accept':'application/json'
}

#print(payload)
conn.request(method, path, payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

Hi @DaveM! Welcome to Coinbase Cloud Developer’s forum!

We understand that you are having trouble with placing a sell order using the Create Order endpoint. In this regard, please note that we actually found a forum thread that is somehow similar to your case wherein the forumUser is also receiving a “Go” type of error. Based on the inputs from another forumUser, it was noted that such types of error usually happen when you try to put a different type of value versus what was expected. In your case, we can see that you have actually inputted a string value to a variable that expects a boolean. We suggest that you try rebuilding your code again and have the post_only value as boolean (False) and not as a string (“False”).

We hope this helps. Please do not hesitate to reply back to this thread if the issue still persists.

Thank you and have a great day!

2 Likes

Thank you for the information. Almost fixed the script. Lower case f was necessary… boolean (false)

Working code:

#!/usr/bin/env python3

import http.client
import hmac
import hashlib
import time
import json
import datetime
import base64


timestamp = str(int(time.time()))



secretKey='********************'
accessKey='********************'

conn = http.client.HTTPSConnection("api.coinbase.com")


method = "POST"
path = "/api/v3/brokerage/orders"

zulu_plus_3 = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(hours=3)
zulu_plus_3_iso = str(zulu_plus_3.isoformat())#order good for three hours

payload = "{\"client_order_id\":\"default\",\"product_id\":\"OXT-USD\",\"side\":\"SELL\",\"order_configuration\": {\"limit_limit_gtd\": {\"base_size\":\"178\",\"limit_price\":\"0.07\",\"end_time\":" + "\"" + zulu_plus_3_iso + "\"" + ",\"post_only\":false }}}"

message = timestamp + method + path.split('?')[0] + str(payload)
signature = hmac.new(secretKey.encode('utf-8'), message.encode('utf-8'), digestmod=hashlib.sha256).hexdigest()


headers={
'CB-ACCESS-KEY': accessKey,
'CB-ACCESS-TIMESTAMP': timestamp,
'CB-ACCESS-SIGN': signature,
'accept':'application/json'
}

print(payload)
conn.request(method, path, payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
1 Like

Hi @DaveM! We are glad that the suggested fix actually helped you to arrive with a working code. Thank you also for updating us about the boolean value that actually has to be in lowercase. Have a great day! :sunny:

1 Like