def tradecal(self, _fields="trade_date, istradeday"): self.__lazy_login() df, msg = self.__api.query( view="jz.secTradeCal", fields=_fields) log.debug('request jz.secTradeCal') return df
def instrumentinfo(self, _fields="", _filter="inst_type=1&status=1&market=SH,SZ"): self.__lazy_login() df, msg = self.__api.query(view="jz.instrumentInfo", fields=_fields, filter=_filter, data_format='pandas') log.debug('request jz.instrumentInfo') return df
def request_kline(symbol, freq , **kwargs): query = kline.KlineQuery(symbol) log.debug('begin to request [%s]' % symbol) if query.isEmpty(freq): ## TODO request all info = composite.get_basic().info(symbol) if info is None: raise ValueError('%s not exist'% symbol) born = info['timeToMarket'] return request_kline_core(symbol, start_date=trade_calendar.create_v2(born, freq), end_date = trade_calendar.last_trade_date(freq), freq = freq, **kwargs) else: db_start, db_end = query.duration(freq) if db_start is None and db_end is None: log.error('duration in db is error') raise RuntimeError('[%s] isn\'t exist, but duration ???' % symbol) last_date = trade_calendar.last_trade_date(freq) if trade_calendar.compare_v2(db_end, last_date, freq) == 0: ## TODO check suspend stock log.info('%s needn\'t update' % symbol) return 1 elif trade_calendar.compare_v2(db_end, last_date, freq) < 0: db_end.shift(count = 1) return request_kline_core(symbol, db_end, last_date, freq, **kwargs) else: raise RuntimeError("????")
def bar(self, _symbol, _trade_date, _freq="5M", _fields=""): self.__lazy_login() df, msg = self.__api.bar(symbol=_symbol, trade_date=_trade_date, freq=_freq, fields=_fields) log.debug('request bar') return df
def get(self, symbol): df = self.load() ret = df[df['code'] == symbol] log.debug('symbol %s' % symbol) if isinstance(ret, pd.DataFrame): return ret[['close', 'open', 'high', 'low', 'vol', 'tor', 'amount', 'datetime']] else: raise RuntimeError('invalid symbol %s' % symbol)
def daily(self, symbol, start_date, end_date, freq='1d', fields= "", adjust_mode='post'): self.__lazy_login() df, msg = self.__api.daily( symbol=symbol, freq=freq, start_date=start_date, end_date=end_date, fields=fields, adjust_mode=adjust_mode) log.debug('request daily %s' % msg) return df
def __replace(self, symbol, start, end, df): log.info('replace %s from %s to %s' % (symbol, start, end)) info = {'symbol': symbol, 'start_date':start.datetime(),\ 'end_date':end.datetime()} klines = util.to_json(df) for k in klines: k['datetime'] = trade_calendar.create_v2(k['datetime'], self.freq).datetime() self.table.update({'_id': symbol}, { '$set':{'info': info}, \ ## TODO sort operation '$setOnInsert':{'kline': klines} \ }, upsert=True) log.debug('replace end')
def subscribe(self, _symbol, _func, _fields): self.__lazy_login() sublist, msg = self.__api.subscribe(_symbol, func=_func, fields=_fields) log.debug('request subscribe') return sublist