Created
October 24, 2018 20:37
-
-
Save uneasyguy/df6f83bd551bd90a4d532f3aa7f136fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os,sys,csv | |
from binance.client import Client | |
pathname = os.path.dirname(sys.argv[0]) | |
full_path = '{}/'.format(str(os.path.abspath(pathname))) | |
def create_needed_directories(): | |
directory_finder = [x[0] for x in os.walk(full_path)] | |
concatenated_price_data_directory = '{}concatenated_price_data'.format(str(full_path)) | |
if concatenated_price_data_directory not in directory_finder: | |
os.makedirs(concatenated_price_data_directory) | |
def grab_currencies_list(): | |
currencies_list = list() | |
info = Client(None,None) | |
pair_query = info.get_all_tickers() | |
list_preference = input('Which base currencies would you like to concatenate data for?(eg. BTC or ETH,BNB or BTC,ETH,BNB,USDT) ') | |
if list_preference.lower().replace(' ','') in ['btc']: | |
for x in range(0,len(pair_query)): | |
symbol = pair_query[x]['symbol'] | |
if symbol[-3:] == 'BTC': | |
currencies_list.append(symbol) | |
return currencies_list | |
elif list_preference.lower().replace(' ','') in ['eth']: | |
for x in range(0,len(pair_query)): | |
symbol = pair_query[x]['symbol'] | |
if symbol[-3:] == 'ETH': | |
currencies_list.append(symbol) | |
return currencies_list | |
elif list_preference.lower().replace(' ','') in ['bnb']: | |
for x in range(0,len(pair_query)): | |
symbol = pair_query[x]['symbol'] | |
if symbol[-3:] == 'BNB': | |
currencies_list.append(symbol) | |
return currencies_list | |
elif list_preference.lower().replace(' ','') in ['usdt']: | |
for x in range(0,len(pair_query)): | |
symbol = pair_query[x]['symbol'] | |
if symbol[-4:] == 'USDT': | |
currencies_list.append(symbol) | |
return currencies_list | |
elif list_preference.lower().replace(' ','') in ['btc,eth','eth,btc']: | |
for x in range(0,len(pair_query)): | |
symbol = pair_query[x]['symbol'] | |
if symbol[-3:] in ['BTC','ETH']: | |
currencies_list.append(symbol) | |
return currencies_list | |
elif list_preference.lower().replace(' ','') in ['btc,bnb','bnb,btc']: | |
for x in range(0,len(pair_query)): | |
symbol = pair_query[x]['symbol'] | |
if symbol[-3:] in ['BTC','BNB']: | |
currencies_list.append(symbol) | |
return currencies_list | |
elif list_preference.lower().replace(' ','') in ['eth,bnb','bnb,eth']: | |
for x in range(0,len(pair_query)): | |
symbol = pair_query[x]['symbol'] | |
if symbol[-3:] in ['ETH','BNB']: | |
currencies_list.append(symbol) | |
return currencies_list | |
elif list_preference.lower().replace(' ','') in ['btc,usdt','usdt,btc']: | |
for x in range(0,len(pair_query)): | |
symbol = pair_query[x]['symbol'] | |
if symbol[-3:] in ['BTC']: | |
currencies_list.append(symbol) | |
elif symbol[-4:] in ['USDT']: | |
currencies_list.append(symbol) | |
return currencies_list | |
elif list_preference.lower().replace(' ','') in ['eth,usdt','usdt,eth']: | |
for x in range(0,len(pair_query)): | |
symbol = pair_query[x]['symbol'] | |
if symbol[-3:] in ['ETH']: | |
currencies_list.append(symbol) | |
elif symbol[-4:] in ['USDT']: | |
currencies_list.append(symbol) | |
return currencies_list | |
elif list_preference.lower().replace(' ','') in ['bnb,usdt','usdt,bnb']: | |
for x in range(0,len(pair_query)): | |
symbol = pair_query[x]['symbol'] | |
if symbol[-3:] in ['BNB']: | |
currencies_list.append(symbol) | |
elif symbol[-4:] in ['USDT']: | |
currencies_list.append(symbol) | |
return currencies_list | |
elif list_preference.lower().replace(' ','') in ['btc,eth,usdt','btc,usdt,eth','usdt,btc,eth','usdt,eth,btc','eth,usdt,btc','eth,btc,usdt']: | |
for x in range(0,len(pair_query)): | |
symbol = pair_query[x]['symbol'] | |
if symbol[-3:] in ['BTC','ETH']: | |
currencies_list.append(symbol) | |
elif symbol[-4:] in ['USDT']: | |
currencies_list.append(symbol) | |
return currencies_list | |
elif list_preference.lower().replace(' ','') in ['bnb,eth,usdt','bnb,usdt,eth','usdt,bnb,eth','usdt,eth,bnb','eth,usdt,bnb','eth,bnb,usdt']: | |
for x in range(0,len(pair_query)): | |
symbol = pair_query[x]['symbol'] | |
if symbol[-3:] in ['BNB','ETH']: | |
currencies_list.append(symbol) | |
elif symbol[-4:] in ['USDT']: | |
currencies_list.append(symbol) | |
return currencies_list | |
elif list_preference.lower().replace(' ','') in ['btc,eth,usdt,bnb','btc,usdt,eth,bnb','btc,bnb,eth,usdt','btc,bnb,usdt,eth','btc,usdt,bnb,eth','btc,eth,bnb,usdt','usdt,eth,btc,bnb','usdt,btc,eth,bnb','usdt,btc,bnb,eth','usdt,eth,bnb,btc','usdt,bnb,btc,eth','usdt,bnb,eth,btc','eth,usdt,btc,bnb','eth,btc,usdt,bnb','eth,btc,bnb,usdt','eth,usdt,bnb,btc','eth,bnb,usdt,btc','eth,bnb,btc,usdt','bnb,btc,eth,usdt','bnb,btc,usdt,eth','bnb,eth,btc,usdt','bnb,eth,usdt,btc','bnb,usdt,eth,btc','bnb,usdt,btc,eth']: | |
for x in range(0,len(pair_query)): | |
symbol = pair_query[x]['symbol'] | |
currencies_list.append(symbol) | |
return currencies_list | |
def concatenate_csvs(pair_list): | |
for y in range(0,len(pair_list)): | |
pair = pair_list[y] | |
csv_files = [f for f in os.listdir('{}historical_price_data/{}'.format(str(full_path),str(pair))) if os.path.isfile(os.path.join('{}historical_price_data/{}'.format(str(full_path),str(pair)), f))] | |
if len(csv_files)>0: | |
for x in range(0,len(csv_files)): | |
file = csv_files[x] | |
outpath = '{}concatenated_price_data/{}.csv'.format(str(full_path),str(pair)) | |
fout=open(outpath,"a") | |
if x == 0: | |
for line in open('{}historical_price_data/{}/{}'.format(str(full_path),str(pair),str(file))): | |
fout.write(line) | |
else: | |
f = open('{}historical_price_data/{}/{}'.format(str(full_path),str(pair),str(file))) | |
f.__next__() | |
for line in f: | |
fout.write(line) | |
fout.close() | |
def main(): | |
create_needed_directories() | |
pair_list = grab_currencies_list() | |
concatenate_csvs(pair_list) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment