当前位置: 首页>>代码示例>>Python>>正文


Python Proxy.x_request方法代码示例

本文整理汇总了Python中proxy.Proxy.x_request方法的典型用法代码示例。如果您正苦于以下问题:Python Proxy.x_request方法的具体用法?Python Proxy.x_request怎么用?Python Proxy.x_request使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在proxy.Proxy的用法示例。


在下文中一共展示了Proxy.x_request方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: XApi

# 需要导入模块: from proxy import Proxy [as 别名]
# 或者: from proxy.Proxy import x_request [as 别名]
class XApi(AbstractApi):
    """
    Api 基类
    """
    proxy = None  # Proxy
    handle = None
    _path1 = None
    _local_path = None

    _reconnectInterval = 0
    server = None  # ServerInfoField
    user = None  # UserInfoField

    _x_response = None

    def __init__(self, path, queue, local_path, server_address, broker_id, investor_id, password,
                 user_product_info, auth_code, is_market):
        super(XApi, self).__init__(path, queue, local_path, server_address, broker_id, investor_id, password,
                             user_product_info, auth_code, is_market)
        self._path1 = path
        self._local_path = local_path
        self._x_response = fnOnRespone(self._on_response)
        self._reconnectInterval = 0

        self.server = ServerInfoField()
        self.server.BrokerID = broker_id
        self.server.Address = server_address
        self.server.UserProductInfo = user_product_info
        self.server.AuthCode = auth_code

        self.user = UserInfoField()
        self.user.UserID = investor_id
        self.user.Password = password

    def connect(self):
        """
        Connect to the server.
        """
        if self.proxy is None:
            self.proxy = Proxy(self._path1)

        self.handle = self.proxy.x_request(Create)
        # 将API与队列进行绑定
        self.proxy.x_request(Register, self.handle, ptr1=self._queue.handle)
        self._queue.register(self._x_response)
        # 启动队列循环
        # self._queue.start_pulling()

        self.proxy.x_request(Connect, self.handle, ptr1=byref(self.server), ptr2=byref(self.user),
                             ptr3=self._local_path)

    def disconnect(self):
        self.is_connected = False
        if self.proxy is not None:
            self.proxy.x_request(Disconnect, self.handle)
            self.proxy.x_request(Release, self.handle)
        self.proxy = None
        self.handle = None

    def get_api_type(self):
        if self.proxy is None:
            self.proxy = Proxy(self._path1)
        return self.proxy.x_request(GetApiType)

    def get_api_version(self):
        if self.proxy is None:
            self.proxy = Proxy(self._path1)
        ptr = self.proxy.x_request(GetApiVersion)
        return c_char_p(ptr).value

    def get_api_name(self):
        if self.proxy is None:
            self.proxy = Proxy(self._path1)
        ptr = self.proxy.x_request(GetApiName)
        return c_char_p(ptr).value

    def subscribe(self, instrument_ids, exchange_id=b''):
        """
        Subscribe market data for the given instruments.
        :param instrument_ids: [string], list of instrument ids.
        :param exchange_id: string, exchange id
        """
        self.proxy.x_request(Subscribe, self.handle,
                             ptr1=c_char_p(
                                 b','.join(instrument_ids) if isinstance(instrument_ids, list) else instrument_ids),
                             ptr2=c_char_p(exchange_id))

    def unsubscribe(self, instrument_ids, exchange_id=b''):
        """
         Un-subscribe market data for the given instruments.
        :param instrument_ids: [string], list of instrument ids.
        :param exchange_id: string, exchange id
        """
        self.proxy.x_request(Unsubscribe, self.handle,
                             ptr1=b','.join(instrument_ids) if isinstance(instrument_ids, list) else instrument_ids,
                             ptr2=exchange_id)

    def send_order(self, order_ref, future_id, exchange_id, order_type, time_in_force, side, open_close,
                   hedge_flag, qty, price, stop_price):
        """
#.........这里部分代码省略.........
开发者ID:jasonweiyi,项目名称:ctxalgotrading,代码行数:103,代码来源:api_manager.py

示例2: Queue

# 需要导入模块: from proxy import Proxy [as 别名]
# 或者: from proxy.Proxy import x_request [as 别名]
class Queue(object):
    """
    queue service, used by api
    """
    proxy = None
    handle = None

    def __init__(self, path):
        self.proxy = Proxy(path)
        self.handle = self.proxy.x_request(Create)

    def start_pulling(self):
        if self.proxy is not None:
            # 启动消息队列循环
            self.proxy.x_request(Connect, self.handle)

    def disconnect(self):
        if self.proxy is not None:
            self.register(None)
            # 停止底层线程
            self.proxy.x_request(Disconnect, self.handle)
            self.proxy.x_request(Release, self.handle)
        self.proxy = None
        self.handle = None

    def process_first_message(self):
        """
        Process the first message in the queue (if any).
        Invoke corresponding callback function for that message.
        """
        if self.proxy is not None:
            return self.proxy.x_request(Process, self.handle)
        return False

    def register(self, ptr1):
        if self.proxy is not None:
            self.proxy.x_request(Register, self.handle, ptr1=ptr1)

    def clear(self):
        """
        Clear all messages in current message queue.
        """
        if self.proxy is not None:
            self.proxy.x_request(Clear, self.handle)
开发者ID:jasonweiyi,项目名称:ctxalgotrading,代码行数:46,代码来源:api_manager.py


注:本文中的proxy.Proxy.x_request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。