Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def compute_interval(dataframe: DataFrame, exchange_interval=False):
"""
calculates the interval of the given dataframe for us
:param dataframe:
:param exchange_interval: should we convert the result to an exchange interval or just a number
:return:
"""
res_interval = int((dataframe['date'] - dataframe['date'].shift()).min().total_seconds() // 60)
if exchange_interval:
# convert to our allowed ticker values
from technical.exchange import TICKER_INTERVAL_MINUTES
converted = list(TICKER_INTERVAL_MINUTES.keys())[
list(TICKER_INTERVAL_MINUTES.values()).index(exchange_interval)]
if len(converted) > 0:
return converted
else:
raise Exception(
f"sorry, your interval of {res_interval} is not "
f"supported in {TICKER_INTERVAL_MINUTES}")
return res_interval