def get_minute_data(self, code, period='1', adjust="", expire=60 * 6): """ 获取一支股票分钟级数据保存到本地 """ UT.check_dir(CT.MINUTE_DIR + '/' + period) file_path = CT.MINUTE_DIR + '/' + period + '/' + code expired = UT.check_file_expired(file_path, expire) if expired or not os.path.exists(file_path): symbol = self._code_to_symbol(code) start_date = CT.START end_date = date_time.get_today_str() adjust = 'qfq' # d = ak.stock_zh_a_minute(symbol, period, adjust) d = self.stock_zh_a_minute(symbol, period, adjust) if d is None: return d d.to_csv(file_path, sep='\t') if not os.path.exists(file_path): return None #d = pd.read_csv(file_path, sep='\t', index_col=1) d = pd.read_csv(file_path, sep='\t', skiprows=0, parse_dates=True, header=0, index_col=0) return d
def get_daily_data(self, code, expire=60 * 6): """ 获取一支股票所有历史数据保存到本地 """ UT.check_dir(CT.DAILY_DIR) file_path = CT.DAILY_DIR + code expired = UT.check_file_expired(file_path, expire) if expired or not os.path.exists(file_path): symbol = self._code_to_symbol(code) start_date = CT.START end_date = date_time.get_today_str() adjust = 'qfq' if is_index(code): d = ak.stock_zh_index_daily(symbol) else: d = ak.stock_zh_a_daily(symbol, start_date, end_date, adjust) if d is None: return d d.to_csv(file_path, sep='\t') if not os.path.exists(file_path): return None #d = pd.read_csv(file_path, sep='\t', index_col=0) d = pd.read_csv(file_path, sep='\t', skiprows=0, parse_dates=True, header=0, index_col=0) return d
def main(argv): #get_all_tick_data('000001') try: opts, args = getopt.getopt(argv[1:], "dhe:m:i:t:s:a:") except getopt.GetoptError as err: print(err) return -1 log_level = logging.INFO mode = '' index = 0 thread = 1 symbol = '000000' date = date_time.get_today_str() for ok, ov in opts: if ok in ('-d', '--debug'): log_level = logging.DEBUG if ok in ('-e', '--expire'): global g_expire g_expire = int(ov) if ok in ('-m', '--mode'): mode = ov if ok in ('-i', '--index'): index = int(ov) if ok in ('-t', '--thread'): thread = int(ov) if ok in ('-s', '--symbol'): symbol = ov if ok in ('-a', '--date'): date = ov if ok in ('-h', '--help'): help() return logging.basicConfig( level=log_level, format= '%(levelname)s: %(asctime)s [%(pathname)s:%(lineno)d] %(message)s', datefmt='%Y-%M-%d %H:%M:%S', filename=CT.LOG_DIR + 'tick.log', filemode='a') log_str = 'running model[%s] index[%d] thread[%d] symbol[%s] date[%s]' % ( mode, index, thread, symbol, date) print(log_str) logging.info(log_str) if mode == 'symbol': get_tick_data_symbol(symbol, index, thread) elif mode == 'date': get_tick_data_date(date, index, thread) elif mode == 'allsince': get_tick_data_since(date, index, thread) elif mode == 'since': get_symbol_tick_data_since(symbol, date) elif mode == 'tick': q = Quotation() q.get_tick_data(symbol, date) else: print(('args err mode[%s]' % (mode))) logging.error('args err mode[%s]' % (mode)) return
def get_sina_dd(self, code, date='', vol=400): """ 大单交易数据 """ if date == '': date = date_time.get_today_str() d = ts.get_sina_dd(code, date=date, vol=vol) return d
def get_h_data(self, symbol, expire=60): """ 获取一支股票所有历史数据保存到本地 """ if not os.path.exists(CT.HIS_DIR): os.makedirs(CT.HIS_DIR) file_path = CT.HIS_DIR + symbol expired = date_time.check_file_expired(file_path, expire) if expired: today = date_time.get_today_str() d = ts.get_h_data(symbol, autype=None, start=CT.START, end=today, drop_factor=False) d.to_csv(CT.HIS_DIR + symbol) return d else: d = pd.read_csv(file_path) return d
def get_h_data(self, symbol, expire=60*6): """ 获取一支股票所有历史数据保存到本地 """ if not os.path.exists(CT.HIS_DIR): os.makedirs(CT.HIS_DIR) file_path = CT.HIS_DIR + symbol expired = date_time.check_file_expired(file_path, expire) if expired or not os.path.exists(file_path): today = date_time.get_today_str() d = ts.get_h_data(symbol, autype=None, start=CT.START, end=today, drop_factor=False) #index = [] #for i in list(d.index): # index.append(date_time.date_to_str(i)) #d = d.reindex(index, method='ffill') if d is None: return d d.to_csv(CT.HIS_DIR + symbol, sep='\t') #return d if not os.path.exists(file_path): return None d = pd.read_csv(file_path, sep='\t', index_col=0) return d
'''.encode('utf-8')) def main(argv): #get_all_tick_data('000001') try: opts, args = getopt.getopt(argv[1:], "dhe:m:i:t:s:a:") except getopt.GetoptError, err: print err return -1 log_level = logging.INFO mode = '' index = 0 thread = 1 symbol = '000000' date = date_time.get_today_str() for ok, ov in opts: if ok in ('-d', '--debug'): log_level = logging.DEBUG if ok in ('-e', '--expire'): global g_expire g_expire = int(ov) if ok in ('-m', '--mode'): mode = ov if ok in ('-i', '--index'): index = int(ov) if ok in ('-t', '--thread'): thread = int(ov) if ok in ('-s', '--symbol'): symbol = ov if ok in ('-a', '--date'):