Beispiel #1
0
 def get_current_data(self, symbol):
     yahoo_symbol = Symbols.get_mapped_symbol(symbol)
     url = 'https://finance.yahoo.com/quote/%s/' % yahoo_symbol
     content = HttpHelper.http_get(url)
     try:
         sub_content = string_fetch(content, 'Currency in USD', 'At close:')
         sub_content = string_fetch(sub_content, 'react-text', 'react-text')
         value = string_fetch(sub_content, '-->', '<!--')
         return float(value.replace(',', ''))
     except Exception:
         sub_content = string_fetch(content, '\"close\":', ',')
         value = round(float(sub_content), 2)
         return value
Beispiel #2
0
 def get_data_by_symbol(symbol):
     logger = Logger(__name__, PathMgr.get_log_path())
     yahoo_symbol = Symbols.get_mapped_symbol(symbol)
     url = 'https://finance.yahoo.com/quote/%s/' % yahoo_symbol
     logger.info('Http request to: %s' % url, False)
     content = HttpHelper.http_get(url)
     try:
         sub_content = string_fetch(content, 'Currency in USD', 'At close:')
         sub_content = string_fetch(sub_content, 'react-text', 'react-text')
         value = string_fetch(sub_content, '-->', '<!--')
         return float(value.replace(',', ''))
     except Exception:
         sub_content = string_fetch(content, '\"close\":', ',')
         value = round(float(sub_content), 2)
         return value
Beispiel #3
0
 def history(self, symbol, field, window):
     fields_dic = {
         'open': 'openPrice',
         'close': 'adjclosePrice',
         'high': 'highPrice',
         'low': 'lowPrice',
         'price': 'adjclosePrice'
     }
     fields = fields_dic.keys()
     if field.lower() not in field:
         raise Exception('the field should be in %s...' % fields)
     price_field = fields_dic[field]
     yahoo_symbol = Symbols.get_mapped_symbol(symbol)
     from_date = TradeTime.get_from_date_by_window(window)
     rows = YahooEquityDAO().get_all_equity_price_by_symbol(
         yahoo_symbol, from_date.strftime('%Y-%m-%d'), price_field)
     return rows
Beispiel #4
0
 def get_start_end_date_by_symbols(self):
     reversed_yahoo_symbol_mapping = Symbols.get_reversed_yahoo_symbol_mapping(
     )
     conn = self.get_connection()
     cursor = conn.cursor()
     records = []
     for symbol in Symbols.get_all_symbols():
         start_date = self.get_start_date_by_symbol(symbol, cursor)
         end_date = self.get_end_date_by_symbol(symbol, cursor)
         records.append([
             Symbols.get_mapped_symbol(symbol,
                                       reversed_yahoo_symbol_mapping),
             start_date, end_date
         ])
         records.sort()
     conn.close()
     return records