Beispiel #1
0
 def setUp(self):
     self.price_events = Queue.Queue()
     self.order_events = Queue.Queue()
     stoprequest = threading.Event()
     self.ticker = MockPriceStream(self.price_events, stoprequest)
     #bid=3, ask=4
     self.ticker.newprice(3, 4)
     #        self.ticker.stream_to_queue()
     self.pf = Portfolio(self.ticker, self.order_events, "EUR", 1, 10000,
                         0.02)
     self.leverage_pf = Portfolio(self.ticker, self.order_events, "EUR", 20,
                                  10000, 0.02)
Beispiel #2
0
        prices = StreamingForexPrices_OANDA(STREAM_DOMAIN, ACCESS_TOKEN,
                                            ACCOUNT_ID, instruments, events,
                                            stoprequest)
        # Create the execution handler making sure to
        # provide authentication commands
        execution = ExecutionAtOANDA(API_DOMAIN, ACCESS_TOKEN, ACCOUNT_ID,
                                     events)

    # Create the strategy/signal generator, passing the
    # instrument, quantity of units and the events queue
    strategy = TestRandomStrategy(events)

    # Create the portfolio object that will be used to
    # compare the OANDA positions with the local, to
    # ensure backtesting integrity.
    portfolio = Portfolio(prices, events, equity=units)

    # Create two separate threads: One for the trading loop
    # and another for the market price streaming class
    trade_thread = threading.Thread(target=trade,
                                    args=(events, strategy, portfolio,
                                          execution, stoprequest))
    price_thread = threading.Thread(target=prices.stream_to_queue, args=[])

    # Start both threads
    trade_thread.start()
    price_thread.start()

    # say to the threads if i have pressed ctrl+c
    try:
        while trade_thread.is_alive():