List Historical Orders returns empty reponse

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!

Hello @Yori! Welcome to the forum! We’re happy to help, but first can you check on this link if you currently have any open orders? This is to verify if the data you fetched is valid. Please note that the List Orders endpoint will only return data for all OPEN orders, hence, if you currently do not have open orders, your API call is expected to return null data.

You may learn more about Order Management through this Help Center article.

Looking forward to your response. Thank you!

I see, that makes sense! Thanks so much for your help! @Mamoshi27

3 Likes

Hi @Yori! We’re always happy to help. If you need anything else in the future, please feel free to let us know. Have a great day!

1 Like