Example #1
0
    def create_order(self,
                     account,
                     contract,
                     action,
                     order_type,
                     quantity,
                     limit_price=None,
                     aux_price=None,
                     trail_stop_price=None,
                     trailing_percent=None,
                     percent_offset=None,
                     time_in_force=None,
                     outside_rth=None):
        """
        创建订单对象.
        :param account:
        :param contract:
        :param action:
        :param order_type:
        :param quantity:
        :param limit_price: 限价
        :param aux_price: 在止损单表示止损价格; 在跟踪止损单表示价差
        :param trail_stop_price: 跟踪止损单--触发止损单的价格
        :param trailing_percent: 跟踪止损单--百分比
        :param percent_offset:
        :param time_in_force: 订单有效期, 'DAY'(当日有效)和'GTC'(取消前有效)
        :param outside_rth: 是否允许盘前盘后交易(美股专属)
        :return:
        """
        params = AccountsParams()
        params.account = account if account else self._account
        request = OpenApiRequest(ORDER_NO, biz_model=params)
        response_content = self.__fetch_data(request)
        if response_content:
            response = OrderIdResponse()
            response.parse_response_content(response_content)
            if response.is_success():
                order_id = response.order_id
                order = Order(account,
                              contract,
                              action,
                              order_type,
                              quantity,
                              limit_price=limit_price,
                              aux_price=aux_price,
                              trail_stop_price=trail_stop_price,
                              trailing_percent=trailing_percent,
                              percent_offset=percent_offset,
                              time_in_force=time_in_force,
                              outside_rth=outside_rth,
                              order_id=order_id)
                return order
            else:
                raise ApiException(response.code, response.message)

        return None
Example #2
0
 def get_managed_accounts(self):
     params = AccountsParams()
     params.account = self._account
     request = OpenApiRequest(ACCOUNTS, biz_model=params)
     response_content = self.__fetch_data(request)
     if response_content:
         response = ProfilesResponse()
         response.parse_response_content(response_content)
         if response.is_success():
             return response.profiles
         else:
             raise ApiException(response.code, response.message)
     return None
Example #3
0
    def create_order(self, account, contract, action, order_type, quantity, limit_price=None, aux_price=None,
                     trail_stop_price=None, trailing_percent=None, percent_offset=None, time_in_force=None,
                     outside_rth=None):
        params = AccountsParams()
        params.account = self._account
        request = OpenApiRequest(ORDER_NO, biz_model=params)
        response_content = self.__fetch_data(request)
        if response_content:
            response = OrderIdResponse()
            response.parse_response_content(response_content)
            if response.is_success():
                order_id = response.order_id
                order = Order(account, contract, action, order_type, quantity, limit_price=limit_price,
                              aux_price=aux_price, trail_stop_price=trail_stop_price,
                              trailing_percent=trailing_percent, percent_offset=percent_offset,
                              time_in_force=time_in_force, outside_rth=outside_rth, order_id=order_id)
                return order
            else:
                raise ApiException(response.code, response.message)

        return None
Example #4
0
def get_account_info():
    client_config = get_client_config()
    openapi_client = TigerOpenClient(client_config)
    account = AccountsParams()
    account.account = 'DU575569'
    request = OpenApiRequest(method=ACCOUNTS, biz_model=account)

    response_content = None
    try:
        response_content = openapi_client.execute(request)
    except Exception as e:
        print(traceback.format_exc())
    if not response_content:
        print("failed to execute")
    else:
        response = TigerResponse()
        response.parse_response_content(response_content)
        if response.is_success():
            print("get response data:" + response.data)
        else:
            print(response.code + "," + response.msg + "," + response.data)
def get_account_info():
    from tigeropen.common.consts.service_types import ACCOUNTS
    openapi_client = TigerOpenClient(client_config)
    account = AccountsParams()
    account.account = client_config.account
    request = OpenApiRequest(method=ACCOUNTS, biz_model=account)

    response_content = None
    try:
        response_content = openapi_client.execute(request)
    except Exception as e:
        print(traceback.format_exc())
    if not response_content:
        print("failed to execute")
    else:
        response = TigerResponse()
        response.parse_response_content(response_content)
        if response.is_success():
            print("get response data:" + response.data)
        else:
            print("%d,%s,%s" % (response.code, response.message, response.data))
Example #6
0
 def get_managed_accounts(self, account=None):
     """
     获取管理的账号列表
     :param account:
     :return: AccountProfile 对象, 有如下属性:
         account: 交易账户
         capability: 账户类型(CASH:现金账户, MGRN: Reg T 保证金账户, PMGRN: 投资组合保证金)
         status: 账户状态(New, Funded, Open, Pending, Abandoned, Rejected, Closed, Unknown)
     """
     params = AccountsParams()
     params.account = account if account else self._account
     request = OpenApiRequest(ACCOUNTS, biz_model=params)
     response_content = self.__fetch_data(request)
     if response_content:
         response = ProfilesResponse()
         response.parse_response_content(response_content)
         if response.is_success():
             return response.profiles
         else:
             raise ApiException(response.code, response.message)
     return None