获取此错误:ValueError:tuple.index(x):尝试在元组列表中查找时间戳匹配项时,x不在元组中

2024-04-24 16:59:13 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我获取时间戳匹配的方式:

import pickle

asset_list = ["BTC", "ETH", "AAVE", "YFI", "COMP"]

timestamp_dict = {}
for i in asset_list:
    with open("D:\\Programming\\TradingInvestment\\Datasets\\Samples\\" + i + ".pickle", "rb") as f:
        data =  pickle.load(f)
        timestamp_dict[i] = [timestamp[0] for timestamp in data]

time_matches = set(timestamp_dict["BTC"]).intersection(
set(timestamp_dict["ETH"]),
set(timestamp_dict["AAVE"]),
set(timestamp_dict["YFI"]),
set(timestamp_dict["COMP"]))

这就是我想要实现的目标:

  • take each timestamp in time_matches
  • index the sample data for a transaction matching the timestamp
  • get the price in that transaction for each asset
  • store in format: {"timestamp" : [price1, price2 ... pricen]} for n number of assets
  • try allowing for a few seconds each side of times in timematches and average those times

这是我不完整的尝试(我还没有到最后一部分,在那里我填写字典“数据”:

for timestamp in time_matches:
    for i in asset_list:
        prices = []
        with open("D:\\Programming\\TradingInvestment\\Datasets\\Samples\\" + i + ".pickle", "rb") as f:
            transactions =  pickle.load(f)
            for element in transactions:
                tx = element.index(timestamp)
                prices.append(tx[1])

Tags: theinfordatatimeassetpickledict