@lifi/perps-sdk 33.1.0 → 33.2.0
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/README.md +85 -3
- package/dist/cjs/index.d.ts +8 -3
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +16 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/math/fills.d.ts +2 -0
- package/dist/cjs/math/fills.d.ts.map +1 -1
- package/dist/cjs/math/fills.js +77 -16
- package/dist/cjs/math/fills.js.map +1 -1
- package/dist/cjs/math/funding.d.ts +4 -0
- package/dist/cjs/math/funding.d.ts.map +1 -0
- package/dist/cjs/math/funding.js +17 -0
- package/dist/cjs/math/funding.js.map +1 -0
- package/dist/cjs/math/position.d.ts +1 -0
- package/dist/cjs/math/position.d.ts.map +1 -1
- package/dist/cjs/math/position.js +10 -9
- package/dist/cjs/math/position.js.map +1 -1
- package/dist/cjs/services/getFundingAverages.d.ts +9 -0
- package/dist/cjs/services/getFundingAverages.d.ts.map +1 -0
- package/dist/cjs/services/getFundingAverages.js +12 -0
- package/dist/cjs/services/getFundingAverages.js.map +1 -0
- package/dist/cjs/services/getFundingHistory.d.ts +10 -0
- package/dist/cjs/services/getFundingHistory.d.ts.map +1 -0
- package/dist/cjs/services/getFundingHistory.js +13 -0
- package/dist/cjs/services/getFundingHistory.js.map +1 -0
- package/dist/cjs/transport/fetchWithRetry.d.ts +1 -0
- package/dist/cjs/transport/fetchWithRetry.d.ts.map +1 -1
- package/dist/cjs/transport/fetchWithRetry.js +5 -1
- package/dist/cjs/transport/fetchWithRetry.js.map +1 -1
- package/dist/cjs/transport/request.d.ts.map +1 -1
- package/dist/cjs/transport/request.js +26 -23
- package/dist/cjs/transport/request.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/websocket/WsProviderBase.d.ts +4 -1
- package/dist/cjs/websocket/WsProviderBase.d.ts.map +1 -1
- package/dist/cjs/websocket/WsProviderBase.js +35 -2
- package/dist/cjs/websocket/WsProviderBase.js.map +1 -1
- package/dist/cjs/websocket/wsLog.d.ts +1 -0
- package/dist/cjs/websocket/wsLog.d.ts.map +1 -1
- package/dist/cjs/websocket/wsLog.js +3 -0
- package/dist/cjs/websocket/wsLog.js.map +1 -1
- package/dist/esm/index.d.ts +8 -3
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +6 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/math/fills.d.ts +26 -0
- package/dist/esm/math/fills.d.ts.map +1 -1
- package/dist/esm/math/fills.js +103 -15
- package/dist/esm/math/fills.js.map +1 -1
- package/dist/esm/math/funding.d.ts +16 -0
- package/dist/esm/math/funding.d.ts.map +1 -0
- package/dist/esm/math/funding.js +25 -0
- package/dist/esm/math/funding.js.map +1 -0
- package/dist/esm/math/position.d.ts +1 -0
- package/dist/esm/math/position.d.ts.map +1 -1
- package/dist/esm/math/position.js +1 -1
- package/dist/esm/math/position.js.map +1 -1
- package/dist/esm/services/getFundingAverages.d.ts +22 -0
- package/dist/esm/services/getFundingAverages.d.ts.map +1 -0
- package/dist/esm/services/getFundingAverages.js +16 -0
- package/dist/esm/services/getFundingAverages.js.map +1 -0
- package/dist/esm/services/getFundingHistory.d.ts +24 -0
- package/dist/esm/services/getFundingHistory.d.ts.map +1 -0
- package/dist/esm/services/getFundingHistory.js +17 -0
- package/dist/esm/services/getFundingHistory.js.map +1 -0
- package/dist/esm/transport/fetchWithRetry.d.ts +9 -0
- package/dist/esm/transport/fetchWithRetry.d.ts.map +1 -1
- package/dist/esm/transport/fetchWithRetry.js +12 -1
- package/dist/esm/transport/fetchWithRetry.js.map +1 -1
- package/dist/esm/transport/request.d.ts.map +1 -1
- package/dist/esm/transport/request.js +29 -24
- package/dist/esm/transport/request.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/websocket/WsProviderBase.d.ts +24 -2
- package/dist/esm/websocket/WsProviderBase.d.ts.map +1 -1
- package/dist/esm/websocket/WsProviderBase.js +56 -2
- package/dist/esm/websocket/WsProviderBase.js.map +1 -1
- package/dist/esm/websocket/wsLog.d.ts +5 -0
- package/dist/esm/websocket/wsLog.d.ts.map +1 -1
- package/dist/esm/websocket/wsLog.js +7 -0
- package/dist/esm/websocket/wsLog.js.map +1 -1
- package/dist/types/index.d.ts +8 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/math/fills.d.ts +26 -0
- package/dist/types/math/fills.d.ts.map +1 -1
- package/dist/types/math/funding.d.ts +16 -0
- package/dist/types/math/funding.d.ts.map +1 -0
- package/dist/types/math/position.d.ts +1 -0
- package/dist/types/math/position.d.ts.map +1 -1
- package/dist/types/services/getFundingAverages.d.ts +22 -0
- package/dist/types/services/getFundingAverages.d.ts.map +1 -0
- package/dist/types/services/getFundingHistory.d.ts +24 -0
- package/dist/types/services/getFundingHistory.d.ts.map +1 -0
- package/dist/types/transport/fetchWithRetry.d.ts +9 -0
- package/dist/types/transport/fetchWithRetry.d.ts.map +1 -1
- package/dist/types/transport/request.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/websocket/WsProviderBase.d.ts +24 -2
- package/dist/types/websocket/WsProviderBase.d.ts.map +1 -1
- package/dist/types/websocket/wsLog.d.ts +5 -0
- package/dist/types/websocket/wsLog.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +16 -1
- package/src/math/fills.ts +141 -14
- package/src/math/funding.ts +43 -0
- package/src/math/position.ts +1 -1
- package/src/services/getFundingAverages.ts +39 -0
- package/src/services/getFundingHistory.ts +45 -0
- package/src/transport/fetchWithRetry.ts +18 -1
- package/src/transport/request.ts +35 -30
- package/src/version.ts +1 -1
- package/src/websocket/WsProviderBase.ts +70 -6
- package/src/websocket/wsLog.ts +10 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../../../src/math/position.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B,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MACA,CAAA;AAElE;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CA4D1D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,MAAM,GAChB,QAAQ,CAuBV"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { FundingAveragesResponse } from '@lifi/perps-types';
|
|
2
|
+
import type { SDKRequestOptions } from '../types/config.js';
|
|
3
|
+
import type { PerpsSDKClient } from '../types/provider.js';
|
|
4
|
+
/**
|
|
5
|
+
* Parameters for {@link getFundingAverages}.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface GetFundingAveragesParams {
|
|
10
|
+
provider: string;
|
|
11
|
+
/** Optional filter of opaque `Market.id`s (not display symbols). */
|
|
12
|
+
marketIds?: string[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Get the settled funding averages (8h, 24h, 3d, 7d) for markets, optionally
|
|
16
|
+
* filtered by `Market.id`. The rates are raw hourly fractions, not an APR.
|
|
17
|
+
*
|
|
18
|
+
* @throws {PerpsError} On backend error responses, network, or parsing errors.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export declare function getFundingAverages(client: PerpsSDKClient, params: GetFundingAveragesParams, options?: SDKRequestOptions): Promise<FundingAveragesResponse>;
|
|
22
|
+
//# sourceMappingURL=getFundingAverages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFundingAverages.d.ts","sourceRoot":"","sources":["../../../src/services/getFundingAverages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAA;AAEhE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAE1D;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,MAAM,CAAA;IAChB,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;CACrB;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,cAAc,EACtB,MAAM,EAAE,wBAAwB,EAChC,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,uBAAuB,CAAC,CAWlC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { FundingHistoryRange, FundingHistoryResponse } from '@lifi/perps-types';
|
|
2
|
+
import type { SDKRequestOptions } from '../types/config.js';
|
|
3
|
+
import type { PerpsSDKClient } from '../types/provider.js';
|
|
4
|
+
/**
|
|
5
|
+
* Parameters for {@link getFundingHistory}.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface GetFundingHistoryParams {
|
|
10
|
+
provider: string;
|
|
11
|
+
/** Opaque provider `Market.id`, not a display symbol. */
|
|
12
|
+
marketId: string;
|
|
13
|
+
/** Pick from the provider's `Provider.fundingHistoryRanges`. */
|
|
14
|
+
range: FundingHistoryRange;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Get the settled funding history of a market, oldest bucket first. The rates
|
|
18
|
+
* are raw hourly fractions, not an APR.
|
|
19
|
+
*
|
|
20
|
+
* @throws {PerpsError} On backend, network, or parsing errors.
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export declare function getFundingHistory(client: PerpsSDKClient, params: GetFundingHistoryParams, options?: SDKRequestOptions): Promise<FundingHistoryResponse>;
|
|
24
|
+
//# sourceMappingURL=getFundingHistory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFundingHistory.d.ts","sourceRoot":"","sources":["../../../src/services/getFundingHistory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAE1D;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,MAAM,CAAA;IAChB,yDAAyD;IACzD,QAAQ,EAAE,MAAM,CAAA;IAChB,gEAAgE;IAChE,KAAK,EAAE,mBAAmB,CAAA;CAC3B;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,cAAc,EACtB,MAAM,EAAE,uBAAuB,EAC/B,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,sBAAsB,CAAC,CAYjC"}
|
|
@@ -21,6 +21,15 @@ export interface FetchWithRetryOptions {
|
|
|
21
21
|
* @public
|
|
22
22
|
*/
|
|
23
23
|
export declare function isAbortError(error: unknown): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* True when `error` is a caller cancellation of a request that `signal`
|
|
26
|
+
* controls: an {@link isAbortError} rejection, or the abort reason of `signal`,
|
|
27
|
+
* such as a custom `Error` or the `TimeoutError` of `AbortSignal.timeout()`.
|
|
28
|
+
* A different rejection stays a failure, also when `signal` aborts later.
|
|
29
|
+
*
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
export declare function isAbortRejection(error: unknown, signal: AbortSignal | undefined): boolean;
|
|
24
33
|
/**
|
|
25
34
|
* Wrap `fetch` with policy-driven retry. Honors `Retry-After` (when present
|
|
26
35
|
* and `respectRetryAfter` is true), otherwise falls back to exponential
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchWithRetry.d.ts","sourceRoot":"","sources":["../../../src/transport/fetchWithRetry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAuB,MAAM,kBAAkB,CAAA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|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../src/transport/request.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAI5E,OAAO,EAGL,KAAK,WAAW,EAEjB,MAAM,kBAAkB,CAAA;AAEzB;;;;GAIG;AACH,MAAM,WAAW,cAAe,SAAQ,WAAW;IACjD,+EAA+E;IAC/E,KAAK,CAAC,EAAE,WAAW,GAAG,KAAK,CAAA;IAC3B;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,wEAAwE;IACxE,UAAU,CAAC,EAAE,CACX,OAAO,EAAE,OAAO,EAChB,gBAAgB,EAAE,MAAM,EACxB,kBAAkB,EAAE,MAAM,KACvB,IAAI,CAAA;CACV;AAED;;;;;GAKG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC7B,MAAM,EAAE,eAAe,EACvB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,cAAmB,EAC5B,UAAU,CAAC,EAAE,iBAAiB,GAC7B,OAAO,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../src/transport/request.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAI5E,OAAO,EAGL,KAAK,WAAW,EAEjB,MAAM,kBAAkB,CAAA;AAEzB;;;;GAIG;AACH,MAAM,WAAW,cAAe,SAAQ,WAAW;IACjD,+EAA+E;IAC/E,KAAK,CAAC,EAAE,WAAW,GAAG,KAAK,CAAA;IAC3B;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,wEAAwE;IACxE,UAAU,CAAC,EAAE,CACX,OAAO,EAAE,OAAO,EAChB,gBAAgB,EAAE,MAAM,EACxB,kBAAkB,EAAE,MAAM,KACvB,IAAI,CAAA;CACV;AAED;;;;;GAKG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC7B,MAAM,EAAE,eAAe,EACvB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,cAAmB,EAC5B,UAAU,CAAC,EAAE,iBAAiB,GAC7B,OAAO,CAAC,CAAC,CAAC,CA4FZ;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,GAC5D,MAAM,CAWR"}
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type MarketContext, type Subscription, type SubscriptionEvent } from '@lifi/perps-types';
|
|
2
2
|
import type { ProviderGetQuoteParams, QuoteListener } from '../types/provider.js';
|
|
3
3
|
import type { ReconnectingWebSocket } from './ReconnectingWebSocket.js';
|
|
4
4
|
import type { SubscriptionErrorListener, SubscriptionListener, WsProvider, WsStatusListener } from './types.js';
|
|
@@ -19,6 +19,13 @@ export declare const WS_CHANNEL_TEARDOWN_LINGER_MS = 250;
|
|
|
19
19
|
* @public
|
|
20
20
|
*/
|
|
21
21
|
export declare const WS_MARKETS_CONTEXT_INTERVAL_MS = 1000;
|
|
22
|
+
/**
|
|
23
|
+
* Most time that a stream frame waits for an optional REST read before it
|
|
24
|
+
* emits without the result of that read.
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export declare const WS_FRAME_ENRICHMENT_TIMEOUT_MS = 5000;
|
|
22
29
|
/**
|
|
23
30
|
* Base for per-provider realtime transports. Owns the {@link
|
|
24
31
|
* ReconnectingWebSocket}, the fan-out lifecycle — ref-counted multi-listener
|
|
@@ -26,7 +33,9 @@ export declare const WS_MARKETS_CONTEXT_INTERVAL_MS = 1000;
|
|
|
26
33
|
* number of consumers (and StrictMode double-mounts) collapse to exactly one
|
|
27
34
|
* wire subscribe/unsubscribe per key, and the wire-subscription registry:
|
|
28
35
|
* subs recorded via {@link WsProviderBase.registerSub} are sent only while
|
|
29
|
-
* connected and replayed (failure-isolated) on every (re)open.
|
|
36
|
+
* connected and replayed (failure-isolated) on every (re)open. A replay send
|
|
37
|
+
* that throws `SetupRequired` or `Unauthorized` drops the sub and rejects the
|
|
38
|
+
* channels from {@link WsProviderBase.resolveChannelKeys}. Subclasses own
|
|
30
39
|
* everything wire-specific via {@link WsProviderBase.openChannel}, {@link
|
|
31
40
|
* WsProviderBase.sendSubscribe} and {@link WsProviderBase.handleMessage}:
|
|
32
41
|
* payload framing, frame validation and dispatch.
|
|
@@ -80,6 +89,13 @@ export declare abstract class WsProviderBase<TSub = unknown> implements WsProvid
|
|
|
80
89
|
protected emitMarketsContext(snapshot: () => Record<string, MarketContext>): void;
|
|
81
90
|
private deliverMarketsContext;
|
|
82
91
|
private cancelPendingMarketsContext;
|
|
92
|
+
/**
|
|
93
|
+
* Run an optional REST read that adds data to a frame. The `signal` aborts
|
|
94
|
+
* after {@link WS_FRAME_ENRICHMENT_TIMEOUT_MS}, and `read` must stop on it.
|
|
95
|
+
* A rejection or a timeout logs a warning and gives `undefined`, so a slow
|
|
96
|
+
* or failed read never drops or holds the frame.
|
|
97
|
+
*/
|
|
98
|
+
protected readFrameEnrichment<T>(label: string, read: (signal: AbortSignal) => Promise<T>): Promise<T | undefined>;
|
|
83
99
|
/**
|
|
84
100
|
* Tear `key` off the wire immediately if no listener holds it — i.e. it is
|
|
85
101
|
* lingering in the deferred-teardown window (or its open is still
|
|
@@ -99,6 +115,12 @@ export declare abstract class WsProviderBase<TSub = unknown> implements WsProvid
|
|
|
99
115
|
protected registerSub(key: string, state: TSub): Promise<void>;
|
|
100
116
|
/** Forget a wire subscription so the next (re)open no longer replays it. */
|
|
101
117
|
protected unregisterSub(key: string): void;
|
|
118
|
+
/**
|
|
119
|
+
* Channel keys that lose their stream when the replay of the wire sub
|
|
120
|
+
* `key` throws a credential error. The default treats the wire key as the
|
|
121
|
+
* channel key; a subclass whose registry uses other keys overrides it.
|
|
122
|
+
*/
|
|
123
|
+
protected resolveChannelKeys(key: string, _state: TSub): string[];
|
|
102
124
|
private replaySubs;
|
|
103
125
|
/** Venue-specific {@link WsProvider.subscribeQuote}; see `resolveSubscribeQuote`. */
|
|
104
126
|
abstract subscribeQuote(params: ProviderGetQuoteParams, onQuote: QuoteListener): Promise<() => void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WsProviderBase.d.ts","sourceRoot":"","sources":["../../../src/websocket/WsProviderBase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"WsProviderBase.d.ts","sourceRoot":"","sources":["../../../src/websocket/WsProviderBase.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACvB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,KAAK,EACV,sBAAsB,EACtB,aAAa,EACd,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,KAAK,EACV,yBAAyB,EACzB,oBAAoB,EACpB,UAAU,EACV,gBAAgB,EACjB,MAAM,YAAY,CAAA;AAGnB;;;;;;;;GAQG;AACH,eAAO,MAAM,6BAA6B,MAAM,CAAA;AAEhD;;;;;GAKG;AACH,eAAO,MAAM,8BAA8B,OAAQ,CAAA;AAEnD;;;;;GAKG;AACH,eAAO,MAAM,8BAA8B,OAAQ,CAAA;AAuBnD;;;;;;;;;;;;;;;;;;GAkBG;AACH,8BAAsB,cAAc,CAAC,IAAI,GAAG,OAAO,CAAE,YAAW,UAAU;IACxE,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,qBAAqB,CAAA;IAC7C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AAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAiBlD;;;;;;OAMG;cACa,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAepE,4EAA4E;IAC5E,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAI1C;;;;OAIG;IACH,SAAS,CAAC,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,GAAG,MAAM,EAAE;YAInD,UAAU;IAmCxB,qFAAqF;IACrF,QAAQ,CAAC,cAAc,CACrB,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,MAAM,IAAI,CAAC;IAEtB,iFAAiF;IACjF,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM;IAEnD;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC;IAEtE;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,EAAE,IAAI,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAEnE,6DAA6D;IAC7D,SAAS,CAAC,QAAQ,CAAC,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAEnD,mFAAmF;IACnF,SAAS,CAAC,OAAO,IAAI,IAAI;IAEzB,OAAO,CAAC,YAAY;YAYN,cAAc;IA6D5B,OAAO,CAAC,cAAc;CA6CvB"}
|
|
@@ -53,6 +53,11 @@ export declare const wsLog: {
|
|
|
53
53
|
* being skipped until the next cooldown-gated retry, so logged at `warn`.
|
|
54
54
|
*/
|
|
55
55
|
readonly marketRefreshFailure: (provider: string, error: unknown) => void;
|
|
56
|
+
/**
|
|
57
|
+
* An optional REST read for a frame rejected or timed out. The frame emits
|
|
58
|
+
* without the data of that read, so logged at `warn`.
|
|
59
|
+
*/
|
|
60
|
+
readonly enrichmentFailure: (provider: string, read: string, error: unknown) => void;
|
|
56
61
|
/**
|
|
57
62
|
* A consumer listener callback threw during fan-out. Logged and skipped so
|
|
58
63
|
* one bad listener cannot starve sibling listeners or break socket flow.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wsLog.d.ts","sourceRoot":"","sources":["../../../src/websocket/wsLog.ts"],"names":[],"mappings":"AAeA;;;;;;GAMG;AACH,eAAO,MAAM,KAAK;IAChB;;;OAGG;sCACoB,MAAM,OAAO,MAAM,KAAG,IAAI;IAGjD;;;;OAIG;wCACsB,MAAM,SAAS,OAAO,KAAG,IAAI;IAGtD;;;;;OAKG;qCACmB,MAAM,WAAW,MAAM,KAAG,IAAI;IAGpD;;;;OAIG;0CACwB,MAAM,WAAW,MAAM,SAAS,OAAO,KAAG,IAAI;IAMzE;;;;OAIG;uCACqB,MAAM,YAAY,MAAM,KAAG,IAAI;IAKvD;;;;OAIG;oCAES,MAAM,OACX,MAAM,SACJ,MAAM,SACN,OAAO,aACH,MAAM,KAChB,IAAI;IAaP;;;;OAIG;oCACkB,MAAM,OAAO,MAAM,UAAU,MAAM,KAAG,IAAI;IAO/D;;;OAGG;8CAC4B,MAAM,SAAS,OAAO,KAAG,IAAI;IAG5D;;;OAGG;yCAES,MAAM,gBACF,MAAM,SACb,OAAO,KACb,IAAI;IAMP;;;;OAIG;+CAC6B,MAAM,SAAS,OAAO,KAAG,IAAI;CAGrD,CAAA"}
|
|
1
|
+
{"version":3,"file":"wsLog.d.ts","sourceRoot":"","sources":["../../../src/websocket/wsLog.ts"],"names":[],"mappings":"AAeA;;;;;;GAMG;AACH,eAAO,MAAM,KAAK;IAChB;;;OAGG;sCACoB,MAAM,OAAO,MAAM,KAAG,IAAI;IAGjD;;;;OAIG;wCACsB,MAAM,SAAS,OAAO,KAAG,IAAI;IAGtD;;;;;OAKG;qCACmB,MAAM,WAAW,MAAM,KAAG,IAAI;IAGpD;;;;OAIG;0CACwB,MAAM,WAAW,MAAM,SAAS,OAAO,KAAG,IAAI;IAMzE;;;;OAIG;uCACqB,MAAM,YAAY,MAAM,KAAG,IAAI;IAKvD;;;;OAIG;oCAES,MAAM,OACX,MAAM,SACJ,MAAM,SACN,OAAO,aACH,MAAM,KAChB,IAAI;IAaP;;;;OAIG;oCACkB,MAAM,OAAO,MAAM,UAAU,MAAM,KAAG,IAAI;IAO/D;;;OAGG;8CAC4B,MAAM,SAAS,OAAO,KAAG,IAAI;IAG5D;;;OAGG;2CACyB,MAAM,QAAQ,MAAM,SAAS,OAAO,KAAG,IAAI;IAMvE;;;OAGG;yCAES,MAAM,gBACF,MAAM,SACb,OAAO,KACb,IAAI;IAMP;;;;OAIG;+CAC6B,MAAM,SAAS,OAAO,KAAG,IAAI;CAGrD,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/perps-sdk",
|
|
3
|
-
"version": "33.
|
|
3
|
+
"version": "33.2.0",
|
|
4
4
|
"description": "LI.FI Perps SDK for perpetuals trading",
|
|
5
5
|
"homepage": "https://github.com/lifinance/perps-sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@lifi/types": "^18.3.0",
|
|
46
46
|
"big.js": "^7.0.1",
|
|
47
47
|
"partysocket": "^1.1.19",
|
|
48
|
-
"@lifi/perps-types": "^29.
|
|
48
|
+
"@lifi/perps-types": "^29.1.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"viem": ">=2.57.11 <2.57.12"
|
package/src/index.ts
CHANGED
|
@@ -79,10 +79,16 @@ export {
|
|
|
79
79
|
rethrowWithKnownResults,
|
|
80
80
|
} from './errors/PerpsExecutionError.js'
|
|
81
81
|
export {
|
|
82
|
+
buildFill,
|
|
82
83
|
calculateAverageFillPrice,
|
|
84
|
+
calculateFillClosedSize,
|
|
83
85
|
classifyFillFromPosition,
|
|
84
86
|
FillClassification,
|
|
85
87
|
} from './math/fills.js'
|
|
88
|
+
export {
|
|
89
|
+
annualizeFundingRate,
|
|
90
|
+
safeAnnualizeFundingRate,
|
|
91
|
+
} from './math/funding.js'
|
|
86
92
|
export type { ExpectedPnl } from './math/order.js'
|
|
87
93
|
export {
|
|
88
94
|
buildQuote,
|
|
@@ -174,6 +180,10 @@ export type { GetAssetsParams } from './services/getAssets.js'
|
|
|
174
180
|
export { getAssets } from './services/getAssets.js'
|
|
175
181
|
export type { GetFillsParams } from './services/getFills.js'
|
|
176
182
|
export { getFills } from './services/getFills.js'
|
|
183
|
+
export type { GetFundingAveragesParams } from './services/getFundingAverages.js'
|
|
184
|
+
export { getFundingAverages } from './services/getFundingAverages.js'
|
|
185
|
+
export type { GetFundingHistoryParams } from './services/getFundingHistory.js'
|
|
186
|
+
export { getFundingHistory } from './services/getFundingHistory.js'
|
|
177
187
|
export type { GetGasRecommendationParams } from './services/getGasRecommendation.js'
|
|
178
188
|
export {
|
|
179
189
|
getGasRecommendation,
|
|
@@ -218,7 +228,11 @@ export { createMemoryStorage } from './storage/storage.js'
|
|
|
218
228
|
export type { StorageAdapter } from './storage/types.js'
|
|
219
229
|
export { errorCodeFromStatus } from './transport/errorCodeFromStatus.js'
|
|
220
230
|
export type { FetchWithRetryOptions } from './transport/fetchWithRetry.js'
|
|
221
|
-
export {
|
|
231
|
+
export {
|
|
232
|
+
fetchWithRetry,
|
|
233
|
+
isAbortError,
|
|
234
|
+
isAbortRejection,
|
|
235
|
+
} from './transport/fetchWithRetry.js'
|
|
222
236
|
export type {
|
|
223
237
|
ProviderRetryConfig,
|
|
224
238
|
ResolvedRetryPolicy,
|
|
@@ -373,6 +387,7 @@ export type {
|
|
|
373
387
|
} from './websocket/types.js'
|
|
374
388
|
export {
|
|
375
389
|
WS_CHANNEL_TEARDOWN_LINGER_MS,
|
|
390
|
+
WS_FRAME_ENRICHMENT_TIMEOUT_MS,
|
|
376
391
|
WS_MARKETS_CONTEXT_INTERVAL_MS,
|
|
377
392
|
WsProviderBase,
|
|
378
393
|
} from './websocket/WsProviderBase.js'
|
package/src/math/fills.ts
CHANGED
|
@@ -4,14 +4,24 @@ import {
|
|
|
4
4
|
FillClassification,
|
|
5
5
|
OrderSide,
|
|
6
6
|
} from '@lifi/perps-types'
|
|
7
|
-
import Big from 'big.js'
|
|
8
7
|
import {
|
|
8
|
+
absDecimalString,
|
|
9
|
+
addDecimalString,
|
|
9
10
|
addDecimalStrings,
|
|
10
11
|
divideDecimalString,
|
|
11
12
|
multiplyDecimalString,
|
|
13
|
+
subtractDecimalString,
|
|
12
14
|
} from '../decimal/arithmetic.js'
|
|
13
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
compareDecimalStrings,
|
|
17
|
+
isDecimalStringGreaterThan,
|
|
18
|
+
isDecimalStringZero,
|
|
19
|
+
} from '../decimal/compare.js'
|
|
14
20
|
import { isDecimalString } from '../decimal/parse.js'
|
|
21
|
+
import {
|
|
22
|
+
calculateInitialMarginRoe,
|
|
23
|
+
isPositiveDecimalString,
|
|
24
|
+
} from './position.js'
|
|
15
25
|
|
|
16
26
|
/**
|
|
17
27
|
* Re-exported fill taxonomy used by {@link classifyFillFromPosition}.
|
|
@@ -41,36 +51,37 @@ export function classifyFillFromPosition(
|
|
|
41
51
|
? FillClassification.BUY
|
|
42
52
|
: FillClassification.SELL
|
|
43
53
|
}
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
54
|
+
const end =
|
|
55
|
+
side === OrderSide.BUY
|
|
56
|
+
? addDecimalString(startPosition, sz)
|
|
57
|
+
: subtractDecimalString(startPosition, sz)
|
|
47
58
|
|
|
48
|
-
if (
|
|
49
|
-
return end
|
|
59
|
+
if (isDecimalStringZero(startPosition)) {
|
|
60
|
+
return isDecimalStringGreaterThan(end, '0')
|
|
50
61
|
? FillClassification.OPENED_LONG
|
|
51
62
|
: FillClassification.OPENED_SHORT
|
|
52
63
|
}
|
|
53
64
|
|
|
54
|
-
if (
|
|
55
|
-
if (end
|
|
65
|
+
if (isDecimalStringGreaterThan(startPosition, '0')) {
|
|
66
|
+
if (isDecimalStringZero(end)) {
|
|
56
67
|
return FillClassification.CLOSED_LONG
|
|
57
68
|
}
|
|
58
|
-
if (end
|
|
69
|
+
if (compareDecimalStrings(end, '0') < 0) {
|
|
59
70
|
return FillClassification.SWITCHED_SHORT
|
|
60
71
|
}
|
|
61
|
-
if (end
|
|
72
|
+
if (isDecimalStringGreaterThan(end, startPosition)) {
|
|
62
73
|
return FillClassification.INCREASED_LONG
|
|
63
74
|
}
|
|
64
75
|
return FillClassification.REDUCED_LONG
|
|
65
76
|
}
|
|
66
77
|
|
|
67
|
-
if (end
|
|
78
|
+
if (isDecimalStringZero(end)) {
|
|
68
79
|
return FillClassification.CLOSED_SHORT
|
|
69
80
|
}
|
|
70
|
-
if (end
|
|
81
|
+
if (isDecimalStringGreaterThan(end, '0')) {
|
|
71
82
|
return FillClassification.SWITCHED_LONG
|
|
72
83
|
}
|
|
73
|
-
if (end
|
|
84
|
+
if (compareDecimalStrings(end, startPosition) < 0) {
|
|
74
85
|
return FillClassification.INCREASED_SHORT
|
|
75
86
|
}
|
|
76
87
|
return FillClassification.REDUCED_SHORT
|
|
@@ -99,3 +110,119 @@ export function calculateAverageFillPrice(
|
|
|
99
110
|
)
|
|
100
111
|
return divideDecimalString(notional, totalSize)
|
|
101
112
|
}
|
|
113
|
+
|
|
114
|
+
const CLOSING_CLASSIFICATIONS: ReadonlySet<FillClassification> = new Set([
|
|
115
|
+
FillClassification.REDUCED_LONG,
|
|
116
|
+
FillClassification.REDUCED_SHORT,
|
|
117
|
+
FillClassification.CLOSED_LONG,
|
|
118
|
+
FillClassification.CLOSED_SHORT,
|
|
119
|
+
FillClassification.SWITCHED_LONG,
|
|
120
|
+
FillClassification.SWITCHED_SHORT,
|
|
121
|
+
])
|
|
122
|
+
|
|
123
|
+
// Without `startPosition` a flip hides how much of the fill closed.
|
|
124
|
+
const FULL_SIZE_CLOSING_CLASSIFICATIONS: ReadonlySet<FillClassification> =
|
|
125
|
+
new Set([
|
|
126
|
+
FillClassification.REDUCED_LONG,
|
|
127
|
+
FillClassification.REDUCED_SHORT,
|
|
128
|
+
FillClassification.CLOSED_LONG,
|
|
129
|
+
FillClassification.CLOSED_SHORT,
|
|
130
|
+
])
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Part of a fill that reduced the position held before it:
|
|
134
|
+
* `min(|startPosition|, size)`. Without `startPosition`, the full `size` of a
|
|
135
|
+
* reducing or closing fill.
|
|
136
|
+
*
|
|
137
|
+
* @returns `undefined` for a fill that opens, increases or trades spot, for a
|
|
138
|
+
* flip without `startPosition`, when `size` is not a positive decimal
|
|
139
|
+
* string, or when `startPosition` is zero or not a decimal string. Never
|
|
140
|
+
* throws.
|
|
141
|
+
* @public
|
|
142
|
+
*/
|
|
143
|
+
export function calculateFillClosedSize(
|
|
144
|
+
fill: Pick<Fill, 'size' | 'startPosition' | 'classification'>
|
|
145
|
+
): DecimalString | undefined {
|
|
146
|
+
const { size, startPosition, classification } = fill
|
|
147
|
+
if (!isPositiveDecimalString(size)) {
|
|
148
|
+
return undefined
|
|
149
|
+
}
|
|
150
|
+
if (startPosition === undefined) {
|
|
151
|
+
return FULL_SIZE_CLOSING_CLASSIFICATIONS.has(classification)
|
|
152
|
+
? size
|
|
153
|
+
: undefined
|
|
154
|
+
}
|
|
155
|
+
if (
|
|
156
|
+
!CLOSING_CLASSIFICATIONS.has(classification) ||
|
|
157
|
+
!isDecimalString(startPosition) ||
|
|
158
|
+
isDecimalStringZero(startPosition)
|
|
159
|
+
) {
|
|
160
|
+
return undefined
|
|
161
|
+
}
|
|
162
|
+
const heldSize = absDecimalString(startPosition)
|
|
163
|
+
return isDecimalStringGreaterThan(size, heldSize) ? heldSize : size
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// A sell closes a long: pnl = (price − entry) × closedSize. A buy closes a short.
|
|
167
|
+
const calculateEntryPriceFromPnl = (
|
|
168
|
+
fill: Fill,
|
|
169
|
+
pnl: DecimalString | undefined,
|
|
170
|
+
closedSize: DecimalString
|
|
171
|
+
): DecimalString | undefined => {
|
|
172
|
+
if (!isDecimalString(pnl) || !isPositiveDecimalString(fill.price)) {
|
|
173
|
+
return undefined
|
|
174
|
+
}
|
|
175
|
+
const pnlPerUnit = divideDecimalString(pnl, closedSize)
|
|
176
|
+
const entryPrice =
|
|
177
|
+
fill.side === OrderSide.SELL
|
|
178
|
+
? subtractDecimalString(fill.price, pnlPerUnit)
|
|
179
|
+
: addDecimalString(fill.price, pnlPerUnit)
|
|
180
|
+
return isDecimalStringGreaterThan(entryPrice, '0') ? entryPrice : undefined
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Complete a fill with `closedSize`, `entryPrice` and `returnOnEquity`. A
|
|
185
|
+
* positive `entryPrice` on the input stays; otherwise it comes from
|
|
186
|
+
* `realizedPnl`, `closedSize` and `price`. ROE comes from
|
|
187
|
+
* `calculateInitialMarginRoe`, and a `null` `realizedPnl` counts as zero.
|
|
188
|
+
* A fill without a closed part gives none of the three fields.
|
|
189
|
+
*
|
|
190
|
+
* @param leverage - Leverage for the ROE: `Fill.leverage` when the venue sends
|
|
191
|
+
* it, else the current setting of the market. No ROE when it is not a
|
|
192
|
+
* positive decimal string.
|
|
193
|
+
* @returns A new fill. Never throws or warns.
|
|
194
|
+
* @public
|
|
195
|
+
*/
|
|
196
|
+
export function buildFill(
|
|
197
|
+
fill: Fill,
|
|
198
|
+
leverage: DecimalString | undefined
|
|
199
|
+
): Fill {
|
|
200
|
+
const {
|
|
201
|
+
closedSize: _closedSize,
|
|
202
|
+
entryPrice: inputEntryPrice,
|
|
203
|
+
returnOnEquity: _returnOnEquity,
|
|
204
|
+
...fields
|
|
205
|
+
} = fill
|
|
206
|
+
const closedSize = calculateFillClosedSize(fill)
|
|
207
|
+
if (closedSize === undefined) {
|
|
208
|
+
return fields
|
|
209
|
+
}
|
|
210
|
+
const built: Fill = { ...fields, closedSize }
|
|
211
|
+
const pnl = fill.realizedPnl === null ? '0' : fill.realizedPnl
|
|
212
|
+
const entryPrice = isPositiveDecimalString(inputEntryPrice)
|
|
213
|
+
? inputEntryPrice
|
|
214
|
+
: calculateEntryPriceFromPnl(fill, pnl, closedSize)
|
|
215
|
+
if (entryPrice === undefined) {
|
|
216
|
+
return built
|
|
217
|
+
}
|
|
218
|
+
built.entryPrice = entryPrice
|
|
219
|
+
if (isDecimalString(pnl) && isPositiveDecimalString(leverage)) {
|
|
220
|
+
built.returnOnEquity = calculateInitialMarginRoe(
|
|
221
|
+
pnl,
|
|
222
|
+
closedSize,
|
|
223
|
+
entryPrice,
|
|
224
|
+
leverage
|
|
225
|
+
)
|
|
226
|
+
}
|
|
227
|
+
return built
|
|
228
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { DecimalString } from '@lifi/perps-types'
|
|
2
|
+
import {
|
|
3
|
+
divideDecimalString,
|
|
4
|
+
multiplyDecimalString,
|
|
5
|
+
} from '../decimal/arithmetic.js'
|
|
6
|
+
import { numberToDecimalString } from '../decimal/convert.js'
|
|
7
|
+
import { invalidInput } from '../errors/invalidInput.js'
|
|
8
|
+
import { createSafeFunction } from '../utils/createSafeFunction.js'
|
|
9
|
+
|
|
10
|
+
const SECONDS_PER_YEAR = String(365 * 24 * 60 * 60)
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Simple APR of a funding rate: `rate × (365 days in seconds ÷ ratePeriodSeconds)`,
|
|
14
|
+
* as a signed fraction. It does not compound.
|
|
15
|
+
*
|
|
16
|
+
* @param rate - Funding rate as a fraction for one rate period, for example
|
|
17
|
+
* `MarketContext.funding.rate` or a settled funding average.
|
|
18
|
+
* @param ratePeriodSeconds - `Provider.funding.ratePeriodSeconds`.
|
|
19
|
+
* @throws {PerpsError} `ValidationError` when `rate` does not match the
|
|
20
|
+
* decimal pattern, or `ratePeriodSeconds` is not a finite number above zero.
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export function annualizeFundingRate(
|
|
24
|
+
rate: DecimalString,
|
|
25
|
+
ratePeriodSeconds: number
|
|
26
|
+
): DecimalString {
|
|
27
|
+
if (!Number.isFinite(ratePeriodSeconds) || ratePeriodSeconds <= 0) {
|
|
28
|
+
throw invalidInput(
|
|
29
|
+
'ratePeriodSeconds',
|
|
30
|
+
`must be a finite number above zero, got ${ratePeriodSeconds}`
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
return divideDecimalString(
|
|
34
|
+
multiplyDecimalString(rate, SECONDS_PER_YEAR),
|
|
35
|
+
numberToDecimalString(ratePeriodSeconds)
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** @public */
|
|
40
|
+
export const safeAnnualizeFundingRate = createSafeFunction(
|
|
41
|
+
'annualizeFundingRate',
|
|
42
|
+
annualizeFundingRate
|
|
43
|
+
)
|
package/src/math/position.ts
CHANGED
|
@@ -596,7 +596,7 @@ export function isPositionMarginRemovable(position: Position): boolean {
|
|
|
596
596
|
)
|
|
597
597
|
}
|
|
598
598
|
|
|
599
|
-
const isPositiveDecimalString = (value: unknown): value is string =>
|
|
599
|
+
export const isPositiveDecimalString = (value: unknown): value is string =>
|
|
600
600
|
isDecimalString(value) && isDecimalStringGreaterThan(value, '0')
|
|
601
601
|
|
|
602
602
|
/** Complete a position, retaining explicit venue value and ROE.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { FundingAveragesResponse } from '@lifi/perps-types'
|
|
2
|
+
import { buildUrl, request } from '../transport/request.js'
|
|
3
|
+
import type { SDKRequestOptions } from '../types/config.js'
|
|
4
|
+
import type { PerpsSDKClient } from '../types/provider.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Parameters for {@link getFundingAverages}.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export interface GetFundingAveragesParams {
|
|
12
|
+
provider: string
|
|
13
|
+
/** Optional filter of opaque `Market.id`s (not display symbols). */
|
|
14
|
+
marketIds?: string[]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Get the settled funding averages (8h, 24h, 3d, 7d) for markets, optionally
|
|
19
|
+
* filtered by `Market.id`. The rates are raw hourly fractions, not an APR.
|
|
20
|
+
*
|
|
21
|
+
* @throws {PerpsError} On backend error responses, network, or parsing errors.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export async function getFundingAverages(
|
|
25
|
+
client: PerpsSDKClient,
|
|
26
|
+
params: GetFundingAveragesParams,
|
|
27
|
+
options?: SDKRequestOptions
|
|
28
|
+
): Promise<FundingAveragesResponse> {
|
|
29
|
+
const url = buildUrl(`${client.config.apiUrl}/fundingAverages`, {
|
|
30
|
+
provider: params.provider,
|
|
31
|
+
marketIds: params.marketIds?.join(','),
|
|
32
|
+
})
|
|
33
|
+
return request<FundingAveragesResponse>(
|
|
34
|
+
client.config,
|
|
35
|
+
url,
|
|
36
|
+
{ provider: params.provider },
|
|
37
|
+
options
|
|
38
|
+
)
|
|
39
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FundingHistoryRange,
|
|
3
|
+
FundingHistoryResponse,
|
|
4
|
+
} from '@lifi/perps-types'
|
|
5
|
+
import { buildUrl, request } from '../transport/request.js'
|
|
6
|
+
import type { SDKRequestOptions } from '../types/config.js'
|
|
7
|
+
import type { PerpsSDKClient } from '../types/provider.js'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Parameters for {@link getFundingHistory}.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export interface GetFundingHistoryParams {
|
|
15
|
+
provider: string
|
|
16
|
+
/** Opaque provider `Market.id`, not a display symbol. */
|
|
17
|
+
marketId: string
|
|
18
|
+
/** Pick from the provider's `Provider.fundingHistoryRanges`. */
|
|
19
|
+
range: FundingHistoryRange
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Get the settled funding history of a market, oldest bucket first. The rates
|
|
24
|
+
* are raw hourly fractions, not an APR.
|
|
25
|
+
*
|
|
26
|
+
* @throws {PerpsError} On backend, network, or parsing errors.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export async function getFundingHistory(
|
|
30
|
+
client: PerpsSDKClient,
|
|
31
|
+
params: GetFundingHistoryParams,
|
|
32
|
+
options?: SDKRequestOptions
|
|
33
|
+
): Promise<FundingHistoryResponse> {
|
|
34
|
+
const url = buildUrl(`${client.config.apiUrl}/fundingHistory`, {
|
|
35
|
+
provider: params.provider,
|
|
36
|
+
marketId: params.marketId,
|
|
37
|
+
range: params.range,
|
|
38
|
+
})
|
|
39
|
+
return request<FundingHistoryResponse>(
|
|
40
|
+
client.config,
|
|
41
|
+
url,
|
|
42
|
+
{ provider: params.provider },
|
|
43
|
+
options
|
|
44
|
+
)
|
|
45
|
+
}
|
|
@@ -27,6 +27,23 @@ export function isAbortError(error: unknown): boolean {
|
|
|
27
27
|
return error instanceof Error && error.name === 'AbortError'
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* True when `error` is a caller cancellation of a request that `signal`
|
|
32
|
+
* controls: an {@link isAbortError} rejection, or the abort reason of `signal`,
|
|
33
|
+
* such as a custom `Error` or the `TimeoutError` of `AbortSignal.timeout()`.
|
|
34
|
+
* A different rejection stays a failure, also when `signal` aborts later.
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export function isAbortRejection(
|
|
39
|
+
error: unknown,
|
|
40
|
+
signal: AbortSignal | undefined
|
|
41
|
+
): boolean {
|
|
42
|
+
return (
|
|
43
|
+
isAbortError(error) || (signal?.aborted === true && error === signal.reason)
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
30
47
|
/**
|
|
31
48
|
* Wrap `fetch` with policy-driven retry. Honors `Retry-After` (when present
|
|
32
49
|
* and `respectRetryAfter` is true), otherwise falls back to exponential
|
|
@@ -57,7 +74,7 @@ export async function fetchWithRetry(
|
|
|
57
74
|
try {
|
|
58
75
|
response = await fetchImpl(input, mergedInit)
|
|
59
76
|
} catch (error) {
|
|
60
|
-
if (
|
|
77
|
+
if (isAbortRejection(error, signal)) {
|
|
61
78
|
throw error
|
|
62
79
|
}
|
|
63
80
|
networkError = error
|