У меня возникли проблемы с вызовом одной функции из другой
Вот код, который у меня есть:
supported_timeframes = ['1m', '5m', '1h', '1d']
supported_indicators = ['SMA', ... ]
supported_sources = ['open', 'close']
indicator_values = {}
class Indicator:
def __init__(self):
self.indictor = '' # indicator
self.timeframe = '' # timeframe
self.period = 0 # look-back period
self.source = '' # open / close
def error(self, indicator, timeframe, period, source):
if timeframe not in supported_timeframes:
return 'timeframe not supported --', 'supported
timeframes:', supported_indicators
if indicator not in supported_indicators:
return 'indicator not found --', 'supported indicators:',
supported_indicators
if source not in supported_sources:
return 'source is not -- open -- or -- close'
else:
pass
def SMA(self, indicator, timeframe, period, source):
error()
# TODO get candle data from timeframe
# TODO calc requested indicator from candle data and append to
# indicator_values dict
# return indicator
for indicator in indicator_values:
return indicator
Сначала у меня есть ошибка функции, чтобы проверить, были ли введены неправильные значения в параметры.
Затем я хочу вызвать эту функцию в функции def SMA(...)
, потому что у меня будет много других функций, каждая из которых вычисляет индикатор, аналогичный SMA, поэтому, чтобы все было кратко, я пытаюсь вызвать error()
в каждой из них вместо копирования и вставки. код внутри каждый раз.
Однако при этом я получаю сообщение об ошибке в def SMA(...)
, в котором говорится, что error()
не определено.
Заранее большое спасибо, если сможете мне помочь!
Если я что-то не упустил, вам просто нужно добавить себя, когда вы вызываете error()
def SMA(self, indicator, timeframe, period, source):
self.error()