maxicus / ib-tws-api Goto Github PK
View Code? Open in Web Editor NEWInteractive Brokers API client for Node.JS. TWS or IB Gateway as a server
License: MIT License
Interactive Brokers API client for Node.JS. TWS or IB Gateway as a server
License: MIT License
Given the complexity of IB classes, TypeScript type information would be tremendously useful for this package.
Would you be interested in a contribution that converted the code to TypeScript and added type annotations and documentation?
Thanks for sharing the package I found it to be very useful (the only one that's working with latest API)
But I found a problem with the openOrders fields for example totalQuantity is at orderType and so on it's all mixed
[
{
contract: {
conId: NaN,
symbol: 'STK',
secType: '',
lastTradeDateOrContractMonth: '0',
strike: NaN,
right: '',
exchange: 'SMART',
currency: 'USD',
localSymbol: 'TSLA',
comboLegsDescrip: ''
},
order: {
orderId: 76792991,
action: 'NMS',
totalQuantity: NaN,
orderType: '1000',
lmtPrice: NaN,
auxPrice: 0,
tif: '0.0',
ocaGroup: 'DAY',
account: '',
openClose: 'DU1900817',
origin: NaN,
orderRef: '0',
clientId: NaN,
permId: 1,
outsideRth: false,
hidden: false,
discretionaryAmt: 0,
goodAfterTime: '0',
faGroup: '797567953.0/DU1900817/100',
faMethod: '',
faPercentage: '',
faProfile: '',
modelCode: '',
goodTillDate: '',
rule80A: '',
percentOffset: 0,
settlingFirm: '',
shortSaleSlot: NaN,
designatedLocation: '0',
auctionStrategy: NaN,
startingPrice: -1,
stockRefPrice: 0,
delta: NaN,
stockRangeLower: NaN,
stockRangeUpper: NaN,
displaySize: NaN,
blockOrder: false,
sweepToFill: false,
allOrNone: false,
minQty: 0,
ocaType: 0,
eTradeOnly: false,
firmQuoteOnly: false,
nbboPriceCap: 0,
parentId: 0,
triggerMethod: NaN,
volatility: 0,
volatilityType: 0,
deltaNeutralOrderType: '',
deltaNeutralAuxPrice: 0,
continuousUpdate: false,
referencePriceType: NaN,
trailStopPrice: NaN,
basisPoints: NaN,
basisPointsType: NaN,
notSuppScaleNumComponents: NaN,
scaleInitLevelSize: 0,
scalePriceIncrement: 0,
clearingAccount: '',
clearingIntent: '0',
whatIf: false,
conditionsIgnoreRth: false,
conditionsCancelOrder: false,
adjustedOrderType: '0',
triggerPrice: 0,
lmtPriceOffset: 1.7976931348623157e+308,
adjustedStopPrice: 1.7976931348623157e+308,
adjustedStopLimitPrice: 1.7976931348623157e+308,
adjustedTrailingAmount: 1.7976931348623157e+308,
adjustableTrailingUnit: 1,
softDollarTier: [Object],
cashQty: 1.7976931348623157e+308,
dontUseAutoPriceForHedge: false,
isOmsContainer: false,
discretionaryUpToLimitPrice: false,
usePriceMgmtAlgo: false
},
orderState: {
status: '',
initMarginBefore: '',
maintMarginBefore: '',
equityWithLoanBefore: '',
initMarginChange: '',
maintMarginChange: '0',
equityWithLoanChange: '0',
initMarginAfter: '0',
maintMarginAfter: '',
equityWithLoanAfter: '',
commission: NaN,
minCommission: NaN,
maxCommission: 0,
commissionCurrency: '',
warningText: 'IB'
}
},
{
contract: {
conId: NaN,
symbol: 'STK',
secType: '',
lastTradeDateOrContractMonth: '0',
strike: NaN,
right: '',
exchange: 'SMART',
currency: 'USD',
localSymbol: 'TSLA',
comboLegsDescrip: ''
},
order: {
orderId: 76792991,
action: 'NMS',
totalQuantity: NaN,
orderType: '500',
lmtPrice: NaN,
auxPrice: 0,
tif: '0.0',
ocaGroup: 'DAY',
account: '',
openClose: 'DU1900817',
origin: NaN,
orderRef: '0',
clientId: NaN,
permId: 1,
outsideRth: false,
hidden: false,
discretionaryAmt: 0,
goodAfterTime: '0',
faGroup: '797567954.0/DU1900817/100',
faMethod: '',
faPercentage: '',
faProfile: '',
modelCode: '',
goodTillDate: '',
rule80A: '',
percentOffset: 0,
settlingFirm: '',
shortSaleSlot: NaN,
designatedLocation: '0',
auctionStrategy: NaN,
startingPrice: -1,
stockRefPrice: 0,
delta: NaN,
stockRangeLower: NaN,
stockRangeUpper: NaN,
displaySize: NaN,
blockOrder: false,
sweepToFill: false,
allOrNone: false,
minQty: 0,
ocaType: 0,
eTradeOnly: false,
firmQuoteOnly: false,
nbboPriceCap: 0,
parentId: 0,
triggerMethod: NaN,
volatility: 0,
volatilityType: 0,
deltaNeutralOrderType: '',
deltaNeutralAuxPrice: 0,
continuousUpdate: false,
referencePriceType: NaN,
trailStopPrice: NaN,
basisPoints: NaN,
basisPointsType: NaN,
notSuppScaleNumComponents: NaN,
scaleInitLevelSize: 0,
scalePriceIncrement: 0,
clearingAccount: '',
clearingIntent: '0',
whatIf: false,
conditionsIgnoreRth: false,
conditionsCancelOrder: false,
adjustedOrderType: '0',
triggerPrice: 0,
lmtPriceOffset: 1.7976931348623157e+308,
adjustedStopPrice: 1.7976931348623157e+308,
adjustedStopLimitPrice: 1.7976931348623157e+308,
adjustedTrailingAmount: 1.7976931348623157e+308,
adjustableTrailingUnit: 1,
softDollarTier: [Object],
cashQty: 1.7976931348623157e+308,
dontUseAutoPriceForHedge: false,
isOmsContainer: false,
discretionaryUpToLimitPrice: false,
usePriceMgmtAlgo: false
},
orderState: {
status: '',
initMarginBefore: '',
maintMarginBefore: '',
equityWithLoanBefore: '',
initMarginChange: '',
maintMarginChange: '0',
equityWithLoanChange: '0',
initMarginAfter: '0',
maintMarginAfter: '',
equityWithLoanAfter: '',
commission: NaN,
minCommission: NaN,
maxCommission: 0,
commissionCurrency: '',
warningText: 'IB'
}
}
]
How should combos be created? The code isn't quite self-explanatory :) Does a .legs
field need to be set? Are the legs passed as an array? Where?
The jsdocs are still formatted similar to how they would be in python, so the documentation doesn't show in intellisense. Also the incomplete APIs show in my intellisense, which crouds it when i'm trying to find working APIs.
Less of a complaint and more of an issue for me to attach to a pull request i'm making. Dispite this API being incomplete, the async/await syntax on this is something i've been looking for for a while now, so i'm going to clean up the jsdocs and add typings to the parameters in the jsdocs. I may make other commits to this repo in the future as well.
Great work on this so far, and i'm happy to help going forward!
IB has changed the timezone format in TWS 10.17+ and now it requires us to provide timezone at the end of the dates.
See info here: https://forum.amibroker.com/t/please-look-at-timeinforce-part-of-place-order-code/31980/3
So instead:
let details = await api.getHistoricalData({
contract: Contract.stock('AAPL'),
endDateTime: '20200308 12:00:00,
duration: '1 D',
barSizeSetting: '1 min',
whatToShow: 'TRADES',
useRth: 1,
formatDate: 1
});
Valid date format is now:
let details = await api.getHistoricalData({
contract: Contract.stock('AAPL'),
endDateTime: '20200308 12:00:00 US/Eastern', // or for UTC: 20200308-12:00:00
duration: '1 D',
barSizeSetting: '1 min',
whatToShow: 'TRADES',
useRth: 1,
formatDate: 1
});
The problem:
With your example I'm able to see the available expirations + strikes, but not the full option chain with puts/calls side by side.
The problem is that I'll end up with a lot of requests just to see an option chain. The nr of individual requests = 2 * nr of strikes per expiration which is a lot.
There should be a better way to do this, from a single call, in the TWS API I found this: https://interactivebrokers.github.io/tws-api/options.html#option_chains
Potential solution:
What I've tried was to manually "bruteforce" my way into Contract. options removing the asserts and to add the localSymbol, but that actually generated more problems.
Can you help me with an example of how I could get the option chain without doing individual requests for every strike?
When I try and run the example 'historical-data.js', I get this error:
Error: Warning: Your API version does not support fractional share size rules. Please upgrade to a minimum version 163. Trimmed value 9390.73 to 9390 at IncomeFieldsetHandlerBus.requestIdEmit
Using TWS version 10.25.1i
When making historical tick requests I can only get BID_ASK, not TRADES. When I request TRADES it returns an empty array. Is this a known bug / limitation?
Hi!
I think the scanners are not implemented, right?
I would like to create a PR if you point me in the correct direction.
Thanks!
getHistoricalData returns an undocumented custom object that doesn't match the official Bar class.
There are extra .dateStart and .dateEnd fields, and the bars arrive in .bars
. OK, not so bad. But then each bar renames time
to date
, WAP
to average
(presumably), and count
to barCount
.
What has been the reasoning here?
Hi, thanks for this package! I'm migrating from node-ib.
I've noticed that https://github.com/maxicus/ib-tws-api/releases points to 1.1 as the latest version, but the latest on NPM is 1.3.
Is there a way to set a longer timeout interval for large data requests, or handle / avoid / correct api timeouts for large data requests?
In TWS, I tried changing the value of edit>Global Configuration>API>Settings>Timeout to send bulk data to API, but this did not seem to produce a change in behavior, the timeout is still generated at 30s after the request is submitted.
Why do you need large requests?
The API provides historical ADJUSTED_LAST data, apparently going back a long way. For example:
{contract: Contract.stock('GE'),duration: '10 Y', barSizeSetting: '1 hour', whatToShow: 'ADJUSTED_LAST', useRth: 1, formatDate: 1}
However, pulling a lot of data results in an api timeout.
I don't see a way to page the data because with the use of whatToShow: 'ADJUSTED_LAST', it is disallowed to use endDateTime to request the data in chunks. There are probably other circumstances where people need to make large data requests.
Is there a way to override the api timeout duration, or otherwise succeed in making a large data request?
Thank you
I get this error while trying your module in v12.16.1. NodeJS:
Looks like the new node requires all the ES6 files named as .mjs
import { Client } from 'ib-tws-api';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:1072:16)
at Module._compile (internal/modules/cjs/loader.js:1122:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47
placeOrder says "The order status will be returned by the orderStatus event." How exactly should we listen to that event? placeOrder returns a number
, not an EventEmitter.
I have more than one account and would be happy to test an implementation of reqManagedAccts.
All examples have a process.exit
at the end to prevent the script from hanging at the end.
Would it be possible to provide a method to disconnect from IB, like @pilwon's disconnect()?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.