Exemple #1
0
    def get_ticker_object(
            self,
            contract_object_with_ib_data: futuresContract,
            trade_list_for_multiple_legs: tradeQuantity = None
    ) -> tickerWithBS:

        specific_log = contract_object_with_ib_data.specific_log(self.log)

        ibcontract = self.ib_futures_contract(
            contract_object_with_ib_data,
            trade_list_for_multiple_legs=trade_list_for_multiple_legs,
        )

        if ibcontract is missing_contract:
            specific_log.warn("Can't find matching IB contract for %s" %
                              str(contract_object_with_ib_data))
            return missing_contract

        self.ib.reqMktData(ibcontract, "", False, False)
        ticker = self.ib.ticker(ibcontract)

        ib_BS_str, ib_qty = resolveBS_for_list(trade_list_for_multiple_legs)

        ticker_with_bs = tickerWithBS(ticker, ib_BS_str)

        return ticker_with_bs
    def _build_ib_order(
        self,
        trade_list: tradeQuantity,
        account: str = "",
        order_type: brokerOrderType = market_order_type,
        limit_price: float = None,
    ) -> ibOrder:

        ib_BS_str, ib_qty = resolveBS_for_list(trade_list)

        if order_type is market_order_type:
            ib_order = ibMarketOrder(ib_BS_str, ib_qty)
        elif order_type is limit_order_type:
            if limit_price is None:
                self.log.critical("Need to have limit price with limit order!")
                return missing_order
            else:
                ib_order = ibLimitOrder(ib_BS_str, ib_qty, limit_price)
        else:
            self.log.critical("Order type %s not recognised!" % order_type)
            return missing_order

        if account != "":
            ib_order.account = account

        return ib_order
Exemple #3
0
    def get_ticker_object(self,
                          contract_object_with_ib_data,
                          trade_list_for_multiple_legs=None):

        specific_log = self.log.setup(
            instrument_code=contract_object_with_ib_data.instrument_code,
            contract_date=contract_object_with_ib_data.date_str,
        )

        ibcontract = self.ib_futures_contract(
            contract_object_with_ib_data,
            trade_list_for_multiple_legs=trade_list_for_multiple_legs,
        )
        if ibcontract is missing_contract:
            specific_log.warn("Can't find matching IB contract for %s" %
                              str(contract_object_with_ib_data))
            return missing_contract

        self.ib.reqMktData(ibcontract, "", False, False)
        ticker = self.ib.ticker(ibcontract)

        ib_BS_str, ib_qty = resolveBS_for_list(trade_list_for_multiple_legs)

        ticker_with_bs = tickerWithBS(ticker, ib_BS_str)

        return ticker_with_bs
Exemple #4
0
    def ib_submit_order(
        self,
        contract_object_with_ib_data,
        trade_list,
        account="",
        order_type="market",
        limit_price=None,
    ):

        if contract_object_with_ib_data.is_spread_contract():
            ibcontract_with_legs = self.ib_futures_contract(
                contract_object_with_ib_data,
                trade_list_for_multiple_legs=trade_list,
                return_leg_data=True,
            )
            ibcontract = ibcontract_with_legs.ibcontract
        else:
            ibcontract = self.ib_futures_contract(contract_object_with_ib_data)
            ibcontract_with_legs = ibcontractWithLegs(ibcontract)

        if ibcontract is missing_contract:
            return missing_order

        ib_BS_str, ib_qty = resolveBS_for_list(trade_list)

        if order_type == "market":
            ib_order = MarketOrder(ib_BS_str, ib_qty)
        elif order_type == "limit":
            if limit_price is None:
                self.log.critical("Need to have limit price with limit order!")
                return missing_order
            else:
                ib_order = LimitOrder(ib_BS_str, ib_qty, limit_price)
        else:
            self.log.critical("Order type %s not recognised!" % order_type)
            return missing_order

        if account != "":
            ib_order.account = account

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

        # for consistency with spread orders
        trade_with_contract = tradeWithContract(ibcontract_with_legs,
                                                order_object)

        return trade_with_contract
    def ib_submit_calendar_leg_market_order(self,
                                            contract_object_with_ib_data,
                                            trade_list,
                                            account=""):
        ibcontract_with_legs = self.ib_futures_contract(
            contract_object_with_ib_data,
            trade_list_for_multiple_legs=trade_list,
            return_leg_data=True)
        ibcontract = ibcontract_with_legs.ibcontract
        if ibcontract is missing_contract:
            return missing_order

        ib_BS_str, ib_qty = resolveBS_for_list(trade_list)
        ib_order = MarketOrder(ib_BS_str, ib_qty)
        if account != '':
            ib_order.account = account

        order_object = self.ib.placeOrder(ibcontract, ib_order)
        placed_broker_trade_object = tradeWithContract(ibcontract_with_legs,
                                                       order_object)

        return placed_broker_trade_object