def testCancelOrder(self):

        stock = Stock(symbol='symbol',
                      description='a stock',
                      ISIN='US123456789',
                      exchange=self.exchange)
        order1 = BuyOrder(account=self.account,
                          security=stock,
                          price=13.2,
                          share=10)
        order2 = BuyOrder(account=self.account,
                          security=stock,
                          price=13.25,
                          share=10)

        self.session.add(order1)
        self.session.add(order2)
        self.session.commit()

        tc = TradingCenter(self.session, self.pubsub)

        order1.cancel()
        self.assertEquals([order2], tc.open_orders(stock))
        # cancel open orders
        self.assertEquals([order2], tc.cancel_orders())
        self.assertEquals(CancelOrderStage, type(order1.current_stage))
        self.assertEquals([], tc.open_orders(stock))
Beispiel #2
0
class TradingCenterThread(Thread):
    def __init__(self, session, pubsub):
        Thread.__init__(self)
        self.trading_center = TradingCenter(session, pubsub)

    def run(self):
        while True:
            self.trading_center.consume()
Beispiel #3
0
class TradingCenterThread(Thread):

    def __init__(self, session, pubsub):
        Thread.__init__(self)
        self.trading_center = TradingCenter(session, pubsub)

    def run(self):
        while True:
            self.trading_center.consume()
    def testGetOpenOrdersBySymbol(self):

        stock=Stock(symbol='symbol', description='a stock', ISIN='US123456789', exchange=self.exchange)
        order1=BuyOrder(account=self.account, security=stock, price=13.2, share=10)
        order2=BuyOrder(account=self.account, security=stock, price=13.25, share=10)
        self.session.add(order1)
        self.session.add(order2)
        self.session.commit()

        tc=TradingCenter(self.session)
        orders=tc.open_orders_by_symbol('symbol')
        self.assertEquals([order1, order2], list(orders))
    def testCancelAllOpenOrders(self):
        security=Stock(symbol='symbol', description='a stock', ISIN='US123456789', exchange=self.exchange)
        order1=BuyOrder(account=self.account, security=security, price=13.2, share=10)
        order2=BuyOrder(account=self.account, security=security, price=13.25, share=10)

        self.session.add(order1)
        self.session.add(order2)
        self.session.commit()

        tc=TradingCenter(self.session)

        tc.cancel_all_open_orders()

        self.assertEquals([], tc.open_orders)
    def test_open_orders_by_order_id(self):
        stock=Stock(symbol='symbol', description='a stock', ISIN='US123456789', exchange=self.exchange)
        order1=BuyOrder(account=self.account, security=stock, price=13.2, share=10)
        order2=BuyOrder(account=self.account, security=stock, price=13.25, share=10)
        self.session.add(order1)
        self.session.add(order2)
        self.session.commit()

        tc=TradingCenter(self.session)
        order=tc.open_order_by_id(order1.id)
        self.assertEquals(order1, order)

        order=tc.open_order_by_id(100)
        self.assertEquals(None, order)
    def testCancelOrder(self):

        stock=Stock(symbol='symbol', description='a stock', ISIN='US123456789', exchange=self.exchange)
        order1=BuyOrder(account=self.account, security=stock, price=13.2, share=10)
        order2=BuyOrder(account=self.account, security=stock, price=13.25, share=10)

        self.session.add(order1)
        self.session.add(order2)
        self.session.commit()

        tc=TradingCenter(self.session, self.pubsub)

        order1.cancel()
        self.assertEquals([order2], tc.open_orders(stock))
        # cancel open orders
        self.assertEquals([order2], tc.cancel_orders())
        self.assertEquals(CancelOrderStage, type(order1.current_stage))
        self.assertEquals([], tc.open_orders(stock))
    def test_retrievet_open_orders(self):

        stock = Stock(symbol='symbol',
                      description='a stock',
                      ISIN='US123456789',
                      exchange=self.exchange)
        order1 = BuyOrder(account=self.account,
                          security=stock,
                          price=13.2,
                          share=10)
        order2 = BuyOrder(account=self.account,
                          security=stock,
                          price=13.25,
                          share=10)
        self.session.add(order1)
        self.session.add(order2)
        self.session.commit()

        tc = TradingCenter(self.session, self.pubsub)
        orders = tc.open_orders(stock)
        self.assertEquals([order1, order2], list(orders))
    def testCancelAllOpenOrders(self):
        security = Stock(symbol='symbol',
                         description='a stock',
                         ISIN='US123456789',
                         exchange=self.exchange)
        order1 = BuyOrder(account=self.account,
                          security=security,
                          price=13.2,
                          share=10)
        order2 = BuyOrder(account=self.account,
                          security=security,
                          price=13.25,
                          share=10)

        self.session.add(order1)
        self.session.add(order2)
        self.session.commit()

        tc = TradingCenter(self.session, self.pubsub)

        tc.cancel_orders()

        self.assertEquals([], tc.open_orders(security))
Beispiel #10
0
 def __init__(self, session, pubsub):
     Thread.__init__(self)
     self.trading_center = TradingCenter(session, pubsub)
Beispiel #11
0
 def __init__(self, session, pubsub):
     Thread.__init__(self)
     self.trading_center = TradingCenter(session, pubsub)