Hi, I was running the following code to get historical orders based on the official document
My code here:
import http.client
import json
import time
from dotenv import load_dotenv
import os
import hmac, hashlib, base64
load_dotenv()
api_key = os.getenv("API_Key")
api_secret = os.getenv("API_Secret")
conn = http.client.HTTPSConnection("api.coinbase.com")
timestamp = str(int(time.time()))
method = "GET"
requestPath = f"/api/v3/brokerage/orders/historical/batch"
body = ""
path = "/api/v3/brokerage/orders/historical/batch?product_id=BTC-USD&order_status=FILLED&limit=25&start_date=2023-02-01T00:00:00Z&end_date=2023-02-05T00:00:00Z&user_native_currency=USD"
message = timestamp + method + requestPath + body
signature = hmac.new(
api_secret.encode("utf-8"), message.encode("utf-8"), digestmod=hashlib.sha256
).hexdigest()
headers = {
"accept": "application/json",
"CB-ACCESS-KEY": api_key,
"CB-ACCESS-SIGN": signature,
"CB-ACCESS-TIMESTAMP": timestamp,
}
# Send request
conn.request(method, path, body, headers)
# Get response
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
The output is:
{"orders":[],"sequence":"0","has_next":false,"cursor":""}
No orders got fetched and I couldn’t figure out what part went wrong… Any advice is much appreciated, thanks!