0

我正在尝试从 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}&timestamp.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 编码。

4

2 回答 2

0

您可以使用 & 向 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={日期.今天()}'

于 2021-12-27T11:43:45.590 回答
0

正如过滤部分所说

许多表端点采用过滤器参数。这应该是 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={%22startTime%22:%222021-12-20%22,%22timestamp.time%22:%2212:00:00.000%22}

于 2021-12-27T11:45:19.837 回答