working on coinbase-advanced rest api. response code 404 in get market trades, and need fix

47 views Asked by At

using this get market trades function, and im getting this response. im trying to access the market trades. what am i doing wrong?its not my api key or signiture as im usinng those in other funnctions with no problem its not the ts its not the headers

`Response Code: 404
Response Data: b'{"error":"NOT_FOUND","error_details":"ProductID \\"product_id\\" could not be found.","message":"ProductID \\"product_id\\" could not be found."}'
b'{"error":"NOT_FOUND","error_details":"ProductID \\"product_id\\" could not be found.","message":"ProductID \\"product_id\\" could not be found."}'
`
`
config = configparser.ConfigParser()
config.read(r"D:\repos\repo\Coinbase\config.ini")
API_KEY = config.get('coinbase', 'API_KEY')
SECRET_KEY = config.get('coinbase', 'SECRET_KEY')

limiter = RateLimiter(max_calls=1, period=1, callback=1)

@limiter
def get_market_trades(product_id="BTC-USD", limit=10):
    api_key = API_KEY
    api_secret = SECRET_KEY
    api_version = '2021-07-09'
    timestamp = str(int(time.time()))
    method = 'GET'
    path = f"/api/v3/brokerage/products/{product_id}/ticker"
    query_params = f"limit={limit}"
    message = f"{timestamp}{method}{path}"
    signature = hmac.new(api_secret.encode('utf-8'), message.encode('utf-8'), digestmod=hashlib.sha256).hexdigest()
    conn = client.HTTPSConnection("api.coinbase.com")
    payload = ''
    headers = {
        'CB-ACCESS-KEY': api_key,
        'CB-ACCESS-SIGN': signature,
        'CB-ACCESS-TIMESTAMP': timestamp,
        'Content-Type': 'application/json',
        'CB-VERSION': api_version
    }
    conn.request(method=method, url=f"{path}?{query_params}", body=payload, headers=headers)
    res = conn.getresponse()
    response_code = res.status
    data = res.read()
    print("Response Code:", response_code)
    print("Response Data:", data)
    logging.info("Response Code: %s", response_code)
    logging.info("Response Data: %s", data)
    conn.close()
    return data

def fetch_market_trades():
    result = get_market_trades("product_id", 10)
    print(result)

fetch_market_trades()

`

ive tried all normal trouble shooting methonds, the docs, and chat gpt no nothing.

0

There are 0 answers