當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。