save_tdx.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:QUANTAXIS 作者: yutiansut 项目源码 文件源码
def QA_SU_save_stock_day(client=QA_Setting.client):
    stock_list = QA_fetch_get_stock_time_to_market()
    coll_stock_day = client.quantaxis.stock_day
    coll_stock_day.create_index(
        [("code", pymongo.ASCENDING), ("date_stamp", pymongo.ASCENDING)])
    err = []

    def __saving_work(code, coll_stock_day):
        try:
            QA_util_log_info(
                '##JOB01 Now Saving STOCK_DAY==== %s' % (str(code)))

            ref = coll_stock_day.find({'code': str(code)[0:6]})
            end_date = str(now_time())[0:10]
            if ref.count() > 0:
                    # ????????????????????? ???????? ???????????

                start_date = ref[ref.count() - 1]['date']
            else:
                start_date = '1990-01-01'
            QA_util_log_info(' UPDATE_STOCK_DAY \n Trying updating %s from %s to %s' %
                             (code, start_date, end_date))
            if start_date != end_date:
                coll_stock_day.insert_many(
                    QA_util_to_json_from_pandas(
                        QA_fetch_get_stock_day(str(code), start_date, end_date, '00')[1::]))
        except:
            err.append(str(code))
    for item in range(len(stock_list)):
        QA_util_log_info('The %s of Total %s' %
                         (item, len(stock_list)))
        QA_util_log_info('DOWNLOAD PROGRESS %s ' % str(
            float(item / len(stock_list) * 100))[0:4] + '%')

        __saving_work(stock_list.index[item], coll_stock_day)
    if len(err) < 1:
        QA_util_log_info('SUCCESS')
    else:
        QA_util_log_info('ERROR CODE \n ')
        QA_util_log_info(err)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号