@lifi/perps-sdk 12.1.0 → 13.0.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.
Files changed (52) hide show
  1. package/dist/cjs/client/PerpsClient.d.ts +4 -3
  2. package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
  3. package/dist/cjs/client/PerpsClient.js +7 -0
  4. package/dist/cjs/client/PerpsClient.js.map +1 -1
  5. package/dist/cjs/index.d.ts +3 -3
  6. package/dist/cjs/index.d.ts.map +1 -1
  7. package/dist/cjs/index.js.map +1 -1
  8. package/dist/cjs/types/api.d.ts +6 -1
  9. package/dist/cjs/types/api.d.ts.map +1 -1
  10. package/dist/cjs/types/provider.d.ts +6 -1
  11. package/dist/cjs/types/provider.d.ts.map +1 -1
  12. package/dist/cjs/version.d.ts +1 -1
  13. package/dist/cjs/version.js +1 -1
  14. package/dist/cjs/websocket/PerpsWsClient.d.ts +7 -2
  15. package/dist/cjs/websocket/PerpsWsClient.d.ts.map +1 -1
  16. package/dist/cjs/websocket/PerpsWsClient.js +3 -0
  17. package/dist/cjs/websocket/PerpsWsClient.js.map +1 -1
  18. package/dist/esm/client/PerpsClient.d.ts +12 -3
  19. package/dist/esm/client/PerpsClient.d.ts.map +1 -1
  20. package/dist/esm/client/PerpsClient.js +15 -0
  21. package/dist/esm/client/PerpsClient.js.map +1 -1
  22. package/dist/esm/index.d.ts +3 -3
  23. package/dist/esm/index.d.ts.map +1 -1
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/esm/types/api.d.ts +11 -1
  26. package/dist/esm/types/api.d.ts.map +1 -1
  27. package/dist/esm/types/provider.d.ts +15 -1
  28. package/dist/esm/types/provider.d.ts.map +1 -1
  29. package/dist/esm/version.d.ts +1 -1
  30. package/dist/esm/version.js +1 -1
  31. package/dist/esm/websocket/PerpsWsClient.d.ts +25 -6
  32. package/dist/esm/websocket/PerpsWsClient.d.ts.map +1 -1
  33. package/dist/esm/websocket/PerpsWsClient.js +13 -2
  34. package/dist/esm/websocket/PerpsWsClient.js.map +1 -1
  35. package/dist/types/client/PerpsClient.d.ts +12 -3
  36. package/dist/types/client/PerpsClient.d.ts.map +1 -1
  37. package/dist/types/index.d.ts +3 -3
  38. package/dist/types/index.d.ts.map +1 -1
  39. package/dist/types/types/api.d.ts +11 -1
  40. package/dist/types/types/api.d.ts.map +1 -1
  41. package/dist/types/types/provider.d.ts +15 -1
  42. package/dist/types/types/provider.d.ts.map +1 -1
  43. package/dist/types/version.d.ts +1 -1
  44. package/dist/types/websocket/PerpsWsClient.d.ts +25 -6
  45. package/dist/types/websocket/PerpsWsClient.d.ts.map +1 -1
  46. package/package.json +2 -2
  47. package/src/client/PerpsClient.ts +32 -1
  48. package/src/index.ts +3 -0
  49. package/src/types/api.ts +12 -0
  50. package/src/types/provider.ts +21 -0
  51. package/src/version.ts +1 -1
  52. package/src/websocket/PerpsWsClient.ts +29 -6
@@ -3,12 +3,11 @@ import type { GetQuoteParams } from '../services/getQuote.js';
3
3
  import type { PerpsSDKClient, QuoteListener } from '../types/provider.js';
4
4
  import type { EventForSubscription, WsProvider, WsStatusListener } from './types.js';
5
5
  /**
6
- * Factory for a per-provider WS plugin. Invoked once per provider key the
7
- * first time `subscribe(...)` is called against it.
6
+ * Call parameters of a {@link WsProviderFactory}.
8
7
  *
9
8
  * @public
10
9
  */
