예제 #1
0
파일: views.py 프로젝트: keel1982/ctpbee
    def post(self):
        global current_user
        from ctpbee import current_app
        if current_app != None:
            current_user = current_app.config["CONNECT_INFO"]['userid']
            return true_response(message="登录成功")
        info = request.values
        app = CtpBee(name=info.get("username"), import_name=__name__)
        login_info = {
            "CONNECT_INFO": info,
            "INTERFACE": "ctp",
            "TD_FUNC": True,
            "MD_FUNC": True,
        }
        app.config.from_mapping(login_info)
        default = DefaultSettings("default_settings", app, io)
        app.start()
        sleep(1)
        if not app.td_login_status:
            return false_response(message="登录出现错误")
        current_user = login_info['CONNECT_INFO']['userid']

        def run(app: CtpBee):
            while True:
                app.query_position()
                sleep(1)
                app.query_account()
                sleep(1)

        p = Thread(target=run, args=(app, ))
        p.start()
        return true_response(message="登录成功")
예제 #2
0
파일: serve.py 프로젝트: sixuerain/ctpbee
def go():
    app = CtpBee("ctpbee", __name__)

    from ctpbee import switch_app

    info = {
        "CONNECT_INFO": {
            "userid": "",
            "password": "",
            "brokerid": "",
            "md_address": "",
            "td_address": "",
            "appid": "",
            "auth_code": "",

        },
        "TD_FUNC": True,
    }
    app.config.from_mapping(info)
    data_recorder = DataRecorder("data_recorder", app)
    app.start()
    sleep(1)
    # 开始订阅 行情
    for contract in app.recorder.get_all_contracts():
        subscribe(contract.symbol)
    print("完成!")
예제 #3
0
 def sign_in(self, info):
     bee_app = CtpBee(name=info.get("username"),
                      import_name=__name__,
                      refresh=True)
     login_info = {
         "CONNECT_INFO": info,
         "INTERFACE": info.get('interface'),
         "TD_FUNC": True,
         "MD_FUNC": True,
     }
     bee_app.config.from_mapping(login_info)
     bee_app.start()
     # loading
     self.loading = LoadingDialog()
     G.loading = self.loading
     self.timer.start(2000)  # ms
     self.loading.msg.setText("正在连接服务器...")
     self.loading.exec_()
     if bee_app and \
             bee_app.trader and \
             bee_app.td_login_status:
         ##
         G.signin_success(info['userid'])
         ##
         self.load_config()
         ###
         mainwindow = MainWindow()
         mainwindow.sign_in_success()
         mainwindow.show()
         self.close()
         return True
     else:
         return False
예제 #4
0
def go():
    app = CtpBee("last", __name__, engine_method="async")
    info = {
        "CONNECT_INFO": {
            "userid": "089131",
            "password": "******",
            "brokerid": "9999",
            # 24小时
            "md_address": "tcp://180.168.146.187:10131",
            "td_address": "tcp://180.168.146.187:10130",
            # 移动
            # "md_address": "tcp://218.202.237.33:10112",
            # "td_address": "tcp://218.202.237.33:10102",
            "product_info": "",
            "appid": "simnow_client_test",
            "auth_code": "0000000000000000",
        },
        "INTERFACE": "ctp",
        "TD_FUNC": True,
        "MD_FUNC": True,
    }
    """ 
        载入配置信息 

    """
    app.config.from_mapping(info)
    app.update_risk_gateway(RiskMe)
    """ 
        载入用户层定义层 你可以编写多个继承CtpbeeApi ,然后实例化它, 记得传入app, 当然你可以通过app.remove_extension("data_recorder")
        data_recorder 就是下面传入的插件名字

    """
    data_recorder = DataRecorder("data_recorder", app)
    """ 启动 """
    app.start()
