Skip to content

Commit

Permalink
matching symbols test added
Browse files Browse the repository at this point in the history
  • Loading branch information
rylorin committed Sep 18, 2023
1 parent d71ac1f commit a5ea744
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 81 deletions.
39 changes: 32 additions & 7 deletions src/api-next/api-next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,9 @@ export class IBApiNext {
],
]);

if (hasChanged) {
if (!subscription.endEventReceived) {
subscription.lastAllValue = cached;
} else if (hasChanged) {
subscription.next({
all: cached,
changed: accountSummaryUpdate,
Expand All @@ -450,6 +452,25 @@ export class IBApiNext {
}
};

/** accountSummaryEnd event handler */
private readonly onAccountSummaryEnd = (
subscriptions: Map<number, IBApiNextSubscription<MutableAccountSummaries>>,
reqId: number,
): void => {
// get the subscription
const subscription = subscriptions.get(reqId);
if (!subscription) {
return;
}

// get latest value on cache
const cached = subscription.lastAllValue ?? new MutableAccountSummaries();

// sent data to subscribers
subscription.endEventReceived = true;
subscription.next({ all: cached });
};

/**
* Create subscription to receive the account summaries of all linked accounts as presented in the TWS' Account Summary tab.
*
Expand Down Expand Up @@ -507,7 +528,10 @@ export class IBApiNext {
(reqId) => {
this.api.cancelAccountSummary(reqId);
},
[[EventName.accountSummary, this.onAccountSummary]],
[
[EventName.accountSummary, this.onAccountSummary],
[EventName.accountSummaryEnd, this.onAccountSummaryEnd],
],
`${group}:${tags}`,
);
}
Expand Down Expand Up @@ -713,7 +737,12 @@ export class IBApiNext {
accountName: string,
): void => {
this.logger.debug(LOG_TAG, `onAccountDownloadEnd(${accountName})`);
// TODO finish implementation
// notify all subscribers
subscriptions.forEach((subscription) => {
const all: AccountUpdate = subscription.lastAllValue ?? {};
subscription.endEventReceived = true;
subscription.next({ all });
});
};

/**
Expand Down Expand Up @@ -2426,10 +2455,6 @@ export class IBApiNext {
all: lastAllValue,
};
subscription.endEventReceived = true;

// console.log("onScannerDataEnd", updated);

// subscription.next(updated);
subscription.next(updated);
};

Expand Down
3 changes: 0 additions & 3 deletions src/api-next/common/item-list-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ export interface ItemListUpdate<T> {
/** All items with its latest values, as received by TWS. */
readonly all: T;

/** all value is set with all items (ie not still being built = End message received from TWS) */
readonly allset?: boolean;

/** Items that have been added since last [[IBApiNextUpdate]]. */
readonly added?: T;

Expand Down
1 change: 0 additions & 1 deletion src/core/api-next/item-list-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ export class IBApiNextItemListUpdate<T> implements ItemListUpdate<T> {
public readonly added?: T,
public readonly changed?: T,
public readonly removed?: T,
public readonly allset?: boolean,
) {}
}
21 changes: 3 additions & 18 deletions src/core/api-next/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import { IBApiNext, IBApiNextError, ItemListUpdate } from "../../api-next";
import { ConnectionState } from "../../api-next/common/connection-state";
import { IBApiNextItemListUpdate } from "./item-list-update";

export type IBApiNextItemListUpdateMinimal<T> = Omit<
IBApiNextItemListUpdate<T>,
"added" | "changed" | "removed"
>;

/**
* @internal
*
Expand Down Expand Up @@ -56,8 +51,8 @@ export class IBApiNextSubscription<T> {
/** The [[Subscription]] on the connection state. */
private connectionState$?: Subscription;

/** true when the end-event on an enumeration request has been received, false otherwise. */
private _endEventReceived = false;
/** @internal True when the end-event on an enumeration request has been received, false otherwise. */
public endEventReceived = false;

/** Get the last 'all' value as send to subscribers. */
get lastAllValue(): T | undefined {
Expand All @@ -69,16 +64,6 @@ export class IBApiNextSubscription<T> {
this._lastAllValue = value;
}

/** @internal Get the end event flag. For internal use only. */
get endEventReceived(): boolean {
return this._endEventReceived;
}

/** @internal Set the end event flag seen. For internal use only. */
set endEventReceived(value: boolean) {
this._endEventReceived = value;
}

/**
* Send the next value to subscribers.
*
Expand All @@ -102,7 +87,7 @@ export class IBApiNextSubscription<T> {
*/
error(error: IBApiNextError): void {
delete this._lastAllValue;
this._endEventReceived = false;
this.endEventReceived = false;
this.hasError = true;
this.subject.error(error);
this.cancelTwsSubscription();
Expand Down
2 changes: 1 addition & 1 deletion src/core/io/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const EOL = "\0";
* @hidden
* add a delay after connect before sending commands
*/
const CONNECT_DELAY = 600;
// const CONNECT_DELAY = 600;

/**
* @internal
Expand Down
Loading

0 comments on commit a5ea744

Please sign in to comment.