Interactive Brokers SDK is a high-level object model build atop the native javascript API. It is all about straightforward programmatic access to your portfolio and market data subscriptions.
- An Interactive Brokers trading account.
- Install the IB Gateway or IB TWS (Trader Workstation).
The IB Gateway and IB TWS (Trader Workstation) software are graphical Java processes that encrypt and proxy calls to back-end servers. Without dedicated communication infrastructure, there is no IB support for direct connections to their server tier.
The SDK uses the native javascript API to manage a TCP socket connection from Node.js to an IB Gateway or TWS instance.
npm install ib-sdk
Login to the IB Gateway or IB TWS (Trader Workstation) software.
- The SDK expects to connect to an authenticated user session.
- The IB software must be configured to accept API connections.
- The SDK connects over
tcp://localhost:4001
by default. - Use ib-controller to automate UI interaction if so desired.
The main interface of the SDK is the session
object returned by the sdk.open
method callback.
require("ib-sdk").open({
host: "localhost",
port: 4001,
clientId: 0
}, (err, session) => {
if (err) console.log(err);
else session.close();
});
Invoke session.close()
to trigger disconnect logic and generally be a good person (but if you don't it will probably be okay).
Each session
is associated with one or more accounts. The most common case is access to a single account. Other use cases can benefit from the lightweight account summary model.
Use the SDK's symbol syntax to create security objects from which you can access market data and initiate orders.
Manage system events like changes in market data farm connectivity, IB bulletins, and FYI's. If you connect to the graphical TWS software, you can interact with display groups.
This package makes use of the Sugar library, which modifies javascript prototypes (at least the way it is used in this case).
The programming model is built on top of the service module, which makes interacting with the IB API pub/sub paradigm easier and enables remoting.
Copyright 2017 Jonathan Hollinger
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.