From cd6996ac58b67ee0feb46fdc04d1cb741c5d42dd Mon Sep 17 00:00:00 2001 From: Zheng Chen Date: Fri, 6 Dec 2024 05:24:44 +0800 Subject: [PATCH] feat(account-info-resolver): onPositionExit (#935) Co-authored-by: CZ --- .../account-info-resolver/2024-12-05-21-03.json | 10 ++++++++++ .../etc/account-info-resolver.api.md | 4 ++++ libraries/account-info-resolver/src/index.ts | 9 +++++++++ libraries/account-info-resolver/src/model.ts | 1 + 4 files changed, 24 insertions(+) create mode 100644 common/changes/@yuants/account-info-resolver/2024-12-05-21-03.json diff --git a/common/changes/@yuants/account-info-resolver/2024-12-05-21-03.json b/common/changes/@yuants/account-info-resolver/2024-12-05-21-03.json new file mode 100644 index 000000000..da3c579b8 --- /dev/null +++ b/common/changes/@yuants/account-info-resolver/2024-12-05-21-03.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@yuants/account-info-resolver", + "comment": "sync onPositionExit callback", + "type": "minor" + } + ], + "packageName": "@yuants/account-info-resolver" +} \ No newline at end of file diff --git a/libraries/account-info-resolver/etc/account-info-resolver.api.md b/libraries/account-info-resolver/etc/account-info-resolver.api.md index 857311321..e7c89e5bf 100644 --- a/libraries/account-info-resolver/etc/account-info-resolver.api.md +++ b/libraries/account-info-resolver/etc/account-info-resolver.api.md @@ -16,6 +16,10 @@ export class AccountInfoResolver implements IAccountInfoResolver { // (undocumented) mapAccountIdToAccountInfo: Map; // (undocumented) + onPositionExit(callback: (position: IPosition) => void): { + dispose: () => void; + }; + // (undocumented) positionExit$: AsyncIterable; // (undocumented) updateAccountInfo(accountInfo: IAccountInfo): void; diff --git a/libraries/account-info-resolver/src/index.ts b/libraries/account-info-resolver/src/index.ts index e4366a548..b97c670d5 100644 --- a/libraries/account-info-resolver/src/index.ts +++ b/libraries/account-info-resolver/src/index.ts @@ -40,6 +40,15 @@ export class AccountInfoResolver implements IAccountInfoResolver { private _positionExit$ = new Subject(); positionExit$: AsyncIterable = observableToAsyncIterable(this._positionExit$); + onPositionExit(callback: (position: IPosition) => void): { dispose: () => void } { + const sub = this._positionExit$.subscribe(callback); + return { + dispose: () => { + sub.unsubscribe(); + }, + }; + } + private dirtyPositions = new Set(); private dirtyProductIds: Set = new Set(); private mapProductIdToProduct = new Map(); diff --git a/libraries/account-info-resolver/src/model.ts b/libraries/account-info-resolver/src/model.ts index 654e884a4..b7609658e 100644 --- a/libraries/account-info-resolver/src/model.ts +++ b/libraries/account-info-resolver/src/model.ts @@ -11,4 +11,5 @@ export interface IAccountInfoResolver { mapAccountIdToAccountInfo: ReadonlyMap; positionExit$: AsyncIterable; + onPositionExit: (callback: (position: IPosition) => void) => { dispose: () => void }; }