Interactive Brokers offers the ability to trade, monitor and manage your IBKR account using a single RESTful API.
Web API – Connect to Brokerage Session
When authenticating your login session this allows you equivalent access as a read-only user. You can query positions, account details, security definition and portfolio analyst data. Once authenticated, you can then connect to the brokerage session which provides access to market data, scanners and placing orders.
Web API – How to connect to WebSocket
WebSocket is a bidirectional, fully-duplex protocol that is used in the same scenario as client-server communication. It is a stateful protocol, which means the connection between the client and server will keep alive until it is terminated by either the client or server.
To help limit loss and lock in a profit you can bracket an order with additional opposite-side orders. A BUY order is bracketed by a high-side sell limit and a low-side sell stop order. A SELL order is bracketed by a high-side buy stop order and a low side buy limit order.
How to Code an OCA Order in the Web API
One-Cancels All (OCA) order type allows an investor to place multiple and possibly unrelated orders assigned to a group. It’s designed to allow investors to submit several orders aimed at taking advantage of the most desirable price within the group. Completion of one piece of the group causes cancellation of the remaining group orders while partial completion causes the group to rebalance.