예제 #5
0
def letsgo():
    app = CtpBee(name="demo", import_name=__name__)
    # 创建对象
    demo = Demo("test")
    # 添加对象, 你可以继承多个类 然后实例化不同的插件 再载入它, 这些都是极其自由化的操作
    # info = {
    #     "CONNECT_INFO": {
    #         "userid": "089131",
    #         "password": "******",
    #         "brokerid": "9999",
    #         "md_address": "tcp://180.168.146.187:10131",
    #         "td_address": "tcp://180.168.146.187:10130",
    #         "product_info": "",
    #         "appid": "simnow_client_test",
    #         "auth_code": "0000000000000000"
    #     },
    #     "INTERFACE": "ctp",  # 接口声明
    #     "TD_FUNC": True,  # 开启交易功能
    #     "MD_FUNC": True,
    #     "QA_SETUP": {"password": "******"}
    # }
    running = Fancy("fancy", ['ag2010.SHFE'])

    app.add_extension(demo)
    app.add_extension(running)
    app.config.from_json("config.json")
    app.start(log_output=True)
예제 #6
0
def create_app():
    app = CtpBee("last", __name__)

    info = {
        "CONNECT_INFO": {
            "userid": "089131",
            "password": "******",
            "brokerid": "9999",
            "md_address": "tcp://180.168.146.187:10131",
            "td_address": "tcp://180.168.146.187:10130",
            # "md_address": "tcp://218.202.237.33:10112",
            # "td_address": "tcp://218.202.237.33:10102",
            "product_info": "",
            "appid": "simnow_client_test",
            "auth_code": "0000000000000000",
        },
        "INTERFACE": "ctp",
        "TD_FUNC": True,
        "MD_FUNC": True,
    }
    app.config.from_mapping(info)
    converter.init_app(app)

    data_recorder = DataRecorder("data_recorder", app)

    app.start()
    return app
예제 #7
0
파일: views.py 프로젝트: merz9b/ctpbee
def login():
    if request.method == 'POST':
        info = request.values
        app = CtpBee(__name__)
        app.config.from_mapping(info)
        app.start()
        return redirect(url_for("personal_center"))
    return render_template("trade_login.html")
예제 #8
0
async def add_trade(item: TradeLogin):
    """
    增加交易账户,每日自动进行托管
    """
    app = CtpBee(item.app_name, __name__)
    app.config.from_mapping(item)
    app.start(log_output=False)
    return RT.true_response(message="add trade successful")
예제 #9
0
def letsgo():
    app = CtpBee(name="demo", import_name=__name__)
    # 创建对象
    demo = Demo("test")
    # 添加对象, 你可以继承多个类 然后实例化不同的插件 再载入它, 这些都是极其自由化的操作
    app.add_extension(demo)
    app.config.from_json("config.json")
    app.start(log_output=True)
예제 #10
0
def go_ahead():
    app = CtpBee("hello wh", __name__)
    app.config.from_json("config.json")
    double_ma = DoubleMaStrategy(app=app,
                                 cta_symbol="ag1902.SHFE",
                                 name="double_ma")
    app.start()
    app.subscribe("ag1912")
예제 #11
0
async def add_market(item: Market):
    """
    注册行情提供行情
    """
    app = CtpBee(item.typed, __name__)
    app.config.from_mapping(item)
    app.start()
    return RT.true_response(data=None, message="add market successful")
