import os
import pandas as pd
from datetime import datetime

# os.chdir('/Users/wzhia/Desktop/Year 5 Sem1/FINA4380/Project/data/')

def get_file(type,col, coin_all,col_name):
    df_all = pd.DataFrame()
    for coin in coin_all:
        if not coin.startswith('.'):
            df = pd.DataFrame()
            dir_list = os.listdir(coin + '/'+ type)
            for file in dir_list:
                data = pd.read_csv(coin+'/'+type+'/'+file,header=None,names=col_name)
                df = pd.concat([df, data[col]], axis=0) # get close price
            time = [datetime.fromtimestamp(int(t))for t in df.index/1000]
            df.index = time
            df.sort_index()
            df_all = pd.concat([df_all,df],axis=1)

    name = ['BTC', 'LTC', 'XRP', 'LUNA', 'ADA', 'SOL', 'DOT', 'DOGE', 'TRX', 'SHIB', 'ETH', 'BNB'] # change crypto name according to coin_all
    df_all.columns = name
    df_all.to_csv(col+'_'+type+'.csv') # change file name
    return


coin_all = os.listdir() # ['BTC','ETH','BNB','SOL','ADA','XRP','DOT','DOGE','SHIB','LUNA','TRX','LTC']
col_name = ['open','high','low','close','volume','close_time','quote_av','trades','tb_base_av','tb_quote_av','ignore']
type = "1d" # "1d" or "1h" or "1m"
col = "volume" # "close" or "volume"

get_file(type, col, coin_all, col_name)
