getActiveVirtualAccountByKey
Read a subaccount’s active Virtual Account (VA) for an isolation key (isolationType, symbolId): the VA that new quotes on that market, and side, are routed into while the subaccount runs in single-VA mode. It wraps the AccountLayer’s getActiveVAByKey. Predicting the next VA (usePredictedNextVirtualAccount) answers where the next position would go; this answers which VA holds the position now.
import { getActiveVirtualAccountByKey, isolationTypeForSide, PositionType } from "@symmio/trading-core";
const va = await getActiveVirtualAccountByKey(config, {
subAccount,
isolationType: isolationTypeForSide(PositionType.LONG),
symbolId: 42n,
});The active VA changes when a position on the key opens or fully closes, so invalidate the query after those writes rather than caching it forever.
Parameters
subAccountAddressrequiredThe parent subaccount.
isolationTypeVirtualAccountIsolationTyperequiredIsolation bucket of the VA. Use isolationTypeForSide(positionType) for a side.
symbolIdbigintrequiredMarket id.
chainIdnumberoptionalOptional chain override.
Returns
Address | nullThe active VA, or null when none is active for the key. The contract returns the zero address in that case.
Query options
import { getActiveVirtualAccountByKeyQueryOptions } from "@symmio/trading-core";
import { useQuery } from "@tanstack/react-query";
useQuery(getActiveVirtualAccountByKeyQueryOptions(config, { subAccount, isolationType, symbolId }));Raw ABI
For consumers that want to call viem directly:
import { accountLayerAbi } from "@symmio/trading-core";
await publicClient.readContract({
abi: accountLayerAbi,
address: accountLayerAddress,
functionName: "getActiveVAByKey",
args: [subAccount, isolationType, symbolId],
});