node-ib
node-ib copied to clipboard
net.connect is not a function when calling ib.connect()
Hi,
I am using node_ib with electron and angular 5! When calling ib.connect, i get the exception that net.connect is not a function.
I read the other issues, but i don´t understand, why net.connect doesn´t work in this environment. Is there a workaround to still use node-ib in this scenario?
Best regards, Christian
@dreamrockz any update on this one? have the same problem.
Hi,
Think it has to do with the webpack configuration. You need to make sure, that you require ib into the correct scope. Otherwise it is not visible. Working for me in these two cases:
- create class to handle all ib calling outside of renderer
- Inside renderer scope you need to require it from electron remote
Hope that helps!
Hi,
I don't use webpack or electron. I simply created a new angular project (v7, but also didn't worked wiht v5) installed ib via npm install ib and then used following code in my app.component.ts to test:
import {
Component
} from '@angular/core';
import * as ibS from 'ib';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'app';
constructor() {
}
public init(): void {
const ib = new ibS({
clientId: 10,
host: '127.0.0.1',
port: 7497
});
ib.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);
}
}
Hi,
for me it only works with the good old require like this:
this.ib = new (require("ib"))({ clientId: clientId, host: config.host, port: config.port })
Best of luck...
also imported ib with npm, though!