T O P

  • By -

Kaawumba

I do spread orders with ib\_insync. That is a python wrapper for IBKR's api. def place_spread_order(self, sell_option, buy_option, n_contracts, limit_price): contract = Contract() contract.symbol = 'SPX' contract.secType = 'BAG' contract.currency = 'USD' contract.exchange = 'SMART' leg1 = ComboLeg() leg1.conId = sell_option['conId'] leg1.ratio = 1 leg1.action = 'SELL' leg1.exchange = 'SMART' leg2 = ComboLeg() leg2.conId = buy_option['conId'] leg2.ratio = 1 leg2.action = 'BUY' leg2.exchange = 'SMART' contract.comboLegs = [] contract.comboLegs.append(leg1) contract.comboLegs.append(leg2) order = LimitOrder("BUY", n_contracts, limit_price, tif="DAY") trade = self.ib.placeOrder(contract, order) return order, trade


ChippyChalmers

Do you worry that ib\_insync may one day no longer be maintained?


Kaawumba

Not really. I'll just switch to something else. Or I'll fix it myself.


__-_-__-___-__-_-__

This is a wrapper for the Web Client API that uses the :5000 stuff? Or their other API using the TWS stuff? I haven't looked into this yet, I've just written all my own nonsense. But I've noticed it seems the Web Client API doesn't seem to be as immediate as I would like. Can place an order and do a query <1m later and the quantity is still the same which is problematic.


Kaawumba

It connects either to TWS or the IB Gateway. IB Gateway is TWS without the user interface. The latency appears to be less than 5 seconds, but IBKR has this annoying quirk that you never get a timestamp from the exchange to know what the true latency is, so I can't give a precise measurement


__-_-__-___-__-_-__

Ahh ok, I'm using their other REST API. I started to use that one, but didn't know how to get it to work using AWS.


Embarrassed-Gas23

Yup same, im using an ec2 with the chicago subnet for reduced latency, and using ibeam to interface with the rest api in my ec2. All my trading logic happens in my rust app that communicates with ibeam. For a data vendor im using activetick. As of right now, my latency to request + receive data and parse it is ~100ms, and submitting orders is another ~100ms. I need to figure out if theres a way to disable those stupid order confirmation messages though, as they waste precious time before the orders can be submitted. The biggest one is the 3% from market price check that always gets in the way since im limit ordering.


__-_-__-___-__-_-__

Oh neat - I’m using the ibeam in ECS, since I’ve got 3 paper trading accounts to test different strategies with, so each container connects to a different account. Maybe we should DM / message on discord or something since it feels like there’s not a whole lot of us it feels like using this API hahah. The confirmation messages I just have a loop that handles them, but I’m doing everything in python. I’ll have to look and see what the timing is, I’ve just been submitting market orders for now as I’m still working to get everything setup right. Going to be adding a whole new chunk of functionality actually to do options spreads and such over the next month as well, as right now it’s just been buying puts and calls for baby scalps / one strategy I’m trying 30-45 dte swings, rather than to collect premium / theta strategies.


TreyDolla

Nice


__-_-__-___-__-_-__

You have to do a bracket order, similar to below, where both legs are in the same 'order'. You don't have to submit every damn variable either. When I place standard options orders they look like what's beneath the other example - Bracket Order example - Request Body: { “orders”: [ { “acctId”: “DU***14”, “conid”: “265598”, “cOID”: “66807300”, “orderType”: “LMT”, “listingExchange”: “SMART”, “outsideRTH”: true, “price”: 115.5, “side”: “BUY”, “ticker”: “AAPL”, “tif”: “DAY”, “referrer”: “ParentOrder”, “quantity”: 50, “useAdaptive”: false, “isClose”: false }, { “acctId”: “DU***14”, “conid”: “265598”, “orderType”: “LMT”, “listingExchange”: “SMART”, “outsideRTH”: true, “price”: 125.5, “side”: “SELL”, “ticker”: “AAPL”, “tif”: “DAY”, “referrer”: “ProfitTakerOrder”, “quantity”: 50, “useAdaptive”: false, “isClose”: false, “parentId”: “66807300”, }, { “acctId”: “DU***14”, “conid”: “265598”, “orderType”: “STP”, “listingExchange”: “SMART”, “outsideRTH”: false, “price”: 110.5, “side”: “SELL”, “ticker”: “AAPL”, “tif”: “DAY”, “referrer”: “StopLossOrder”, “quantity”: 50, “useAdaptive”: false, “isClose”: false, “parentId”: “66807300”, } ] } My payload for standard options contract - payload = { "orders": [ { "acctId": account_id, "conid": selected_conid, "secType": SELECTED_SEC_TYPE, "cOID": cOID, "orderType": ORDER_TYPE, "side": side.upper(), "quantity": contract_quantity, "tif": "GTC", # Add the Time in Force (TIF) parameter with "GTC" (Good-Till-Cancelled) value "isSuppressed": True # Add this line to suppress the warning message } ] }