Esempio n. 1
0
    def _update_daily_quotation(self, row, stock):

        try:
            row['daycode'] = stock['daycode']
            row['change'] = stock['change']

            row['volume'] = Utils.to_int(stock['成交股數'])
            row['deal'] = Utils.to_int(stock['成交筆數'])
            row['amount'] = Utils.to_int(stock['成交金額'])
            row['open_price'] = Utils.to_float(stock['開盤價'])
            row['top_price'] = Utils.to_float(stock['最高價'])
            row['low_price'] = Utils.to_float(stock['最低價'])
            row['close_price'] = Utils.to_float(stock['收盤價'])

            row['final_reveal_buy_price'] = Utils.to_float(stock['最後揭示買價'])
            row['final_reveal_buy_vol'] = Utils.to_int(stock['最後揭示買量'])
            row['final_reveal_sell_price'] = Utils.to_float(stock['最後揭示賣價'])
            row['final_reveal_sell_vol'] = Utils.to_int(stock['最後揭示賣量'])
        except:
            raise ValueError('Parsing Error!')

        #Update StockInfo if this is not found in StockInfo
        if (self.stockinfo_get_by_code(stock["證券代號"]) == None):
            new_stockinfo = StockInfo()
            new_stockinfo.market = stock['market']
            new_stockinfo.code = stock['證券代號']
            new_stockinfo.name = stock['證券名稱']
            new_stockinfo.tags = ("UNKNOWN", )
            self.stockinfo_set(new_stockinfo)
Esempio n. 2
0
    def stockinfo_get_by_code(self, stock_code):

        table = self.tbl_stockinfo

        enc_stock_code = stock_code.encode(self.encoding, errors="replace")
        for row in table.where("code == enc_stock_code"):
            ret_stockinfo = StockInfo()
            ret_stockinfo.market = row['market'].decode(self.encoding)
            ret_stockinfo.code = row['code'].decode(self.encoding)
            ret_stockinfo.name = row['name'].decode(self.encoding)
            ret_stockinfo.tags = row['tags'].decode(self.encoding)
            return ret_stockinfo

        return None