[ad_1]
I am utilizing the brand new RobinHood crypto API documented right here: https://docs.robinhood.com/crypto/buying and selling/#tag/Buying and selling/operation/api_v1_post_crypto_trading_order
I’m profitable with all GET endpoints, however can not seem to place an order utilizing the POST endpoints. It fails with a verification error, which testing reveals normally imply one thing concerning the message is mistaken. So far as I can inform although, I’ve adopted the documentation precisely.
Right here is my code. Is there one thing that I am lacking?
url = "https://buying and selling.robinhood.com/api/v1/crypto/buying and selling/orders/"
api_path = "/api/v1/crypto/buying and selling/orders/"
http_method_type = "POST"
physique = {
"client_order_id" : "131de903-5a9c-4260-abc1-28d562a5dcf0",
"facet" : "purchase",
"image" : "BTC-USD",
"kind" : "market",
"market_order_config" : {
"asset_quantity" : "0.1"
}
}
current_unix_timestamp = int(time.time())
message = (
f"{API_KEY_ROBIN_HOOD}"
f"{current_unix_timestamp}"
f"{api_path}"
f"{http_method_type}"
f"{physique}"
)
signature = PRIV_KEY.signal(message.encode("utf-8"))
base64_signature = base64.b64encode(signature).decode("utf-8")
PUB_KEY.confirm(signature, message.encode("utf-8"))
headers = {
'x-api-key': API_KEY_ROBIN_HOOD,
'x-timestamp': str(current_unix_timestamp),
'x-signature': base64_signature,
'Content material-Kind': 'utility/json; charset=utf-8',
}
response = requests.put up(url, headers=headers, json=physique)
All the code is nearly equivalent to my (working) GET features, besides that it is a POST request and that for the primary time, the request (and the message) features a physique aspect.
Do you see one thing I’ve neglected?
[ad_2]