Ejemplo n.º 1
0
    def __init__(self, addr="tcp://140.207.224.19:8910", use_jrpc=False):
        """Create DataApi client.
        
        If use_jrpc, try to load the C version of JsonRpc. If failed, use pure
        Python version of JsonRpc.
        """
        self._remote = None
        #        if use_jrpc:
        #            try:
        #                import jrpc
        #                self._remote = jrpc.JRpcClient()
        #            except Exception as e:
        #                print "Can't load jrpc", e.message

        if not self._remote:
            self._remote = jrpc_py.JRpcClient()

        self._remote.on_rpc_callback = self._on_rpc_callback
        self._remote.on_disconnected = self._on_disconnected
        self._remote.on_connected = self._on_connected
        self._remote.connect(addr)

        self._on_jsq_callback = None

        self._connected = False
        self._loggined = False
        self._username = ""
        self._password = ""
        self._data_format = "default"
        self._callback = None
        self._schema = []
        self._schema_id = 0
        self._sub_hash = ""
        self._subscribed_set = set()
        self._timeout = 20
Ejemplo n.º 2
0
    def __init__(self, addr, use_jrpc=True, prod_type="jzts"):
        """
            use_jrpc:
                True     -- Use jrcp_client of C version, for jzts only
                False    -- Use pure python version
            prod_type:
                "jaqs"   -- jrpc_msgpack_wth_snappy
                "jzts"   -- jrpc_msgpack
        """

        self._remote = None
        if prod_type == "jzts":
            try:
                if use_jrpc:
                    import jrpc
                    self._remote = jrpc.JsonRpcClient()
                else:
                    import jrpc_py
                    self._remote = jrpc_py.JRpcClient(data_format="msgpack")
            except Exception as e:
                print "Exception", e

            if not self._remote:
                import jrpc_py
                self._remote = jrpc_py.JRpcClient(data_format="msgpack")

        else:
            import jrpc_py
            self._remote = jrpc_py.JRpcClient(data_format="msgpack_snappy")

        self._remote.on_rpc_callback = self._on_rpc_callback
        self._remote.on_disconnected = self._on_disconnected
        self._remote.on_connected = self._on_connected
        self._remote.connect(addr)

        self._ordstatus_callback = None
        self._taskstatus_callback = None
        self._internal_order_callback = None
        self._trade_callback = None
        self._on_connection_callback = None
        self._connected = False
        self._username = ""
        self._password = ""
        self._strategy_id = 0
        self._strategy_selected = False
        self._data_format = "default"