Refer to API key setup to generate your API key and secret.
Authenticate Using Signature (HMAC SHA256)
👍 Keep your API secret safe!
Using signature is a safer method of authenticating since your API secret is not passed along in the requests. This prevents potential API secret leakage during transport.
To authenticate with this method, the following headers should be sent with the request:
# Code Example
import os
import time
import json
import hmac
import hashlib
import requests
API_KEY = os.environ["API_KEY"]
API_SECRET = os.environ["API_SECRET"]
def get_headers(path, method, body):
timestamp = str(time.time_ns())
# If the body is empty, it would look like:
# concat = 'API_KEY,1673425955575713842,GET,/account,'
concat = f"{API_KEY},{timestamp},{method.upper()},{path},{body}".encode("utf-8")
signature = hmac.new(API_SECRET.encode("utf-8"), concat, hashlib.sha256).hexdigest()
headers = {
"AEVO-TIMESTAMP": timestamp,
"AEVO-SIGNATURE": signature,
"AEVO-KEY": API_KEY,
}
return headers
# GET method - you pass in an empty string as the body
headers = get_headers("/account", "GET", "")
req = requests.get("https://api-testnet.aevo.xyz/account", headers=headers)
print(req.json())
# POST method - you have to pass in the JSON string used in the request body
body = json.dumps({"name": "My API key"})
print(body)
headers = get_headers("/api-key", "POST", body)
req = requests.post("https://api-testnet.aevo.xyz/api-keys",
headers=headers,
data=body)
print(req.json())