在 Coinbase-Advanced REST API 上工作。获取市场交易中的响应代码 404,需要修复

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

提问人:Michael King 提问时间:10/25/2023 更新时间:10/25/2023 访问量:13

问:

使用此获取市场交易功能,我得到此响应。我正在尝试进入市场交易。我做错了什么?它不是我的 API 密钥或标志,因为我在其他功能中使用那些没有问题,它不是 TS,它不是标头

`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()

`

我尝试了所有正常的故障排除方法、文档和聊天 GPT,什么都没有。

python http-status-code-404 httpresponse coinbase-api

评论

0赞 Claudiu 10/31/2023
查看响应似乎product_id有问题,您是否在其他函数中实际使用相同的代码?还是你在邮递员中测试过?

答: 暂无答案