Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
: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
def resample_to_interval(dataframe, interval):
if isinstance(interval, str):
interval = TICKER_INTERVAL_MINUTES[interval]
"""
resamples the given dataframe to the desired interval.
Please be aware you need to upscale this to join the results
with the other dataframe
:param dataframe: dataframe containing close/high/low/open/volume
:param interval: to which ticker value in minutes would you like to resample it
:return:
"""
df = dataframe.copy()
df = df.set_index(DatetimeIndex(df['date']))
ohlc_dict = {
'open': 'first',
'high': 'max',