def fillMarketOrder(self, broker_, order, bar): # Calculate the fill size for the order. # redefined fillSize = self.__calculateFillSize(broker_, order, bar) if fillSize == 0: broker_.getLogger().debug( "Not enough volume to fill %s market order [%s] for %s share/s" % (order.getInstrument(), order.getId(), order.getRemaining())) return None # here fill on close is changed its meaning ,it means whether use the opposite value if order.getFillOnClose(): if order.getAction() == pyalgotrade.broker.Order.Action.BUY: price = bar.getAp() else: #sell short price = bar.getBp() else: if order.getAction( ) == pyalgotrade.broker.Order.Action.BUY: #not use the opposite value price = bar.getBp() else: price = bar.getAp() assert price is not None # Don't slip prices when the bar represents the trading activity of a single trade. if bar.getFrequency() != pyalgotrade.bar.Frequency.TRADE: price = self.__slippageModel.calculatePrice( order, price, fillSize, bar, self.__volumeUsed[order.getInstrument()]) return FillInfo(price, fillSize)
def onBars(self, bars): # If a position was not opened, check if we should enter a long position. bar = bars[self.__instrument] print bar.getDateTime(), bar.getBp(), bar.getAp(), self.__sma[-1]