@lifi/perps-sdk 1.0.0 → 1.0.1

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 CHANGED
@@ -15,7 +15,7 @@ Core of the [LI.FI Perps SDK](https://public-perps-docs.mintlify.app/) — a Typ
15
15
  - **Provider plugins** — each DEX ships as a separate package you register on the client.
16
16
  - **Agent-based signing** — trades execute without per-order wallet popups (one-time wallet signature during setup).
17
17
  - **Two layers** — low-level service functions and the high-level `PerpsClient`.
18
- - **Realtime** — WebSocket subscriptions for prices, orderbook, and fills.
18
+ - **Streaming** — WebSocket subscriptions for prices, orderbook, and fills.
19
19
  - **Fully typed** — all types exported, sourced from `@lifi/perps-types`.
20
20
 
21
21
  ## Installation
@@ -24,8 +24,6 @@ Install the core SDK plus the provider plugin(s) for the DEX(es) you target:
24
24
 
25
25
  ```bash
26
26
  pnpm add @lifi/perps-sdk @lifi/perps-sdk-provider-hyperliquid
27
- # or
28
- npm install @lifi/perps-sdk @lifi/perps-sdk-provider-hyperliquid
29
27
  ```
30
28
 
31
29
  | Package | Install for |
@@ -36,150 +34,12 @@ npm install @lifi/perps-sdk @lifi/perps-sdk-provider-hyperliquid
36
34
 
37
35
  Get an API key from the [LI.FI Partner Portal](https://portal.li.fi/).
38
36
 
39
- ## Gotchas
40
-
41
- - **Register every provider plugin on the client.** The core SDK ships no DEX
42
- logic — pass the plugins via the `providers` option (`hyperliquidProvider()`,
43
- `lighterProvider()`) or a call to any provider-specific service throws.
44
- - **Setup needs a one-time wallet signature.** `placeOrder` signs with a
45
- per-user agent, not the wallet. Run `checkSetup` and complete the returned
46
- steps (one user-signed step provisions the agent) before trading; `isReady`
47
- flips `true` once everything is satisfied.
48
- - **Markets are referenced by opaque `marketId`, not display symbol.** A
49
- `MarketRef` is `{ marketId, categoryId }` where `marketId` is `Market.id`
50
- from `getMarkets` — not a string like `'BTC'`. The same applies to the
51
- `marketIds` filter on `getMarkets` / `getPrices`.
52
-
53
37
  ## Architecture
54
38
 
55
39
  ### Package layering
56
40
 
57
41
  `@lifi/perps-types` is a zero-dependency wire-type package at the base. The core `@lifi/perps-sdk` depends on it. Each provider plugin depends on `@lifi/perps-types` directly and takes the core SDK as a peer dependency — so your project installs exactly one copy of the SDK.
58
42
 
59
- ### Action lifecycle
60
-
61
- Every mutating action (order placement, cancellation, withdrawal, setup) follows the same pipeline: `PerpsClient` requests unsigned action steps from the LI.FI backend (`createAction`), the provider plugin signs them, and the client submits the signed steps back (`executeAction`). The developer experience is one wallet signature at setup time — the agent provisioned during setup signs all subsequent orders automatically, with no per-order wallet popups.
62
-
63
- ### Data-plane split
64
-
65
- Market-structure reads (markets, assets, prices, OHLCV, orderbook) go through the LI.FI backend, which fans out to each venue on your behalf. Per-user reads (account state, positions, orders, fills, activity) go from the SDK directly to the venue API using the end-user's own IP — this keeps venue rate limits per-user rather than concentrating them on the backend's single egress address.
66
-
67
- ## Quick Start
68
-
69
- ### Fetch market data
70
-
71
- ```typescript
72
- import { createPerpsClient, getProviders, getMarkets, getPrices } from '@lifi/perps-sdk'
73
-
74
- const client = createPerpsClient({ integrator: 'my-app', apiKey: 'your-api-key' })
75
-
76
- // getProviders returns the live provider list; provider: takes a key string
77
- // like 'hyperliquid' or 'lighter'.
78
- const { providers } = await getProviders(client)
79
- const { markets } = await getMarkets(client, { provider: providers[0].key })
80
- const { prices } = await getPrices(client, {
81
- provider: 'hyperliquid',
82
- marketIds: markets.slice(0, 2).map((m) => m.id),
83
- })
84
- ```
85
-
86
- ### Trade with PerpsClient
87
-
88
- Register the provider plugin(s), run the one-time setup flow, then place orders:
89
-
90
- ```typescript
91
- import { PerpsClient, OrderSide, OrderType } from '@lifi/perps-sdk'
92
- import { hyperliquidProvider } from '@lifi/perps-sdk-provider-hyperliquid'
93
-
94
- const perps = new PerpsClient({
95
- integrator: 'my-app',
96
- apiKey: 'your-api-key',
97
- providers: [hyperliquidProvider()],
98
- })
99
-
100
- // One-time setup: provisions the signing agent and reports any steps still
101
- // needing the user's wallet signature. isReady === true once satisfied.
102
- const setup = await perps.checkSetup({ provider: 'hyperliquid', address })
103
-
104
- // Resolve the market to trade from getMarkets, then place the order — the
105
- // agent signs automatically, no wallet popups.
106
- const result = await perps.placeOrder({
107
- provider: 'hyperliquid',
108
- address,
109
- market: { marketId: market.id, categoryId: market.categoryId },
110
- side: OrderSide.BUY,
111
- type: OrderType.MARKET,
112
- size: '0.1',
113
- price: '95000.00',
114
- })
115
- ```
116
-
117
- See the [`agent-trading` example](https://github.com/lifinance/perps-sdk/tree/main/examples) for the full setup flow, including signing the user-gated steps.
118
-
119
- ### Venue-correct order formatting
120
-
121
- Tick/lot rules and margin models differ per venue, so price/size formatting and
122
- liquidation previews are provider methods — always route them through the
123
- market's own provider rather than applying one venue's rules to another's
124
- markets:
125
-
126
- ```typescript
127
- const provider = perps.client.getProvider(market.providerId)!
128
- const price = provider.formatOrderPrice(market, 95000.25)
129
- const size = provider.formatOrderSize(market, 0.123456)
130
- const liq = provider.estimateLiquidationPrice(market, {
131
- entryPrice: 95000,
132
- leverage: 10,
133
- isLong: true,
134
- }) // number, or undefined when the venue model can't be evaluated client-side
135
- ```
136
-
137
- ## Realtime (WebSocket)
138
-
139
- `PerpsWsClient` is the realtime layer. It lazily opens one socket per provider
140
- on first subscribe, ref-counts listeners onto a single wire subscription per
141
- channel, and fans each event out to every listener — so each consumer
142
- subscribes independently and the SDK dedupes. Active subscriptions are replayed
143
- automatically on reconnect.
144
-
145
- ```typescript
146
- import { PerpsWsClient, createPerpsClient } from '@lifi/perps-sdk'
147
- import { hyperliquidWsProvider } from '@lifi/perps-sdk-provider-hyperliquid'
148
- import { lighterWsProvider } from '@lifi/perps-sdk-provider-lighter'
149
-
150
- const client = createPerpsClient({ integrator: 'my-app', apiKey: 'your-api-key' })
151
-
152
- const ws = new PerpsWsClient(client, {
153
- wsProviders: {
154
- hyperliquid: hyperliquidWsProvider(),
155
- lighter: lighterWsProvider(),
156
- },
157
- })
158
-
159
- const unsubscribe = await ws.subscribe(
160
- { channel: 'prices', dex: 'hyperliquid' },
161
- (event) => console.log(event.data), // Market.id → last-trade price
162
- (status) => console.log(status), // 'connected' | 'reconnecting' | 'disconnected'
163
- )
164
-
165
- unsubscribe() // release this listener; socket closes when the last one releases
166
- ws.close() // close all sockets and drop cached providers
167
- ```
168
-
169
- Lighter's account-scoped channels (`orderUpdates`, `positions`) require an
170
- `authProvider` on `lighterWsProvider()`. See the
171
- [`websocket-subscriptions` example](https://github.com/lifinance/perps-sdk/tree/main/examples)
172
- and the [SDK documentation](https://public-perps-docs.mintlify.app/) for the
173
- full channel list, authentication, and reconnect model.
174
-
175
- ## Provider plugins
176
-
177
- Register one plugin per DEX you trade. Each plugin's README documents its
178
- signing model, setup flow, and exported surface:
179
-
180
- - [`@lifi/perps-sdk-provider-hyperliquid`](https://www.npmjs.com/package/@lifi/perps-sdk-provider-hyperliquid)
181
- - [`@lifi/perps-sdk-provider-lighter`](https://www.npmjs.com/package/@lifi/perps-sdk-provider-lighter)
182
-
183
43
  ## Examples
184
44
 
185
45
  Runnable scripts live in the [`examples/`](https://github.com/lifinance/perps-sdk/tree/main/examples) directory of the repository — market data, account data, agent trading, error handling, custom storage, and WebSocket subscriptions.
@@ -1,3 +1,3 @@
1
1
  export declare const name = "@lifi/perps-sdk";
2
- export declare const version = "1.0.0";
2
+ export declare const version = "1.0.1";
3
3
  //# sourceMappingURL=version.d.ts.map
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = exports.name = void 0;
4
4
  exports.name = '@lifi/perps-sdk';
5
- exports.version = '1.0.0';
5
+ exports.version = '1.0.1';
6
6
  //# sourceMappingURL=version.js.map
@@ -1,3 +1,3 @@
1
1
  export declare const name = "@lifi/perps-sdk";
2
- export declare const version = "1.0.0";
2
+ export declare const version = "1.0.1";
3
3
  //# sourceMappingURL=version.d.ts.map
@@ -1,3 +1,3 @@
1
1
  export const name = '@lifi/perps-sdk';
2
- export const version = '1.0.0';
2
+ export const version = '1.0.1';
3
3
  //# sourceMappingURL=version.js.map
@@ -1,3 +1,3 @@
1
1
  export declare const name = "@lifi/perps-sdk";
2
- export declare const version = "1.0.0";
2
+ export declare const version = "1.0.1";
3
3
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/perps-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "LI.FI Perps SDK for perpetuals trading",
5
5
  "homepage": "https://github.com/lifinance/perps-sdk",
6
6
  "bugs": {
@@ -44,7 +44,7 @@
44
44
  "@lifi/types": "17.82.1",
45
45
  "partysocket": "^1.1.19",
46
46
  "viem": "^2.48.8",
47
- "@lifi/perps-types": "1.0.0"
47
+ "@lifi/perps-types": "1.0.1"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public"
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/perps-sdk'
2
- export const version = '1.0.0'
2
+ export const version = '1.0.1'