def broker_fx_market_order(self, trade, ccy1, account=arg_not_supplied, ccy2="USD"): """ Get some spot fx data :param ccy1: first currency in pair :param ccy2: second currency in pair :param qty: :return: broker order object """ ccy_code = ccy1 + ccy2 specific_log = self.log.setup(currency_code=ccy_code) ibcontract = self.ib_spotfx_contract(ccy1, ccy2=ccy2, log=specific_log) if ibcontract is missing_contract: return missing_contract ib_BS_str, ib_qty = resolveBS(trade) ib_order = MarketOrder(ib_BS_str, ib_qty) if account != "": ib_order.account = account order_object = self.ib.placeOrder(ibcontract, ib_order) # for consistency with spread orders trade_with_contract = tradeWithContract(ibcontractWithLegs(ibcontract), order_object) return trade_with_contract
def ib_submit_single_leg_market_order(self, contract_object_with_ib_data, trade, account): ibcontract = self.ib_futures_contract(contract_object_with_ib_data) if ibcontract is missing_contract: return missing_order ## account?!s ib_BS_str, ib_qty = resolveBS(trade) ib_order = MarketOrder(ib_BS_str, ib_qty) if account != '': ib_order.account = account trade = self.ib.placeOrder(ibcontract, ib_order) return trade
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_single_leg_market_order(self, contract_object_with_ib_data, trade, account=""): ibcontract = self.ib_futures_contract(contract_object_with_ib_data) if ibcontract is missing_contract: return missing_order ib_BS_str, ib_qty = resolveBS(trade) ib_order = MarketOrder(ib_BS_str, ib_qty) if account != '': ib_order.account = account order_object = self.ib.placeOrder(ibcontract, ib_order) # for consistency with spread orders trade_with_contract = tradeWithContract(ibcontractWithLegs(ibcontract), 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
def reqCommissionsFromIB(self, contracts: List) -> Dict: order = MarketOrder('BUY', 1) commissions = { contract.symbol: self.read_from_file_or_ib('commission', 'whatIfOrder', contract, order) for contract in contracts } missing_commissions = [] for contract, commission in commissions.copy().items(): if not commission: missing_commissions.append(contract) del commissions[contract] commissions.update(self.getCommissionBySymbol(missing_commissions)) return commissions
headlines = ib.reqHistoricalNews(intc.conId, codes, "", "", 10) latest = headlines[0] print(latest) article = ib.reqNewsArticle(latest.providerCode, latest.articleId) print(article) if 0: ib.reqNewsBulletins(True) ib.sleep(5) print(ib.newsBulletins()) if 0: ticker = ib.reqMktDepth(eurusd, 5) while ib.sleep(5): print([d.price for d in ticker.domBids], [d.price for d in ticker.domAsks]) if 0: order = MarketOrder('BUY', 100) state = ib.whatIfOrder(amd, order) print(state) if 0: start = datetime.datetime(2017, 7, 24, 16, 0, 0) end = '' ticks = ib.reqHistoricalTicks( eurusd, start, end, 100, 'MIDPOINT', True, False, []) print(ticks) if 0: start = datetime.time(10, 10, 10) end = datetime.time(14, 13) for t in ib.timeRange(start, end, 5): print(t) if 0: histo = ib.reqHistogramData(amd, True, '1 week')