Getting this error: ValueError: tuple.index(x): x not in tuple when trying to find timestamp matches in a list of tuples

Viewed 1879

This is how I get the timestamp matches:

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"]))

This is what I want to achieve:

  • 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

This is my incomplete attempt (I haven't got to the final part where I fill up the dictionary "data":

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])
0 Answers
Related