Пример #1
0
    def broker_fx_market_order(self,
                               trade: float,
                               ccy1: str,
                               account_id: str = arg_not_supplied,
                               ccy2: str = "USD") -> tradeWithContract:
        """
        Get some spot fx data

        :param ccy1: first currency in pair
        :param ccy2: second currency in pair
        :param qty:
        :return: broker order object
        """

        ibcontract = self.ib_spotfx_contract(ccy1, ccy2=ccy2)
        if ibcontract is missing_contract:
            return missing_contract

        ib_order = self._create_fx_market_order_for_submission(
            trade=trade, account_id=account_id)
        order_object = self.ib.placeOrder(ibcontract, ib_order)

        # for consistency with spread orders use this kind of object
        contract_object_to_return = ibcontractWithLegs(ibcontract)
        trade_with_contract = tradeWithContract(contract_object_to_return,
                                                order_object)

        return trade_with_contract
Пример #2
0
    def modify_limit_price_given_original_objects(
            self, original_order_object: ibOrder,
            original_contract_object_with_legs: ibcontractWithLegs,
            new_limit_price: float) -> tradeWithContract:

        original_contract_object = original_contract_object_with_legs.ibcontract
        original_order_object.lmtPrice = new_limit_price

        new_trade_object = self.ib.placeOrder(original_contract_object,
                                              original_order_object)

        new_trade_with_contract = tradeWithContract(
            original_contract_object_with_legs, new_trade_object)

        return new_trade_with_contract
Пример #3
0
    def add_contract_legs_to_order(
            self, raw_order_from_ib: ibTrade) -> tradeWithContract:
        combo_legs = getattr(raw_order_from_ib.contract, "comboLegs", [])
        legs_data = []
        for leg in combo_legs:
            contract_for_leg = self.ib_get_contract_with_conId(
                raw_order_from_ib.contract.symbol, leg.conId)
            legs_data.append(contract_for_leg)

        ibcontract_with_legs = ibcontractWithLegs(raw_order_from_ib.contract,
                                                  legs=legs_data)
        trade_with_contract = tradeWithContract(ibcontract_with_legs,
                                                raw_order_from_ib)

        return trade_with_contract
Пример #4
0
    def broker_submit_order(
        self,
        futures_contract_with_ib_data: futuresContract,
        trade_list: tradeQuantity,
        account_id: str = arg_not_supplied,
        order_type: brokerOrderType = market_order_type,
        limit_price: float = None,
    ) -> tradeWithContract:
        """

        :param ibcontract: contract_object_with_ib_data: contract where instrument has ib metadata
        :param trade: int
        :param account: str
        :param order_type: str, market or limit
        :param limit_price: None or float

        :return: brokers trade object

        """
        ibcontract_with_legs = self.ib_futures_contract_with_legs(
            futures_contract_with_ib_data=futures_contract_with_ib_data,
            trade_list_for_multiple_legs=trade_list,
        )

        if ibcontract_with_legs is missing_contract:
            return missing_order

        ibcontract = ibcontract_with_legs.ibcontract

        ib_order = self._build_ib_order(
            trade_list=trade_list,
            account_id=account_id,
            order_type=order_type,
            limit_price=limit_price,
        )

        order_object = self.ib.placeOrder(ibcontract, ib_order)

        trade_with_contract = tradeWithContract(ibcontract_with_legs,
                                                order_object)

        return trade_with_contract