Giter Club home page Giter Club logo

Comments (5)

ceddybi avatar ceddybi commented on July 19, 2024

@saifali96

Turn on esModuleInterop in your tsconfig.json

or simply

import * as ibkr from '@stoqey/ibkr'

from ibkr.

ceddybi avatar ceddybi commented on July 19, 2024

@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.

saifali96 avatar saifali96 commented on July 19, 2024

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.

saifali96 avatar saifali96 commented on July 19, 2024

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.

ceddybi avatar ceddybi commented on July 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.