ib_insync v1.0.0
Introduction
A simple Interactive Brokers library for Node.js based on ib_insync. This library takes the most popular IB library on Github, that's written in python, and makes it available in Node, using a library called boa.
Built With
Getting Started
- Install node modules.
npm install ib_insync
- NPM will postinstall the python version of ib_insync and it's dependencies in the node_modules folder.
- Spin up IB Gateway for ib_insync to connect to. (Here's a nice way of doing it with docker)
- ???
- Profit
Usage
Check out the full Documentation
Here's a simple example to get things going.
You can now use ib_insync just as you would in python.
const {boa, ib_insync, toOBJECT, toJSON} = require('ib_insync');
//connect to ib gateway
let ib = ib_insync.IB();
ib.connect(boa.kwargs({
host: '127.0.0.1',
port: 4002,
clientId: 0
}));
//get positions
let positions = ib.positions();
//convert python object to js and console log
let posObj = toOBJECT(positions);
console.log(posObj);
A few things to note:
- You can use
toJSON(obj)
andtoOBJECT(obj)
to convert from a boa PythonObject to something usable in javascript - In the next examples, take note of how maps and filters use
[...PythonObjectArray]
- Also, the use of
boa.kwargs({})
to define named function params
Here's some more usage examples for you!
How about using streams?
Here's a simple example that subscribes to a price feed and spits out prices to console.
For more examples, please refer to the full python Documentation
Contributing
Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
License
Distributed under the MIT License. See LICENSE.txt
for more information.
Other Projects
Here's a few other projects you might be interested in!
ib_gateway_docker - Docker container of IB Gateway that does all the heavy lifting for you
1 year ago