• Stars
    star
    380
  • Rank 112,766 (Top 3 %)
  • Language
    Java
  • Created over 11 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Interactive Brokers TWS API client library for Node.js

Logo

NPM NPM

ib is an Interactive Brokers TWS (or IB Gateway) API client library for Node.js. Refer to the official Trader Workstation API documentation for details.

This is a direct port of Interactive Brokers' official Java client. There is no C++/Java library dependency. It makes a socket connection to TWS (or IB Gateway) using the net module, and all messages are entirely processed in JavaScript. It uses EventEmitter to pass the result back to user.

MAINTAINERS NEEDED

The libary is lagging behind the official Java reference and no updates have been made after v9.70 (~2017). This means that some newer features aren't implemented:

Installation

$ npm install ib

Usage

var ib = new (require('ib'))({
  // clientId: 0,
  // host: '127.0.0.1',
  // port: 7496
}).on('error', function (err) {
  console.error('error --- %s', err.message);
}).on('result', function (event, args) {
  console.log('%s --- %s', event, JSON.stringify(args));
}).once('nextValidId', function (orderId) {
  ib.placeOrder(
    orderId,
    ib.contract.stock('AAPL'),
    ib.order.limit('BUY', 1, 0.01)  // safe, unreal value used for demo
  );
  ib.reqOpenOrders();
}).once('openOrderEnd', function () {
  ib.disconnect();
})

ib.connect()
  .reqIds(1);

API

Connection

.connect()
.disconnect()

Methods

.calculateImpliedVolatility(reqId, contract, optionPrice, underPrice)
.calculateOptionPrice(reqId, contract, volatility, underPrice)
.cancelAccountSummary(reqId)
.cancelAccountUpdatesMulti(requestId)
.cancelCalculateImpliedVolatility(reqId)
.cancelCalculateOptionPrice(reqId)
.cancelFundamentalData(reqId)
.cancelHistoricalData(tickerId)
.cancelMktData(tickerId)
.cancelMktDepth(tickerId)
.cancelNewsBulletins()
.cancelOrder(id)
.cancelPositions()
.cancelPositionsMulti(requestId)
.cancelRealTimeBars(tickerId)
.cancelScannerSubscription(tickerId)
.cancelTickByTickData(tickerId)
.exerciseOptions(tickerId, contract, exerciseAction, exerciseQuantity, account, override)
.placeOrder(id, contract, order)
.replaceFA(faDataType, xml)
.reqAccountSummary(reqId, group, tags)
.reqAccountUpdates(subscribe, acctCode)
.reqAccountUpdatesMulti(requestId, account, modelCode, ledgerAndNLV)
.reqAllOpenOrders()
.reqAutoOpenOrders(bAutoBind)
.reqContractDetails(reqId, contract)
.reqCurrentTime()
.reqExecutions(reqId, filter)
.reqFundamentalData(reqId, contract, reportType)
.reqGlobalCancel()
.reqHistoricalData(tickerId, contract, endDateTime, durationStr, barSizeSetting, whatToShow, useRTH, formatDate, keepUpToDate)
.reqHistoricalTicks(tickerId, contract, startDateTime, endDateTime, numberOfTicks, whatToShow, useRTH, ignoreSize)
.reqTickByTickData(tickerId, contract, tickType, numberOfTicks, ignoreSize)
.reqIds(numIds)
.reqManagedAccts()
.reqMarketDataType(marketDataType)
.reqMatchingSymbols(tickerId, pattern)
.reqMktData(tickerId, contract, genericTickList, snapshot, regulatorySnapshot)
.reqMktDepth(tickerId, contract, numRows)
.reqNewsBulletins(allMsgs)
.reqOpenOrders()
.reqPositions()
.reqPositionsMulti(requestId, account, modelCode)
.reqRealTimeBars(tickerId, contract, barSize, whatToShow, useRTH)
.reqScannerParameters()
.reqScannerSubscription(tickerId, subscription)
.requestFA(faDataType)
.queryDisplayGroups(reqId)
.subscribeToGroupEvents(reqId, group)
.unsubscribeToGroupEvents(reqId)
.updateDisplayGroup(reqId, contract)
.setServerLogLevel(logLevel)

Note that .reqContractDetails doesn't respect the official format of the ContractDetails class. For example, the Contract field is replaced with a summary field that contains some of the attributes in the contract.

Events

// General
.on('error', function (err, data))
.on('result', function (event, args))  // exclude connection
.on('all', function (event, args))  // error + connection + result

// Connection
.on('connected', function ())
.on('disconnected', function ())
.on('received', function (tokens, data))
.on('sent', function (tokens, data))
.on('server', function (version, connectionTime))

