[英]Binance Delivery Futures Historical Prices
I'm trying to get from binance the historical futures prices of the futures contract that expires on the 31st of December 2021.我试图从binance获取 2021 年 12 月 31 日到期的期货合约的历史期货价格。
I have figured this out for perps but am struggling with a futures contract with a delivery date.我已经为perps解决了这个问题,但我正在为一份有交割日期的期货合约而苦苦挣扎。 The code for the perps is below perps 的代码如下
df = pd.DataFrame(client.futures_historical_klines(
symbol='BTCUSDT',
interval='1d',
start_str='2021-06-01',
end_str='2021-06-30'
))
I assumed that replacing the symbol with BTCUSD_211231
or BTCUSDT_211231
would have done the trick, but unfortunately I get the below error message:我假设用BTCUSD_211231
或BTCUSDT_211231
替换符号就可以解决问题,但不幸的是我收到以下错误消息:
BinanceAPIException: APIError(code=-1121): Invalid symbol.
Any help is much appreciated!任何帮助深表感谢!
Thanks谢谢
According to the binance documentation , you can set contractType
for the desired contract.根据binance 文档,您可以为所需的合约设置contractType
。
The following options for contractType
are available: contractType
的以下选项可用:
The following code works for me:以下代码对我有用:
import binance
import pandas as pd
client = binance.Client()
r = client.futures_continous_klines(
pair='BTCUSDT',
contractType='CURRENT_QUARTER',
interval='1d',
)
df = pd.DataFrame(r)
print(df)
Output: Output:
0 1 2 3 4 5 6 7 8 9 10 11
0 1612310400000 36054.1 39000.0 31111.0 38664.1 688.738 1612396799999 21632849.1822 33908 336.944 10440572.5057 0
1 1612396800000 38664.1 43820.2 37445.4 38328.3 757.761 1612483199999 29584739.5781 16925 387.058 15156395.7362 0
2 1612483200000 38304.6 39955.4 37858.3 39848.1 383.410 1612569599999 14995639.3696 5563 183.214 7170636.7752 0
3 1612569600000 39876.5 42727.3 39437.6 41245.1 453.336 1612655999999 18775322.9609 8898 225.566 9347858.6798 0
4 1612656000000 41240.3 41642.5 38639.2 40592.0 428.693 1612742399999 17269756.5859 7553 202.850 8175165.3435 0
.. ... ... ... ... ... ... ... ... ... ... ... ..
242 1633219200000 48654.6 50479.1 48100.0 49325.1 2222.058 1633305599999 109305621.1491 27633 1106.026 54396950.3347 0
243 1633305600000 49325.1 50738.3 47961.5 50461.2 1808.321 1633391999999 89174286.5122 28367 925.258 45643475.0561 0
244 1633392000000 50491.5 53151.3 50245.3 52764.5 1860.870 1633478399999 95741544.2087 29105 921.897 47452449.1528 0
245 1633478400000 52769.4 57442.1 51606.6 56710.1 2431.580 1633564799999 132849081.0296 38013 1225.920 67014360.6873 0
246 1633564800000 56723.3 56739.9 54769.0 55645.2 1188.181 1633651199999 66322580.2665 21176 570.967 31878146.7653 0
[247 rows x 12 columns]
The meaning of each column in the above dataframe is documented in the Binance documentation (see right side, under "Response") .上述 dataframe 中每一列的含义记录在 Binance 文档中(见右侧,“响应”下) 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.