예제 #12
0
def go():
    app = CtpBee("last", __name__, refresh=True)

    # info = {
    #     "CONNECT_INFO": {
    #         "userid": "089131",
    #         "password": "******",
    #         "brokerid": "9999",
    #         "md_address": "tcp://180.168.146.187:10131",
    #         "td_address": "tcp://180.168.146.187:10130",
    #         # "md_address": "tcp://218.202.237.33:10112",
    #         # "td_address": "tcp://218.202.237.33:10102",
    #         # "md_address": "tcp://180.168.146.187:10110",
    #         # "td_address": "tcp://180.168.146.187:10100",
    #         # "md_address": "tcp://180.168.146.187:10111",
    #         # "td_address": "tcp://180.168.146.187:10101",
    #         "product_info": "",
    #         "appid": "simnow_client_test",
    #         "auth_code": "0000000000000000",
    #     },
    #     "INTERFACE": "ctp",
    #     "TD_FUNC": True,
    #     "MD_FUNC": True,
    #     "REFRESH_INTERVAL": 3
    # }

    info = {
        "CONNECT_INFO": {
            "userid": "129842",
            "password": "******",
            "brokerid": "9999",
            "md_address": "tcp://218.202.237.33:10112",
            "td_address": "tcp://218.202.237.33:10102",
            "product_info": "",
            "appid": "simnow_client_test",
            "auth_code": "0000000000000000"
        },
        "INTERFACE": "ctp",
        "TD_FUNC": True,
        "MD_FUNC": True,
        "REFRESH_INTERVAL": 1.5
    }
    """ 
        载入配置信息 
    """
    app.config.from_mapping(info)
    """ 
        载入用户层定义层 你可以编写多个继承CtpbeeApi ,然后实例化它, 记得传入app, 当然你可以通过app.remove_extension("data_recorder")
        data_recorder 就是下面传入的插件名字
      
    """
    app.add_risk_gateway(RiskMe)

    data_recorder = DataRecorder("data_recorder", app)
    """ 添加自定义的风控 """
    """ 启动 """
    app.start(log_output=True)
예제 #13
0
def gopro(userid, password, brokerid, mdaddr, tdaddr, appid, authcode,
          realaddr):
    app = CtpBee("last", __name__)
    info = {
        "CONNECT_INFO": {
            "userid": userid,
            "password": password,
            "brokerid": brokerid,
            "md_address": mdaddr,
            "td_address": tdaddr,
            "appid": appid,
            "auth_code": authcode,
        },
        "TD_FUNC": True,
        "MD_FUNC": False
    }
    another = {
        "CONNECT_INFO": {
            "userid": "",  # 期货账户名
            "password": "",  # 登录密码
            "brokerid": "8899",  # 期货公司id
            "md_address": realaddr,  # 行情地址
            "td_address": "",  # 交易地址
            "appid": "",  # 产品名
            "auth_code": "",  # 认证码
            "product_info": ""  # 产品信息
        },
        "INTERFACE": "ctp",  # 登录期货生产环境接口
        "TD_FUNC": False
    }
    NEW_APP = CtpBee("NEW", __name__)
    NEW_APP.config.from_mapping(another)
    app.config.from_mapping(info)
    data_recorder = DataRecorder("data_recorder", model='pro')
    # 或者直接  data_recorder = DataRecorder("data_recorder", app)
    # app.add_extension(data_recorder)
    app.start()
    NEW_APP.add_extension(data_recorder)
    NEW_APP.start()
    print('start engine')
    import time
    time.sleep(3)
    contracts = app.recorder.get_all_contracts()
    cur_date = str(date.today())
    contractdb = pymongo.MongoClient(host=eval(ip)).QAREALTIME.contract
    for item in contracts:
        cont = item.__dict__
        cont['exchange'] = cont['exchange'].value
        cont['product'] = cont['product'].value
        cont['date'] = cur_date
        NEW_APP.action.subscribe(item.local_symbol)
        contractdb.update_one({
            'gateway_name': 'ctp',
            'symbol': cont['symbol']
        }, {'$set': cont},
                              upsert=True)
