Why the variable freq is not defined in the method update? I am calling the method candle on init and this method contains freq?
class candle:
def __init__(self):
self.freq = None
self.open_price = None
self.high_price = None
self.low_price = None
self.last_price = None
self.volume = 0
def addTick(self,tick):
if self.open_price is None:
self.open_price = tick.price
if self.high_price is None or tick.price >self.high_price:
self.high_price = tick.price
if self.low_price is None or tick.price <self.low_price:
self.low_price = tick.price
self.last_price = tick.price
self.volume = self.volume +1
def update(self,tick):
self.candle.addTick(tick)
if keyfunc(current_time,freq) != reference_timestamp[freq]:
self.notify(self.candle)
self.candle = candle()
There is no implicit self in Python, you must be explicit when accessing member variables.
if keyfunc(current_time,freq) != reference_timestamp[freq]:
should be
if keyfunc(current_time, self.freq) != reference_timestamp[self.freq]:
not sure where reference_timestamp is defined, assuming it's global.
You're trying to access a local variable (which is not defined in that scope) instead of class instance attribute. Try self.freq instead of freq.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With