Skip to content
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

Properly disconnecting from IB Gateway #221

Open
kfiroo opened this issue Aug 8, 2024 · 0 comments
Open

Properly disconnecting from IB Gateway #221

kfiroo opened this issue Aug 8, 2024 · 0 comments

Comments

@kfiroo
Copy link

kfiroo commented Aug 8, 2024

Hey!
First of all, thanks for all the effort! it is much appreciated ❤️

I am working with the new IBApiNext and I am wondering on what is the best way to disconnect a client.

I am connecting using a random clientId and doing my best to call disconnect when my work is done but in my IB Gateway app I see that the API Client is still connected.

This didn't happen to me when I used the python module ib_insync and I am wondering if there is something that I am doing wrong or is it the expected behavior?

Sample code:

const clientId = getRandonId()

const apiNext = new IBApiNext({
  port: configuration.IB_PORT,
})

// Subject for connected - I guess this is not really needed as you do it internally right?
const connected$ = apiNext.connectionState.pipe(
  filter((state) => state === ConnectionState.Connected),
  first(),
)

try {
  apiNext.connect(clientId)

  await firstValueFrom(connected$)

  await doSomethingWithIBApi(apiNext)
} catch (error) {
  logger.error(error)
  throw error
} finally {
  // not this this actually disconnects me :(
  apiNext.disconnect()
}

Thanks in advance 🙏🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant