@metamask-previews/perps-controller 25.0.0-preview-4046c2f69 → 26.0.0-preview-203750488
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/CHANGELOG.md +105 -9
- package/dist/PerpsController-method-action-types.d.ts +149 -3
- package/dist/PerpsController-method-action-types.d.ts.map +1 -1
- package/dist/PerpsController-method-action-types.js.map +1 -1
- package/dist/PerpsController.d.ts +125 -3
- package/dist/PerpsController.d.ts.map +1 -1
- package/dist/PerpsController.js +787 -31
- package/dist/PerpsController.js.map +1 -1
- package/dist/constants/eventNames.d.ts +69 -9
- package/dist/constants/eventNames.d.ts.map +1 -1
- package/dist/constants/eventNames.js +82 -11
- package/dist/constants/eventNames.js.map +1 -1
- package/dist/constants/hyperLiquidConfig.d.ts +15 -0
- package/dist/constants/hyperLiquidConfig.d.ts.map +1 -1
- package/dist/constants/hyperLiquidConfig.js +14 -0
- package/dist/constants/hyperLiquidConfig.js.map +1 -1
- package/dist/constants/perpsConfig.d.ts +10 -2
- package/dist/constants/perpsConfig.d.ts.map +1 -1
- package/dist/constants/perpsConfig.js +11 -3
- package/dist/constants/perpsConfig.js.map +1 -1
- package/dist/index.d.ts +10 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/internal/accountReturnOnEquity.d.ts +12 -0
- package/dist/internal/accountReturnOnEquity.d.ts.map +1 -0
- package/dist/internal/accountReturnOnEquity.js +18 -0
- package/dist/internal/accountReturnOnEquity.js.map +1 -0
- package/dist/internal/hyperLiquidHip3Rebalance.d.ts +14 -0
- package/dist/internal/hyperLiquidHip3Rebalance.d.ts.map +1 -0
- package/dist/internal/hyperLiquidHip3Rebalance.js +18 -0
- package/dist/internal/hyperLiquidHip3Rebalance.js.map +1 -0
- package/dist/internal/marketNumericValues.d.ts +10 -0
- package/dist/internal/marketNumericValues.d.ts.map +1 -0
- package/dist/internal/marketNumericValues.js +9 -0
- package/dist/internal/marketNumericValues.js.map +1 -0
- package/dist/internal/perpsDisplaySymbol.d.ts +12 -0
- package/dist/internal/perpsDisplaySymbol.d.ts.map +1 -0
- package/dist/internal/perpsDisplaySymbol.js +21 -0
- package/dist/internal/perpsDisplaySymbol.js.map +1 -0
- package/dist/perpsErrorCodes.d.ts +1 -0
- package/dist/perpsErrorCodes.d.ts.map +1 -1
- package/dist/perpsErrorCodes.js +1 -0
- package/dist/perpsErrorCodes.js.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.d.ts +47 -1
- package/dist/providers/AggregatedPerpsProvider.d.ts.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.js +140 -0
- package/dist/providers/AggregatedPerpsProvider.js.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.ts +72 -4
- package/dist/providers/HyperLiquidProvider.d.ts.map +1 -1
- package/dist/providers/HyperLiquidProvider.js +751 -159
- package/dist/providers/HyperLiquidProvider.js.map +1 -1
- package/dist/providers/LighterProvider.d.ts +2 -1
- package/dist/providers/LighterProvider.d.ts.map +1 -1
- package/dist/providers/LighterProvider.js +11 -6
- package/dist/providers/LighterProvider.js.map +1 -1
- package/dist/selectors.d.ts +15 -5
- package/dist/selectors.d.ts.map +1 -1
- package/dist/selectors.js +23 -5
- package/dist/selectors.js.map +1 -1
- package/dist/services/AggregatedOrderBookConnection.d.ts.map +1 -1
- package/dist/services/AggregatedOrderBookConnection.js +8 -10
- package/dist/services/AggregatedOrderBookConnection.js.map +1 -1
- package/dist/services/HyperLiquidClientService.d.ts +8 -0
- package/dist/services/HyperLiquidClientService.d.ts.map +1 -1
- package/dist/services/HyperLiquidClientService.js +65 -0
- package/dist/services/HyperLiquidClientService.js.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.d.ts +30 -1
- package/dist/services/HyperLiquidSubscriptionService.d.ts.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.js +117 -30
- package/dist/services/HyperLiquidSubscriptionService.js.map +1 -1
- package/dist/services/MarketDataService.d.ts +20 -3
- package/dist/services/MarketDataService.d.ts.map +1 -1
- package/dist/services/MarketDataService.js +55 -3
- package/dist/services/MarketDataService.js.map +1 -1
- package/dist/services/StreamChannelManager.d.ts +139 -0
- package/dist/services/StreamChannelManager.d.ts.map +1 -0
- package/dist/services/StreamChannelManager.js +475 -0
- package/dist/services/StreamChannelManager.js.map +1 -0
- package/dist/services/TerminalMarketService.d.ts.map +1 -1
- package/dist/services/TerminalMarketService.js +7 -0
- package/dist/services/TerminalMarketService.js.map +1 -1
- package/dist/services/agentSigner.d.ts +8 -0
- package/dist/services/agentSigner.d.ts.map +1 -1
- package/dist/services/agentSigner.js +13 -0
- package/dist/services/agentSigner.js.map +1 -1
- package/dist/types/hyperliquid-types.d.ts +9 -1
- package/dist/types/hyperliquid-types.d.ts.map +1 -1
- package/dist/types/hyperliquid-types.js +10 -0
- package/dist/types/hyperliquid-types.js.map +1 -1
- package/dist/types/index.d.ts +434 -17
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utils/accountAggregation.d.ts +17 -0
- package/dist/utils/accountAggregation.d.ts.map +1 -1
- package/dist/utils/accountAggregation.js +21 -5
- package/dist/utils/accountAggregation.js.map +1 -1
- package/dist/utils/accountUtils.d.ts +31 -10
- package/dist/utils/accountUtils.d.ts.map +1 -1
- package/dist/utils/accountUtils.js +68 -28
- package/dist/utils/accountUtils.js.map +1 -1
- package/dist/utils/closeCalculations.d.ts +17 -4
- package/dist/utils/closeCalculations.d.ts.map +1 -1
- package/dist/utils/closeCalculations.js +23 -7
- package/dist/utils/closeCalculations.js.map +1 -1
- package/dist/utils/hyperLiquidAdapter.d.ts +10 -1
- package/dist/utils/hyperLiquidAdapter.d.ts.map +1 -1
- package/dist/utils/hyperLiquidAdapter.js +17 -1
- package/dist/utils/hyperLiquidAdapter.js.map +1 -1
- package/dist/utils/hyperLiquidPositionPreview.d.ts +133 -9
- package/dist/utils/hyperLiquidPositionPreview.d.ts.map +1 -1
- package/dist/utils/hyperLiquidPositionPreview.js +264 -29
- package/dist/utils/hyperLiquidPositionPreview.js.map +1 -1
- package/dist/utils/index.d.ts +4 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/lighterAdapter.d.ts.map +1 -1
- package/dist/utils/lighterAdapter.js +46 -9
- package/dist/utils/lighterAdapter.js.map +1 -1
- package/dist/utils/marketDataTransform.d.ts.map +1 -1
- package/dist/utils/marketDataTransform.js +13 -8
- package/dist/utils/marketDataTransform.js.map +1 -1
- package/dist/utils/marketUtils.d.ts +1 -2
- package/dist/utils/marketUtils.d.ts.map +1 -1
- package/dist/utils/marketUtils.js +7 -17
- package/dist/utils/marketUtils.js.map +1 -1
- package/dist/utils/orderBookGrouping.d.ts +35 -5
- package/dist/utils/orderBookGrouping.d.ts.map +1 -1
- package/dist/utils/orderBookGrouping.js +62 -6
- package/dist/utils/orderBookGrouping.js.map +1 -1
- package/dist/utils/perpsClientCopy.d.ts.map +1 -1
- package/dist/utils/perpsClientCopy.js +4 -0
- package/dist/utils/perpsClientCopy.js.map +1 -1
- package/dist/utils/perpsDiskPersistence.d.ts.map +1 -1
- package/dist/utils/perpsDiskPersistence.js +10 -0
- package/dist/utils/perpsDiskPersistence.js.map +1 -1
- package/dist/utils/perpsFormatters.d.ts +31 -0
- package/dist/utils/perpsFormatters.d.ts.map +1 -1
- package/dist/utils/perpsFormatters.js +26 -0
- package/dist/utils/perpsFormatters.js.map +1 -1
- package/dist/utils/priceDeviation.d.ts +9 -6
- package/dist/utils/priceDeviation.d.ts.map +1 -1
- package/dist/utils/priceDeviation.js +17 -26
- package/dist/utils/priceDeviation.js.map +1 -1
- package/dist/utils/sortMarkets.d.ts +13 -5
- package/dist/utils/sortMarkets.d.ts.map +1 -1
- package/dist/utils/sortMarkets.js +60 -38
- package/dist/utils/sortMarkets.js.map +1 -1
- package/docs/architecture.md +54 -24
- package/docs/client-contract.md +52 -27
- package/docs/contracts/events.md +38 -32
- package/docs/contracts/feature-flags.md +4 -4
- package/docs/formatting.md +2 -0
- package/docs/venues/lighter/capabilities.md +18 -15
- package/package.json +1 -1
package/dist/types/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { CHASE_ORDER_STATUS } from '../constants/perpsConfig.js';
|
|
|
5
5
|
import type { PerpsErrorDetails } from '../errors.js';
|
|
6
6
|
import type { PerpsErrorCode } from '../perpsErrorCodes.js';
|
|
7
7
|
import type { LighterProvider } from '../providers/LighterProvider.js';
|
|
8
|
+
import type { HyperLiquidMarginTier } from '../utils/hyperLiquidPositionPreview.js';
|
|
8
9
|
import type { LighterSignerBridge } from './lighter-types.js';
|
|
9
10
|
import type { CandleData, OrderDirection, OrderType, StrategyOrderType, TpslLinkage, TriggerDirection, TriggerOrderType } from './perps-types.js';
|
|
10
11
|
/**
|
|
@@ -804,17 +805,21 @@ export type CrossMarginSummary = {
|
|
|
804
805
|
notional: string;
|
|
805
806
|
};
|
|
806
807
|
export type AccountState = {
|
|
807
|
-
/**
|
|
808
|
+
/**
|
|
809
|
+
* Venue account mode when confirmed by the current account stream or read
|
|
810
|
+
* (Hyperliquid `userAbstraction`). Pass it to `calculateAccountSummary`.
|
|
811
|
+
*/
|
|
808
812
|
accountMode?: string;
|
|
809
813
|
/**
|
|
810
814
|
* Total USD equity on this venue — collateral + unrealized PnL. Live MTM.
|
|
811
|
-
* HL
|
|
815
|
+
* HL Unified / Portfolio Margin: spot USDC total
|
|
816
|
+
* HL Standard: marginSummary.accountValue + spot(USDC) − spot.hold
|
|
812
817
|
*/
|
|
813
818
|
totalBalance: string;
|
|
814
819
|
/**
|
|
815
820
|
* Max USD that can immediately collateralize a new position on this venue,
|
|
816
821
|
* with no internal transfer required.
|
|
817
|
-
* HL Unified:
|
|
822
|
+
* HL Unified / Portfolio Margin: spot USDC total − hold
|
|
818
823
|
* HL Standard: withdrawable
|
|
819
824
|
*/
|
|
820
825
|
spendableBalance: string;
|
|
@@ -824,7 +829,7 @@ export type AccountState = {
|
|
|
824
829
|
* contract guarantees HL's own abstraction (Unified) or the direct
|
|
825
830
|
* perps-clearinghouse (Standard) is what actually settles the
|
|
826
831
|
* withdraw — no client-side spot→perps sweep is performed.
|
|
827
|
-
* HL Unified
|
|
832
|
+
* HL Unified / Portfolio Margin: spot USDC total − hold (HL withdraw3 draws from the unified ledger server-side)
|
|
828
833
|
* HL Standard: withdrawable (perps-clearinghouse only; spot is a separate ledger)
|
|
829
834
|
*/
|
|
830
835
|
withdrawableBalance: string;
|
|
@@ -1093,6 +1098,14 @@ export type MarketInfo = {
|
|
|
1093
1098
|
marginMode?: 'strictIsolated' | 'noCross';
|
|
1094
1099
|
onlyIsolated?: true;
|
|
1095
1100
|
isDelisted?: true;
|
|
1101
|
+
/**
|
|
1102
|
+
* HyperLiquid margin tiers for `marginTableId`, lowest notional first, as
|
|
1103
|
+
* `resolveHyperLiquidMarginTiers` resolves them from the venue's `meta`.
|
|
1104
|
+
* Omitted when the table cannot be resolved, and on lists served from the
|
|
1105
|
+
* Terminal market snapshot; `getOrderCapabilities` always reads them from
|
|
1106
|
+
* the venue.
|
|
1107
|
+
*/
|
|
1108
|
+
marginTiers?: HyperLiquidMarginTier[];
|
|
1096
1109
|
minimumOrderSize?: number;
|
|
1097
1110
|
providerId?: PerpsProviderType;
|
|
1098
1111
|
/** Cross-venue identity from the Terminal snapshot. */
|
|
@@ -1252,6 +1265,22 @@ export type PerpsMarketData = {
|
|
|
1252
1265
|
marketKey?: string;
|
|
1253
1266
|
/** Venue price divided by canonical market price. */
|
|
1254
1267
|
priceScale?: number;
|
|
1268
|
+
/**
|
|
1269
|
+
* Unformatted numbers behind the display strings, which `sortMarkets` sorts
|
|
1270
|
+
* on. A value is absent when the venue did not report it.
|
|
1271
|
+
*/
|
|
1272
|
+
numericValues?: PerpsMarketNumericValues;
|
|
1273
|
+
};
|
|
1274
|
+
/**
|
|
1275
|
+
* Unformatted values of a {@link PerpsMarketData} row: `price` and USD
|
|
1276
|
+
* `volume` and `openInterest`, and `change24hPercent` in percent (`2.5` for
|
|
1277
|
+
* 2.5%).
|
|
1278
|
+
*/
|
|
1279
|
+
export type PerpsMarketNumericValues = {
|
|
1280
|
+
price?: number;
|
|
1281
|
+
change24hPercent?: number;
|
|
1282
|
+
volume?: number;
|
|
1283
|
+
openInterest?: number;
|
|
1255
1284
|
};
|
|
1256
1285
|
/** One display row with its original venue rows, preferred venue first. */
|
|
1257
1286
|
export type GroupedPerpsMarket = PerpsMarketData & {
|
|
@@ -1659,7 +1688,17 @@ export type PriceUpdate = {
|
|
|
1659
1688
|
bestBid?: string;
|
|
1660
1689
|
bestAsk?: string;
|
|
1661
1690
|
spread?: string;
|
|
1691
|
+
/**
|
|
1692
|
+
* The venue's mark price (HyperLiquid `markPx`, Lighter `mark_price`): the
|
|
1693
|
+
* price unrealized PnL, margin and liquidation use. Not the oracle price.
|
|
1694
|
+
*/
|
|
1662
1695
|
markPrice?: string;
|
|
1696
|
+
/**
|
|
1697
|
+
* The venue's oracle price (HyperLiquid `oraclePx`, Lighter
|
|
1698
|
+
* `index_price`): the reference for the limit-price deviation check
|
|
1699
|
+
* (`isPriceOutsideDeviationBand`) and `isTradable`.
|
|
1700
|
+
*/
|
|
1701
|
+
oraclePrice?: string;
|
|
1663
1702
|
funding?: number;
|
|
1664
1703
|
openInterest?: number;
|
|
1665
1704
|
volume24h?: number;
|
|
@@ -1841,6 +1880,11 @@ export type GetSupportedPathsParams = {
|
|
|
1841
1880
|
export type GetAvailableDexsParams = Record<string, never>;
|
|
1842
1881
|
/** Field to sort markets by. */
|
|
1843
1882
|
export type SortField = 'volume' | 'priceChange' | 'fundingRate' | 'openInterest';
|
|
1883
|
+
/**
|
|
1884
|
+
* Field `sortMarkets` sorts on: a {@link SortField}, the current price, or the
|
|
1885
|
+
* market name.
|
|
1886
|
+
*/
|
|
1887
|
+
export type MarketSortField = SortField | 'price' | 'name';
|
|
1844
1888
|
/** Direction for market sorting. */
|
|
1845
1889
|
export type SortDirection = 'asc' | 'desc';
|
|
1846
1890
|
export type GetMarketsParams = {
|
|
@@ -1849,6 +1893,7 @@ export type GetMarketsParams = {
|
|
|
1849
1893
|
skipFilters?: boolean;
|
|
1850
1894
|
standalone?: boolean;
|
|
1851
1895
|
useTerminalApi?: boolean;
|
|
1896
|
+
skipCache?: boolean;
|
|
1852
1897
|
};
|
|
1853
1898
|
/**
|
|
1854
1899
|
* Parameters for {@link PerpsController.getMarketDataWithPrices}.
|
|
@@ -1859,7 +1904,7 @@ export type GetMarketDataWithPricesParams = {
|
|
|
1859
1904
|
standalone?: boolean;
|
|
1860
1905
|
categories?: MarketTypeFilter[];
|
|
1861
1906
|
excludeSymbols?: string[];
|
|
1862
|
-
sortBy?:
|
|
1907
|
+
sortBy?: MarketSortField;
|
|
1863
1908
|
direction?: SortDirection;
|
|
1864
1909
|
limit?: number;
|
|
1865
1910
|
useTerminalApi?: boolean;
|
|
@@ -1867,7 +1912,10 @@ export type GetMarketDataWithPricesParams = {
|
|
|
1867
1912
|
export type SubscribePricesParams = {
|
|
1868
1913
|
symbols: string[];
|
|
1869
1914
|
callback: (prices: PriceUpdate[]) => void;
|
|
1915
|
+
/** Minimum time between deliveries to this subscriber; other subscribers of the same channel are unaffected. */
|
|
1870
1916
|
throttleMs?: number;
|
|
1917
|
+
/** Called when the stream moves to another provider or account; the next delivery is the new context's data. */
|
|
1918
|
+
onReset?: () => void;
|
|
1871
1919
|
includeOrderBook?: boolean;
|
|
1872
1920
|
includeMarketData?: boolean;
|
|
1873
1921
|
};
|
|
@@ -1878,6 +1926,10 @@ export type SubscribePositionsParams = {
|
|
|
1878
1926
|
includeSnapshotStatus?: boolean;
|
|
1879
1927
|
accountId?: CaipAccountId;
|
|
1880
1928
|
includeHistory?: boolean;
|
|
1929
|
+
/** Minimum time between deliveries to this subscriber; other subscribers of the same channel are unaffected. */
|
|
1930
|
+
throttleMs?: number;
|
|
1931
|
+
/** Called when the stream moves to another provider or account; the next delivery is the new context's data. */
|
|
1932
|
+
onReset?: () => void;
|
|
1881
1933
|
};
|
|
1882
1934
|
export type SubscribeOrderFillsParams = {
|
|
1883
1935
|
/**
|
|
@@ -1889,6 +1941,10 @@ export type SubscribeOrderFillsParams = {
|
|
|
1889
1941
|
callback: (fills: OrderFill[], isSnapshot?: boolean, sourceProviderId?: PerpsProviderType) => void;
|
|
1890
1942
|
accountId?: CaipAccountId;
|
|
1891
1943
|
since?: number;
|
|
1944
|
+
/** Minimum time between deliveries to this subscriber; other subscribers of the same channel are unaffected. */
|
|
1945
|
+
throttleMs?: number;
|
|
1946
|
+
/** Called when the stream moves to another provider or account; the next delivery is the new context's data. */
|
|
1947
|
+
onReset?: () => void;
|
|
1892
1948
|
};
|
|
1893
1949
|
export type SubscribeOrdersParams = {
|
|
1894
1950
|
/**
|
|
@@ -1903,6 +1959,10 @@ export type SubscribeOrdersParams = {
|
|
|
1903
1959
|
includeSnapshotStatus?: boolean;
|
|
1904
1960
|
accountId?: CaipAccountId;
|
|
1905
1961
|
includeHistory?: boolean;
|
|
1962
|
+
/** Minimum time between deliveries to this subscriber; other subscribers of the same channel are unaffected. */
|
|
1963
|
+
throttleMs?: number;
|
|
1964
|
+
/** Called when the stream moves to another provider or account; the next delivery is the new context's data. */
|
|
1965
|
+
onReset?: () => void;
|
|
1906
1966
|
};
|
|
1907
1967
|
export type SubscribeTwapOrdersParams = {
|
|
1908
1968
|
/**
|
|
@@ -1921,6 +1981,10 @@ export type SubscribeTwapOrdersParams = {
|
|
|
1921
1981
|
*/
|
|
1922
1982
|
callback: (twapOrders: TwapOrder[], isSnapshot?: boolean) => void;
|
|
1923
1983
|
accountId?: CaipAccountId;
|
|
1984
|
+
/** Minimum time between deliveries to this subscriber; other subscribers of the same channel are unaffected. */
|
|
1985
|
+
throttleMs?: number;
|
|
1986
|
+
/** Called when the stream moves to another provider or account; the next delivery is the new context's data. */
|
|
1987
|
+
onReset?: () => void;
|
|
1924
1988
|
};
|
|
1925
1989
|
/** Subscription to the merged live TWAP list. */
|
|
1926
1990
|
export type SubscribeLiveTwapOrdersParams = {
|
|
@@ -1932,6 +1996,10 @@ export type SubscribeLiveTwapOrdersParams = {
|
|
|
1932
1996
|
callback: (twapOrders: TwapOrder[]) => void;
|
|
1933
1997
|
/** Called when a read fails; the list keeps its last state. */
|
|
1934
1998
|
onError?: (error: Error) => void;
|
|
1999
|
+
/** Minimum time between deliveries to this subscriber; other subscribers of the same channel are unaffected. */
|
|
2000
|
+
throttleMs?: number;
|
|
2001
|
+
/** Called when the stream moves to another provider or account; the next delivery is the new context's data. */
|
|
2002
|
+
onReset?: () => void;
|
|
1935
2003
|
};
|
|
1936
2004
|
/** Subscription to the live chase lists. */
|
|
1937
2005
|
export type SubscribeChaseOrderListsParams = {
|
|
@@ -1939,6 +2007,10 @@ export type SubscribeChaseOrderListsParams = {
|
|
|
1939
2007
|
callback: (lists: ChaseOrderLists) => void;
|
|
1940
2008
|
/** Called when a read fails; the lists keep their last state. */
|
|
1941
2009
|
onError?: (error: Error) => void;
|
|
2010
|
+
/** Minimum time between deliveries to this subscriber; other subscribers of the same channel are unaffected. */
|
|
2011
|
+
throttleMs?: number;
|
|
2012
|
+
/** Called when the stream moves to another provider or account; the next delivery is the new context's data. */
|
|
2013
|
+
onReset?: () => void;
|
|
1942
2014
|
};
|
|
1943
2015
|
/**
|
|
1944
2016
|
* USD amount the venue lets the account commit to a new order on one market,
|
|
@@ -1983,6 +2055,10 @@ export type SubscribeAvailableToTradeParams = {
|
|
|
1983
2055
|
* WebSocket transport is replaced.
|
|
1984
2056
|
*/
|
|
1985
2057
|
onError?: (error: Error) => void;
|
|
2058
|
+
/** Minimum time between deliveries to this subscriber; other subscribers of the same channel are unaffected. */
|
|
2059
|
+
throttleMs?: number;
|
|
2060
|
+
/** Called when the stream moves to another provider or account; the next delivery is the new context's data. */
|
|
2061
|
+
onReset?: () => void;
|
|
1986
2062
|
};
|
|
1987
2063
|
export type SubscribeAccountParams = {
|
|
1988
2064
|
/** Aggregated streams include completeness metadata even when account is null,
|
|
@@ -1997,6 +2073,10 @@ export type SubscribeAccountParams = {
|
|
|
1997
2073
|
* it keep each venue's lenient default.
|
|
1998
2074
|
*/
|
|
1999
2075
|
requireCompleteAccount?: boolean;
|
|
2076
|
+
/** Minimum time between deliveries to this subscriber; other subscribers of the same channel are unaffected. */
|
|
2077
|
+
throttleMs?: number;
|
|
2078
|
+
/** Called when the stream moves to another provider or account; the next delivery is the new context's data. */
|
|
2079
|
+
onReset?: () => void;
|
|
2000
2080
|
};
|
|
2001
2081
|
export type SubscribeOICapsParams = {
|
|
2002
2082
|
callback: (caps: string[]) => void;
|
|
@@ -2007,6 +2087,10 @@ export type SubscribeOICapsParams = {
|
|
|
2007
2087
|
* supply one to pin the stream to that venue.
|
|
2008
2088
|
*/
|
|
2009
2089
|
providerId?: PerpsProviderType;
|
|
2090
|
+
/** Minimum time between deliveries to this subscriber; other subscribers of the same channel are unaffected. */
|
|
2091
|
+
throttleMs?: number;
|
|
2092
|
+
/** Called when the stream moves to another provider or account; the next delivery is the new context's data. */
|
|
2093
|
+
onReset?: () => void;
|
|
2010
2094
|
};
|
|
2011
2095
|
export type SubscribeCandlesParams = {
|
|
2012
2096
|
symbol: string;
|
|
@@ -2021,6 +2105,10 @@ export type SubscribeCandlesParams = {
|
|
|
2021
2105
|
* list the same symbol and the data must come from a specific one.
|
|
2022
2106
|
*/
|
|
2023
2107
|
providerId?: PerpsProviderType;
|
|
2108
|
+
/** Minimum time between deliveries to this subscriber; other subscribers of the same channel are unaffected. */
|
|
2109
|
+
throttleMs?: number;
|
|
2110
|
+
/** Called when the stream moves to another provider or account; the next delivery is the new context's data. */
|
|
2111
|
+
onReset?: () => void;
|
|
2024
2112
|
};
|
|
2025
2113
|
/**
|
|
2026
2114
|
* One public trade on a market (any user's), the same shape for every
|
|
@@ -2077,6 +2165,10 @@ export type SubscribePublicTradesParams = {
|
|
|
2077
2165
|
callback: (trades: PublicTrade[]) => void;
|
|
2078
2166
|
/** Receives a failure to open the stream. */
|
|
2079
2167
|
onError?: (error: Error) => void;
|
|
2168
|
+
/** Minimum time between deliveries to this subscriber; other subscribers of the same channel are unaffected. */
|
|
2169
|
+
throttleMs?: number;
|
|
2170
|
+
/** Called when the stream moves to another provider or account; the next delivery is the new context's data. */
|
|
2171
|
+
onReset?: () => void;
|
|
2080
2172
|
};
|
|
2081
2173
|
/**
|
|
2082
2174
|
* Single price level in the order book
|
|
@@ -2138,6 +2230,49 @@ export type SubscribeOrderBookParams = {
|
|
|
2138
2230
|
callback: (orderBook: OrderBookData) => void;
|
|
2139
2231
|
/** Callback for errors */
|
|
2140
2232
|
onError?: (error: Error) => void;
|
|
2233
|
+
/** Minimum time between deliveries to this subscriber; other subscribers of the same channel are unaffected. */
|
|
2234
|
+
throttleMs?: number;
|
|
2235
|
+
/** Called when the stream moves to another provider or account; the next delivery is the new context's data. */
|
|
2236
|
+
onReset?: () => void;
|
|
2237
|
+
};
|
|
2238
|
+
/** A Cross order to estimate with `estimateCrossLiquidation`. */
|
|
2239
|
+
export type EstimateCrossLiquidationParams = {
|
|
2240
|
+
/** Venue market symbol. */
|
|
2241
|
+
symbol: string;
|
|
2242
|
+
/** Order direction. */
|
|
2243
|
+
direction: 'long' | 'short';
|
|
2244
|
+
/** Order size in base units, positive. */
|
|
2245
|
+
size: string;
|
|
2246
|
+
/** Expected fill or limit price, positive. */
|
|
2247
|
+
entryPrice: string;
|
|
2248
|
+
/** Cross leverage the order sets on the market. */
|
|
2249
|
+
leverage: number;
|
|
2250
|
+
/**
|
|
2251
|
+
* Fee the order pays in USD, taken from the Cross collateral at the fill.
|
|
2252
|
+
* Omit for an estimate without the fee. A negative or non-finite fee makes
|
|
2253
|
+
* the estimate `unavailable` (`missing_inputs`).
|
|
2254
|
+
*/
|
|
2255
|
+
feeAmountUsd?: number;
|
|
2256
|
+
/** Provider that would place the order when calculations are aggregated. */
|
|
2257
|
+
providerId?: PerpsProviderType;
|
|
2258
|
+
};
|
|
2259
|
+
/**
|
|
2260
|
+
* Liquidation price of the Cross position an order would leave. Never a
|
|
2261
|
+
* rejection: `none` means no price liquidates it at the account's collateral;
|
|
2262
|
+
* `unavailable` says why there is no estimate (`missing_inputs`: an order or
|
|
2263
|
+
* market input is invalid or unknown, or the order closes the position;
|
|
2264
|
+
* `account_unknown`: the account could not be read or changed during the
|
|
2265
|
+
* read; `provider`: the provider or account mode has no Cross estimate).
|
|
2266
|
+
*/
|
|
2267
|
+
export type CrossLiquidationEstimate = {
|
|
2268
|
+
status: 'price';
|
|
2269
|
+
price: string;
|
|
2270
|
+
} | {
|
|
2271
|
+
status: 'none';
|
|
2272
|
+
reason: 'covered_by_account';
|
|
2273
|
+
} | {
|
|
2274
|
+
status: 'unavailable';
|
|
2275
|
+
reason: 'missing_inputs' | 'account_unknown' | 'provider';
|
|
2141
2276
|
};
|
|
2142
2277
|
export type LiquidationPriceParams = {
|
|
2143
2278
|
entryPrice: number;
|
|
@@ -2159,7 +2294,10 @@ export type PositionModifyPreviewSource = Pick<Position, 'symbol' | 'size' | 'ma
|
|
|
2159
2294
|
*
|
|
2160
2295
|
* Isolated-margin previews model `updateLeverage` before placement: the venue
|
|
2161
2296
|
* keeps the existing margin and the order margins its own size at
|
|
2162
|
-
* `leverage`. Cross
|
|
2297
|
+
* `leverage`. Hyperliquid Cross previews margin the whole resulting position
|
|
2298
|
+
* at `leverage` and price liquidation against the account's Cross collateral
|
|
2299
|
+
* and the maintenance of every Cross position, starting from the position the
|
|
2300
|
+
* account holds when it can be read.
|
|
2163
2301
|
*/
|
|
2164
2302
|
export type PositionModifyPreviewParams = {
|
|
2165
2303
|
position: PositionModifyPreviewSource;
|
|
@@ -2175,16 +2313,17 @@ export type PositionModifyPreviewParams = {
|
|
|
2175
2313
|
*/
|
|
2176
2314
|
price: string;
|
|
2177
2315
|
/**
|
|
2178
|
-
*
|
|
2179
|
-
* order is margined at this leverage and the existing margin is kept.
|
|
2180
|
-
* the leverage the existing margin can cover, the venue rejects the
|
|
2181
|
-
* and the resulting margin and liquidation price are unavailable.
|
|
2316
|
+
* Leverage the provider will set on the asset before placing. Isolated:
|
|
2317
|
+
* the order is margined at this leverage and the existing margin is kept.
|
|
2318
|
+
* Below the leverage the existing margin can cover, the venue rejects the
|
|
2319
|
+
* change and the resulting margin and liquidation price are unavailable.
|
|
2320
|
+
* Cross: the whole resulting position is margined at this leverage.
|
|
2182
2321
|
*/
|
|
2183
2322
|
leverage: number;
|
|
2184
2323
|
reduceOnly?: boolean;
|
|
2185
2324
|
/**
|
|
2186
|
-
* Estimated trading fees in USD. Deducted from isolated margin
|
|
2187
|
-
* increases and flips. Omit when unknown: the resulting margin and
|
|
2325
|
+
* Estimated trading fees in USD. Deducted from isolated margin, or from
|
|
2326
|
+
* Cross collateral, on increases and flips. Omit when unknown: the resulting margin and
|
|
2188
2327
|
* liquidation price of an increase or flip are then unavailable. Pass 0
|
|
2189
2328
|
* only for a known zero fee.
|
|
2190
2329
|
*/
|
|
@@ -2195,15 +2334,23 @@ export type PositionModifyPreviewParams = {
|
|
|
2195
2334
|
*/
|
|
2196
2335
|
providerId?: PerpsProviderType;
|
|
2197
2336
|
};
|
|
2337
|
+
/**
|
|
2338
|
+
* Why a projected value is unavailable. `covered_by_account`: no price
|
|
2339
|
+
* liquidates the position at the account's collateral. `missing_inputs`: an
|
|
2340
|
+
* input the estimate needs is unknown.
|
|
2341
|
+
*/
|
|
2342
|
+
export type PositionPreviewUnavailableReason = 'covered_by_account' | 'missing_inputs';
|
|
2198
2343
|
/**
|
|
2199
2344
|
* Independently available numeric projection. Margin can be known when
|
|
2200
2345
|
* liquidation cannot (missing maintenance-tier data, or no liquidation risk).
|
|
2346
|
+
* Hyperliquid Cross liquidation previews set `reason`; other previews omit it.
|
|
2201
2347
|
*/
|
|
2202
2348
|
export type PositionPreviewValue = {
|
|
2203
2349
|
available: true;
|
|
2204
2350
|
value: number;
|
|
2205
2351
|
} | {
|
|
2206
2352
|
available: false;
|
|
2353
|
+
reason?: PositionPreviewUnavailableReason;
|
|
2207
2354
|
};
|
|
2208
2355
|
export type PositionModifyPreviewKind = 'increase' | 'decrease' | 'flip';
|
|
2209
2356
|
export type PositionModifyPreviewCurrent = {
|
|
@@ -2223,7 +2370,7 @@ export type PositionModifyPreviewOpen = {
|
|
|
2223
2370
|
* Effective isolated leverage, mark notional / resulting margin. Below the
|
|
2224
2371
|
* selected leverage when margin kept from before a leverage rise exceeds
|
|
2225
2372
|
* the new initial margin; the selected leverage when margin is
|
|
2226
|
-
* unavailable.
|
|
2373
|
+
* unavailable, and always for a Cross position.
|
|
2227
2374
|
*/
|
|
2228
2375
|
leverage: number;
|
|
2229
2376
|
margin: PositionPreviewValue;
|
|
@@ -2238,6 +2385,11 @@ export type PositionModifyPreviewFullClose = {
|
|
|
2238
2385
|
};
|
|
2239
2386
|
export type PositionModifyPreviewUnsupported = {
|
|
2240
2387
|
status: 'unsupported';
|
|
2388
|
+
/**
|
|
2389
|
+
* `cross_margin` comes only from `previewHyperLiquidIsolatedPositionModify`
|
|
2390
|
+
* given a Cross position; `previewPositionModify` projects Cross on
|
|
2391
|
+
* Hyperliquid.
|
|
2392
|
+
*/
|
|
2241
2393
|
reason: 'cross_margin' | 'provider';
|
|
2242
2394
|
};
|
|
2243
2395
|
export type PositionModifyPreviewNone = {
|
|
@@ -2296,6 +2448,203 @@ export type PerpsMarginModeLock = Readonly<{
|
|
|
2296
2448
|
providerId?: PerpsProviderType;
|
|
2297
2449
|
reason: MarginModeLockUnavailableReason;
|
|
2298
2450
|
}>;
|
|
2451
|
+
/** Isolated position whose margin adjustment limits are requested. */
|
|
2452
|
+
export type GetMarginAdjustmentLimitsParams = {
|
|
2453
|
+
/** Provider-specific market identifier, including any routing prefix. */
|
|
2454
|
+
symbol: string;
|
|
2455
|
+
providerId?: PerpsProviderType;
|
|
2456
|
+
};
|
|
2457
|
+
/**
|
|
2458
|
+
* Why margin adjustment limits cannot be reported: no isolated position on
|
|
2459
|
+
* the market, an account that changed or could not be read consistently, or
|
|
2460
|
+
* a provider (or account mode) that cannot answer.
|
|
2461
|
+
*/
|
|
2462
|
+
export type MarginAdjustmentLimitsUnavailableReason = 'no_isolated_position' | 'account_unknown' | 'provider';
|
|
2463
|
+
/**
|
|
2464
|
+
* Margin the venue lets an isolated position take in (`maxAdd`) and release
|
|
2465
|
+
* (`maxRemove`), in USD as decimal strings.
|
|
2466
|
+
*/
|
|
2467
|
+
export type MarginAdjustmentLimits = {
|
|
2468
|
+
status: 'available';
|
|
2469
|
+
maxAdd: string;
|
|
2470
|
+
maxRemove: string;
|
|
2471
|
+
} | {
|
|
2472
|
+
status: 'unavailable';
|
|
2473
|
+
reason: MarginAdjustmentLimitsUnavailableReason;
|
|
2474
|
+
};
|
|
2475
|
+
/**
|
|
2476
|
+
* Stream an isolated position's margin adjustment limits. The callback
|
|
2477
|
+
* receives the current limits at once, then each change.
|
|
2478
|
+
*/
|
|
2479
|
+
export type SubscribeMarginAdjustmentLimitsParams = GetMarginAdjustmentLimitsParams & {
|
|
2480
|
+
/** Receives the limits, or why they are unavailable. */
|
|
2481
|
+
callback: (limits: MarginAdjustmentLimits) => void;
|
|
2482
|
+
/** Receives a failure to open the stream. */
|
|
2483
|
+
onError?: (error: Error) => void;
|
|
2484
|
+
/** Minimum time between deliveries to this subscriber; other subscribers of the same channel are unaffected. */
|
|
2485
|
+
throttleMs?: number;
|
|
2486
|
+
/** Called when the stream moves to another provider or account; the next delivery is the new context's data. */
|
|
2487
|
+
onReset?: () => void;
|
|
2488
|
+
};
|
|
2489
|
+
/** Market (or every market, when `symbol` is omitted) whose metadata is requested. */
|
|
2490
|
+
export type GetMarketMetaParams = {
|
|
2491
|
+
/** Provider-specific market identifier, including any routing prefix. */
|
|
2492
|
+
symbol?: string;
|
|
2493
|
+
providerId?: PerpsProviderType;
|
|
2494
|
+
};
|
|
2495
|
+
/** Venue metadata for one market, from the provider's session cache. */
|
|
2496
|
+
export type PerpsMarketMeta = {
|
|
2497
|
+
/** Market identifier, including any routing prefix. */
|
|
2498
|
+
symbol: string;
|
|
2499
|
+
/** Hyperliquid margin tiers, ascending; null when the venue has none. */
|
|
2500
|
+
marginTiers: HyperLiquidMarginTier[] | null;
|
|
2501
|
+
isDelisted: boolean;
|
|
2502
|
+
maxLeverage: number;
|
|
2503
|
+
/** Whether the market rejects Cross margin. */
|
|
2504
|
+
onlyIsolated: boolean;
|
|
2505
|
+
};
|
|
2506
|
+
/**
|
|
2507
|
+
* Stream every market's metadata (margin tiers, delisting, max leverage,
|
|
2508
|
+
* Cross support). The callback receives the provider's current list at once,
|
|
2509
|
+
* then a new list whenever the controller refreshes its market data.
|
|
2510
|
+
*/
|
|
2511
|
+
export type SubscribeMarketMetaParams = {
|
|
2512
|
+
/** Provider whose markets are streamed; defaults to the active route. */
|
|
2513
|
+
providerId?: PerpsProviderType;
|
|
2514
|
+
/** Receives the full market list; never an empty list for a failed read. */
|
|
2515
|
+
callback: (markets: PerpsMarketMeta[]) => void;
|
|
2516
|
+
/** Receives a failed read; the last list stays current. */
|
|
2517
|
+
onError?: (error: Error) => void;
|
|
2518
|
+
/** Minimum time between deliveries to this subscriber; other subscribers of the same channel are unaffected. */
|
|
2519
|
+
throttleMs?: number;
|
|
2520
|
+
/** Called when the stream moves to another provider or account; the next delivery is the new context's data. */
|
|
2521
|
+
onReset?: () => void;
|
|
2522
|
+
};
|
|
2523
|
+
/**
|
|
2524
|
+
* Stream the round trip of the provider's WebSocket keepalive. The callback
|
|
2525
|
+
* receives the last measured value at once when there is one, then each new
|
|
2526
|
+
* measurement.
|
|
2527
|
+
*/
|
|
2528
|
+
export type SubscribeConnectionLatencyParams = {
|
|
2529
|
+
/** Provider whose connection is measured; defaults to the active route. */
|
|
2530
|
+
providerId?: PerpsProviderType;
|
|
2531
|
+
/** Receives each round trip in whole milliseconds. */
|
|
2532
|
+
callback: (latencyMs: number) => void;
|
|
2533
|
+
/** Receives a failure to open the stream. */
|
|
2534
|
+
onError?: (error: Error) => void;
|
|
2535
|
+
/** Minimum time between deliveries to this subscriber; other subscribers of the same channel are unaffected. */
|
|
2536
|
+
throttleMs?: number;
|
|
2537
|
+
/** Called when the stream moves to another provider or account; the next delivery is the new context's data. */
|
|
2538
|
+
onReset?: () => void;
|
|
2539
|
+
};
|
|
2540
|
+
/**
|
|
2541
|
+
* A market's post-discount fee rates: what `calculateFees` returns for a
|
|
2542
|
+
* taker fill (`isMaker: false`) and a maker fill (`isMaker: true`).
|
|
2543
|
+
*/
|
|
2544
|
+
export type PerpsFeeRates = {
|
|
2545
|
+
/** Market the rates apply to. */
|
|
2546
|
+
symbol: string;
|
|
2547
|
+
/** The `calculateFees` result for a taker fill. */
|
|
2548
|
+
taker: FeeCalculationResult;
|
|
2549
|
+
/** The `calculateFees` result for a maker fill. */
|
|
2550
|
+
maker: FeeCalculationResult;
|
|
2551
|
+
};
|
|
2552
|
+
/**
|
|
2553
|
+
* Stream a market's fee rates. The callback receives one read at once, then a
|
|
2554
|
+
* new read after the account's own fills (its volume tier can change), an
|
|
2555
|
+
* account switch, or `invalidateSubscriptionBenefits`. There is no timer.
|
|
2556
|
+
*/
|
|
2557
|
+
export type SubscribeFeeRatesParams = {
|
|
2558
|
+
/** Market, including any routing prefix. */
|
|
2559
|
+
symbol: string;
|
|
2560
|
+
/**
|
|
2561
|
+
* Order type both rates are priced for. Omitted, the taker rate is priced
|
|
2562
|
+
* as `market` and the maker rate as `limit`.
|
|
2563
|
+
*/
|
|
2564
|
+
orderType?: OrderType;
|
|
2565
|
+
/** Provider whose fees are read; defaults to the active route. */
|
|
2566
|
+
providerId?: PerpsProviderType;
|
|
2567
|
+
/** Account whose fills trigger a re-read; defaults to the selected account. */
|
|
2568
|
+
accountId?: CaipAccountId;
|
|
2569
|
+
/** Receives the rates; unchanged reads are not delivered again. */
|
|
2570
|
+
callback: (rates: PerpsFeeRates) => void;
|
|
2571
|
+
/** Receives a failed read; the last rates stay current. */
|
|
2572
|
+
onError?: (error: Error) => void;
|
|
2573
|
+
/** Minimum time between deliveries to this subscriber; other subscribers of the same channel are unaffected. */
|
|
2574
|
+
throttleMs?: number;
|
|
2575
|
+
/** Called when the stream moves to another provider or account; the next delivery is the new context's data. */
|
|
2576
|
+
onReset?: () => void;
|
|
2577
|
+
};
|
|
2578
|
+
/**
|
|
2579
|
+
* Whether an account's trading agent is valid for the venue:
|
|
2580
|
+
* - `not_required`: the venue, or this host, signs trades without an agent.
|
|
2581
|
+
* - `valid`: the venue lists the agent; `validUntil` is its expiry in epoch
|
|
2582
|
+
* milliseconds, or null when it does not expire.
|
|
2583
|
+
* - `invalid`: `no_agent` (none is set or resolved for the account),
|
|
2584
|
+
* `not_approved` (the venue does not list it), `expired` (listed past its
|
|
2585
|
+
* `validUntil` by this device's clock) or `rejected` (the venue refused a
|
|
2586
|
+
* request it signed).
|
|
2587
|
+
* - `unknown`: the account or the venue's agent list could not be read.
|
|
2588
|
+
*/
|
|
2589
|
+
export type PerpsTradingAgentValidity = {
|
|
2590
|
+
status: 'not_required';
|
|
2591
|
+
} | {
|
|
2592
|
+
status: 'valid';
|
|
2593
|
+
agentAddress: Hex;
|
|
2594
|
+
validUntil: number | null;
|
|
2595
|
+
} | {
|
|
2596
|
+
status: 'invalid';
|
|
2597
|
+
reason: 'no_agent' | 'not_approved' | 'expired' | 'rejected';
|
|
2598
|
+
agentAddress?: Hex;
|
|
2599
|
+
} | {
|
|
2600
|
+
status: 'unknown';
|
|
2601
|
+
reason: 'account_unknown' | 'read_failed';
|
|
2602
|
+
};
|
|
2603
|
+
/** Stream whether an account's trading agent is valid for the venue. */
|
|
2604
|
+
export type SubscribeTradingAgentValidityParams = {
|
|
2605
|
+
/** Account to check; defaults to the selected account, following switches. */
|
|
2606
|
+
accountId?: CaipAccountId;
|
|
2607
|
+
/** Provider whose agent is checked; defaults to the active route. */
|
|
2608
|
+
providerId?: PerpsProviderType;
|
|
2609
|
+
/** Receives the validity; unchanged values are not delivered again. */
|
|
2610
|
+
callback: (validity: PerpsTradingAgentValidity) => void;
|
|
2611
|
+
/** Receives a failure to open the stream. */
|
|
2612
|
+
onError?: (error: Error) => void;
|
|
2613
|
+
/** Minimum time between deliveries to this subscriber; other subscribers of the same channel are unaffected. */
|
|
2614
|
+
throttleMs?: number;
|
|
2615
|
+
/** Called when the stream moves to another provider or account; the next delivery is the new context's data. */
|
|
2616
|
+
onReset?: () => void;
|
|
2617
|
+
};
|
|
2618
|
+
/** Parameters of each `PerpsController.subscribeTo*` stream, by stream name. */
|
|
2619
|
+
export type PerpsStreamParams = {
|
|
2620
|
+
account: SubscribeAccountParams;
|
|
2621
|
+
availableToTrade: SubscribeAvailableToTradeParams;
|
|
2622
|
+
candles: SubscribeCandlesParams;
|
|
2623
|
+
chaseOrderLists: SubscribeChaseOrderListsParams;
|
|
2624
|
+
connectionLatency: SubscribeConnectionLatencyParams;
|
|
2625
|
+
feeRates: SubscribeFeeRatesParams;
|
|
2626
|
+
liveTwapOrders: SubscribeLiveTwapOrdersParams;
|
|
2627
|
+
marginAdjustmentLimits: SubscribeMarginAdjustmentLimitsParams;
|
|
2628
|
+
marketMeta: SubscribeMarketMetaParams;
|
|
2629
|
+
oiCaps: SubscribeOICapsParams;
|
|
2630
|
+
orderBook: SubscribeOrderBookParams;
|
|
2631
|
+
orderFills: SubscribeOrderFillsParams;
|
|
2632
|
+
orders: SubscribeOrdersParams;
|
|
2633
|
+
positions: SubscribePositionsParams;
|
|
2634
|
+
prices: SubscribePricesParams;
|
|
2635
|
+
publicTrades: SubscribePublicTradesParams;
|
|
2636
|
+
tradingAgentValidity: SubscribeTradingAgentValidityParams;
|
|
2637
|
+
twapOrders: SubscribeTwapOrdersParams;
|
|
2638
|
+
};
|
|
2639
|
+
/** Name of a `PerpsController.subscribeTo*` stream. */
|
|
2640
|
+
export type PerpsStreamName = keyof PerpsStreamParams;
|
|
2641
|
+
/**
|
|
2642
|
+
* The parameters that pick a stream's channel: the `subscribeTo*` parameters
|
|
2643
|
+
* without callbacks and throttle.
|
|
2644
|
+
*/
|
|
2645
|
+
export type PerpsStreamSnapshotParams<Stream extends PerpsStreamName> = Omit<PerpsStreamParams[Stream], 'callback' | 'onError' | 'onReset' | 'throttleMs'>;
|
|
2646
|
+
/** The arguments a stream's callback last received. */
|
|
2647
|
+
export type PerpsStreamSnapshot<Stream extends PerpsStreamName> = Parameters<PerpsStreamParams[Stream]['callback']>;
|
|
2299
2648
|
/** Inputs for a provider-normalized Scale price ladder preview. */
|
|
2300
2649
|
export type GetScalePriceLadderParams = {
|
|
2301
2650
|
/** Market symbol, including its provider route when applicable. */
|
|
@@ -2376,9 +2725,10 @@ export type PerpsOrderLimits = Readonly<{
|
|
|
2376
2725
|
}>;
|
|
2377
2726
|
/**
|
|
2378
2727
|
* Furthest a limit price may sit from the oracle price, as a fraction
|
|
2379
|
-
* (0.95 = 95%): a price is rejected when
|
|
2380
|
-
*
|
|
2381
|
-
* with
|
|
2728
|
+
* (0.95 = 95%): a price `p` is rejected when
|
|
2729
|
+
* `|p - oracle| / oracle > maxOraclePriceDeviation`, the rule
|
|
2730
|
+
* `isMarketTradable` also applies. Check it with
|
|
2731
|
+
* `isPriceOutsideDeviationBand`.
|
|
2382
2732
|
*/
|
|
2383
2733
|
maxOraclePriceDeviation?: number;
|
|
2384
2734
|
}>;
|
|
@@ -2463,6 +2813,13 @@ type ReadyPerpsOrderCapabilities = Readonly<{
|
|
|
2463
2813
|
supportedMarginModes?: readonly MarginMode[];
|
|
2464
2814
|
/** Why a market that reports margin modes prohibits Cross. */
|
|
2465
2815
|
crossMarginUnavailableReason?: 'noCross' | 'strictIsolated' | 'isolatedOnly';
|
|
2816
|
+
/**
|
|
2817
|
+
* HyperLiquid margin tiers for the market, lowest notional first, read from
|
|
2818
|
+
* the venue's `meta` (`marginTableId` resolved against `marginTables`). Pass
|
|
2819
|
+
* them to the liquidation and margin estimates. Omitted when the venue does
|
|
2820
|
+
* not use tiers (Lighter) or the table cannot be resolved.
|
|
2821
|
+
*/
|
|
2822
|
+
marginTiers?: HyperLiquidMarginTier[];
|
|
2466
2823
|
/**
|
|
2467
2824
|
* Most take-profit and most stop-loss legs one order can attach
|
|
2468
2825
|
* (`OrderParams.takeProfitPrice` / `stopLossPrice`). Omitted means not
|
|
@@ -2873,6 +3230,45 @@ export type PerpsProvider = {
|
|
|
2873
3230
|
* @returns The current lock, or a typed unavailable result.
|
|
2874
3231
|
*/
|
|
2875
3232
|
getMarginModeLock?(params: GetMarginModeLockParams): Promise<PerpsMarginModeLock>;
|
|
3233
|
+
/**
|
|
3234
|
+
* Stream an isolated position's margin adjustment limits from the
|
|
3235
|
+
* provider's live account and position streams, without venue reads.
|
|
3236
|
+
* The callback receives the current limits at once, then each change.
|
|
3237
|
+
* Providers without it are reported as `unavailable`/`provider`.
|
|
3238
|
+
*
|
|
3239
|
+
* @param params - Market, optional route, callback and error handler.
|
|
3240
|
+
* @returns A cleanup function to unsubscribe.
|
|
3241
|
+
*/
|
|
3242
|
+
subscribeToMarginAdjustmentLimits?(params: SubscribeMarginAdjustmentLimitsParams): () => void;
|
|
3243
|
+
/**
|
|
3244
|
+
* Stream the round trip of the provider's WebSocket keepalive, in whole
|
|
3245
|
+
* milliseconds, measured on the keepalive the transport already sends.
|
|
3246
|
+
* Providers without one never call back.
|
|
3247
|
+
*
|
|
3248
|
+
* @param params - Callback and error handler.
|
|
3249
|
+
* @returns A cleanup function to unsubscribe.
|
|
3250
|
+
*/
|
|
3251
|
+
subscribeToConnectionLatency?(params: SubscribeConnectionLatencyParams): () => void;
|
|
3252
|
+
/**
|
|
3253
|
+
* Report whether the account's trading agent is valid for the venue. The
|
|
3254
|
+
* callback receives one read at once, then a new value on events only: an
|
|
3255
|
+
* agent set or cleared, a venue rejection of the agent, and the agent's
|
|
3256
|
+
* `validUntil` expiry (one timeout at the deadline). Providers without it
|
|
3257
|
+
* have no agent step, and the controller reports `not_required`.
|
|
3258
|
+
*
|
|
3259
|
+
* @param params - Optional account and route, callback and error handler.
|
|
3260
|
+
* @returns A cleanup function to unsubscribe.
|
|
3261
|
+
*/
|
|
3262
|
+
subscribeToTradingAgentValidity?(params: SubscribeTradingAgentValidityParams): () => void;
|
|
3263
|
+
/**
|
|
3264
|
+
* Return how much margin an isolated position can take in and release.
|
|
3265
|
+
* Providers may omit this hook; the controller then reports the limits as
|
|
3266
|
+
* unavailable.
|
|
3267
|
+
*
|
|
3268
|
+
* @param params - Market and optional provider route.
|
|
3269
|
+
* @returns The limits, or a typed unavailable result.
|
|
3270
|
+
*/
|
|
3271
|
+
getMarginAdjustmentLimits?(params: GetMarginAdjustmentLimitsParams): Promise<MarginAdjustmentLimits>;
|
|
2876
3272
|
/**
|
|
2877
3273
|
* Normalize a Scale ladder using the selected provider's venue rules.
|
|
2878
3274
|
*
|
|
@@ -3029,9 +3425,16 @@ export type PerpsProvider = {
|
|
|
3029
3425
|
* Read-only projection of the position that would remain after the proposed
|
|
3030
3426
|
* order. Isolated-margin venues apply selected leverage to the whole
|
|
3031
3427
|
* resulting position and use the maintenance tier at liquidation notional.
|
|
3032
|
-
*
|
|
3428
|
+
* Hyperliquid projects Cross positions too; `reason: 'cross_margin'` is no
|
|
3429
|
+
* longer returned by it.
|
|
3033
3430
|
*/
|
|
3034
3431
|
previewPositionModify(params: PositionModifyPreviewParams): Promise<PositionModifyPreviewResult>;
|
|
3432
|
+
/**
|
|
3433
|
+
* Liquidation price of the Cross position an order would leave, as a typed
|
|
3434
|
+
* result that never rejects. Optional: a provider without it is treated as
|
|
3435
|
+
* `{ status: 'unavailable', reason: 'provider' }`.
|
|
3436
|
+
*/
|
|
3437
|
+
estimateCrossLiquidation?(params: EstimateCrossLiquidationParams): Promise<CrossLiquidationEstimate>;
|
|
3035
3438
|
subscribeToPrices(params: SubscribePricesParams): () => void;
|
|
3036
3439
|
subscribeToPositions(params: SubscribePositionsParams): () => void;
|
|
3037
3440
|
subscribeToOrderFills(params: SubscribeOrderFillsParams): () => void;
|
|
@@ -3371,7 +3774,15 @@ export type PerpsDebugLogger = {
|
|
|
3371
3774
|
* - Extension: Implement with whatever streaming solution they use
|
|
3372
3775
|
*/
|
|
3373
3776
|
export type PerpsStreamManager = {
|
|
3777
|
+
/**
|
|
3778
|
+
* @deprecated Core pauses its own stream channels. Still called for one
|
|
3779
|
+
* release so a client-side stream manager keeps working.
|
|
3780
|
+
*/
|
|
3374
3781
|
pauseChannel(channel: string): void;
|
|
3782
|
+
/**
|
|
3783
|
+
* @deprecated Core resumes its own stream channels. Still called for one
|
|
3784
|
+
* release so a client-side stream manager keeps working.
|
|
3785
|
+
*/
|
|
3375
3786
|
resumeChannel(channel: string): void;
|
|
3376
3787
|
clearAllChannels(): void;
|
|
3377
3788
|
};
|
|
@@ -3613,6 +4024,12 @@ export type PerpsPlatformDependencies = {
|
|
|
3613
4024
|
metrics: PerpsMetrics;
|
|
3614
4025
|
performance: PerpsPerformance;
|
|
3615
4026
|
tracer: PerpsTracer;
|
|
4027
|
+
/**
|
|
4028
|
+
* @deprecated Core's stream channels pause, rebind and reopen themselves
|
|
4029
|
+
* (`PerpsController.resubscribeStreams` replaces a client-side reconnect).
|
|
4030
|
+
* Still called for one release; a client without its own stream manager
|
|
4031
|
+
* can pass no-ops.
|
|
4032
|
+
*/
|
|
3616
4033
|
streamManager: PerpsStreamManager;
|
|
3617
4034
|
featureFlags: {
|
|
3618
4035
|
/**
|