예제 #14
0
def go():
    app = CtpBee("last", __name__)

    # 风险控制层
    # @app.risk_gateway.connect_via()
    # def conn(app: CtpBee):
    #     """
    #     用户可以在每个app实例下面来使用app.risk_control.connect_via() 来装饰函数
    #     接受一个参数来访问到当前app的实例, 以此判断是否进行下单 , 需要注意, 如果一旦返回错误, 那么函数这单将无法下载
    #     """
    #     return False  # return True

    #  或者
    # def conn(app: CtpBee):
    #     return False  # return True
    # app.risk_control.connect(conn)

    info = {
        "CONNECT_INFO": {
            "userid": "089131",
            "password": "******",
            "brokerid": "9999",
            "md_address": "tcp://180.168.146.187:10131",
            "td_address": "tcp://180.168.146.187:10130",
            # "md_address": "tcp://218.202.237.33:10112",
            # "td_address": "tcp://218.202.237.33:10102",
            "product_info": "",
            "appid": "simnow_client_test",
            "auth_code": "0000000000000000",
        },
        "INTERFACE": "ctp",
        "TD_FUNC": True,
        "MD_FUNC": True,
    }
    """ 
        载入配置信息 
    """
    app.config.from_mapping(info)
    """ 
        载入用户层定义层 你可以编写多个继承CtpbeeApi ,然后实例化它, 记得传入app, 当然你可以通过app.remove_extension("data_recorder")
        data_recorder 就是下面传入的插件名字
    
    """
    data_recorder = DataRecorder("data_recorder", app)
    """ 启动 """
    app.start()
    while True:
        app.query_position()
        sleep(1)

        app.query_account()
        sleep(1)
예제 #15
0
    def post(self):
        """
        bee_app:   token if check userid,password else false_response
        not bee_app:  token if td_login_status else false_response
        :return:
        """
        info = dict(request.values)
        authorization = info.pop('authorization', None)
        if not authorization or not G.check_authorization(authorization):
            return false_response(msg='授权码错误')
        userid = info.get('userid')
        password = info.get('password')
        # bee_current_app存在
        if bee_current_app and \
                bee_current_app.trader and \
                bee_current_app.td_login_status:
            if userid == bee_current_app.trader.userid and password == bee_current_app.trader.password:
                token = Auth.authenticate(info)
                return true_response(data=token, msg='登录成功')
            return false_response(msg='Refuse!')

        else:  # bee_current_app 不不存在
            bee_app = CtpBee(name=info.get("username"),
                             import_name=__name__,
                             refresh=True,
                             logger_class=VLog)
            login_info = {
                "CONNECT_INFO": info,
                "INTERFACE": info.get('interface'),
                "TD_FUNC": True,
                "MD_FUNC": True,
            }
            bee_app.config.from_mapping(login_info)
            default = DefaultSettings("default_settings", bee_app, io)
            load_strategy(bee_app)  # 加载策略
            bee_app.start()
            sleep(1)

            if bee_current_app and \
                    bee_current_app.trader and \
                    bee_current_app.td_login_status:
                token = Auth.authenticate(info)

                return true_response(data=token, msg='重新登录成功')
            else:
                del_app(__name__)
                return false_response(msg="重新登录出现错误")
예제 #16
0
def go():
    app = CtpBee("last", __name__)
    info = {
        "CONNECT_INFO": {
            "userid": "",
            "password": "",
            "brokerid": "",
            "md_address": "",
            "td_address": "",
            "appid": "",
            "auth_code": "",
        },
        "TD_FUNC": True,
    }
    app.config.from_mapping(info)
    data_recorder = DataRecorder("data_recorder", app)
    app.start()
    for contract in app.recorder.get_all_contracts():
        subscribe(contract.symbol)
예제 #17
0
def go(userid, password, brokerid, mdaddr, tdaddr, appid, authcode):
    app = CtpBee("last", __name__)
    info = {
        "CONNECT_INFO": {
            "userid": userid,
            "password": password,
            "brokerid": brokerid,
            "md_address": mdaddr,
            "td_address": tdaddr,
            "appid": appid,
            "auth_code": authcode,
        },
        "TD_FUNC": True,
    }

    app.config.from_mapping(info)
    data_recorder = DataRecorder("data_recorder")
    # 或者直接  data_recorder = DataRecorder("data_recorder", app)
    app.add_extension(data_recorder)
    app.start()
    print('start engine')
    import time
    time.sleep(5)
    contracts = app.recorder.get_all_contracts()
    print(contracts)
    cur_date = str(date.today())
    contractdb = pymongo.MongoClient(host=ip).QAREALTIME.contract
    for item in contracts:
        cont = item.__dict__
        cont['exchange'] = cont['exchange'].value
        cont['product'] = cont['product'].value
        cont['date'] = cur_date
        print(cont)
        try:
            contractdb.update_one(
                {
                    'gateway_name': 'ctp',
                    'symbol': cont['symbol']
                }, {'$set': cont},
                upsert=True)
        except Exception as e:
            print(e)
