ValueError:传递值的长度为7,索引为0

问题描述 投票:2回答:1

我试图使用ccxt从bitmex获得1分钟的开放,高,低,关闭,音量值。一切似乎都很好,但我不知道如何解决这个错误。我知道索引是7,因为我进入数据帧的OHLC列中有7个值。我不知道为什么它反而暗示有0。非常感谢这一直让我头疼一整天:(

# noinspection PyUnresolvedReferences
from datetime import datetime
# noinspection PyUnresolvedReferences
import time
# noinspection PyUnresolvedReferences
import ccxt
# noinspection PyUnresolvedReferences
import numpy as np
import pandas as pd
# noinspection PyUnresolvedReferences
from IPython.display import display, clear_output


OHLCVcolumns = ['date', 'timestamp', 'open', 'high', 'low', 'close', 'volume']

dfOHLCV = pd.DataFrame(index=[], columns=OHLCVcolumns)

bitmex = ccxt.bitmex()


def fetch_current(x):
    while True:
        if datetime.now().second == x:
            break
        time.sleep(0.5)


def fetch_mex():
    listOHLCV = bitmex.fetch_ohlcv('BTC/USD',
                                   timeframe='1m',
                                   limit=5,
                                   params={'reverse': True})

    lst = list(listOHLCV[1])

    lst.insert(0, datetime.fromtimestamp((lst[0]) / (1000 + 60 * 60 * 9 - 60)).strftime("%Y/%d/%m, %H: %M:"))

    series = pd.Series(lst, index=dfOHLCV)

    return listOHLCV, series


while True:
    fetch_current(1)

    listOHLCV, series = fetch_mex()

    dfOHLCV = dfOHLCV.append(series, ignore_index=True)


clear_output(wait=True)
display(listOHLCV)
display(dfOHLCV)

fetch_current(55)
python python-3.x algorithmic-trading ccxt
1个回答
1
投票

不知道你在哪里得到错误,是吗?

series = pd.Series(lst, index=dfOHLCV)

如果是这样,你可以尝试:

series = pd.Series(lst, index=OHLCVcolumns)

因为当你运行它时,索引引用空数据帧dfOHLCV。

© www.soinside.com 2019 - 2024. All rights reserved.