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