Example #1
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)
Example #2
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)
Example #3
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)
Example #4
0
def create_app():
    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.add_extension(api)
    """ 启动 """
    return [app]
Example #5
0
def create_app():
    app = CtpBee("last", __name__, refresh=True)
    """ 
        载入配置信息 
    """
    app.config.from_json("config.json")
    """ 
        载入用户层定义层 你可以编写多个继承CtpbeeApi ,然后实例化它, 记得传入app, 当然你可以通过app.remove_extension("data_recorder")
        data_recorder 就是下面传入的插件名字

    """
    m = M("name")
    app.add_extension(m)
    """ 启动 """
    return [app]
Example #6
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)
Example #7
0
def create_app():
    app = CtpBee("last",
                 __name__,
                 action_class=ActionMe,
                 logger_class=Vlog,
                 work_mode="limit_time",
                 refresh=True,
                 risk=RiskMe)
    """ 
        载入配置信息 
    """
    app.config.from_json("config.json")
    """ 
        载入用户层定义层 你可以编写多个继承CtpbeeApi ,然后实例化它, 记得传入app, 当然你可以通过app.remove_extension("data_recorder")
        data_recorder 就是下面传入的插件名字
      
    """
    data_recorder = DataRecorder("data_recorder")
    app.add_extension(api)
    """ 启动 """
    return app
Example #8
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()
Example #9
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
Example #10
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,
        })
Example #11
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)
def create_app():
    from ctpbee import CtpBee
    app = CtpBee("recorder", __name__)
    info = {
        "CONNECT_INFO": {
            "userid": "",  # 期货账户名
            "password": "",  # 登录密码
            "brokerid": "",  # 期货公司id
            "md_address": "",  # 行情地址
            "td_address": "",  # 交易地址
            "appid": "",  # 产品名
            "auth_code": "",  # 认证码
            "product_info": ""  # 产品信息
        },
        "INTERFACE": "ctp",  # 登录期货生产环境接口
    }
    # 载入配置信息
    app.config.from_mapping(info)
    # 创建实例
    ext = Market("market")
    # 载入容器
    app.add_extension(ext)
    return app
Example #13
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)
Example #14
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)
Example #15
0
        # print(tick)

    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,  # 开启交易功能
Example #16
0
        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)
Example #17
0
        "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": "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",
        },
Example #18
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)
Example #19
0
    info = {
        "PATTERN": "looper",
        "LOOPER": {
            "initial_capital": 100000,
            "margin_ratio": {
                "rb2010.CTP": 0.00003,
            },
            "commission_ratio": {
                "rb2010.CTP": {
                    "close": 0.00001
                },
            },
            "size_map": {
                "rb2010.CTP": 10
            }
        }
    }
    app.config.from_mapping(info)
    strategy = DoubleMaStrategy("ma")

    data_api = DataApi()
    data = data_api.get_tick("rb2010",
                             start_date="2020-04-10",
                             end_date="2020-07-21",
                             today=False)
    # data = data_support.get_future_min("rb2010.SHFE", frq="1min", start="2019-10-01", end="2020-07-15")
    app.add_data(data)
    app.add_extension(strategy)
    app.start()
    result = app.get_result(report=True, auto_open=True)
Example #20
0
from ctpbee import CtpBee

from data_pointer.pointer import DataPointer

if __name__ == '__main__':
    """ 简单的基于ctpbee的数据发送端 """
    app = CtpBee("data_pointer", __name__)
    app.config.from_json("data_pointer/config.json")
    pointer = DataPointer("origin_pointer", ("10.40.25.15", 12572), "fancy")
    app.add_extension(pointer)
    app.start()