def fs_fuquan(code, start_date=perYearStr(), end_date=todayStr(), autype='qfq', del_duplicate=True): ''' 获取某个股票的复权数据 并入库 :param code: :param start_date: :param end_date: :param autype: :return: ''' if autype == 'none': autype = None s_date, e_date = gen_time_interval(code, autype, start_date, end_date) if s_date and e_date: df = fetch_fuquan(code, s_date, e_date, autype) write2db(df, TN_FUQUAN, 'append') if del_duplicate: _delete_duplicate_data(TN_FUQUAN, 'date', 'code', 'autype') else: print("%s数据已是最新,不需要重新获取")
def dataset_add_type(type): if type == ds.TO_TRANS_D['type']: form = CreateTransDDataSetForm(perYearStr(), todayStr()) if form.validate_on_submit(): name = form.name.data start_date = form.start_date.data end_date = form.end_date.data date_offset = form.date_offset.data if start_date < end_date: type = ds.TO_TRANS_D['type'] dataset = ds.get_dataset(type, name) if dataset: flash_danger("类型为【%s】的数据集【%s】已存在,请尝试换一个名字,或删除重名数据集" % (ds.TO_TRANS_D['name'], name)) else: dataset = ds.gen_trans_d_dataset(name, start_date, end_date, int(date_offset)) dataset.feed_all() flash_success("数据集【%s】创建成功" % name) return redirect(url_for('main.dataset_manage')) else: flash_warning("起始日期需小于截止日期") return make_response( render_template('dataset/creater/trans_d.html', creater_list=creater_list(), form=form)) return make_response(render_template('dataset/dataset_add.html'))
def query_trans_d(code, start_date, end_date=strutils.todayStr()): ''' 查询交易数据 :param code :param start_date: :param end_date: :return: ''' return read_sql( "select * from '%s' where date >= '%s' and date <= '%s' and code = '%s';" % (TN_TRANSACTION_D, start_date, end_date, code))
def gen_trans_d_dataset(name, start_date, end_date=strutils.todayStr(), offset_day=1): ''' 生成日交易记录数据集 :param name: 数据集名称 :param start_date: 起始日期 :param end_date: 结束日期 :param offset_day: Y数据相对于X数据的日期偏差 :return: ''' des = "开始时间%s,结束时间%s,日期间隔%s" % (start_date, end_date, offset_day) return TransDDataSet(TO_TRANS_D, name, pd.DataFrame(), pd.DataFrame(), des, start_date, end_date, offset_day)
def fs_transaction_d(code, del_duplicate=True): ''' 获取某只股票的最新的日交易数据 并入库 :param code: :return: ''' ktype = 'D' s = start_date(code, ktype) if s is todayStr(): print("%s 数据已是最新 无需获取 [%s]" % (str(code), s)) else: df = fetch_transaction(code, s, ktype) write2db(df, TN_TRANSACTION_D, if_exists='append') if del_duplicate: _delete_duplicate_data(TN_TRANSACTION_D, 'code', 'date')
def fs_fuquan_all(start_date=perYearStr(), end_date=todayStr(), autype='qfq', del_duplicate=True): ''' 获取全部股票的复权数据 并入库 :param start_date: :param end_date: :param autype: :return: ''' codes = all_codes() for code in codes: fs_fuquan(code, start_date, end_date, autype, del_duplicate=False) if del_duplicate: _delete_duplicate_data(TN_FUQUAN, 'date', 'code', 'autype')
def fs_stock_basics_daily(date=todayStr(), del_duplicate=True): ''' 获取大盘某日股票基本信息数据 并入库 :param date: :return: ''' is_exist = check_is_exist_in_stock_basics_daily(date) if is_exist: print("该日期 %s 记录已存在" % date) else: try: df = fetch_stock_basics_daily(date) write2db(df, TN_STOCK_BASICS_DAILY, if_exists='append') if del_duplicate: _delete_duplicate_data(TN_STOCK_BASICS_DAILY, 'code', 'date') except: print("该日期 %s 没有数据" % date)
def resp(views): ''' 获取日交易数据操作界面的布局相应对象 :return: ''' c_names = tu.column_names(tu.TN_TRANSACTION_D) columns = [] if c_names: c_names.remove('date') c_names.remove('code') for name in c_names: label = tu.column_label(name) columns.append({'name': name, 'label': label}) date = {'start': perYearStr(), 'end': todayStr()} return make_response( render_template('view_pages/page_trans_d.html', views=views, columns=columns, date=date))
def gen_getdata_items(): ''' 数据获取 表格数据生成 :return: ''' items = [getdata_form(id=1, name="【股票基础数据】", table=tu.T_STOCK, method=tu.fs_stock, ), getdata_form(id=2, name="【股票行业数据】", table=tu.T_STOCK_INDUSTRY, method=tu.fs_stock_industry, ), getdata_form(id=3, name="【股票地区数据】", table=tu.T_STOCK_AREA, method=tu.fs_stock_area, ), getdata_form(id=4, name="【股票概念数据】", table=tu.T_STOCK_CONCEPT, method=tu.fs_stock_concept, ), getdata_form(id=5, name="【大盘全部股票基本数据】", table=tu.T_STOCK_BASICS_DAILY, params=[ param(label='日期', name='date', def_value=todayStr(), hint='请输入日期', type="date") ], method=tu.fs_stock_basics_daily, ), getdata_form(id=6, name="【获取大盘指定时间区间内的股票基本数据】", table=tu.T_STOCK_BASICS_DAILY, params=[ param(label='起始日期', name='begin_date', def_value=perYearStr(), hint='请输入日期', type="date"), param(label='结束日期', name='end_date', def_value=todayStr(), hint='请输入日期', type="date") ], method=tu.fs_stock_basics_daily_r, ), getdata_form(id=7, name="【股票分笔数据】", table=tu.T_TICK, params=[ param(label='股票代码', name='nameCode', hint='请输入股票代码', type='stock'), param(label='日期', name='date', def_value=todayStr(), hint='请输入日期', type="date") ], method=tu.fs_tick, ), getdata_form(id=8, name="【指定时间区间内的股票分笔数据】", table=tu.T_TICK, params=[ param(label='股票代码', name='nameCode', hint='请输入股票代码', type='stock'), param(label='起始日期', name='begin_date', def_value=perYearStr(), hint='请输入日期', type="date"), param(label='结束日期', name='end_date', def_value=todayStr(), hint='请输入日期', type="date") ], method=tu.fs_tick_r, ), getdata_form(id=9, name="【股票最新的日交易数据】", table=tu.T_TRANSACTION_D, params=[ param(label='股票代码', name='nameCode', hint='请输入股票代码', type='stock') ], method=tu.fs_transaction_d, ), getdata_form(id=10, name="【股票最新的5分钟交易数据】", table=tu.T_TRANSACTION_5MIN, params=[ param(label='股票代码', name='nameCode', hint='请输入股票代码', type='stock') ], method=tu.fs_transaction_5min, ), getdata_form(id=11, name="【全部股票的最新的日交易数据】", table=tu.T_TRANSACTION_D, method=tu.fs_transaction_d_all, ), getdata_form(id=12, name="【全部股票的最新的5分钟交易数据】", table=tu.T_TRANSACTION_5MIN, method=tu.fs_transaction_5min_all, ), getdata_form(id=13, name="【股票复权数据】", table=tu.T_FUQUAN, params=[ param(label='股票代码', name='nameCode', hint='请输入股票代码', type='stock'), param(label='起始日期', name='start_date', def_value=perYearStr(), hint='请输入日期', type="date"), param(label='结束日期', name='end_date', def_value=todayStr(), hint='请输入日期', type="date"), param(label='复权类型', name='autype', def_value='qfq', hint='qfq/hfq/none') ], method=tu.fs_fuquan, ), getdata_form(id=14, name="【指定时间区间内的股票复权数据】", table=tu.T_FUQUAN, params=[ param(label='起始日期', name='start_date', def_value=perYearStr(), hint='请输入日期', type="date"), param(label='结束日期', name='end_date', def_value=todayStr(), hint='请输入日期', type="date"), param(label='复权类型', name='autype', def_value='qfq', hint='qfq/hfq/none') ], method=tu.fs_fuquan_all, ), ] return items