Skip to content

Commit

Permalink
feat(account-info-resolver): onPositionExit (#935)
Browse files Browse the repository at this point in the history
Co-authored-by: CZ <cz@ntnl.io>
  • Loading branch information
zccz14 and CZ authored Dec 5, 2024
1 parent 257ffb7 commit cd6996a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions common/changes/@yuants/account-info-resolver/2024-12-05-21-03.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@yuants/account-info-resolver",
"comment": "sync onPositionExit callback",
"type": "minor"
}
],
"packageName": "@yuants/account-info-resolver"
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export class AccountInfoResolver implements IAccountInfoResolver {
// (undocumented)
mapAccountIdToAccountInfo: Map<string, IAccountInfo>;
// (undocumented)
onPositionExit(callback: (position: IPosition) => void): {
dispose: () => void;
};
// (undocumented)
positionExit$: AsyncIterable<IPosition>;
// (undocumented)
updateAccountInfo(accountInfo: IAccountInfo): void;
Expand Down
9 changes: 9 additions & 0 deletions libraries/account-info-resolver/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ export class AccountInfoResolver implements IAccountInfoResolver {
private _positionExit$ = new Subject<IPosition>();
positionExit$: AsyncIterable<IPosition> = observableToAsyncIterable(this._positionExit$);

onPositionExit(callback: (position: IPosition) => void): { dispose: () => void } {
const sub = this._positionExit$.subscribe(callback);
return {
dispose: () => {
sub.unsubscribe();
},
};
}

private dirtyPositions = new Set<IPosition>();
private dirtyProductIds: Set<string> = new Set();
private mapProductIdToProduct = new Map<string, IProduct>();
Expand Down
1 change: 1 addition & 0 deletions libraries/account-info-resolver/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export interface IAccountInfoResolver {

mapAccountIdToAccountInfo: ReadonlyMap<string, IAccountInfo>;
positionExit$: AsyncIterable<IPosition>;
onPositionExit: (callback: (position: IPosition) => void) => { dispose: () => void };
}

0 comments on commit cd6996a

Please sign in to comment.