// Result
.on('accountDownloadEnd', function (accountName))
.on('accountUpdateMulti', function (reqId, account, modelCode, key, value, currency))
.on('accountUpdateMultiEnd', function (reqId))
.on('accountSummary', function (reqId, account, tag, value, currency))
.on('accountSummaryEnd', function (reqId))
.on('bondContractDetails', function (reqId, contract))
.on('commissionReport', function (commissionReport))
.on('contractDetails', function (reqId, contract))
.on('contractDetailsEnd', function (reqId))
.on('currentTime', function (time))
.on('deltaNeutralValidation', function (reqId, underComp))
.on('execDetails', function (reqId, contract, exec))
.on('execDetailsEnd', function (reqId))
.on('fundamentalData', function (reqId, data))
.on('historicalData', function (reqId, date, open, high, low, close, volume, count, WAP, hasGaps))
.on('historicalTickTradeData', (reqId, timestamp, mask, price, size, exchange, specialConditions))
.on('historicalTickBidAskData', (reqId, timestamp, mask, priceBid, priceAsk, sizeBid, sizeAsk))
.on('historicalTickMidPointData', (reqId, timestamp, price, size))
.on('tickByTickAllLast', reqId, tickType, time, price, size, { pastLimit, unreported }, exchange, specialConditions)
.on('tickByTickBidAsk', reqId, time, bidPrice, askPrice, bidSize, askSize, { bidPastLow, askPastHigh })
.on('tickByTickMidPoint', reqId, time, midPoint))
.on('managedAccounts', function (accountsList))
.on('marketDataType', function (reqId, marketDataType))
.on('nextValidId', function (orderId))
.on('openOrder', function (orderId, contract, order, orderState))
.on('openOrderEnd', function ())
.on('orderStatus', function (id, status, filled, remaining, avgFillPrice, permId, parentId, lastFillPrice, clientId, whyHeld))
.on('position', function (account, contract, pos, avgCost))
.on('positionEnd', function ())
.on('positionMulti', function (reqId, account, modelCode, contract, pos, avgCost))
.on('positionMultiEnd', function (reqId))
.on('realtimeBar', function (reqId, time, open, high, low, close, volume, wap, count))
.on('receiveFA', function (faDataType, xml))
.on('scannerData', function (tickerId, rank, contract, distance, benchmark, projection, legsStr))
.on('scannerDataEnd', function (tickerId))
.on('scannerParameters', function (xml))
.on('symbolSamples', function (contractDescriptions))
.on('tickEFP', function (tickerId, tickType, basisPoints, formattedBasisPoints, impliedFuturesPrice, holdDays, futureExpiry, dividendImpact, dividendsToExpiry))
.on('tickGeneric', function (tickerId, tickType, value))
.on('tickOptionComputation', function (tickerId, tickType, impliedVol, delta, optPrice, pvDividend, gamma, vega, theta, undPrice))
.on('tickPrice', function (tickerId, tickType, price, canAutoExecute))
.on('tickSize', function (tickerId, sizeTickType, size))
.on('tickSnapshotEnd', function (reqId))
.on('tickString', function (tickerId, tickType, value))
.on('updateAccountTime', function (timeStamp))
.on('updateAccountValue', function (key, value, currency, accountName))
.on('updateMktDepth', function (id, position, operation, side, price, size))
.on('updateMktDepthL2', function (id, position, marketMaker, operation, side, price, size))
.on('updateNewsBulletin', function (newsMsgId, newsMsgType, newsMessage, originatingExch))
.on('updatePortfolio', function (contract, position, marketPrice, marketValue, averageCost, unrealizedPNL, realizedPNL, accountName))
.on('displayGroupList', function(id, list))
.on('displayGroupUpdated', function(id, contract))

Builders

// Contract
.contract.combo(symbol, currency, exchange)
.contract.forex(symbol, currency)
.contract.future(symbol, expiry, currency, exchange)
.contract.option(symbol, expiry, strike, right, exchange, currency)
.contract.stock(symbol, exchange, currency)

// Order
.order.limit(action, quantity, price, transmitOrder)
.order.market(action, quantity, transmitOrder, goodAfterTime, goodTillDate)
.order.marketClose(action, quantity, price, transmitOrder)
.order.stop(action, quantity, price, transmitOrder, parentId, tif)
.order.stopLimit(action, quantity, limitPrice, stopPrice, transmitOrder, parentId, tif)
.order.trailingStop(action, quantity, auxPrice, tif, transmitOrder, parentId)

Util

