簡體   English   中英

我無法獲取幣安期貨訂單歷史數據

[英]I can't get binance Futures order book historical data

我正在嘗試使用 API 獲取幣安期貨訂單歷史數據。 於是我向幣安索要數據,得到的答案是“您的歷史期貨訂單簿數據申請已獲批准,請按照我們的 Github 指導使用您的白名單賬戶 API 密鑰訪問”,我已將 ZDB974238714CA8DE634A7ACE1 設置如下。

在此處輸入圖像描述

我修改了啟用符號白名單,如下所示:

在此處輸入圖像描述

下一步,我按照Github指導: https://github.com/binance/binance-public-data/tree/master/Futures_Order_Book_Download

它具有以下示例代碼:

"""
This example python script shows how to download the Historical Future Order Book level 2 Data via API.
The data download API is part of the Binance API (https://binance-docs.github.io/apidocs/spot/en/#general-api-information).
For how to use it, you may find info there with more examples, especially SIGNED Endpoint security as in https://binance-docs.github.io/apidocs/spot/en/#signed-trade-user_data-and-margin-endpoint-security
Before executing this file, please note:
    - The API account needs to have a Futures account to access Futures data.
    - The API key has been whitelisted to access the data.
    - Read the comments section in this file to know where you should specify your request values.
"""

# Install the following required packages
import requests
import time
import hashlib
import hmac
from urllib.parse import urlencode

S_URL_V1 = "https://api.binance.com/sapi/v1"

# Specify the api_key and secret_key with your API Key and secret_key
api_key = "your_api_key"
secret_key = "your_secret_key "

# Specify the four input parameters below:
symbol = "ADAUSDT"  # specify the symbol name
startTime = 1635561504914  # specify the starttime
endTime = 1635561604914  # specify the endtime
dataType = "T_DEPTH"  # specify the dataType to be downloaded


# Function to generate the signature
def _sign(params={}):
    data = params.copy()
    ts = str(int(1000 * time.time()))
    data.update({"timestamp": ts})
    h = urlencode(data)
    h = h.replace("%40", "@")

    b = bytearray()
    b.extend(secret_key.encode())

    signature = hmac.new(b, msg=h.encode("utf-8"), digestmod=hashlib.sha256).hexdigest()
    sig = {"signature": signature}

    return data, sig


# Function to generate the download ID
def post(path, params={}):
    sign = _sign(params)
    query = urlencode(sign[0]) + "&" + urlencode(sign[1])
    url = "%s?%s" % (path, query)
    header = {"X-MBX-APIKEY": api_key}
    resultPostFunction = requests.post(url, headers=header, timeout=30, verify=True)
    return resultPostFunction


# Function to generate the download link
def get(path, params):
    sign = _sign(params)
    query = urlencode(sign[0]) + "&" + urlencode(sign[1])
    url = "%s?%s" % (path, query)
    header = {"X-MBX-APIKEY": api_key}
    resultGetFunction = requests.get(url, headers=header, timeout=30, verify=True)
    return resultGetFunction


"""
Beginning of the execution.
The final output will be:
- A link to download the specific data you requested with the specific parameters.
Sample output will be like the following: {'expirationTime': 1635825806, 'link': 'https://bin-prod-user-rebate-bucket.s3.amazonaws.com/future-data-download/XXX'
Copy the link to the browser and download the data. The link would expire after the expirationTime (usually 24 hours).
- A message reminding you to re-run the code and download the data hours later.
Sample output will be like the following: {'link': 'Link is preparing; please request later. Notice: when date range is very large (across months), we may need hours to generate.'}
"""

timestamp = str(
    int(1000 * time.time())
)  # current timestamp which serves as an input for the params variable
paramsToObtainDownloadID = {
    "symbol": symbol,
    "startTime": startTime,
    "endTime": endTime,
    "dataType": dataType,
    "timestamp": timestamp,
}

# Calls the "post" function to obtain the download ID for the specified symbol, dataType and time range combination
path = "%s/futuresHistDataId" % S_URL_V1
resultDownloadID = post(path, paramsToObtainDownloadID)
print(resultDownloadID)
downloadID = resultDownloadID.json()["id"]
print(downloadID)  # prints the download ID, example: {'id': 324225}


# Calls the "get" function to obtain the download link for the specified symbol, dataType and time range combination
paramsToObtainDownloadLink = {"downloadId": downloadID, "timestamp": timestamp}
pathToObtainDownloadLink = "%s/downloadLink" % S_URL_V1
resultToBeDownloaded = get(pathToObtainDownloadLink, paramsToObtainDownloadLink)
print(resultToBeDownloaded)
print(resultToBeDownloaded.json())

我已將api_keysecret_key修改為我自己的密鑰,這就是我得到的結果。 在此處輸入圖像描述

你能告訴我我哪里做錯了嗎? 提前感謝您的回答。

我想您應該申請將表格列入白名單。 https://docs.google.com/forms/d/e/1FAIpQLSexCgyvZEMI1pw1Xj6gwKtfQTYUbH5HrUQ0gwgPZtM9FaM2Hw/viewform

第二件事 - 你對期貨感興趣,而不是現貨,所以 url 應該是api.binance.com/fapi而不是api.binance.com/sapi

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM