# ib-sdk

> Interactive Brokers SDK framework build atop the native javascript API.

Latest version **0.11.3** (published 2018-01-24) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install ib-sdk
pnpm add ib-sdk
yarn add ib-sdk
bun add ib-sdk
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.11.3 |
| Published | 2018-01-24 |
| First published | 2016-03-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 32 |
| Author | Jonathan Hollinger |
| Maintainers | triploc |
| Keywords | interactive brokers, ib, ib api, brokerage api, trading api |

## Links

- npm: https://www.npmjs.com/package/ib-sdk
- Repository: https://github.com/triploc/ib-sdk
- Homepage: https://github.com/triploc/ib-sdk#readme
- Issues: https://github.com/triploc/ib-sdk/issues
- npm.io page: https://npm.io/package/ib-sdk

## Dependencies (4)

- [ib](https://npm.io/package/ib.md) ^0.2.4
- [luxon](https://npm.io/package/luxon.md) ^0.3.1
- [sugar](https://npm.io/package/sugar.md) ^2.0.4
- [xml2js](https://npm.io/package/xml2js.md) ^0.4.19

## Alternatives

- [@cantoo/pdf-lib](https://npm.io/package/@cantoo/pdf-lib.md) — 297.9K weekly downloads
- [datatables.net-buttons](https://npm.io/package/datatables.net-buttons.md) — 200.1K weekly downloads
- [@ckeditor/ckeditor5-export-pdf](https://npm.io/package/@ckeditor/ckeditor5-export-pdf.md) — 167.0K weekly downloads
- [scanbot-web-sdk](https://npm.io/package/scanbot-web-sdk.md) — 15.0K weekly downloads
- [@syncfusion/ej2-angular-pdfviewer](https://npm.io/package/@syncfusion/ej2-angular-pdfviewer.md) — 8.8K weekly downloads

## Recent versions

- 0.11.3 (latest) — 2018-01-24
- 0.11.2 — 2018-01-24
- 0.11.1 — 2018-01-21
- 0.11.0 — 2018-01-20
- 0.10.8 — 2018-01-14
- 0.10.7 — 2017-11-06
- 0.10.6 — 2017-10-26
- 0.10.5 — 2017-10-25
- 0.10.4 — 2017-08-23
- 0.10.3 — 2017-08-20
- 0.10.2 — 2017-08-20
- 0.10.0 — 2017-08-15
- 0.9.6 — 2017-08-13
- 0.9.4 — 2017-08-03
- 0.9.3 — 2017-08-03
- … 41 more at https://npm.io/package/ib-sdk/versions

## README

[![Logo](./ib-logo.png)](http://interactivebrokers.com/)

# Interactive Brokers SDK

Interactive Brokers SDK is a high-level programming model build atop the [native javascript API](https://github.com/pilwon/node-ib) that is all about straightforward programmatic access to your portfolio and market data subscriptions.

#### Prerequisites

* An [Interactive Brokers](https://www.interactivebrokers.com/) trading account.
* Install the [IB Gateway](https://www.interactivebrokers.com/en/index.php?f=16457) or [IB TWS (Trader Workstation)](https://www.interactivebrokers.com/en/index.php?f=674&ns=T).

#### How It Works

The [IB Gateway](http://interactivebrokers.github.io) and [IB TWS (Trader Workstation)](https://www.interactivebrokers.com/en/index.php?f=674&ns=T) software are graphical Java processes that encrypt and proxy calls to back-end servers.  Without special infrastructure there is no support for direct connections to IB servers, so the SDK uses the [native javascript API](https://github.com/pilwon/node-ib) to manage a TCP socket connection from Node.js to an IB Gateway or TWS instance.

## Installation

    npm install ib-sdk

## Getting Started

Login to the [IB Gateway](http://interactivebrokers.github.io) or [IB TWS (Trader Workstation)](https://www.interactivebrokers.com/en/index.php?f=674&ns=T) 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](https://github.com/ib-controller/ib-controller/releases) to automate UI interaction if necessary.

The entry point is the `session` returned by the `sdk.start` promise.  Each `session` is associated with one or more accounts.  The most common case is access to a single [account](./example/account.js).

```javascript
sdk.start().then(async session => {
    let account = await session.account();

    console.log("Balances:");
    account.balances.each((value, name) => console.log(`${name}: ${value}`));

    console.log("Positions:");
    account.positions.each(position => console.log(position));

    console.log("Orders:");
    account.orders.each(order => console.log(order));

    console.log("Trades:");
    account.trades.each(trade => console.log(trade));
    
    session.close();
}).catch(console.log);
```

For multiple managed accounts, the [accounts](./example/accounts.js) summary must be used.  Otherwise only one account can be subscribed to at a time.

```javascript
let accounts = await session.accounts();
accounts.each((account, name) => {
    console.log(name);

    console.log("Balances:");
    account.balances.each((value, name) => console.log(`${name}: ${value}`));

    console.log("Positions:");
    account.positions.each(position => console.log(position));
});

console.log("Orders:");
accounts.orders.each(order => console.log(order));

console.log("Trades:");
accounts.trades.each(trade => console.log(trade));

session.close();
```

## Market Data

Use the SDK's [symbol](./doc/symbols.md) syntax to create `securities` from which you can access market data.

```javascript
let AAPL = (await session.securities("AAPL stock"))[0];
console.log(AAPL.contract);

let snapshot = await AAPL.fundamentals("snapshot");
console.log(snapshot);

if (!AAPL.contract.marketsOpen) {
    session.frozen = true;
    
    let instant = await AAPL.quote.query();
    console.log(instant);
    
    let chart = await AAPL.charts.minutes.five.history();
    chart.study("SMA20", 20, "SMA");
    console.log(chart.series);
}
else {
    let quote = (await AAPL.quote.stream())
        .on("update", update => console.log(update))
        .on("error", err => console.log(err));

    let depth = (await AAPL.depth.stream())
        .on("update", update => console.log(update))
        .on("error", err => console.log(err));
    
    let charts = (await AAPL.charts.stream())
        .on("update", update => console.log(update))
        .on("error", err => console.log(err));
}
```

## System

Manage [system](./example/system.js) 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.

```javascript
session
    .on("error", console.log)
    .on("disconnected", () => console.log("Disconnected."))
    .on("connectivity", console.log)
    .on("displayGroupUpdated", group => console.log(group.contract))
    .on("bulletin", console.log);

// Make sure stuff has loaded
await session.system();

// IB news bulletins (margin calls, special labelling, etc)
let bulletins = session.bulletins;
console.log(bulletins);

// Market data farm connections
let connectivity = session.connectivity;
console.log(connectivity);

// Access display groups
session.displayGroups.forEach(group => console.log(group.contract));

// Update display group
session.displayGroups[0].update("8314");
```

## Advanced

The [service](./doc/service.md) module makes interacting with the IB API pub/sub paradigm easier and enables [remoting](./doc/remoting.md) from other processes or the browser.

This package uses [Sugar](https://sugarjs.com) in extended mode, which modifies javascript prototypes.

## License

Copyright 2017 Jonathan Hollinger

This is an open source project unrelated to Interactive Brokers.

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.

---
_Source: https://npm.io/package/ib-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
