【发布时间】:2022-01-26 09:11:41
【问题描述】:
我正在尝试从 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 编码。
【问题讨论】:
标签: python api urlencode bitmex