Beispiel #1
0
    def modify_order(self, order, quantity=None, limit_price=None, aux_price=None,
                     trail_stop_price=None, trailing_percent=None, percent_offset=None,
                     time_in_force=None, outside_rth=None):
        params = PlaceModifyOrderParams()
        params.account = order.account
        params.order_id = order.order_id
        params.contract = order.contract
        params.action = order.action
        params.order_type = order.order_type
        params.quantity = quantity if quantity is not None else order.quantity
        params.limit_price = limit_price if limit_price is not None else order.limit_price
        params.aux_price = aux_price if aux_price is not None else order.aux_price
        params.trail_stop_price = trail_stop_price if trail_stop_price is not None else order.trail_stop_price
        params.trailing_percent = trailing_percent if trailing_percent is not None else order.trailing_percent
        params.percent_offset = percent_offset if percent_offset is not None else order.percent_offset
        params.time_in_force = time_in_force if time_in_force is not None else order.time_in_force
        params.outside_rth = outside_rth if outside_rth is not None else order.outside_rth
        request = OpenApiRequest(MODIFY_ORDER, biz_model=params)
        response_content = self.__fetch_data(request)
        if response_content:
            response = OrderIdResponse()
            response.parse_response_content(response_content)
            if response.is_success():
                return response.order_id == order.order_id
            else:
                raise ApiException(response.code, response.message)

        return False
Beispiel #2
0
    def place_order(self, order):
        params = PlaceModifyOrderParams()
        params.account = order.account
        params.contract = order.contract
        params.action = order.action
        params.order_type = order.order_type
        params.order_id = order.order_id
        params.quantity = order.quantity
        params.limit_price = order.limit_price
        params.aux_price = order.aux_price
        params.trail_stop_price = order.trail_stop_price
        params.trailing_percent = order.trailing_percent
        params.percent_offset = order.percent_offset
        params.time_in_force = order.time_in_force
        params.outside_rth = order.outside_rth
        request = OpenApiRequest(PLACE_ORDER, biz_model=params)
        response_content = self.__fetch_data(request)
        if response_content:
            response = OrderIdResponse()
            response.parse_response_content(response_content)
            if response.is_success():
                return response.order_id == order.order_id
            else:
                raise ApiException(response.code, response.message)

        return False
Beispiel #3
0
    def modify_order(self,
                     order,
                     quantity=None,
                     limit_price=None,
                     aux_price=None,
                     trail_stop_price=None,
                     trailing_percent=None,
                     percent_offset=None,
                     time_in_force=None,
                     outside_rth=None):
        """
        修改订单
        :param order:
        :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 = PlaceModifyOrderParams()
        params.account = order.account
        params.order_id = order.order_id
        params.id = order.id
        params.contract = order.contract
        params.action = order.action
        params.order_type = order.order_type
        params.quantity = quantity if quantity is not None else order.quantity
        params.limit_price = limit_price if limit_price is not None else order.limit_price
        params.aux_price = aux_price if aux_price is not None else order.aux_price
        params.trail_stop_price = trail_stop_price if trail_stop_price is not None else order.trail_stop_price
        params.trailing_percent = trailing_percent if trailing_percent is not None else order.trailing_percent
        params.percent_offset = percent_offset if percent_offset is not None else order.percent_offset
        params.time_in_force = time_in_force if time_in_force is not None else order.time_in_force
        params.outside_rth = outside_rth if outside_rth is not None else order.outside_rth
        params.secret_key = order.secret_key if order.secret_key else self._secret_key

        request = OpenApiRequest(MODIFY_ORDER, biz_model=params)
        response_content = self.__fetch_data(request)
        if response_content:
            response = OrderIdResponse()
            response.parse_response_content(response_content)
            if response.is_success():
                return response.order_id == order.order_id if order.order_id else response.id == order.id
            else:
                raise ApiException(response.code, response.message)

        return False
Beispiel #4
0
    def preview_order(self, order):
        """
        预览订单
        :param order:  Order 对象
        :return: dict. 字段如下
            init_margin_before      下单前账户初始保证金
            init_margin             预计下单后的账户初始保证金
            maint_margin_before     下单前账户的维持保证金
            maint_margin            预计下单后的账户维持保证金
            margin_currency         保证金货币币种
            equity_with_loan_before 下单前账户的含借贷值股权(含贷款价值资产)
            equity_with_loan        下单后账户的含借贷值股权(含贷款价值资产)
            min_commission          预期最低佣金
            max_commission          预期最高佣金
            commission_currency     佣金货币币种

            若无法下单, 返回的 dict 中仅有如下字段:
            warning_text            无法下单的原因
        """
        params = PlaceModifyOrderParams()
        params.account = order.account
        params.contract = order.contract
        params.action = order.action
        params.order_type = order.order_type
        params.order_id = order.order_id
        params.quantity = order.quantity
        params.limit_price = order.limit_price
        params.aux_price = order.aux_price
        params.trail_stop_price = order.trail_stop_price
        params.trailing_percent = order.trailing_percent
        params.percent_offset = order.percent_offset
        params.time_in_force = order.time_in_force
        params.outside_rth = order.outside_rth
        params.secret_key = order.secret_key if order.secret_key else self._secret_key
        request = OpenApiRequest(PREVIEW_ORDER, biz_model=params)
        response_content = self.__fetch_data(request)
        if response_content:
            response = PreviewOrderResponse()
            response.parse_response_content(response_content)
            if response.is_success():
                return response.preview_order
            else:
                raise ApiException(response.code, response.message)
Beispiel #5
0
    def place_order(self, order):
        """
        下单
        :param order:  Order 对象
        :return:
        """
        params = PlaceModifyOrderParams()
        params.account = order.account
        params.contract = order.contract
        params.action = order.action
        params.order_type = order.order_type
        params.order_id = order.order_id
        params.quantity = order.quantity
        params.limit_price = order.limit_price
        params.aux_price = order.aux_price
        params.trail_stop_price = order.trail_stop_price
        params.trailing_percent = order.trailing_percent
        params.percent_offset = order.percent_offset
        params.time_in_force = order.time_in_force
        params.outside_rth = order.outside_rth
        params.order_legs = order.order_legs
        params.algo_params = order.algo_params
        params.secret_key = order.secret_key if order.secret_key else self._secret_key

        request = OpenApiRequest(PLACE_ORDER, 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.id
                if order.order_id is None and response.order_id:
                    order.order_id = response.order_id
                return True
            else:
                raise ApiException(response.code, response.message)

        return False