def handle_data(self, data, *args, **kwargs): """ Point of entry. Process an event frame. """ # extract dates dts = [event.datetime for event in data._data.itervalues()] # we have to provide the event with a dt. This is only for # checking if the event is outside the window or not so a # couple of seconds shouldn't matter. We don't add it to # the data parameter, because it would mix dt with the # sid keys. event = Event() event.dt = max(dts) event.data = { k: v.__dict__ for k, v in data._data.iteritems() # Need to check if data has a 'length' to filter # out sids without trade data available. # TODO: expose more of 'no trade available' # functionality to zipline if len(v) } # only modify the trailing window if this is # a new event. This is intended to make handle_data # idempotent. if self.last_dt < event.dt: self.updated = True self._append_to_window(event) else: self.updated = False # return newly computed or cached value return self.get_transform_value(*args, **kwargs)
def handle_data(self, data, *args, **kwargs): """ Point of entry. Process an event frame. """ # extract dates dts = [event.datetime for event in data._data.itervalues()] # we have to provide the event with a dt. This is only for # checking if the event is outside the window or not so a # couple of seconds shouldn't matter. We don't add it to # the data parameter, because it would mix dt with the # sid keys. event = Event() event.dt = max(dts) event.data = {k: v.__dict__ for k, v in data._data.iteritems() # Need to check if data has a 'length' to filter # out sids without trade data available. # TODO: expose more of 'no trade available' # functionality to zipline if len(v)} # only modify the trailing window if this is # a new event. This is intended to make handle_data # idempotent. if self.last_dt < event.dt: self.updated = True self._append_to_window(event) else: self.updated = False # return newly computed or cached value return self.get_transform_value(*args, **kwargs)
def create_trade(sid, price, amount, datetime, source_id="test_factory"): trade = Event() trade.source_id = source_id trade.type = DATASOURCE_TYPE.TRADE trade.sid = sid trade.dt = datetime trade.price = price trade.close_price = price trade.open_price = price trade.low = price * .95 trade.high = price * 1.05 trade.volume = amount return trade
def create_trade(sid, price, amount, datetime, source_id="test_factory"): trade = Event() trade.source_id = source_id trade.type = DATASOURCE_TYPE.TRADE trade.sid = sid trade.dt = datetime trade.price = price trade.close_price = price trade.open_price = price trade.low = price * .95 trade.high = price * 1.05 trade.volume = amount return trade