11
- export type WsProviderFactory = (params: {
10
+ export interface WsProviderFactoryParams {
12
11
  provider: string;
13
12
  /** WS URL discovered from `/providers`. */
14
13
  wsUrl: string;
@@ -25,7 +24,18 @@ export type WsProviderFactory = (params: {
25
24
  * duplicating backend orchestration in the WS layer.
26
25
  */
27
26
  client: PerpsSDKClient;
28
- }) => WsProvider;
27
+ }
28
+ /**
29
+ * Factory for a per-provider WS plugin. Invoked once per provider key the
30
+ * first time `subscribe(...)` is called against it.
31
+ *
32
+ * @public
33
+ */
34
+ export interface WsProviderFactory {
35
+ (params: WsProviderFactoryParams): WsProvider;
36
+ /** `true` when the venue socket serves the `candle` channel. */
37
+ readonly streamsCandles: boolean;
38
+ }
29
39
  /**
30
40
  * Options for {@link PerpsWsClient}.
31
41
  *
@@ -43,7 +53,7 @@ export interface PerpsWsClientOptions {
43
53
  wsProviders?: Record<string, WsProviderFactory>;
44
54
  }
45
55
  /**
46
- * Realtime client: lazily instantiates a per-provider {@link WsProvider} on
56
+ * WebSocket client: lazily instantiates a per-provider {@link WsProvider} on
47
57
  * first subscription and fans subscriptions out to it.
48
58
  *
49
59
  * @public
@@ -56,7 +66,16 @@ export declare class PerpsWsClient {
56
66
  private closed;
57
67
  constructor(client: PerpsSDKClient, options?: PerpsWsClientOptions);
58
68
  /**
59
- * Subscribe to a realtime channel, lazily creating the provider's WS
69
+ * Whether `provider`'s socket serves the `candle` channel, as reported by
70
+ * its registered factory. Returns `false` when no factory is registered.
71
+ * Synchronous: it reads the factory without instantiating the provider and
72
+ * makes no network call, so a caller can branch before the first subscribe.
73
+ *
74
+ * @public
75
+ */
76
+ streamsCandles(provider: string): boolean;
77
+ /**
78
+ * Subscribe to a WebSocket channel, lazily creating the provider's WS
60
79
  * connection. Returns an unsubscribe function.
61
80
  *
62
81
  * @param onStatus - Optional listener for the underlying connection's
@@ -1 +1 @@
1
- {"version":3,"file":"PerpsWsClient.d.ts","sourceRoot":"","sources":["../../../src/websocket/PerpsWsClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAGrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEzE,OAAO,KAAK,EACV,oBAAoB,EAEpB,UAAU,EACV,gBAAgB,EACjB,MAAM,YAAY,CAAA;AAEnB;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE;IACvC,QAAQ,EAAE,MAAM,CAAA;IAChB,2CAA2C;IAC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1B,OAAO,CAAC,MAAM,IAAI,CAAC;IAOtB;;;;;;;;;;OAUG;IACG,cAAc,CAClB,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,MAAM,IAAI,CAAC;IAatB;;;;;;;OAOG;IACH,KAAK;IASL;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAIjC,OAAO,CAAC,UAAU;YASJ,mBAAmB;YAqBnB,YAAY;CAsC3B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/perps-sdk",
3
- "version": "12.1.0",
3
+ "version": "13.0.0",
4
4
  "description": "LI.FI Perps SDK for perpetuals trading",
5
5
  "homepage": "https://github.com/lifinance/perps-sdk",
6
6
  "bugs": {
@@ -46,7 +46,7 @@
46
46
  "big.js": "^7.0.1",
47
47
  "partysocket": "^1.1.19",
48
48
  "viem": "^2.55.18",
49
- "@lifi/perps-types": "^12.0.1"
49
+ "@lifi/perps-types": "^12.3.0"
50
50
  },
51
51
  "publishConfig": {
52
52
  "access": "public"
@@ -9,6 +9,7 @@ import type {
9
9
  MarketRef,
10
10
  MarketSettings,
11
11
  MetaActionType,
12
+ PortfolioHistoryResponse,
12
13
  Position,
13
14
  PositionMarginConstraints,
14
15
  Provider,
@@ -40,6 +41,7 @@ import type {
40
41
  ExecuteProviderSetupResult,
41
42
  GetAccountResult,
42
43
  GetDepositFlowParams,
44
+ GetPortfolioHistoryParams,
43
45
  GetSetupParams,
44
46
  GetWithdrawableBalancesParams,
45
47
  ModifyOrdersParams,
@@ -52,7 +54,11 @@ import type {
52
54
  SubmitOnboardingParams,
53
55
  WithdrawParams,
54
56
  } from '../types/api.js'
55
- import type { PerpsClientSigner, SwitchChainHook } from '../types/config.js'
57
+ import type {
58
+ PerpsClientSigner,
59
+ SDKRequestOptions,
60
+ SwitchChainHook,
61
+ } from '../types/config.js'
56
62
  import type { DepositFlow } from '../types/deposit.js'
57
63
  import type {
58
64
  ActionSignerContribution,
@@ -579,6 +585,31 @@ export class PerpsClient {
579
585
  })
580
586
  }
581
587
 
588
+ /**
589
+ * The account's portfolio value and cumulative PnL over `params.range` at
590
+ * `params.provider`, read directly from the venue.
591
+ *
592
+ * @throws {PerpsError} When the provider plugin is not registered, when it
593
+ * declares no portfolio history read, or when the venue read fails.
594
+ * @public
595
+ */
596
+ async getPortfolioHistory(
597
+ params: GetPortfolioHistoryParams,
598
+ options?: SDKRequestOptions
599
+ ): Promise<PortfolioHistoryResponse> {
600
+ const plugin = this.requireProvider(params.provider)
601
+ if (typeof plugin.getPortfolioHistory !== 'function') {
602
+ throw new PerpsError(
603
+ PerpsErrorCode.SDKError,
604
+ `Provider '${params.provider}' does not implement getPortfolioHistory.`
605
+ )
606
+ }
607
+ return plugin.getPortfolioHistory(
608
+ { address: params.address, range: params.range },
609
+ options
610
+ )
611
+ }
612
+
582
613
  /**
583
614
  * Return the unsatisfied entries on `Provider.setup` for this account as a
584
615
  * flat, self-describing list. Trading is gated on `isReady === true`.
package/src/index.ts CHANGED
@@ -111,6 +111,7 @@ export type {
111
111
  ExecuteMetaActionParams,
112
112
  GetAccountResult,
113
113
  GetDepositFlowParams,
114
+ GetPortfolioHistoryParams,
114
115
  GetSetupParams,
115
116
  GetWithdrawableBalancesParams,
116
117
  ModifyOrdersParams,
@@ -156,6 +157,7 @@ export type {
156
157
  ProviderGetMarketSettingsParams,
157
158
  ProviderGetOrderParams,
158
159
  ProviderGetOrdersParams,
160
+ ProviderGetPortfolioHistoryParams,
159
161
  ProviderGetPositionsParams,
160
162
  ProviderGetQuoteParams,
161
163
  ProviderGetRunningTwapsParams,
@@ -256,6 +258,7 @@ export { cachePromise } from './websocket/cachePromise.js'
256
258
  export type {
257
259
  PerpsWsClientOptions,
258
260
  WsProviderFactory,
261
+ WsProviderFactoryParams,
259
262
  } from './websocket/PerpsWsClient.js'
260
263
  export { PerpsWsClient } from './websocket/PerpsWsClient.js'
261
264
  export type { ReconnectingWebSocketOptions } from './websocket/ReconnectingWebSocket.js'
package/src/types/api.ts CHANGED
@@ -14,6 +14,7 @@ import type {
14
14
  OnboardParams,
15
15
  OrderSide,
16
16
  OrderType,
17
+ PortfolioHistoryRange,
17
18
  ProviderAction,
18
19
  SignedActionStep,
19
20
  TimeInForce,
@@ -298,6 +299,17 @@ export interface GetWithdrawableBalancesParams {
298
299
  address: Address
299
300
  }
300
301
 
302
+ /**
303
+ * Parameters for {@link PerpsClient.getPortfolioHistory}.
304
+ *
305
+ * @public
306
+ */
307
+ export interface GetPortfolioHistoryParams {
308
+ provider: string
309
+ address: Address
310
+ range: PortfolioHistoryRange
311
+ }
312
+
301
313
  /**
302
314
  * One entry on {@link ProviderSetup.checklist}: a user-facing setup
303
315
  * descriptor plus its satisfied state for the queried account.
@@ -16,6 +16,8 @@ import type {
16
16
  OrdersResponse,
17
17
  PerpsMarket,
18
18
  PerpsSigner,
19
+ PortfolioHistoryRange,
20
+ PortfolioHistoryResponse,
19
21
  Position,
20
22
  PositionMarginConstraints,
21
23
  PositionsResponse,
@@ -287,6 +289,16 @@ export interface ProviderGetActivityParams {
287
289
  type?: ActivityType[]
288
290
  }
289
291
 
292
+ /**
293
+ * Read params for {@link PerpsProvider.getPortfolioHistory}.
294
+ *
295
+ * @public
296
+ */
297
+ export interface ProviderGetPortfolioHistoryParams {
298
+ address: Address
299
+ range: PortfolioHistoryRange
300
+ }
301
+
290
302
  /**
291
303
  * Read params for {@link PerpsProviderPlugin.getQuote}. `provider` is implicit
292
304
  * in the provider instance and so is not duplicated here.
@@ -469,6 +481,15 @@ export interface PerpsProviderPlugin {
469
481
  options?: SDKRequestOptions
470
482
  ): Promise<ActivitiesResponse>
471
483
 
484
+ /**
485
+ * Read the account's portfolio value and cumulative PnL over
486
+ * `params.range`, oldest point first, directly from the venue.
487
+ */
488
+ getPortfolioHistory?(
489
+ params: ProviderGetPortfolioHistoryParams,
490
+ options?: SDKRequestOptions
491
+ ): Promise<PortfolioHistoryResponse>
492
+
472
493
  /**
473
494
  * Produce a one-shot fill {@link Quote} for `params.symbol` at `params.size`
474
495
  * USD notional on this venue. The provider resolves the symbol against its
package/src/version.ts CHANGED
@@ -10,4 +10,4 @@ export const name = '@lifi/perps-sdk'
10
10
  *
11
11
  * @public
12
12
  */
13
- export const version = '12.1.0'
13
+ export const version = '13.0.0'
@@ -12,12 +12,11 @@ import type {
12
12
  } from './types.js'
13
13
 
14
14
  /**
15
- * Factory for a per-provider WS plugin. Invoked once per provider key the
16
- * first time `subscribe(...)` is called against it.
15
+ * Call parameters of a {@link WsProviderFactory}.
17
16
  *
18
17
  * @public
19
18
  */
20
- export type WsProviderFactory = (params: {
19
+ export interface WsProviderFactoryParams {
21
20
  provider: string
22
21
  /** WS URL discovered from `/providers`. */
23
22
  wsUrl: string
@@ -34,7 +33,19 @@ export type WsProviderFactory = (params: {
34
33
  * duplicating backend orchestration in the WS layer.
35
34
  */
36
35
  client: PerpsSDKClient
37
- }) => WsProvider
36
+ }
37
+
38
+ /**
39
+ * Factory for a per-provider WS plugin. Invoked once per provider key the
40
+ * first time `subscribe(...)` is called against it.
41
+ *
42
+ * @public
43
+ */
44
+ export interface WsProviderFactory {
45
+ (params: WsProviderFactoryParams): WsProvider
46
+ /** `true` when the venue socket serves the `candle` channel. */
47
+ readonly streamsCandles: boolean
48
+ }
38
49
 
39
50
  /**
40
51
  * Options for {@link PerpsWsClient}.
@@ -54,7 +65,7 @@ export interface PerpsWsClientOptions {
54
65
  }
55
66
 
56
67
  /**
57
- * Realtime client: lazily instantiates a per-provider {@link WsProvider} on
68
+ * WebSocket client: lazily instantiates a per-provider {@link WsProvider} on
58
69
  * first subscription and fans subscriptions out to it.
59
70
  *
60
71
  * @public
@@ -72,7 +83,19 @@ export class PerpsWsClient {
72
83
  }
73
84
 
74
85
  /**
75
- * Subscribe to a realtime channel, lazily creating the provider's WS
86
+ * Whether `provider`'s socket serves the `candle` channel, as reported by
87
+ * its registered factory. Returns `false` when no factory is registered.
88
+ * Synchronous: it reads the factory without instantiating the provider and
89
+ * makes no network call, so a caller can branch before the first subscribe.
90
+ *
91
+ * @public
92
+ */
93
+ streamsCandles(provider: string): boolean {
94
+ return this.options.wsProviders?.[provider]?.streamsCandles ?? false
95
+ }
96
+
97
+ /**
98
+ * Subscribe to a WebSocket channel, lazily creating the provider's WS
76
99
  * connection. Returns an unsubscribe function.
77
100
  *
78
101
  * @param onStatus - Optional listener for the underlying connection's