NodeJS app and interactive broker API

Victor Yeo
2 min readJan 5, 2023

--

This article is about writing an NodeJS app to call interactive broker (IBRK) api and send a limit order.

Firstly, we need to download ib gateway. For Linux, use the link below to download the ib gateway. https://www.interactivebrokers.com/en/trading/ibgateway-latest.php

Secondly, we use NestJS framework to create an NodeJS app. To call IBRK api in NodeJS app, we use @stoqey/ib npm to access IBRK api.

In the NodeJS app, we create an ibex module. In the constructor of the module, we set the port number to 4002, if using ib gateway paper trading account. In the ibex module, we create an controller endpoint to handle the sending of an order. In the service endpoint function, we call ib.placeOrder() function to send the order. Subsequently, event listener is setup to listen to events return by ib gateway.

Thirdly, it is required to run the ib gateway program. On Linux, open a terminal window, cd to ~/Jts/ibgateway/1019, and run ./ibgateway. In another terminal window, enter “npm start” to run the nodeJS app.

screenshot of nodeJS app

If everything is setup correctly (including the account), we will be able to see the log message from the nodeJS app.

The code is available on github, at this repo https://github.com/victoryeo/myprog_ib.

The repo also contains k8s and helm chart yaml files. That is for deployment to the cloud.

The end.

--

--

Responses (1)