예제 #18
0
def letsgo():
    app = CtpBee(name="demo", import_name=__name__)
    # 创建对象
    demo = Demo("test")
    # 添加对象, 你可以继承多个类 然后实例化不同的插件 再载入它, 这些都是极其自由化的操作
    app.add_extension(demo)
    app.config.from_json("config.json")
    app.start()

    def query(time=1):
        nonlocal app
        while True:
            app.query_position()
            sleep(time)
            app.query_account()
            sleep(time)

    # 单独开一个线程来进行查询持仓和账户信息
    p = Thread(target=query, args=(2, ))
    p.setDaemon(daemonic=True)
    p.start()
예제 #19
0
def go():
    app = CtpBee("last", __name__)
    info = {
        "CONNECT_INFO": {
            "userid": "133496",
            "password": "******",
            "brokerid": "9999",
            "md_address": "tcp://218.202.237.33:10112",
            "td_address": "tcp://218.202.237.33:10102",
            "appid": "simnow_client_test",
            "auth_code": "0000000000000000",
        },
        "TD_FUNC": True,
    }

    app.config.from_mapping(info)
    data_recorder = DataRecorder("data_recorder", app)
    app.start()
    print('start engine')
    import time
    time.sleep(5)
    contracts = app.recorder.get_all_contracts()
    print(contracts)
    cur_date = str(date.today())
    contractdb = pymongo.MongoClient().QAREALTIME.contract
    for item in contracts:
        cont = item.__dict__
        cont['exchange'] = cont['exchange'].value
        cont['product'] = cont['product'].value
        cont['date'] = cur_date
        print(cont)
        contractdb.update_one({
            'gateway_name': 'ctp',
            'symbol': cont['symbol']
        }, {'$set': cont},
                              upsert=True)

    for contract in app.recorder.get_all_contracts():
        print(contract.symbol)
        subscribe(contract.symbol)
예제 #20
0
def create_app():
    from ctpbee import CtpBee
    app = CtpBee("recorder", __name__)
    last = CtpBee("trader", __name__)

    last.config.from_mapping({
        "CONNECT_INFO": {
            "userid": "089131",
            "password": "******",
            "brokerid": "9999",
            "md_address": "tcp://218.202.237.33:10112",
            "td_address": "tcp://218.202.237.33:10102",
            "product_info": "",
            "appid": "simnow_client_test",
            "auth_code": "0000000000000000"
        },
        "INTERFACE": "ctp",  # 接口声明
        "TD_FUNC": True,  # 开启交易功能
        "MD_FUNC": False
    })
    last.start()
    x = {
        "CONNECT_INFO": {
            "userid": "",  # 期货账户名
            "password": "",  # 登录密码
            "brokerid": "8899",  # 期货公司id
            "md_address": "tcp://211.95.40.228:42213",  # 行情地址
            "td_address": "",  # 交易地址
            "appid": "",  # 产品名
            "auth_code": "",  # 认证码
            "product_info": ""  # 产品信息
        },
        "INTERFACE": "ctp",  # 登录期货生产环境接口
        "TD_FUNC": False
    }
    # 载入配置信息
    app.config.from_mapping(x)
    app.add_extension(api)
    app.start()
    return app, last
예제 #21
0
    def run(self):
        # try:
        vessel = CtpBee("looper", __name__)

        vessel.add_data(*self.data)
        for i in self.strategy:
            vessel.add_extension(i)
        config = {"PATTERN": "LOOPER"}
        config.update(self.params)
        vessel.config.from_mapping(config)
        vessel.start()
        result = vessel.get_result(report=True)
        del_app(vessel.name)
        error = ""
        # except Exception as e:
        #     result = ""
        #     error = str(e)
        self.sig.emit({
            "name": self.name,
            "url": result,
            "error": error,
        })
