def simulate(self, data, asset, orders_for_asset): self._volume_for_bar = 0 price = data.current(asset, 'close') dt = data.current_dt for order in orders_for_asset: if order.open_amount == 0: continue order.check_triggers(price, dt) if not order.triggered: log.info( 'order has not reached the trigger at current ' 'price {}'.format(price) ) continue execution_price, execution_volume = self.process_order(data, order) if execution_price is not None: transaction = create_transaction( order, dt, execution_price, execution_volume ) self._volume_for_bar += abs(transaction.amount) yield order, transaction
def simulate(self, data, asset, orders_for_asset): self._volume_for_bar = 0 volume = data.current(asset, "volume") if volume == 0: return # can use the close price, since we verified there's volume in this # bar. price = data.current(asset, "close") # BEGIN # # Remove this block after fixing data to ensure volume always has # corresponding price. if isnull(price): return # END dt = data.current_dt for order in orders_for_asset: if order.open_amount == 0: continue order.check_triggers(price, dt) if not order.triggered: continue txn = None try: execution_price, execution_volume = \ self.process_order(data, order) if execution_price is not None: txn = create_transaction( order, data.current_dt, execution_price, execution_volume ) except LiquidityExceeded: break if txn: self._volume_for_bar += abs(txn.amount) yield order, txn