def testPlaceOrder_failed(self): tc = TradingCenter() account = Account(1000, 0) self.mock.StubOutWithMock(account, "validate") accountId = tc.accountManager.addAccount(account) order1 = Order(accountId = accountId, side = Side.BUY, symbol = 'symbol', price = 13.25, share = 10) account.validate(order1).AndReturn(False) self.mock.ReplayAll() self.assertEquals(None, tc.placeOrder(order1) ) # True self.mock.VerifyAll()
def testValidate(self): share = 10 price = 9.1 symbol = 'stock1' account = Account(1000, 1) account._Account__holdings = {symbol: (share, price)} # can't buy because price too high order1 = Order(accountId = 'id1', side = Side.BUY, symbol = symbol, price = 10000, share = 100000) self.assertEquals(False, account.validate(order1) ) # can't buy because of commission fee order1 = Order(accountId = 'id1', side = Side.BUY, symbol = symbol, price = 100, share = 10) self.assertEquals(False, account.validate(order1) ) # buy it order1 = Order(accountId = 'id1', side = Side.BUY, symbol = symbol, price = 100, share = 9) self.assertEquals(True, account.validate(order1) ) # can't sell because don't have the stock order1 = Order(accountId = 'id1', side = Side.SELL, symbol = 'fas89ph2', price = 100, share = 9) self.assertEquals(False, account.validate(order1) ) # can't sell because don't have the enough share order1 = Order(accountId = 'id1', side = Side.SELL, symbol = symbol, price = 100, share = 9000) self.assertEquals(False, account.validate(order1) ) # sell it order1 = Order(accountId = 'id1', side = Side.SELL, symbol = symbol, price = 100, share = 9) self.assertEquals(True, account.validate(order1) )