예제 #22
0
def go():
    app = CtpBee("last", __name__, action_class=ActionMe, risk=RiskMe)

    """ 
        载入配置信息 
    """
    app.config.from_json("config.json")

    """ 
        载入用户层定义层 你可以编写多个继承CtpbeeApi ,然后实例化它, 记得传入app, 当然你可以通过app.remove_extension("data_recorder")
        data_recorder 就是下面传入的插件名字
      
    """
    app.update_risk_gateway(RiskMe)

    data_recorder = DataRecorder("data_recorder")
    app.add_extension(data_recorder)

    """ 添加自定义的风控 """

    """ 启动 """
    app.start(log_output=True)
예제 #23
0
    def post(self):
        info = request.values
        app = CtpBee(info.get("username"), __name__)
        login_info = {
            "CONNECT_INFO": info,
            "INTERFACE": "ctp",
            "TD_FUNC": True,
            "MD_FUNC": True,
        }
        app.config.from_mapping(login_info)
        default = DefaultSettings("default_settings", app, io)
        app.start()

        def run(app: CtpBee):
            while True:
                app.query_position()
                sleep(1)
                app.query_account()
                sleep(1)

        p = Thread(target=run, args=(app, ))
        p.start()
        return redirect(url_for("index"))
예제 #24
0
def letsgo():
    app = CtpBee(name="demo", import_name=__name__, refresh=True)
    # 创建对象
    demo = Demo("test")
    # 添加对象, 你可以继承多个类 然后实例化不同的插件 再载入它, 这些都是极其自由化的操作
    app.add_extension(demo)
    info = {
        "CONNECT_INFO": {
            "userid": "8100243",
            "password": "******",
            "brokerid": "8888",
            "md_address": "tcp://218.56.38.41:41313",
            "td_address": "tcp://218.56.38.41:41305",
            "product_info": "",
            "appid": "client_acmd1234_1.0.0",
            "auth_code": "FAR3EMEEJIT04HKD",
        },
        "INTERFACE": "ctp_se",
        "TD_FUNC": True,
        "MD_FUNC": True,
    }
    app.config.from_mapping(info)
    app.start(log_output=True)
예제 #25
0
        # self.app.subscribe(contract.local_symbol)

    def on_init(self, init: bool):
        pass


if __name__ == '__main__':
    app = CtpBee("test", __name__)
    just_use = JustUse("Hi")

    info = {
        "CONNECT_INFO": {
            "userid": "089131",
            "password": "******",
            "brokerid": "9999",
            # "md_address": "tcp://218.202.237.33:10112",
            # "td_address": "tcp://218.202.237.33:10102",
            "md_address": "tcp://180.168.146.187:10131",
            "td_address": "tcp://180.168.146.187:10130",
            "product_info": "",
            "appid": "simnow_client_test",
            "auth_code": "0000000000000000",
        },
        "INTERFACE": "ctp",
        "TD_FUNC": True,
        "MD_FUNC": False,
    }
    app.config.from_mapping(info)
    app.add_extension(just_use)
    app.start(log_output=False)
예제 #26
0
    def on_bar(self, bar: BarData) -> None:
        pass

    def on_contract(self, contract: ContractData):
        if contract.symbol == "rb2010":
            print(contract)
        x = self.action.subscribe(contract.local_symbol)