.incomingToString(incoming)
.numberToString(number)
.outgoingToString(outgoing)
.tickTypeToString(tickType)

Credits

See the contributors.

License

The MIT License (MIT)

Copyright (c) 2013-2021 Pilwon Huh

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Analytics

More Repositories

1

ultimate-seed

{MEAN Stack on Steroids} The ultimate full-stack AngularJS + Node.js/Express seed (batteries included!) that makes web developers insanely productive. (Angular, AngularUI, Barbeque, Bootstrap, Bower, Browserify, Docker, Express, Font Awesome, Grunt, Handlebars, jQuery, JSHint, Karma/Mocha, LESS/LESSHat, Livereload, Lodash/Underscore, Modernizr, MongoDB/Mongoose, Passport for Facebook/Google/Twitter, Redis, SocketIO, Source Maps, Uglify, Winston)
JavaScript
853
star
2

node-yahoo-finance

Yahoo Finance historical quotes and snapshot data downloader written in Node.js
JavaScript
495
star
3

node-google-finance

Google Finance client library for Node.js.
JavaScript
204
star
4

react-famous

React bridge to Famo.us
JavaScript
172
star
5

barbeque

Redis-based task queue library inspired by Celery and Kue.
JavaScript
56
star
6

ultimate-seed-generator

Yeoman Generator for `ultimate-seed`
JavaScript
50
star
7

go-lambda

Call Go GRPC services from AWS Lambda functions
Go
30
star
8

node-udoo

UDOO GPIO abstraction library for Node.js & command line tool (callback, promise, and synchronous styles supported)
JavaScript
28
star
9

node-get-env

Return `dev`, `prod`, or optional extra environements based on `process.env.NODE_ENV`
JavaScript
23
star
10

node-neospeech

NeoSpeech TTS client library for Node.js
C++
20
star
11

node-youtube-uploader

Youtube video uploader library for Node.js (python wrapper)
Python
19
star
12

node-ultimate

Dependency library for `ultimate-seed`
JavaScript
19
star
13

node-twitter-autofollow-bot

Twitter auto-follow bot written in Node.js.
JavaScript
16
star
14

node-get-config

Automagically build a config object used throughout an application
TypeScript
12
star
15

node-eoddata

EODData client library for Node.js
JavaScript
12
star
16

node-ivona

IVONA Text-to-Speech SaaS client library for Node.js
JavaScript
11
star
17

celery-backends-rethinkdb

Celery's custom result backend for RethinkDB
Python
11
star
18

react-famous-seed

Seed project for react-famous apps
JavaScript
8
star
19

nodejs-for-linaro-ubuntu

Compiled Node.js binaries for Linaro Ubuntu (and how to build instructions)
6
star
20

node-megabus

Megabus Ticket Finder
TypeScript
5
star
21

node-portfolio

Portfolio library for Node.js
JavaScript
3
star
22

go-smugmug

Go client library for SmugMug API v2
Go
3
star
23

node-iron-promise

Promise/A+ supported IronMQ API client library for Node.js (wrapper for the official client)
JavaScript
3
star
24

test-workers

2
star
25

node-project-template

Node.js Project Template
JavaScript
2
star
26

express-promise-wrap

Express helper that allows the use of async functions as route handlers
TypeScript
2
star
27

express-slashes

Express middleware that removes trailing slashes
TypeScript
2
star
28

node-qt

Questrade API client
2
star
29

command-buffer

Simple command buffer abstraction library written in JavaScript.
JavaScript
2
star
30

ultimate-auth

Auth plugin for `ultimate-seed`.
1
star
31

ultimate-auth-twitter

Twitter Auth plugin for `ultimate-seed`.
1
star
32

gogo

gogo
Go
1
star
33

ultimate-admin

Admin plugin for `ultimate-seed`.
1
star
34

go-apexgrpc

go-apexgrpc
Go
1
star
35

ultimate-socketio

Socket.io plugin for `ultimate-seed`.
1
star
36

selenium-webdriver

Unofficial mirror of `selenium-webdriver`
JavaScript
1
star
37

ultimate-auth-facebook

Facebook auth plugin for `ultimate-seed`.
1
star
38

flashlight-app

Malware-free flashlight app
JavaScript
1
star
39

dockerfiles

pilwon's dockerfiles
Shell
1
star
40

ultimate-auth-google

Google Auth plugin for `ultimate-seed`.
1
star
41

koa-slash

Koa middleware that removes trailing slashes
JavaScript
1
star
42

node-gpubsub

Promises wrapper for gcloud-node's pubsub.
JavaScript
1
star
43

ultimate-winston

Winston plugin for `ultimate-seed`.
1
star