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) )
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) )
def testGetHoldingCost(self): share = 10 price = 9.1 account = Account(1000, 1) account._Account__holdings = {'stock1': (share, price)} holdingCost = account.getHoldingCost() self.assertAlmostEquals(share * price, holdingCost)
def testGetHoldingCost(self): share = 10 price = 9.1 account = Account(1000, 1) account._Account__holdings = {'stock1': (share, price)} holdingCost = account.getHoldingCost() self.assertAlmostEquals(share * price, holdingCost)
def testTotalValue(self): share = 10 price = 9.1 curPrice = 10.1 account = Account(1000, 1) account._Account__holdings = {'stock1': (share, price)} account.setLastTickDict({'stock1': Quote(0, 0, 0, 0, curPrice, 0, 0)}) totalValue = account.getTotalValue() self.assertAlmostEquals(1000 + share * curPrice, totalValue)
def testTotalValue(self): share = 10 price = 9.1 curPrice = 10.1 account = Account(1000, 1) account._Account__holdings = {'stock1': (share, price)} account.setLastTickDict({'stock1': Quote(0, 0, 0, 0, curPrice, 0, 0)}) totalValue = account.getTotalValue() self.assertAlmostEquals(1000 + share * curPrice, totalValue)