if __name__ == '__main__':
    app = CtpBee("test", __name__, refresh=True)
    just_use = JustUse("Hi")
    app.config.from_json("config.json")
    app.add_extension(just_use)
    app.start(log_output=True)
    print("one start")
    info = {
        "CONNECT_INFO": {
            "userid": "089131",
            "password": "******",
            "brokerid": "9999",
            "md_address": "tcp://218.202.237.33:10112",
            "td_address": "tcp://218.202.237.33:10102",
            "product_info": "",
            "appid": "simnow_client_test",
            "auth_code": "0000000000000000"
        },
        "INTERFACE": "ctp",  # 接口声明
        "TD_FUNC": True,  # 开启交易功能
        "MD_FUNC": True,
예제 #27
0
파일: login.py 프로젝트: zhuzhenping/ctpbee
        for order in self.center.active_orders:
            self.action.cancel(order.order_id, order)

    def on_trade(self, trade: TradeData) -> None:
        if self.init and trade.offset == Offset.OPEN:
            self.action.cover(trade.price - 1, 1, trade)

    def on_position(self, position: PositionData) -> None:
        pass

    def on_bar(self, bar: BarData) -> None:
        pass

    def on_contract(self, contract: ContractData):
        # setup the code and subscribe market
        # also you can use app.subscribe()
        if contract.symbol == "rb2201":
            self.action.subscribe(contract.local_symbol)

    def on_init(self, init: bool):
        print("Init Successful")
        self.init = True


if __name__ == '__main__':
    app = CtpBee("market", __name__, refresh=True)
    example = Main("DailyCTA")
    app.config.from_json("config.json")
    app.add_extension(example)
    app.start(log_output=True)
예제 #28
0
            "userid": "089131",
            "password": "******",
            "brokerid": "9999",
            "md_address": "tcp://218.202.237.33:10112",
            "td_address": "tcp://218.202.237.33:10102",
            "product_info": "",
            "appid": "simnow_client_test",
            "auth_code": "0000000000000000",
        },
        "INTERFACE": "sim",
        "TD_FUNC": True,
        "MD_FUNC": True,
    }
    core_app.config.from_mapping(info)
    core_app.add_extension(Me("模拟"))
    core_app.start()
    print("模拟已经启动")

    market_app = CtpBee("market", __name__)
    market_app.config.from_mapping({
        "CONNECT_INFO": {
            "userid": "170874",
            "password": "******",
            "brokerid": "9999",
            "md_address": "tcp://218.202.237.33:10112",
            "td_address": "tcp://218.202.237.33:10102",
            "product_info": "",
            "appid": "simnow_client_test",
            "auth_code": "0000000000000000",
        },
        "INTERFACE": "ctp",
예제 #29
0
from ctpbee import CtpBee
from ctpbee import subscribe



app = CtpBee(__name__)
info = {
    "CONNECT_INFO": {
        "userid": "142164",
        "password": "******",
        "brokerid": "9999",
        "md_address": "tcp://180.168.146.187:13040",
        "td_address": "tcp://180.168.146.187:13030",
        "auth_code": "0000000000000000",
        'appid':"5056613036"
    },
    "TD_FUNC": True,
    "XMIN": [3],
    "TICK_DATABASE_TYPE": 'mysql',
    "BAR_DATABASE_TYPE": 'mysql',
    'SUBSCRIBED_SYMBOL':['AP910']
}

app.config.from_mapping(info)
from process_tr import DataRecorder
ext = DataRecorder("recorder", app)
app.start()
for contracts in app.recorder.get_all_contracts():
    subscribe(contracts.symbol)

예제 #30
0
from ctpbee import CtpbeeApi, CtpBee
from ctpbee.constant import *


class Main(CtpbeeApi):
    def on_tick(self, tick: TickData) -> None:
        """ """
        print(self.center.positions)

    def on_bar(self, bar: BarData) -> None:
        pass

    def on_contract(self, contract: ContractData):
        if contract.symbol == "rb2110":
            x = self.action.subscribe(contract.local_symbol)


if __name__ == '__main__':
    # app = CtpBee("test", __name__, refresh=True)
    # just_use = JustUse("Hi")
    # app.config.from_json("config.json")
    # app.add_extension(just_use)
    # app.start(log_output=True)
    # print("one start")
    market = CtpBee("market", __name__, refresh=True)
    main = Main("DailyCTA")
    market.config.from_json("config.json")
    market.add_extension(main)
    market.start(log_output=True)