@pear-protocol/symmio-client 0.3.14 → 0.3.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +49 -1
- package/dist/index.d.ts +49 -1
- package/dist/index.js +191 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +187 -1
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +127 -36
- package/dist/react/index.d.ts +127 -36
- package/dist/react/index.js +486 -73
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +481 -75
- package/dist/react/index.mjs.map +1 -1
- package/dist/react/provider.js +70 -25
- package/dist/react/provider.js.map +1 -1
- package/dist/react/provider.mjs +70 -25
- package/dist/react/provider.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -19856,6 +19856,7 @@ interface SymmAccountOverview {
|
|
|
19856
19856
|
equity: string;
|
|
19857
19857
|
totalAccountValue: string;
|
|
19858
19858
|
maintenanceMargin: string;
|
|
19859
|
+
accountHealthData?: unknown;
|
|
19859
19860
|
totalLocked: string;
|
|
19860
19861
|
marginUsed: string;
|
|
19861
19862
|
totalPendingLocked: string;
|
|
@@ -19870,6 +19871,8 @@ interface SymmDepositWithdrawalTotals {
|
|
|
19870
19871
|
deposit?: SymmAccountNumericValue;
|
|
19871
19872
|
withdraw?: SymmAccountNumericValue;
|
|
19872
19873
|
}
|
|
19874
|
+
type SymmAccountDataLike = Record<string, unknown>;
|
|
19875
|
+
declare function getSymmAccountData(response: unknown): SymmAccountDataLike | undefined;
|
|
19873
19876
|
/**
|
|
19874
19877
|
* Finds a single account's balance info from a core BalanceInfoResponse,
|
|
19875
19878
|
* symm-pear hedger map, or a direct balance-info object.
|
|
@@ -19882,6 +19885,11 @@ declare function getSymmAccountBalanceInfo(response: unknown, accountAddress?: s
|
|
|
19882
19885
|
* margin used = CVA + LF + party A MM
|
|
19883
19886
|
*/
|
|
19884
19887
|
declare function computeSymmAccountOverview({ balanceInfo, upnl: upnlOverride, netDeposited, }: SymmAccountOverviewInput): SymmAccountOverview;
|
|
19888
|
+
declare function computeSymmAccountOverviewFromData({ accountData, upnl, netDeposited, }: {
|
|
19889
|
+
accountData: SymmAccountDataLike;
|
|
19890
|
+
upnl?: SymmAccountNumericValue;
|
|
19891
|
+
netDeposited?: SymmAccountNumericValue;
|
|
19892
|
+
}): SymmAccountOverview;
|
|
19885
19893
|
/**
|
|
19886
19894
|
* Computes the symm-pear net-deposited display value from balance-history
|
|
19887
19895
|
* subgraph totals. Inputs must be integer raw collateral units; USDC defaults
|
|
@@ -19889,4 +19897,44 @@ declare function computeSymmAccountOverview({ balanceInfo, upnl: upnlOverride, n
|
|
|
19889
19897
|
*/
|
|
19890
19898
|
declare function computeSymmNetDeposited(totals: SymmDepositWithdrawalTotals | null | undefined, decimals?: number): string;
|
|
19891
19899
|
|
|
19892
|
-
|
|
19900
|
+
type SymmPnlNumericValue = string | number | null | undefined;
|
|
19901
|
+
interface SymmPnlAssetLegLike {
|
|
19902
|
+
symbol?: string;
|
|
19903
|
+
quantity?: SymmPnlNumericValue;
|
|
19904
|
+
openedPrice?: SymmPnlNumericValue;
|
|
19905
|
+
opened_price?: SymmPnlNumericValue;
|
|
19906
|
+
currentPrice?: SymmPnlNumericValue;
|
|
19907
|
+
current_price?: SymmPnlNumericValue;
|
|
19908
|
+
}
|
|
19909
|
+
interface SymmPnlPositionLike {
|
|
19910
|
+
longAssets?: SymmPnlAssetLegLike[];
|
|
19911
|
+
shortAssets?: SymmPnlAssetLegLike[];
|
|
19912
|
+
unrealizedPnl?: SymmPnlNumericValue;
|
|
19913
|
+
unrealized_pnl?: SymmPnlNumericValue;
|
|
19914
|
+
}
|
|
19915
|
+
type SymmMarkPrices = Record<string, number | string | null | undefined>;
|
|
19916
|
+
interface SymmPositionPnlResult {
|
|
19917
|
+
upnl: number;
|
|
19918
|
+
missingSymbols: string[];
|
|
19919
|
+
positionsCount: number;
|
|
19920
|
+
legsCount: number;
|
|
19921
|
+
usedFallbackPositions: number;
|
|
19922
|
+
}
|
|
19923
|
+
declare function computeSymmPositionUpnl(position: SymmPnlPositionLike, markPrices?: SymmMarkPrices): SymmPositionPnlResult;
|
|
19924
|
+
declare function computeSymmPositionsUpnl(positions?: readonly SymmPnlPositionLike[], markPrices?: SymmMarkPrices): SymmPositionPnlResult;
|
|
19925
|
+
interface SymmUpnlWebSocketMessage {
|
|
19926
|
+
upnl: number;
|
|
19927
|
+
timestamp?: number;
|
|
19928
|
+
availableBalance: number;
|
|
19929
|
+
allocatedBalance: number;
|
|
19930
|
+
cva: number;
|
|
19931
|
+
lf: number;
|
|
19932
|
+
partyAmm: number;
|
|
19933
|
+
pendingPartyAmm: number;
|
|
19934
|
+
pendingCva: number;
|
|
19935
|
+
pendingLf: number;
|
|
19936
|
+
raw: unknown;
|
|
19937
|
+
}
|
|
19938
|
+
declare function normalizeSymmUpnlWebSocketMessage(raw: unknown): SymmUpnlWebSocketMessage | undefined;
|
|
19939
|
+
|
|
19940
|
+
export { type ADLAssurance, ALL_TRADING_SELECTORS, type Account, type AccountBalance, type AccumulatedFundingRate, type AddAccountParams, type AffiliateFeeConfig, AffiliateFeeLevel, type AggregatedPosition, type AllocateParams, ApprovalState, CHAIN_NAMES, CLEARING_HOUSE_ADDRESS, CLOSE_QUOTE_SELECTOR, COLLATERAL_ADDRESS, COLLATERAL_DECIMALS, type CancelQuoteParams, type ChainId, ClearingHouseABI, type ClearingHouseLiquidation, ClearingHouseLiquidationStatus, type ClosePositionParams, type CreateSiweMessageParams, DEFAULT_PARTY_B_ADDRESS, DEFAULT_PRECISION, type DeallocateParams, type DepositAndAllocateParams, type DepositParams, ERC20ABI, FALLBACK_CHAIN_ID, type InstantAuthToken, type InstantCloseParams, type InstantCloseResponse, InstantCloseStatus, type InstantErrorResponse, type InstantLoginParams, type InstantOpenParams, type InstantOpenResponse, type InsuranceVaultConfig, type InternalTransferParams, LIMIT_ORDER_DEADLINE, LiquidationStatus, MARKET_ORDER_DEADLINE, MARKET_PRICE_COEFFICIENT, MAX_LEVERAGE, MULTI_ACCOUNT_ADDRESS, MUON_APP_NAME, MUON_BASE_URLS, type Market, MultiAccountABI, type MuonBatchParams, type MuonBatchSig, MuonClient, type MuonClientConfig, type MuonDeallocateParams, type MuonQuoteParams, type MuonSingleUpnlAndPriceSig, type MuonSingleUpnlSig, type MuonSingleUpnlWithPendingBalanceSig, MuonVerifierABI, OrderType, PositionType, type PreparedTransaction, type Quote, QuoteStatus, type RegisterAffiliateParams, SEND_QUOTE_WITH_AFFILIATE_SELECTOR, SIGNATURE_STORE_ADDRESS, STANDARD_WITHDRAW_COOLDOWN, SYMMIO_DIAMOND_ADDRESS, type SchnorrSign, type SendQuoteParams, type SetAffiliateFeeParams, SignatureStoreABI, type SiweMessageResult, SoftLiquidationLevel, type SoftLiquidationThreshold, SupportedChainId, type SymbolCategory, type SymbolType, type SymmAccountBalanceInfoLike, type SymmAccountDataLike, type SymmAccountNumericValue, type SymmAccountOverview, type SymmAccountOverviewInput, type SymmDepositWithdrawalTotals, type SymmMarkPrices, type SymmPnlAssetLegLike, type SymmPnlNumericValue, type SymmPnlPositionLike, type SymmPositionPnlResult, type SymmUpnlWebSocketMessage, SymmioDiamondABI, type SymmioSDKConfig, SymmioSDKError, type TransactionConfig, type TransactionReceipt, type TransactionResult, V3_CHAIN_IDS, type WithdrawParams, account as accountActions, admin as adminActions, allocate$1 as allocateActions, applySlippage, approval as approvalActions, calculateGasMargin, cancel as cancelActions, close as closeActions, computeSymmAccountOverview, computeSymmAccountOverviewFromData, computeSymmNetDeposited, computeSymmPositionUpnl, computeSymmPositionsUpnl, delegation as delegationActions, deposit$1 as depositActions, encodeCall, formatPrice, fromWei, getAddress, getSymmAccountBalanceInfo, getSymmAccountData, instant as instantActions, normalizeSymmUpnlWebSocketMessage, signature as signatureActions, stats as statsActions, toWei, trade as tradeActions, validateAddress, validateAmount, validateChainId, validateDeadline, validateQuantity, withdraw$1 as withdrawActions, wrapInProxyCall };
|
package/dist/index.d.ts
CHANGED
|
@@ -19856,6 +19856,7 @@ interface SymmAccountOverview {
|
|
|
19856
19856
|
equity: string;
|
|
19857
19857
|
totalAccountValue: string;
|
|
19858
19858
|
maintenanceMargin: string;
|
|
19859
|
+
accountHealthData?: unknown;
|
|
19859
19860
|
totalLocked: string;
|
|
19860
19861
|
marginUsed: string;
|
|
19861
19862
|
totalPendingLocked: string;
|
|
@@ -19870,6 +19871,8 @@ interface SymmDepositWithdrawalTotals {
|
|
|
19870
19871
|
deposit?: SymmAccountNumericValue;
|
|
19871
19872
|
withdraw?: SymmAccountNumericValue;
|
|
19872
19873
|
}
|
|
19874
|
+
type SymmAccountDataLike = Record<string, unknown>;
|
|
19875
|
+
declare function getSymmAccountData(response: unknown): SymmAccountDataLike | undefined;
|
|
19873
19876
|
/**
|
|
19874
19877
|
* Finds a single account's balance info from a core BalanceInfoResponse,
|
|
19875
19878
|
* symm-pear hedger map, or a direct balance-info object.
|
|
@@ -19882,6 +19885,11 @@ declare function getSymmAccountBalanceInfo(response: unknown, accountAddress?: s
|
|
|
19882
19885
|
* margin used = CVA + LF + party A MM
|
|
19883
19886
|
*/
|
|
19884
19887
|
declare function computeSymmAccountOverview({ balanceInfo, upnl: upnlOverride, netDeposited, }: SymmAccountOverviewInput): SymmAccountOverview;
|
|
19888
|
+
declare function computeSymmAccountOverviewFromData({ accountData, upnl, netDeposited, }: {
|
|
19889
|
+
accountData: SymmAccountDataLike;
|
|
19890
|
+
upnl?: SymmAccountNumericValue;
|
|
19891
|
+
netDeposited?: SymmAccountNumericValue;
|
|
19892
|
+
}): SymmAccountOverview;
|
|
19885
19893
|
/**
|
|
19886
19894
|
* Computes the symm-pear net-deposited display value from balance-history
|
|
19887
19895
|
* subgraph totals. Inputs must be integer raw collateral units; USDC defaults
|
|
@@ -19889,4 +19897,44 @@ declare function computeSymmAccountOverview({ balanceInfo, upnl: upnlOverride, n
|
|
|
19889
19897
|
*/
|
|
19890
19898
|
declare function computeSymmNetDeposited(totals: SymmDepositWithdrawalTotals | null | undefined, decimals?: number): string;
|
|
19891
19899
|
|
|
19892
|
-
|
|
19900
|
+
type SymmPnlNumericValue = string | number | null | undefined;
|
|
19901
|
+
interface SymmPnlAssetLegLike {
|
|
19902
|
+
symbol?: string;
|
|
19903
|
+
quantity?: SymmPnlNumericValue;
|
|
19904
|
+
openedPrice?: SymmPnlNumericValue;
|
|
19905
|
+
opened_price?: SymmPnlNumericValue;
|
|
19906
|
+
currentPrice?: SymmPnlNumericValue;
|
|
19907
|
+
current_price?: SymmPnlNumericValue;
|
|
19908
|
+
}
|
|
19909
|
+
interface SymmPnlPositionLike {
|
|
19910
|
+
longAssets?: SymmPnlAssetLegLike[];
|
|
19911
|
+
shortAssets?: SymmPnlAssetLegLike[];
|
|
19912
|
+
unrealizedPnl?: SymmPnlNumericValue;
|
|
19913
|
+
unrealized_pnl?: SymmPnlNumericValue;
|
|
19914
|
+
}
|
|
19915
|
+
type SymmMarkPrices = Record<string, number | string | null | undefined>;
|
|
19916
|
+
interface SymmPositionPnlResult {
|
|
19917
|
+
upnl: number;
|
|
19918
|
+
missingSymbols: string[];
|
|
19919
|
+
positionsCount: number;
|
|
19920
|
+
legsCount: number;
|
|
19921
|
+
usedFallbackPositions: number;
|
|
19922
|
+
}
|
|
19923
|
+
declare function computeSymmPositionUpnl(position: SymmPnlPositionLike, markPrices?: SymmMarkPrices): SymmPositionPnlResult;
|
|
19924
|
+
declare function computeSymmPositionsUpnl(positions?: readonly SymmPnlPositionLike[], markPrices?: SymmMarkPrices): SymmPositionPnlResult;
|
|
19925
|
+
interface SymmUpnlWebSocketMessage {
|
|
19926
|
+
upnl: number;
|
|
19927
|
+
timestamp?: number;
|
|
19928
|
+
availableBalance: number;
|
|
19929
|
+
allocatedBalance: number;
|
|
19930
|
+
cva: number;
|
|
19931
|
+
lf: number;
|
|
19932
|
+
partyAmm: number;
|
|
19933
|
+
pendingPartyAmm: number;
|
|
19934
|
+
pendingCva: number;
|
|
19935
|
+
pendingLf: number;
|
|
19936
|
+
raw: unknown;
|
|
19937
|
+
}
|
|
19938
|
+
declare function normalizeSymmUpnlWebSocketMessage(raw: unknown): SymmUpnlWebSocketMessage | undefined;
|
|
19939
|
+
|
|
19940
|
+
export { type ADLAssurance, ALL_TRADING_SELECTORS, type Account, type AccountBalance, type AccumulatedFundingRate, type AddAccountParams, type AffiliateFeeConfig, AffiliateFeeLevel, type AggregatedPosition, type AllocateParams, ApprovalState, CHAIN_NAMES, CLEARING_HOUSE_ADDRESS, CLOSE_QUOTE_SELECTOR, COLLATERAL_ADDRESS, COLLATERAL_DECIMALS, type CancelQuoteParams, type ChainId, ClearingHouseABI, type ClearingHouseLiquidation, ClearingHouseLiquidationStatus, type ClosePositionParams, type CreateSiweMessageParams, DEFAULT_PARTY_B_ADDRESS, DEFAULT_PRECISION, type DeallocateParams, type DepositAndAllocateParams, type DepositParams, ERC20ABI, FALLBACK_CHAIN_ID, type InstantAuthToken, type InstantCloseParams, type InstantCloseResponse, InstantCloseStatus, type InstantErrorResponse, type InstantLoginParams, type InstantOpenParams, type InstantOpenResponse, type InsuranceVaultConfig, type InternalTransferParams, LIMIT_ORDER_DEADLINE, LiquidationStatus, MARKET_ORDER_DEADLINE, MARKET_PRICE_COEFFICIENT, MAX_LEVERAGE, MULTI_ACCOUNT_ADDRESS, MUON_APP_NAME, MUON_BASE_URLS, type Market, MultiAccountABI, type MuonBatchParams, type MuonBatchSig, MuonClient, type MuonClientConfig, type MuonDeallocateParams, type MuonQuoteParams, type MuonSingleUpnlAndPriceSig, type MuonSingleUpnlSig, type MuonSingleUpnlWithPendingBalanceSig, MuonVerifierABI, OrderType, PositionType, type PreparedTransaction, type Quote, QuoteStatus, type RegisterAffiliateParams, SEND_QUOTE_WITH_AFFILIATE_SELECTOR, SIGNATURE_STORE_ADDRESS, STANDARD_WITHDRAW_COOLDOWN, SYMMIO_DIAMOND_ADDRESS, type SchnorrSign, type SendQuoteParams, type SetAffiliateFeeParams, SignatureStoreABI, type SiweMessageResult, SoftLiquidationLevel, type SoftLiquidationThreshold, SupportedChainId, type SymbolCategory, type SymbolType, type SymmAccountBalanceInfoLike, type SymmAccountDataLike, type SymmAccountNumericValue, type SymmAccountOverview, type SymmAccountOverviewInput, type SymmDepositWithdrawalTotals, type SymmMarkPrices, type SymmPnlAssetLegLike, type SymmPnlNumericValue, type SymmPnlPositionLike, type SymmPositionPnlResult, type SymmUpnlWebSocketMessage, SymmioDiamondABI, type SymmioSDKConfig, SymmioSDKError, type TransactionConfig, type TransactionReceipt, type TransactionResult, V3_CHAIN_IDS, type WithdrawParams, account as accountActions, admin as adminActions, allocate$1 as allocateActions, applySlippage, approval as approvalActions, calculateGasMargin, cancel as cancelActions, close as closeActions, computeSymmAccountOverview, computeSymmAccountOverviewFromData, computeSymmNetDeposited, computeSymmPositionUpnl, computeSymmPositionsUpnl, delegation as delegationActions, deposit$1 as depositActions, encodeCall, formatPrice, fromWei, getAddress, getSymmAccountBalanceInfo, getSymmAccountData, instant as instantActions, normalizeSymmUpnlWebSocketMessage, signature as signatureActions, stats as statsActions, toWei, trade as tradeActions, validateAddress, validateAmount, validateChainId, validateDeadline, validateQuantity, withdraw$1 as withdrawActions, wrapInProxyCall };
|
package/dist/index.js
CHANGED
|
@@ -24741,6 +24741,28 @@ function readTimestamp(source) {
|
|
|
24741
24741
|
const parsed = Number(timestamp);
|
|
24742
24742
|
return Number.isFinite(parsed) ? parsed : void 0;
|
|
24743
24743
|
}
|
|
24744
|
+
function hasAccountDataShape(value) {
|
|
24745
|
+
return isRecord(value) && ("equity" in value || "maintenanceMargin" in value || "availableForOrder" in value || "totalLocked" in value);
|
|
24746
|
+
}
|
|
24747
|
+
function getSymmAccountData(response) {
|
|
24748
|
+
if (!isRecord(response)) {
|
|
24749
|
+
return void 0;
|
|
24750
|
+
}
|
|
24751
|
+
const data = response.data;
|
|
24752
|
+
if (isRecord(data)) {
|
|
24753
|
+
if (hasAccountDataShape(data.accountData)) {
|
|
24754
|
+
return data.accountData;
|
|
24755
|
+
}
|
|
24756
|
+
if (hasAccountDataShape(data)) {
|
|
24757
|
+
return data;
|
|
24758
|
+
}
|
|
24759
|
+
return void 0;
|
|
24760
|
+
}
|
|
24761
|
+
if (hasAccountDataShape(response)) {
|
|
24762
|
+
return response;
|
|
24763
|
+
}
|
|
24764
|
+
return void 0;
|
|
24765
|
+
}
|
|
24744
24766
|
function getBalanceInfoContainer(response) {
|
|
24745
24767
|
if (!isRecord(response)) {
|
|
24746
24768
|
return void 0;
|
|
@@ -24856,6 +24878,38 @@ function computeSymmAccountOverview({
|
|
|
24856
24878
|
timestamp: readTimestamp(balanceInfo)
|
|
24857
24879
|
};
|
|
24858
24880
|
}
|
|
24881
|
+
function computeSymmAccountOverviewFromData({
|
|
24882
|
+
accountData,
|
|
24883
|
+
upnl,
|
|
24884
|
+
netDeposited
|
|
24885
|
+
}) {
|
|
24886
|
+
const equity = readNumber(accountData, ["equity"]);
|
|
24887
|
+
const maintenanceMargin = readNumber(accountData, [
|
|
24888
|
+
"maintenanceMargin",
|
|
24889
|
+
"maintenance_margin"
|
|
24890
|
+
]);
|
|
24891
|
+
const availableForOrder = readNumber(accountData, [
|
|
24892
|
+
"availableForOrder",
|
|
24893
|
+
"available_for_order"
|
|
24894
|
+
]);
|
|
24895
|
+
const totalLocked = readNumber(accountData, ["totalLocked", "total_locked"]);
|
|
24896
|
+
return {
|
|
24897
|
+
allocatedBalance: "0",
|
|
24898
|
+
upnl: toDisplayString(toNumber(upnl)),
|
|
24899
|
+
equity: toDisplayString(equity),
|
|
24900
|
+
totalAccountValue: toDisplayString(equity),
|
|
24901
|
+
maintenanceMargin: toDisplayString(maintenanceMargin),
|
|
24902
|
+
accountHealthData: accountData.accountHealthData,
|
|
24903
|
+
totalLocked: toDisplayString(totalLocked),
|
|
24904
|
+
marginUsed: toDisplayString(totalLocked),
|
|
24905
|
+
totalPendingLocked: "0",
|
|
24906
|
+
availableForOrder: toDisplayString(availableForOrder),
|
|
24907
|
+
availableMargin: toDisplayString(availableForOrder),
|
|
24908
|
+
availableBalance: toDisplayString(availableForOrder),
|
|
24909
|
+
netDeposited: toDisplayString(toNumber(netDeposited)),
|
|
24910
|
+
notional: "0"
|
|
24911
|
+
};
|
|
24912
|
+
}
|
|
24859
24913
|
function computeSymmNetDeposited(totals, decimals = 6) {
|
|
24860
24914
|
if (!totals) {
|
|
24861
24915
|
return "0";
|
|
@@ -24891,6 +24945,138 @@ function parseRawCollateralUnits(value) {
|
|
|
24891
24945
|
return BigInt(value);
|
|
24892
24946
|
}
|
|
24893
24947
|
|
|
24948
|
+
// src/utils/account-pnl.ts
|
|
24949
|
+
function toNumber2(value) {
|
|
24950
|
+
if (value === null || value === void 0 || value === "") {
|
|
24951
|
+
return 0;
|
|
24952
|
+
}
|
|
24953
|
+
const parsed = Number(value);
|
|
24954
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
24955
|
+
}
|
|
24956
|
+
function readOpenedPrice(leg) {
|
|
24957
|
+
return toNumber2(leg.openedPrice ?? leg.opened_price);
|
|
24958
|
+
}
|
|
24959
|
+
function readCurrentPrice(leg) {
|
|
24960
|
+
const parsed = Number(leg.currentPrice ?? leg.current_price);
|
|
24961
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
24962
|
+
}
|
|
24963
|
+
function readMarkPrice(leg, markPrices) {
|
|
24964
|
+
const symbol = leg.symbol?.trim().toUpperCase();
|
|
24965
|
+
if (symbol) {
|
|
24966
|
+
const markPrice = Number(markPrices[symbol]);
|
|
24967
|
+
if (Number.isFinite(markPrice)) {
|
|
24968
|
+
return markPrice;
|
|
24969
|
+
}
|
|
24970
|
+
}
|
|
24971
|
+
return readCurrentPrice(leg);
|
|
24972
|
+
}
|
|
24973
|
+
function getSymbol(leg) {
|
|
24974
|
+
return leg.symbol?.trim().toUpperCase() || void 0;
|
|
24975
|
+
}
|
|
24976
|
+
function computeLegUpnl(leg, side, markPrices) {
|
|
24977
|
+
const markPrice = readMarkPrice(leg, markPrices);
|
|
24978
|
+
if (markPrice === void 0) {
|
|
24979
|
+
return { upnl: 0, missingSymbol: getSymbol(leg) };
|
|
24980
|
+
}
|
|
24981
|
+
const quantity = toNumber2(leg.quantity);
|
|
24982
|
+
const openedPrice = readOpenedPrice(leg);
|
|
24983
|
+
const direction = side === "short" ? -1 : 1;
|
|
24984
|
+
return {
|
|
24985
|
+
upnl: quantity * (markPrice - openedPrice) * direction
|
|
24986
|
+
};
|
|
24987
|
+
}
|
|
24988
|
+
function computeSymmPositionUpnl(position, markPrices = {}) {
|
|
24989
|
+
const missingSymbols = /* @__PURE__ */ new Set();
|
|
24990
|
+
let upnl = 0;
|
|
24991
|
+
let legsCount = 0;
|
|
24992
|
+
for (const leg of position.longAssets ?? []) {
|
|
24993
|
+
legsCount += 1;
|
|
24994
|
+
const result = computeLegUpnl(leg, "long", markPrices);
|
|
24995
|
+
upnl += result.upnl;
|
|
24996
|
+
if (result.missingSymbol) missingSymbols.add(result.missingSymbol);
|
|
24997
|
+
}
|
|
24998
|
+
for (const leg of position.shortAssets ?? []) {
|
|
24999
|
+
legsCount += 1;
|
|
25000
|
+
const result = computeLegUpnl(leg, "short", markPrices);
|
|
25001
|
+
upnl += result.upnl;
|
|
25002
|
+
if (result.missingSymbol) missingSymbols.add(result.missingSymbol);
|
|
25003
|
+
}
|
|
25004
|
+
if (legsCount === 0) {
|
|
25005
|
+
return {
|
|
25006
|
+
upnl: toNumber2(position.unrealizedPnl ?? position.unrealized_pnl),
|
|
25007
|
+
missingSymbols: [],
|
|
25008
|
+
positionsCount: 1,
|
|
25009
|
+
legsCount,
|
|
25010
|
+
usedFallbackPositions: 1
|
|
25011
|
+
};
|
|
25012
|
+
}
|
|
25013
|
+
return {
|
|
25014
|
+
upnl,
|
|
25015
|
+
missingSymbols: Array.from(missingSymbols),
|
|
25016
|
+
positionsCount: 1,
|
|
25017
|
+
legsCount,
|
|
25018
|
+
usedFallbackPositions: 0
|
|
25019
|
+
};
|
|
25020
|
+
}
|
|
25021
|
+
function computeSymmPositionsUpnl(positions = [], markPrices = {}) {
|
|
25022
|
+
const missingSymbols = /* @__PURE__ */ new Set();
|
|
25023
|
+
let upnl = 0;
|
|
25024
|
+
let legsCount = 0;
|
|
25025
|
+
let usedFallbackPositions = 0;
|
|
25026
|
+
for (const position of positions) {
|
|
25027
|
+
const result = computeSymmPositionUpnl(position, markPrices);
|
|
25028
|
+
upnl += result.upnl;
|
|
25029
|
+
legsCount += result.legsCount;
|
|
25030
|
+
usedFallbackPositions += result.usedFallbackPositions;
|
|
25031
|
+
result.missingSymbols.forEach((symbol) => missingSymbols.add(symbol));
|
|
25032
|
+
}
|
|
25033
|
+
return {
|
|
25034
|
+
upnl,
|
|
25035
|
+
missingSymbols: Array.from(missingSymbols),
|
|
25036
|
+
positionsCount: positions.length,
|
|
25037
|
+
legsCount,
|
|
25038
|
+
usedFallbackPositions
|
|
25039
|
+
};
|
|
25040
|
+
}
|
|
25041
|
+
function readMessageNumber(message, keys) {
|
|
25042
|
+
for (const key of keys) {
|
|
25043
|
+
if (key in message) {
|
|
25044
|
+
return toNumber2(message[key]);
|
|
25045
|
+
}
|
|
25046
|
+
}
|
|
25047
|
+
return 0;
|
|
25048
|
+
}
|
|
25049
|
+
function normalizeSymmUpnlWebSocketMessage(raw) {
|
|
25050
|
+
if (typeof raw !== "object" || raw === null) {
|
|
25051
|
+
return void 0;
|
|
25052
|
+
}
|
|
25053
|
+
const message = raw;
|
|
25054
|
+
const timestamp = readMessageNumber(message, ["timestamp"]);
|
|
25055
|
+
return {
|
|
25056
|
+
upnl: readMessageNumber(message, ["upnl"]),
|
|
25057
|
+
timestamp: timestamp || void 0,
|
|
25058
|
+
availableBalance: readMessageNumber(message, [
|
|
25059
|
+
"availableBalance",
|
|
25060
|
+
"available_balance"
|
|
25061
|
+
]),
|
|
25062
|
+
allocatedBalance: readMessageNumber(message, [
|
|
25063
|
+
"allocatedBalance",
|
|
25064
|
+
"allocated_balance"
|
|
25065
|
+
]),
|
|
25066
|
+
cva: readMessageNumber(message, ["cva"]),
|
|
25067
|
+
lf: readMessageNumber(message, ["lf"]),
|
|
25068
|
+
partyAmm: readMessageNumber(message, ["partyAmm", "party_a_mm", "mm"]),
|
|
25069
|
+
pendingPartyAmm: readMessageNumber(message, [
|
|
25070
|
+
"pendingPartyAmm",
|
|
25071
|
+
"pending_party_a_mm",
|
|
25072
|
+
"pending_mm"
|
|
25073
|
+
]),
|
|
25074
|
+
pendingCva: readMessageNumber(message, ["pendingCva", "pending_cva"]),
|
|
25075
|
+
pendingLf: readMessageNumber(message, ["pendingLf", "pending_lf"]),
|
|
25076
|
+
raw
|
|
25077
|
+
};
|
|
25078
|
+
}
|
|
25079
|
+
|
|
24894
25080
|
exports.ALL_TRADING_SELECTORS = ALL_TRADING_SELECTORS;
|
|
24895
25081
|
exports.AffiliateFeeLevel = AffiliateFeeLevel;
|
|
24896
25082
|
exports.ApprovalState = ApprovalState;
|
|
@@ -24939,7 +25125,10 @@ exports.calculateGasMargin = calculateGasMargin;
|
|
|
24939
25125
|
exports.cancelActions = cancel_exports;
|
|
24940
25126
|
exports.closeActions = close_exports;
|
|
24941
25127
|
exports.computeSymmAccountOverview = computeSymmAccountOverview;
|
|
25128
|
+
exports.computeSymmAccountOverviewFromData = computeSymmAccountOverviewFromData;
|
|
24942
25129
|
exports.computeSymmNetDeposited = computeSymmNetDeposited;
|
|
25130
|
+
exports.computeSymmPositionUpnl = computeSymmPositionUpnl;
|
|
25131
|
+
exports.computeSymmPositionsUpnl = computeSymmPositionsUpnl;
|
|
24943
25132
|
exports.delegationActions = delegation_exports;
|
|
24944
25133
|
exports.depositActions = deposit_exports;
|
|
24945
25134
|
exports.encodeCall = encodeCall;
|
|
@@ -24947,7 +25136,9 @@ exports.formatPrice = formatPrice;
|
|
|
24947
25136
|
exports.fromWei = fromWei;
|
|
24948
25137
|
exports.getAddress = getAddress;
|
|
24949
25138
|
exports.getSymmAccountBalanceInfo = getSymmAccountBalanceInfo;
|
|
25139
|
+
exports.getSymmAccountData = getSymmAccountData;
|
|
24950
25140
|
exports.instantActions = instant_exports;
|
|
25141
|
+
exports.normalizeSymmUpnlWebSocketMessage = normalizeSymmUpnlWebSocketMessage;
|
|
24951
25142
|
exports.signatureActions = signature_exports;
|
|
24952
25143
|
exports.statsActions = stats_exports;
|
|
24953
25144
|
exports.toWei = toWei;
|