如何从 Shrimpy.io API 获取历史订单簿数据?

时间:2021-05-12 03:46:27

标签: api

我正在尝试使用 Python 查询 Shrimpy API

我想get historical Order Book data

文档在示例代码中引用了 client,但我找不到有关如何设置它的任何信息。所以我改用他们的 signing request example 的修改版本并将响应打印到控制台。

但每次我这样做时,我得到的回复都是b'{"error":"404 Not Found"}'

这是我正在使用的代码:

import hmac
import hashlib
import time
import base64
import json
import requests


# public API key (not base64 encoded)
api_key = 'REDACTED-KEY-GOES-HERE'

# private API key (base64 encoded)
secret = 'REDACTED-SECRET-GOES-HERE'

nonce = int(time.time() *  1000)
base_url = 'https://dev-api.shrimpy.io'
request_path = "/v1/historical/orderbooks"

body = json.dumps({
    "exchange": "Binance",
    "baseTradingSymbol": "BTC",
    "quoteTradingSymbol": "USDT",
    "startTime": "2020-05-12T00:00:00.000Z",
    "endTime": "2020-05-12T00:01:00.000Z",
    "limit": 10
    })
method = "GET"
prehash_string = ''.join([request_path, method, str(nonce), (body or '')])

secret_key = base64.b64decode(secret)
prehash_string = prehash_string.encode('ascii')

signature = hmac.new(secret_key, prehash_string, hashlib.sha256)
signature_b64 = base64.b64encode(signature.digest()).decode('utf-8')

headers = {
    'Content-Type': 'application/json',
    'DEV-SHRIMPY-API-KEY': api_key,
    'DEV-SHRIMPY-API-NONCE': str(nonce),
    'DEV-SHRIMPY-API-SIGNATURE': signature_b64
}

response  = requests.post(
    base_url + request_path,
    data=body,
    headers=headers
)

print(response.content)

知道我做错了什么吗?

0 个答案:

没有答案