Example #1
0
 def testMarketOrderShort(self):
     self._placed_smo = False
     mf = MultiFeed()
     mf.register_feed(self._feed)
     self._broker = BacktestingBroker(10000, mf)
     mf.subscribe(self.on_bars_3)
     self._broker.getOrderUpdatedEvent().subscribe(self.on_order_update_3)
     mf.start()
Example #2
0
    def __init__(self, barFeed, cash=1000000, broker_=None):
        self.__feed = barFeed
        self.__activePositions = {}
        self.__orderToPosition = {}
        self.__barsProcessedEvent = observer.Event()
        self.__orderUpdatedEvent = observer.Event()
        self.__analyzers = []
        self.__namedAnalyzers = {}

        if broker_ == None:
            # When doing backtesting (broker_ == None), the broker should subscribe to barFeed events before the strategy.
            # This is to avoid executing orders placed in the current tick.
            self.__broker = BacktestingBroker(cash, barFeed)
        else:
            self.__broker = broker_
        self.__broker.getOrderUpdatedEvent().subscribe(self.__onOrderUpdate)
        # very important that this happens after the broker subscribes to the feed
        self.__feed.subscribe(self.__onBars)