-
-
Notifications
You must be signed in to change notification settings - Fork 48
IBApi next generation (IBApiNext)
Matthias Frener edited this page Feb 21, 2021
·
17 revisions
IBApiNext will be second API interface, in parallel to the IBApi.
While the goal of IBApi is it to replace the official TWS API as close as possible, IBApiNext will add additional convenience that makes developer-life easier.
- No more request-function, no more cancel-function, not more event-callback, no more request ids, not more ticker ids.
It is rxjs now. Example: keep track on the PnL for a position with IBApiNext
apiNext.
.getPnLSingle(
account,
model,
conId
)
.subscribe(
(pnlSingle) => {
this.updatePositionPnl(pnlSingle);
},
(err: IBApiError) => {
console.error("getPnLSingle failed with" + err.error.message});
}
);
-
No more Number.MAX_VALUE. If a value if not available, is no more Number.MAX_VALUE, but is it undefined on IBApiNext.
-
Support for full and differntial updates
On functions that return a list, you can select if you want to get full or differential updates only.
Example:
/**
* Create a subscription to receive the positions on all accessible accounts.
*
* All positions are sent on the first event.
* Use incrementalUpdates argument to switch between incremental or full update mode.
* With incremental updates, only changed positions will be sent after the initial complete list.
* If a positions is closed, the positions size will be 0.
* Without incremental updates, the complete list of positions will be sent again if any of it has changed.
*
* @param incrementalUpdates Set to true to enable incremental updates, or false to disable it.
*/
getPositions(incrementalUpdates: boolean): Observable<Position[]>
- The "IB Shell"
Every function on the IBApiNext will have a command line tool to run to from console.
These tools serve as demo code, utilities for i.e., quickly searching contract ID, can be used for testing or you can event trade on console (or via.sh scripts) rather than from TWS – if you want to :)
See https://github.com/stoqey/ib/tree/api-next/src/tools
Example:
node .\dist\tools\account-summary.js
[
[
"DUxxxxxx",
{
"account": "DUxxxxxx",
"values": [
[
"GrossPositionValue",
{
"value": "221224.97",
"currency": "EUR"
}
],
[
"NetLiquidation",
{
"value": "823696.56",
"currency": "EUR"
}
],
[
"TotalCashValue",
{
"value": "602471.59",
"currency": "EUR"
}
]
]
}
]
]
- Auto re-connect
IBApiNext does support automatic reconnection with a configurable re-connection interval.
After a re-connect, observed subscriptions will be renewed so that rxjs observes continue to work. You do not need to case about re-requesting PnLs, positions, market-data, after a connection-loss … IBApiNext will do it for you.
Also it run a watchdog that constantly polls TWS to ensure that dead connections are detected w/o relying on socket termination events.
Preview is aviable on https://github.com/stoqey/ib/tree/api-next
Feedback is very welcome.