コード例 #1
0
    def __init__(self):
        self.log = Logger()
        origin_cfg_file = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), 'config.yml')
        cfg_file = os.path.join(os.getcwd(), 'config.yml')
        if not os.path.exists(cfg_file):
            shutil.copy(origin_cfg_file, cfg_file)
        cfg = yaml.load(open(cfg_file, 'r', encoding='utf-8'))

        # 追单设置
        self.chasing = cfg['ctp_config']['chasing']

        self.stra_path = cfg['stra_path']
        self.cfg_zmq = ''
        if 'zmq_config' in cfg:
            self.cfg_zmq = cfg['zmq_config']
        self.engine_postgres = None
        # if 'postgres_config' in cfg:
        #     self.engine_postgres = create_engine(cfg['postgres_config'])

        self.front_trade = ''
        self.front_quote = ''
        self.broker = ''
        self.investor = ''
        self.pwd = ''
        cfg_ctp = cfg['ctp_config']
        if cfg_ctp['ctp_front'] != '':
            self.front_name = cfg_ctp['ctp_front']
            cfg_ctp_front = cfg_ctp['fronts'][self.front_name]
            self.front_trade = cfg_ctp_front['trade']
            self.front_quote = cfg_ctp_front['quote']
            self.broker = cfg_ctp_front['broker']
            if 'investor' in cfg_ctp and cfg_ctp['investor'] != '':
                self.investor = cfg_ctp['investor']
            if 'password' in cfg_ctp and cfg_ctp['password'] != '':
                self.pwd = cfg_ctp['password']

        self.single_order_one_bar = False
        '''是否每根K线只发一次指令'''

        self.real_order_enable = False
        '''是否实际对接口发单'''

        self.running_as_server = False
        '''是否作为服务7*24运行'''

        self.show_tick_time = False
        '''是否打印行情时间'''

        if 'onoff' in cfg:
            cfg_of = cfg['onoff']
            if 'running_as_server' in cfg_of:
                self.running_as_server = cfg_of['running_as_server']
            if 'single_order_one_bar' in cfg_of:
                self.single_order_one_bar = cfg_of['single_order_one_bar']
            if 'real_order_enable' in cfg_of:
                self.real_order_enable = cfg_of['real_order_enable']
            if 'show_tick_time' in cfg_of:
                self.show_tick_time = cfg_of['show_tick_time']
コード例 #2
0
ファイル: config.py プロジェクト: shengmj168/hfpy
class Config(object):
    """"""
    def __init__(self):
        self.log = Logger()

        self.strategy_name = []
        '''策略配置json格式:stra_name:[stra_id]'''
        if 'strategy_names' in os.environ:
            self.strategy_name = [
                n.strip().strip('"')
                for n in os.environ['strategy_names'].split(',')
            ]

        self.single_order_one_bar = True
        '''是否每根K线只发一次指令'''
        if 'single_order_one_bar' in os.environ:
            self.single_order_one_bar = os.environ['single_order_one_bar']

        self.pg_min: Engine = None
        if 'pg_min' in os.environ:
            self.pg_min = create_engine(os.environ['pg_min'])
            print(f"connecting pg min: {os.environ['pg_min']}")

        self.pg_order: Engine = None
        if 'pg_order' in os.environ:
            self.pg_order = create_engine(os.environ['pg_order'])
            print(f"connecting pg min: {os.environ['pg_order']}")

        self.rds: redis.Redis = None
        '''实时行情库&实时order'''
        if 'redis_addr' in os.environ:
            host, port = os.environ['redis_addr'].split(':')
            self.log.info(f'connecting redis: {host}:{port}')
            pool = redis.ConnectionPool(host=host,
                                        port=port,
                                        db=0,
                                        decode_responses=True)
            self.rds = redis.StrictRedis(connection_pool=pool)
コード例 #3
0
ファイル: config.py プロジェクト: juxiaoqi/hf_at_py
    def __init__(self):
        self.log = Logger()
        # 配置文件顺序:环境变量,工作目录
        config_path = os.getcwd()
        if 'config_path' in os.environ:
            config_path = os.environ['config_path']
        cfg_file = os.path.join(config_path, 'config.yml')
        if not os.path.exists(cfg_file):
            with open(cfg_file, 'w') as f:
                f.write("""---
ctp_config:
    # 为空时不登录
    ctp_front: 'sim_now'
    investor: '008107'
    password: '******'
    product_info: ''
    app_id: 'simnow_client_test'
    auth_code: '0000000000000000'

    # 追单设置
    chasing:
        wait_seconds: 3
        offset_ticks: -2
        resend_times: 3
    # ctp前置配置: 请改用期货公司对应6.3.15(SE)的前置
    fronts:
        sim_now:
            trade: tcp://180.168.146.187:10101
            quote: tcp://180.168.146.187:10111
            broker: '9999'
# 数据源 - zmq配置 替换为宿主ip
zmq_config: tcp://数据服务IP:15555
# 开关
onoff:
    # 是否7*24
    running_as_server: true
    # 是否发送委托
    real_order_enable: true
    # 一根K线只发送一次指令
    single_order_one_bar: true
    # 是否打印行情时间
    show_tick_time: false
# 策略路径配置
stra_path:
    # 路径
    strategies:
        # 策略文件名
        SMACross:
        # 策略配置参数ID
        - 119
""")
        cfg = yaml.load(
            open(cfg_file, 'r', encoding='utf-8').read(), yaml.FullLoader)

        # 追单设置
        self.chasing = cfg['ctp_config']['chasing']

        self.stra_path = cfg['stra_path']
        self.cfg_zmq = ''
        if 'zmq_config' in cfg:
            self.cfg_zmq = cfg['zmq_config']
            self.log.info(f'zmq server: {self.cfg_zmq}')

        self.front_trade = ''
        self.front_quote = ''
        self.broker = ''
        self.investor = ''
        self.password = ''
        self.product_info = ''
        self.app_id = ''
        self.auth_code = ''

        cfg_ctp = cfg['ctp_config']
        if cfg_ctp['ctp_front'] != '':
            self.front_name = cfg_ctp['ctp_front']
            cfg_ctp_front = cfg_ctp['fronts'][self.front_name]
            self.front_trade = cfg_ctp_front['trade']
            self.front_quote = cfg_ctp_front['quote']
            self.broker = cfg_ctp_front['broker']
            for v in [
                    'investor', 'password', 'product_info', 'app_id',
                    'auth_code'
            ]:
                if v in cfg_ctp and cfg_ctp[v] != '':
                    vars(self)[v] = cfg_ctp[v]
            # if 'password' in cfg_ctp and cfg_ctp['password'] != '':
            #     self.pwd = cfg_ctp['password']

        self.single_order_one_bar = False
        '''是否每根K线只发一次指令'''

        self.real_order_enable = False
        '''是否实际对接口发单'''

        self.running_as_server = False
        '''是否作为服务7*24运行'''

        self.show_tick_time = False
        '''是否打印行情时间'''

        if 'onoff' in cfg:
            cfg_of = cfg['onoff']
            if 'running_as_server' in cfg_of:
                self.running_as_server = cfg_of['running_as_server']
            if 'single_order_one_bar' in cfg_of:
                self.single_order_one_bar = cfg_of['single_order_one_bar']
            if 'real_order_enable' in cfg_of:
                self.real_order_enable = cfg_of['real_order_enable']
            if 'show_tick_time' in cfg_of:
                self.show_tick_time = cfg_of['show_tick_time']