Skip to content

Commit

Permalink
Merge branch 'jv/unopened-isolated-positions' into jv/unopened-isolat…
Browse files Browse the repository at this point in the history
…ed-positions-2
  • Loading branch information
jaredvu committed Jan 15, 2025
2 parents ccd39aa + 404ae5f commit 7444281
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions src/abacus-ts/calculators/subaccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,15 @@ export function calculateMarketsNeededForSubaccount(parent: Omit<ParentSubaccoun
);
}

function calculateSubaccountSummary(
subaccountData: ChildSubaccountData,
markets: MarketsData
): SubaccountSummary {
const core = calculateSubaccountSummaryCore(subaccountData, markets);
return {
...core,
...calculateSubaccountSummaryDerived(core),
};
}
const calculateSubaccountSummary = weakMapMemoize(
(subaccountData: ChildSubaccountData, markets: MarketsData): SubaccountSummary => {
const core = calculateSubaccountSummaryCore(subaccountData, markets);
return {
...core,
...calculateSubaccountSummaryDerived(core),
};
}
);

function calculateSubaccountSummaryCore(
subaccountData: ChildSubaccountData,
Expand Down Expand Up @@ -297,20 +296,18 @@ function calculatePositionDerivedExtra(
};
}

export const calculateChildSubaccountSummaries = weakMapMemoize(
(
parent: Omit<ParentSubaccountData, 'live'>,
markets: MarketsData
): Record<string, SubaccountSummary> => {
return pickBy(
mapValues(
parent.childSubaccounts,
(subaccount) => subaccount && calculateSubaccountSummary(subaccount, markets)
),
isTruthy
);
}
);
export function calculateChildSubaccountSummaries(
parent: Omit<ParentSubaccountData, 'live'>,
markets: MarketsData
): Record<string, SubaccountSummary> {
return pickBy(
mapValues(
parent.childSubaccounts,
(subaccount) => subaccount && calculateSubaccountSummary(subaccount, markets)
),
isTruthy
);
}

/**
* @returns a list of pending isolated positions
Expand Down

0 comments on commit 7444281

Please sign in to comment.