fetch_pair_volatility changes
This commit is contained in:
parent
c46b184627
commit
d8e2d8eb77
|
|
@ -17,7 +17,7 @@ def write_to_log(message):
|
||||||
Writes a message to the log file
|
Writes a message to the log file
|
||||||
'''
|
'''
|
||||||
with open("log.txt", "a") as f:
|
with open("log.txt", "a") as f:
|
||||||
f.write(message)
|
f.write(f"{message}\n")
|
||||||
|
|
||||||
|
|
||||||
def yang_zhang(candles):
|
def yang_zhang(candles):
|
||||||
|
|
@ -111,56 +111,41 @@ def get_pair_list(broker, inclusions = ["/USDT"], exclusions = []):
|
||||||
return pair_list
|
return pair_list
|
||||||
|
|
||||||
|
|
||||||
def fetch_data(broker: str, pair_list: list, timeframe: str, samples: int):
|
def fetch_data(broker: str, pair: str, timeframe: str, samples: int):
|
||||||
"""
|
"""
|
||||||
Fetch data from exchange
|
Fetch data from exchange
|
||||||
"""
|
"""
|
||||||
|
|
||||||
global volatilities
|
|
||||||
|
|
||||||
wait_time = .5 #Sleep time between requests
|
|
||||||
index = 0
|
index = 0
|
||||||
|
|
||||||
exchange = getattr(ccxt, broker)
|
|
||||||
exchange = exchange({
|
|
||||||
"apiKey": "",
|
|
||||||
"secret": "",
|
|
||||||
"password": "",
|
|
||||||
"timeout": 30000,
|
|
||||||
"enableRateLimit": True
|
|
||||||
})
|
|
||||||
|
|
||||||
for pair in pair_list:
|
|
||||||
trading_volume = 0
|
trading_volume = 0
|
||||||
index += 1
|
index += 1
|
||||||
try:
|
try:
|
||||||
data = exchange.fetch_ohlcv(pair,timeframe=timeframe,limit=samples)
|
data = exchange.fetch_ohlcv(pair,timeframe=timeframe,limit=samples)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
write_to_log(str(e))
|
write_to_log(str(e))
|
||||||
continue
|
return None
|
||||||
try:
|
try:
|
||||||
parkinson_volatility = parkinson(data)
|
parkinson_volatility = parkinson(data)
|
||||||
yangzhang_volatility = yang_zhang(data)
|
yangzhang_volatility = yang_zhang(data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
write_to_log(str(e))
|
write_to_log(str(e))
|
||||||
continue
|
return None
|
||||||
for item in data:
|
for item in data:
|
||||||
trading_volume += item[4]*item[5]
|
trading_volume += item[4]*item[5]
|
||||||
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)
|
|
||||||
|
|
||||||
return 0
|
print(f"{pair} on {broker} ready, {len(pair_list)-index} pairs remaining.")
|
||||||
|
return [round(yangzhang_volatility*100,2),round(parkinson_volatility*100,2),int(trading_volume)]
|
||||||
|
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
|
|
||||||
threads = []
|
threads = []
|
||||||
pair_list = []
|
|
||||||
volatilities = {}
|
volatilities = {}
|
||||||
samples = 288
|
samples = 288
|
||||||
timeframe = "5m"
|
timeframe = "5m"
|
||||||
minimum_volume = 0
|
minimum_volume = 0
|
||||||
|
wait_time = .5
|
||||||
|
|
||||||
#Create database if it does not exist
|
#Create database if it does not exist
|
||||||
database_connection = sqlite3.connect(f"{get_credentials('VOL_DB_PATH')['path']}{sys.argv[1]}.db")
|
database_connection = sqlite3.connect(f"{get_credentials('VOL_DB_PATH')['path']}{sys.argv[1]}.db")
|
||||||
|
|
@ -175,8 +160,22 @@ if __name__=="__main__":
|
||||||
database_connection.commit()
|
database_connection.commit()
|
||||||
database_connection.close()
|
database_connection.close()
|
||||||
|
|
||||||
|
exchange = getattr(ccxt, sys.argv[1])
|
||||||
|
exchange = exchange({
|
||||||
|
"apiKey": "",
|
||||||
|
"secret": "",
|
||||||
|
"password": "",
|
||||||
|
"timeout": 30000,
|
||||||
|
"enableRateLimit": True
|
||||||
|
})
|
||||||
|
|
||||||
fetch_data(sys.argv[1], get_pair_list(sys.argv[1]), timeframe, samples)
|
pair_list = get_pair_list(sys.argv[1],inclusions = ["/USDT"], exclusions = [])
|
||||||
|
|
||||||
|
for pair in pair_list:
|
||||||
|
data = fetch_data(exchange, pair, timeframe, samples)
|
||||||
|
if data is not None:
|
||||||
|
volatilities[pair] = data
|
||||||
|
time.sleep(wait_time)
|
||||||
|
|
||||||
write_to_db(sys.argv[1],volatilities)
|
write_to_db(sys.argv[1],volatilities)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue