mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-12 09:10:00 +08:00
BUG: Prevent crash in vwap transform due to non-existent member.
The WrongDataForTransform was referencing a `self.fields` member, which did not exist. Add a self.fields member set to `price` and `volume` and use it to iterate over during the check.
This commit is contained in:
@@ -73,6 +73,7 @@ class VWAPEventWindow(EventWindow):
|
||||
"""
|
||||
def __init__(self, market_aware=True, window_length=None, delta=None):
|
||||
EventWindow.__init__(self, market_aware, window_length, delta)
|
||||
self.fields = ('price', 'volume')
|
||||
self.flux = 0.0
|
||||
self.totalvolume = 0.0
|
||||
|
||||
@@ -100,7 +101,8 @@ class VWAPEventWindow(EventWindow):
|
||||
|
||||
# We need numerical price and volume to calculate a vwap.
|
||||
def assert_required_fields(self, event):
|
||||
if 'price' not in event or 'volume' not in event:
|
||||
raise WrongDataForTransform(
|
||||
transform="VWAPEventWindow",
|
||||
fields=self.fields)
|
||||
for field in self.fields:
|
||||
if field not in event:
|
||||
raise WrongDataForTransform(
|
||||
transform="VWAPEventWindow",
|
||||
fields=self.fields)
|
||||
|
||||
Reference in New Issue
Block a user