-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot initialize project - ibkr() is not a function and node:11784 #48
Comments
Turn on or simply
|
@saifali96 you basically need to call the initialization only once, const ib = await ibkr({
port: IB_PORT,
host: IB_HOST,
});
if (!ib) {
// ib failed to start
// ..... do something to stop your code here
}
else {
// success
// the rest of your code here
// .....
// IBKR will automatically stop your code with `process.exit(1)` if it loses connection
} |
This has some new issues! :) The code:
Error:
My
Even if I remove the reference to Lastly upon making it a
Please advise. |
Another try with the code snippet given in the
Error:
I'm sorry if this is all very stupid for you, but I can't seem to run it properly. Would you please kindly make a more detailed get to started guide for the pacakge? Or make a repo that works and compiles by default? That would be very nice of you. |
Here is a complete example // app.ts file
import * as ibkr from '@stoqey/ibkr';
import { getContractDetails, Portfolios } from "@stoqey/ibkr";
async function index() {
try {
const ib = await ibkr({
port: IB_PORT,
host: IB_HOST,
});
if (!ib) {
throw new Error('error connecting to ibkr');
}
// continue
// e.g get a contract
const contract = await getContractDetails("AAPL");
// Get portfolios
const getPortfolios = await Portfolios.Instance.getPortfolios();
// Add the backend service
// ... e.g backendService();
} catch (error) {
console.log('error running app', error);
process.exit(1);
}
}
index(); |
The code snippet given in the README.MD is giving several different errors. Tried with a fresh NodeJS TS project.
I spent quite some time tinkering aroud, first it said
cannot use import statement outside a module
. Here's the error:Later when you change the
type
tomodule
, it saysibkr()
is not a function! Here's the error:Even if we decide to change the import to regular
require()
statement,tsc
starts to complain about using TLA/top-level-awaits, because the file is not a module. The error given:After some tinkering around, I managed to make it work with the following code, which is not very pretty:
Can you please explain or please create a more detailed get started guide?
Also in my code, or in general, how can I handle/catch and sudden TWS/API connection lost? This is critical, because at the moment the program just ends.
Thanks for your support!
node: 14.15.1
os: win10pro 64bit
The text was updated successfully, but these errors were encountered: