我正在嘗試從 bitmex API 獲取最后的資料
基本 URI:https : //www.bitmex.com/api/v1
我真的不明白如何使用過濾器獲取最后的資料(從今天開始):https : //www.bitmex.com/app/restAPI
這是我的代碼:
from datetime import date
import requests
import json
import pandas as pd
today = date.today()
d1 = today.strftime("%Y-%m-%d")
#print("d1 =", d1)
def parser():
today = date.today()
# yy/dd/mm
d1 = today.strftime("%Y-%m-%d")
# print("d1 =", d1)
return f'https://www.bitmex.com/api/v1/trade?symbol=.BVOL24H&startTime={d1}×tamp.time=12:00:00.000&columns=price'
# Making a get request
response = requests.get(parser()).json()
# print(response)
for elem in response:
print(elem)
回應是:
...
{'symbol': '.BVOL24H', 'timestamp': '2021-12-27T08:05:00.000Z', 'price': 2.02}
{'symbol': '.BVOL24H', 'timestamp': '2021-12-27T08:10:00.000Z', 'price': 2.02}
{'symbol': '.BVOL24H', 'timestamp': '2021-12-27T08:15:00.000Z', 'price': 2.02}
它缺少幾個小時,我嘗試使用 endTime、StartTime 和 Count 沒有成功。我想我需要通過另一個過濾器,如 endtime = now 和 timestamp.time = now 但我不知道如何發送有效負載或如何對它進行 url 編碼。
uj5u.com熱心網友回復:
正如過濾部分所說
許多表端點采用過濾器引數。這應該是 JSON
這些引數不是查詢字串中的鍵,而是鍵中給出的字典中的filter鍵
url = "https://www.bitmex.com/api/v1/trade"
filters = {
'startTime': date(2021, 12, 20).strftime("%Y-%m-%d"),
'timestamp.time': '12:00:00.000'
}
params = {
'symbol': '.BVOL24H',
'filter': json.dumps(filters),
}
response = requests.get(url, params=params)
for elem in response.json():
print(elem)
例子
/trade?symbol=.BVOL24H&filter={"startTime":"2021-12-20","timestamp.time":"12:00:00.000"}
uj5u.com熱心網友回復:
您可以使用 & 向 url 添加其他引數,如下所示。
'https://www.bitmex.com/api/v1/trade?symbol=.BVOL24H&startTime={d1}×tamp.time=12:00:00.000&columns=price&endTime={date.today()}×tamp.time={日期.今天()}'
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/394640.html
上一篇:無法安裝需求txt
