Beispiel #1
0
 def fill_info(self):
     log.debug('Fetching %s', self.code)
     self.stock = Stock(self.code)
     try:
         if not self.name:
             self.name = self.stock.name
         self.cur_price = self.stock.get_last_day_close()
         self.cur_p_change = self.stock.get_last_day_p_change()
         self.cur_price_ma40 = self.stock.get_last_day_ma40()
     except Exception as e:
         log.exception('Cannot get info for %s' % self.code)
Beispiel #2
0
 def get_k_data(self):
     try:
         df = ts.get_k_data(self.code, retry_count=10)
         close = np.array([float(x) for x in df['close']])
         df['MA40'] = talib.SMA(close, timeperiod=40)
         self.add_macd(df)
         return df
     except Exception as e:
         log.exception('ts.get_k_data for %s failed', self.code)
         # cons = ts.get_apis()
         # return ts.bar(self.code, conn=cons, retry_count=10)
         raise
Beispiel #3
0
def fetch_basis():
    for _ in range(10):
        try:
            log.info('Fetching stock basics...')
            pro = ts.pro_api(
                '4105aca09e41fde2adac11ff8cdf7e05cef205d946e06935562e0010')
            ret = pro.stock_basic(
                exchange='',
                list_status='L',
                fields='ts_code,symbol,name,area,industry,list_date')
            log.info('Fetched')
            df = ret[['ts_code', 'name']]
            df = df.set_index('ts_code')
            return df.to_json(orient='index')
        except:
            log.exception('Fetch stock basics fail, retrying...')

    raise RuntimeError('Fetch stock basics fail')
Beispiel #4
0
 def builder(code):
     try:
         return unit_cls(code)
     except:
         log.exception('Fail to process %s', code)
         return None