Good morning all,
I'm in the middle of getting a bit of code together to make multiple trades using the bag method, this is what I've come up with thus far and for the most part, it works, up until it gives me the ERROR 1 10268 The 'EtradeOnly' order attribute is not supported.
Also I tried to put this in a code snippet and it wouldn't let me, the other buttons work; I wasn't sure what the correct attribute was to encapsulate it either.
Thanks
Comps
I'm in the middle of getting a bit of code together to make multiple trades using the bag method, this is what I've come up with thus far and for the most part, it works, up until it gives me the ERROR 1 10268 The 'EtradeOnly' order attribute is not supported.
###code start ### from ibapi.client import EClient from ibapi.wrapper import EWrapper from ibapi.contract import Contract, ComboLeg from ibapi.order import Order from ibapi.tag_value import TagValue from ibapi.common import OrderId # Contract definitions contracts = [ {"conId": 120549942, "symbol": "AAPL", "secType": "CFD", "currency": "USD", "exchange": "NASDAQ"}, {"conId": 131067756, "symbol": "TSLA", "secType": "STK", "currency": "USD", "exchange": "NASDAQ"}, {"conId": 118239139, "symbol": "MSFT", "secType": "STK", "currency": "USD", "exchange": "NASDAQ"}, ] # Lookup dictionary contract_lookup = {c["symbol"].upper(): c for c in contracts} # Parse legs from text input def parse_legs_from_text(text: str): legs = [] for line in text.strip().splitlines(): parts = line.split(",") if len(parts) != 4: raise ValueError(f"Invalid line format: {line}") symbol, action, ratio, exchange = [p.strip() for p in parts] symbol = symbol.upper() if symbol not in contract_lookup: raise ValueError(f"Unknown symbol: {symbol}") contract = contract_lookup[symbol] legs.append({ "conId": contract["conId"], "symbol": symbol, "action": action.upper(), "ratio": int(ratio), "exchange": exchange.upper() }) return legs # Main IBKR app class IBApp(EWrapper, EClient): def __init__(self): EClient.__init__(self, self) self.next_order_id = None # will be set via nextValidId # Automatically called by IBKR on connection def nextValidId(self, orderId: int): print(f"Next valid orderId: {orderId}") self.next_order_id = orderId # Optionally place your first order automatically here # self.place_example_order() # Place combo order def multipurchase(self, textbox_input: str, lmtPrice: float = 80, totalQuantity: int = 10): if self.next_order_id is None: print("Next order ID not yet received. Cannot place order.") return orderId = self.next_order_id self.next_order_id += 1 # increment for next order legs_input = parse_legs_from_text(textbox_input) # Build combo contract mycontract = Contract() mycontract.symbol = ",".join([leg["symbol"] for leg in legs_input]) mycontract.secType = "BAG" mycontract.currency = "USD" mycontract.exchange = "SMART" mycontract.comboLegs = [] for leg_data in legs_input: leg = ComboLeg() leg.conId = leg_data["conId"] leg.ratio = leg_data["ratio"] leg.action = leg_data["action"] leg.exchange = leg_data["exchange"] mycontract.comboLegs.append(leg) # Build order myorder = Order() myorder.orderId = orderId myorder.action = "BUY" myorder.orderType = "MKT" myorder.lmtPrice = lmtPrice myorder.totalQuantity = totalQuantity myorder.tif = "GTC" # myorder.smartComboRoutingParams = [TagValue('NonGuaranteed', '1')] # Place the order self.placeOrder(orderId, mycontract, myorder) print(f"Placed combo order with orderId {orderId}") # Optional: IBKR callbacks def openOrder(self, orderId: OrderId, contract: Contract, order: Order, orderState): print(f"openOrder - orderId: {orderId}, contract: {contract.symbol}, action: {order.action}, qty: {order.totalQuantity}, price: {order.lmtPrice}") def orderStatus(self, orderId: OrderId, status: str, filled: float, remaining: float, avgFillPrice: float, permId: int, parentId: int, lastFillPrice: float, clientId: int, whyHeld: str, mktCapPrice: float): print(f"orderStatus - orderId: {orderId}, status: {status}, filled: {filled}, remaining: {remaining}, avgFillPrice: {avgFillPrice}") def execDetails(self, reqId: int, contract: Contract, execution): print(f"execDetails - reqId: {reqId}, contract: {contract.symbol}, executionId: {execution.execId}") # ------------------- Usage ------------------- if __name__ == "__main__": app = IBApp() app.connect("127.0.0.1", 4002, clientId=1000) # Example combo order input textbox_input = """ AAPL,BUY,1,SMART TSLA,SELL,1,SMART MSFT,BUY,2,SMART """ # Wait until nextValidId arrives before placing orders import time import threading def place_order_when_ready(): while app.next_order_id is None: time.sleep(0.1) app.multipurchase(textbox_input, lmtPrice=80, totalQuantity=10) threading.Thread(target=place_order_when_ready, daemon=True).start() app.run() #code end#So I'm not using the etradeonly attribute, any ideas? I've been stuck with this for a few days now and I'm not sure, I can't find anywhere else to ask. Also I tried to put this in a code snippet and it wouldn't let me, the other buttons work; I wasn't sure what the correct attribute was to encapsulate it either.
Thanks
Comps
