![Easy methods to POST utilizing RobinHood Crypto API in Python? Easy methods to POST utilizing RobinHood Crypto API in Python?](https://cillionairee.com/wp-content/uploads/https://cdn.sstatic.net/Sites/bitcoin/Img/apple-touch-icon@2.png?v=b4864ba760f1)
[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 exhibits normally imply one thing in regards to the message is incorrect. 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",
"sort" : "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-Sort': 'software/json; charset=utf-8',
}
response = requests.put up(url, headers=headers, json=physique)
Your complete code is sort of equivalent to my (working) GET capabilities, besides that this can be a POST request and that for the primary time, the request (and the message) features a physique component.
Do you see one thing I’ve ignored?
[ad_2]