コード例 #1
0
 def refresh_list_box(self):
     self.lstboxStockCash.delete(0, END)
     stock_cash_table = StockCashTable()
     stock_cash_list = stock_cash_table.get_all_stock_cash()
     for stock_cash in stock_cash_list:
         self.lstboxStockCash.insert(END, stock_cash.get_symbol())
     return
コード例 #2
0
 def add_stock_cash(self):
     stock_cash = StockCash()
     stock_cash.set_symbol(self.entrySymbol.get())
     stock_cash.set_amount(self.entryAmount.get())
     stock_cash_table = StockCashTable()
     stock_cash_table.add_stock_cash(stock_cash)
     self.set_status("Added")
コード例 #3
0
 def get_cash_value(self):
     stock_cash_table = StockCashTable(self.conn)
     stock_cash = stock_cash_table.get_stock_cash_by_symbol(self.symbol)
     # minus the transaction service fee,
     # the database operation need to decouple from the algorithm
     amount = stock_cash.get_amount() - 20
     return amount
コード例 #4
0
 def get_cash_pool_text(self):
     result = ""
     stock_cash_table = StockCashTable()
     stock_cash_list = stock_cash_table.get_all_stock_cash()
     for stock_cash in stock_cash_list:
         result = result + "{0}".format(stock_cash) + "\n"
     return result
コード例 #5
0
 def fill_symbol_combobox(self):
     stock_cash_table = StockCashTable()
     stock_cash_list = stock_cash_table.get_all_stock_cash()
     symbol_list = []
     for stock_cash in stock_cash_list:
         symbol_list.append(stock_cash.get_symbol())
     self.cbbSymbol["values"] = symbol_list
     return
コード例 #6
0
    def delete_stock_cash(self):
        index = self.lstboxStockCash.curselection()
        if len(index) == 0:
            return

        symbol = self.lstboxStockCash.get(index[0])

        stock_cash = StockCash(symbol)
        stock_cash_table = StockCashTable()
        stock_cash_table.delete_stock_cash(stock_cash)

        self.refresh_list_box()

        return
コード例 #7
0
    def update_stock_cash(self):
        index = self.lstboxStockCash.curselection()
        if len(index) == 0:
            return
        
        symbol = self.lstboxStockCash.get(index[0])
        amount = float(self.entryAmount.get())
        
        stock_cash = StockCash(symbol, amount)
        stock_cash_table = StockCashTable()
        stock_cash_table.update_stock_cash(stock_cash)

        self.refresh_list_box()
        
        return
コード例 #8
0
    def test_stock_cash_sanity(self):
        stock_db_connection = get_default_db_connection()
        reset_table(stock_db_connection)
        stock_cash_table = StockCashTable(stock_db_connection)
        stock_cash = StockCash("601398", 1000)
        stock_cash_table.add_stock_cash(stock_cash)

        # test the new created line
        stock_cash = stock_cash_table.get_stock_cash_by_symbol("601398")
        self.assertEqual(stock_cash.get_symbol(), "601398")
        self.assertEqual(stock_cash.get_amount(), 1000)

        # test update stock cash
        stock_cash.set_amount(23.456)
        stock_cash_table.update_stock_cash(stock_cash)
        stock_cash = stock_cash_table.get_stock_cash_by_symbol("601398")
        self.assertEqual(stock_cash.get_amount(), 23.456)

        # test an unavailable line
        stock_cash = stock_cash_table.get_stock_cash_by_symbol("XXXXXX")
        self.assertEqual(stock_cash, None)

        # insert a new line, and test get_all function
        stock_cash = StockCash("601857", 5000)
        stock_cash_table.add_stock_cash(stock_cash)
        stock_cash_list = stock_cash_table.get_all_stock_cash()
        self.assertEqual(len(stock_cash_list), 2)
        stock_cash = stock_cash_list[0]
        self.assertEqual(stock_cash.get_symbol(), "601398")
        self.assertEqual(stock_cash.get_amount(), 23.456)
        stock_cash = stock_cash_list[1]
        self.assertEqual(stock_cash.get_symbol(), "601857")
        self.assertEqual(stock_cash.get_amount(), 5000)

        # delete a line
        stock_cash = StockCash("601398", 0)
        stock_cash_table.delete_stock_cash(stock_cash)
        stock_cash = stock_cash_table.get_stock_cash_by_symbol("601398")
        self.assertEqual(stock_cash, None)
コード例 #9
0
 def get_cash_value(self):
     stock_cash_table = StockCashTable(self.conn)
     stock_cash = stock_cash_table.get_stock_cash_by_symbol(self.symbol)
     amount = stock_cash.get_amount()
     return amount