Exemplo n.º 1
0
def run():
    args = env_utils.get_args()
    ts_code = args.code
    to_date = args.date
    if to_date is None:
        to_date = date_utils.get_current_dt()

    fetch_broker_recommend.fetch(to_date)
    fetch_trade_cal.fetch(to_date)
    fetch_dividend.update_dividend_to(to_date)

    init_ts_basic.init()

    basic_list = []
    session: Session = db_client.get_session()
    if ts_code is not None and ts_code != '':
        basic_list = session.query(TsBasic).filter(
            TsBasic.ts_code == ts_code).all()
    else:
        basic_list = session.query(TsBasic).all()
    session.close()

    for basic in basic_list:
        if env_utils.parallel():
            threadpool.submit(fetch_by_code,
                              ts_code=basic.ts_code,
                              to_date=to_date)
        else:
            fetch_by_code(ts_code=basic.ts_code, to_date=to_date)

    threadpool.join()

    strategy.generate_strategy_pool(to_date)
Exemplo n.º 2
0
def run(to_date: str = date_utils.get_current_dt()):
    dt_code_map = {}

    # 股票基础信息
    init_ts_basic.init()
    # 交易日历
    fetch_trade_cal.fetch(to_date)

    trade_date_service.refresh_cache(fetch_data_start_date,
                                     date_utils.format_delta(to_date, 30))

    to_fetch_list = [
        # 同花顺指数
        fetch_ths_index.run,
        # 券商金股
        fetch_broker_recommend.fetch,
        # 分红记录
        fetch_dividend.update_dividend_to,
        # 每日指标
        fetch_daily_basic.fetch_by_date,
        # 每日交易
        fetch_daily_bar.fetch_by_date,
        # 复权因子
        fetch_adj_factor.fetch_by_date,
        # 涨跌停价格
        fetch_stk_limit.fetch_by_date,
        # 利润表
        fetch_income.fetch_by_period,
        # 资产负债表
        fetch_balance_sheet.fetch_by_period,
        # 现金流量表
        fetch_cash_flow.fetch_by_period,
        # 预报
        fetch_forecast.fetch_by_period,
        # 快报
        fetch_express.fetch_by_period,
        # 财务指标
        fetch_fina_indicator.fetch_by_period
    ]

    if env_utils.parallel():
        fl = []
        for func in to_fetch_list:
            fl.append(threadpool.submit(func, to_date=to_date))
        for f in fl:
            m = f.result()
            if m is not None:
                fetch.merge_from_map(dt_code_map, m)
    else:
        for func in to_fetch_list:
            m = func(to_date=to_date)
            if m is not None:
                fetch.merge_from_map(dt_code_map, m)

    return dt_code_map
Exemplo n.º 3
0
def daily_run(dt_code_map={}, to_date=date_utils.get_current_dt(), ts_code=None):
    basic_list = []
    session: Session = db_client.get_session()
    if ts_code is not None and ts_code != '':
        basic_list = session.query(TsBasic).filter(TsBasic.ts_code == ts_code).all()
    else:
        basic_list = session.query(TsBasic).all()
    session.close()

    f_list = []
    for basic in basic_list:
        ts_code = basic.ts_code
        clear_from_date = dt_code_map[ts_code] if ts_code in dt_code_map else None
        if env_utils.parallel():
            f_list.append(
                threadpool.submit(cal_by_code, ts_code=ts_code, to_date=to_date, clear_from_date=clear_from_date))
        else:
            cal_by_code(ts_code=ts_code, to_date=to_date, clear_from_date=clear_from_date)

    for f in f_list:
        f.result()
Exemplo n.º 4
0
def cal_ths_index(to_date: str = date_utils.get_current_dt()):
    """
    计算同花顺指数相关的成交量占比,根据配置控制是否并发计算
    :param to_date:
    :return:
    """
    s: Session = db_client.get_session()
    index_list = s.query(ThsIndex).all()
    s.close()

    ignore_index_list = [
        '885338.TI', '885867.TI', '885694.TI', '885520.TI', '885745.TI',
        '885598.TI', '883303.TI', '883300.TI', '883302.TI', '885796.TI',
        '885873.TI', '885869.TI', '885803.TI', '885916.TI', '885907.TI',
        '885906.TI', '885905.TI', '885893.TI', '885639.TI'
    ]

    if env_utils.parallel():
        f_list = []
        for index in index_list:  # type: ThsIndex
            if index.ts_code in ignore_index_list:
                continue
            f_list.append(
                threadpool.submit(cal_by_ths_index_code,
                                  index_code=index.ts_code,
                                  index_name=index.name,
                                  to_date=to_date))
        for f in f_list:
            f.result()
    else:
        for index in index_list:  # type: ThsIndex
            if index.ts_code in ignore_index_list:
                continue
            cal_by_ths_index_code(index_code=index.ts_code,
                                  index_name=index.name,
                                  to_date=to_date)
Exemplo n.º 5
0
                        if new_num > max_num:
                            new_num = max_num
                        self.__left[name] = new_num

                # 处理增加令牌后,有足够令牌可以消耗
                if self.__left[name] >= num_to_get:
                    self.__left[name] = self.__left[name] - num_to_get
                    get = True
            finally:
                l.release()

            if get:
                break
            else:
                time.sleep(rate)

        log.debug('Rate limiter. api: %s. time: %s. cnt: %d' %
                  (name, self.__last_time[name], self.__left[name]))
        return True


def test_get(trt):
    trt.get('test', 60.0 / 40, 40, 2)


if __name__ == '__main__':
    trt = RateLimiter()
    for i in range(200):
        threadpool.submit(test_get, trt=trt)
    threadpool.join()
Exemplo n.º 6
0
import time

from moquant.algo.ratelimit import RateLimiter
from moquant.log import get_logger
from moquant.utils import threadpool

log = get_logger(__name__)


def test_func(r: RateLimiter, start_time, n):
    r.get('test', 1.2, 50)
    now = time.time()
    log.info('%d time, cost %.2f' % (n, now - start_time))


if __name__ == '__main__':
    start = time.time()
    rt = RateLimiter()
    for i in range(200):
        threadpool.submit(test_func, r=rt, start_time=start, n=i)
    threadpool.join()