converted to single threaded
This commit is contained in:
parent
7df8b3a519
commit
c46b184627
|
|
@ -8,6 +8,7 @@ import time
|
|||
import sqlite3
|
||||
import math
|
||||
import statistics
|
||||
import sys
|
||||
from credentials import get_credentials
|
||||
from threading import Thread
|
||||
|
||||
|
|
@ -145,7 +146,7 @@ def fetch_data(broker: str, pair_list: list, timeframe: str, samples: int):
|
|||
continue
|
||||
for item in data:
|
||||
trading_volume += item[4]*item[5]
|
||||
volatilities[broker][pair] = [round(yangzhang_volatility*100,2),round(parkinson_volatility*100,2),int(trading_volume)]
|
||||
volatilities[pair] = [round(yangzhang_volatility*100,2),round(parkinson_volatility*100,2),int(trading_volume)]
|
||||
print(f"{pair} on {broker} ready, {len(pair_list)-index} pairs remaining.")
|
||||
time.sleep(wait_time)
|
||||
|
||||
|
|
@ -155,37 +156,27 @@ def fetch_data(broker: str, pair_list: list, timeframe: str, samples: int):
|
|||
if __name__=="__main__":
|
||||
|
||||
threads = []
|
||||
exchanges = ["binance","gateio","kucoin","okx","bybit"]
|
||||
pair_list = []
|
||||
volatilities = {item:{} for item in exchanges}
|
||||
exchange_list = [item for item in volatilities]
|
||||
volatilities = {}
|
||||
samples = 288
|
||||
timeframe = "5m"
|
||||
minimum_volume = 0
|
||||
|
||||
#Create databases for each exchange
|
||||
for item in exchange_list:
|
||||
database_connection = sqlite3.connect(f"{get_credentials('VOL_DB_PATH')['path']}{item}.db")
|
||||
database_cursor = database_connection.cursor()
|
||||
database_cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS volatilities_table (
|
||||
pair TEXT,
|
||||
timestamp INTEGER,
|
||||
yang_zhang REAL,
|
||||
parkinson REAL,
|
||||
volume REAL)''')
|
||||
database_connection.commit()
|
||||
database_connection.close()
|
||||
#Create database if it does not exist
|
||||
database_connection = sqlite3.connect(f"{get_credentials('VOL_DB_PATH')['path']}{sys.argv[1]}.db")
|
||||
database_cursor = database_connection.cursor()
|
||||
database_cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS volatilities_table (
|
||||
pair TEXT,
|
||||
timestamp INTEGER,
|
||||
yang_zhang REAL,
|
||||
parkinson REAL,
|
||||
volume REAL)''')
|
||||
database_connection.commit()
|
||||
database_connection.close()
|
||||
|
||||
|
||||
for broker in exchange_list:
|
||||
threads.append(Thread(target=fetch_data,args=(broker, get_pair_list(broker), timeframe, samples,)))
|
||||
fetch_data(sys.argv[1], get_pair_list(sys.argv[1]), timeframe, samples)
|
||||
|
||||
for thread in threads:
|
||||
thread.start()
|
||||
for thread in threads:
|
||||
thread.join()
|
||||
|
||||
for item in exchange_list:
|
||||
write_to_db(item,volatilities[item])
|
||||
write_to_db(sys.argv[1],volatilities)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue