Comments (5)
Turn on esModuleInterop
in your tsconfig.json
or simply
import * as ibkr from '@stoqey/ibkr'
from ibkr.
@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
}
from ibkr.
This has some new issues! :)
The code:
import * as ibkr from '@stoqey/ibkr'
const { AccountSummary, IBKREVENTS, IbkrEvents, PortFolioUpdate, getContractDetails } = ibkr;
const ibkrEvents = IbkrEvents.Instance;
const IB_HOST = "localhost";
const IB_PORT = 7497;
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
}
Error:
yarn run v1.22.10
$ tsc && node dist/app.js
src/app.ts:24:49 - error TS2339: Property 'PortFolioUpdate' does not exist on type 'typeof import("E:/work/robinhood/exp/exp1ts/node_modules/@stoqey/ibkr/dist/index")'.
24 const { AccountSummary, IBKREVENTS, IbkrEvents, PortFolioUpdate, getContractDetails } = ibkr;
~~~~~~~~~~~~~~~
src/app.ts:31:18 - error TS2349: This expression is not callable.
Type 'typeof import("E:/work/robinhood/exp/exp1ts/node_modules/@stoqey/ibkr/dist/index")' has no call signatures.
31 const ib = await ibkr({
~~~~
Found 2 errors.
error Command failed with exit code 2.
My tsconfig.json
:
{
"compilerOptions": {
"module": "esnext",
"esModuleInterop": true,
"target": "es2017",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist"
},
"lib": ["es2015"]
}
Even if I remove the reference to PortFolioUpdate
or the await ibkr()
error exits. When I change the expression to await ibkr.default()
, it says file is not a module
!
Lastly upon making it a module
, await ibkr()
still doesn't work, prints the errror:
yarn run v1.22.10
$ tsc && node dist/app.js
src/app.ts:31:18 - error TS2349: This expression is not callable.
Type 'typeof import("E:/work/robinhood/exp/exp1ts/node_modules/@stoqey/ibkr/dist/index")' has no call signatures.
31 const ib = await ibkr({
~~~~
Found 1 error.
Please advise.
from ibkr.
Another try with the code snippet given in the README.MD
:
import ibkr, { AccountSummary, IBKREVENTS, IbkrEvents, PortFolioUpdate, getContractDetails } from '@stoqey/ibkr';
const ibkrEvents = IbkrEvents.Instance;
const IB_HOST = "localhost";
const IB_PORT = 7497;
// 0. Using env process.env.IB_PORT and process.env.IB_HOST
await ibkr();
// 1. Async
await ibkr({ port: IB_PORT, host: IB_HOST });
// 2. Callback
ibkr({ port: IB_PORT, host: IB_HOST }).then(started => {
if(!started){
// Error IBKR has not started
console.log('error cannot start ibkr');
// Not to proceed if not connected with interactive brokers
return process.exit(1);
}
// Your code here
})
Error:
$ tsc && node dist/app.js
file:///E:/work/robinhood/exp/exp1ts/dist/app.js:23
await ibkr();
^
TypeError: ibkr is not a function
at file:///E:/work/robinhood/exp/exp1ts/dist/app.js:23:7
at ModuleJob.run (internal/modules/esm/module_job.js:146:23)
at async Loader.import (internal/modules/esm/loader.js:165:24)
at async Object.loadESM (internal/process/esm_loader.js:68:5)
error Command failed with exit code 1.
ibkr() is not a function
.
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.
from ibkr.
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();
from ibkr.
Related Issues (20)
- Forex market data
- Concurrent orders
- how to start IB_PORT, IB_HOST?
- Property 'on' does not exist on type 'IbkrEvents' HOT 5
- ibkr().then not working HOT 8
- `comboLegsDescrip` in `ContractObject` should be optional HOT 2
- What's a good way to get price data (high, low, open, close, etc)? HOT 4
- Premarket orders? HOT 1
- How to contribute?
- Order values are in max_int HOT 1
- AccountSummary only returns data from 1 account for clients with multiple account IDs HOT 4
- Issues with account portfolio code HOT 7
- placeOrder - only stock are allowed HOT 4
- OrderState commission prices are incorrect scientific notation numbers HOT 1
- contract 'right' attribute is always undefined for options HOT 2
- Can't get PriceUpdates to work HOT 1
- Compatible with IBeam? HOT 2
- add option to prevent process from exiting immediately on disconnect HOT 2
- Searching securities HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ibkr.