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

Two active subscriptions for the same Event #193

Open
rylorin opened this issue Oct 10, 2023 · 0 comments
Open

Two active subscriptions for the same Event #193

rylorin opened this issue Oct 10, 2023 · 0 comments

Comments

@rylorin
Copy link
Member

rylorin commented Oct 10, 2023

Hello,

If you setup 2 active subscriptions using the same event, but different callbacks, for example:

this.subscriptions.register<OpenOrder[]>(
      () => {
        this.api.reqOpenOrders();
      },
      undefined,
      [
        [EventName.openOrder, this.onOpenOrder],
        [EventName.orderStatus, this.onOrderStatus],
        [EventName.orderBound, this.onOrderBound],
        [EventName.openOrderEnd, this.onOpenOrderEnd],
      ],
      "getOpenOrders", // use same instance id each time, to make sure there is only 1 pending request at time
    );

and

this.subscriptions
        .register<OpenOrder[]>(
          () => {
            this.api.reqAllOpenOrders();
          },
          undefined,
          [
            [EventName.openOrder, this.onOpenOrder],
            [EventName.orderStatus, this.onOrderStatus],
            [EventName.orderBound, this.onOrderBound],
            [EventName.openOrderEnd, this.onOpenOrderComplete],
          ],
          "getAllOpenOrders", // use same instance id each time, to make sure there is only 1 pending request at time
        );

As the subscription registry maintains a Map with the EventName as key and a callback and it's subscriptions as entry:

  /** A Map containing the subscription registry, with event name as key. */
  private readonly entires = new IBApiNextMap<EventName, RegistryEntry>();

The second callback for the same EventName.openOrderEnd will be ignored (in favour of the first active subscription callback) leading to undesired behaviour.

Thanks

rylorin added a commit that referenced this issue Oct 11, 2023
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