@pear-protocol/core-sdk 1.12.1 → 1.13.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.
@@ -1904,6 +1904,7 @@ declare class Core {
1904
1904
  connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
1905
1905
  type: "spot" | "perp" | "hip3";
1906
1906
  leverage: number;
1907
+ marginMode: "any" | "isolated" | "cross";
1907
1908
  precision: {
1908
1909
  quantity: {
1909
1910
  decimals: number;
@@ -1930,6 +1931,7 @@ declare class Core {
1930
1931
  instruments: {
1931
1932
  id: string;
1932
1933
  base: string;
1934
+ marginMode: "any" | "isolated" | "cross";
1933
1935
  precision: {
1934
1936
  quantity: {
1935
1937
  contractSize: number;
@@ -1974,8 +1976,11 @@ declare class Core {
1974
1976
  connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
1975
1977
  basketKey: string;
1976
1978
  displaySymbol: string;
1977
- longInstrumentIds: string[];
1978
- shortInstrumentIds: string[];
1979
+ legs: {
1980
+ id: string;
1981
+ symbol: string;
1982
+ side: "BUY" | "SELL";
1983
+ }[];
1979
1984
  price: string;
1980
1985
  priceChange24h: string;
1981
1986
  weightRatio: string;
@@ -1991,13 +1996,25 @@ declare class Core {
1991
1996
  hasMaterializedStats: boolean;
1992
1997
  }[];
1993
1998
  }>;
1999
+ basketPositions: (body: HttpTypes.MarketBasketPositionCountsPayloadInput, headers?: ClientHeaders) => Promise<{
2000
+ counts: {
2001
+ basketKey: string;
2002
+ opened: number;
2003
+ traders: number;
2004
+ }[];
2005
+ }>;
1994
2006
  };
1995
2007
  notifications: {
1996
2008
  list: (query?: HttpTypes.NotificationListParamsInput, headers?: ClientHeaders) => Promise<{
1997
2009
  notifications: {
1998
2010
  id: string;
1999
- category: "TAKE_PROFIT_HIT" | "STOP_LOSS_HIT" | "TRIGGER_ORDER_HIT" | "TAKE_PROFIT_FAILED" | "STOP_LOSS_FAILED" | "TRIGGER_ORDER_FAILED" | "ATTACHED_TRIGGER_DISCARDED";
2011
+ category: "TAKE_PROFIT_HIT" | "STOP_LOSS_HIT" | "TRIGGER_ORDER_HIT" | "TAKE_PROFIT_FAILED" | "STOP_LOSS_FAILED" | "TRIGGER_ORDER_FAILED" | "ATTACHED_TRIGGER_DISCARDED" | "AUTO_REBALANCE_EXECUTED" | "AUTO_REBALANCE_FAILED" | "AUTO_REBALANCE_PAUSED";
2000
2012
  parameters: {
2013
+ legs: {
2014
+ id: string;
2015
+ symbol: string;
2016
+ side: "BUY" | "SELL";
2017
+ }[];
2001
2018
  type: "take_profit";
2002
2019
  triggerId: string;
2003
2020
  positionId: string;
@@ -2006,6 +2023,11 @@ declare class Core {
2006
2023
  level?: number | undefined;
2007
2024
  reason?: string | undefined;
2008
2025
  } | {
2026
+ legs: {
2027
+ id: string;
2028
+ symbol: string;
2029
+ side: "BUY" | "SELL";
2030
+ }[];
2009
2031
  type: "stop_loss";
2010
2032
  triggerId: string;
2011
2033
  positionId: string;
@@ -2014,6 +2036,11 @@ declare class Core {
2014
2036
  level?: number | undefined;
2015
2037
  reason?: string | undefined;
2016
2038
  } | {
2039
+ legs: {
2040
+ id: string;
2041
+ symbol: string;
2042
+ side: "BUY" | "SELL";
2043
+ }[];
2017
2044
  type: "trigger_order";
2018
2045
  triggerId: string;
2019
2046
  positionId: string;
@@ -2022,6 +2049,11 @@ declare class Core {
2022
2049
  level?: number | undefined;
2023
2050
  reason?: string | undefined;
2024
2051
  } | {
2052
+ legs: {
2053
+ id: string;
2054
+ symbol: string;
2055
+ side: "BUY" | "SELL";
2056
+ }[];
2025
2057
  type: "default_trigger";
2026
2058
  triggerId: string;
2027
2059
  connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
@@ -2029,6 +2061,11 @@ declare class Core {
2029
2061
  level?: number | undefined;
2030
2062
  reason?: string | undefined;
2031
2063
  } | {
2064
+ legs: {
2065
+ id: string;
2066
+ symbol: string;
2067
+ side: "BUY" | "SELL";
2068
+ }[];
2032
2069
  type: "attached_trigger_discarded";
2033
2070
  positionId: string;
2034
2071
  positionKey: string;
@@ -2040,6 +2077,51 @@ declare class Core {
2040
2077
  level?: number | undefined;
2041
2078
  }[];
2042
2079
  activeTriggerLimit: number;
2080
+ } | {
2081
+ legs: {
2082
+ id: string;
2083
+ symbol: string;
2084
+ side: "BUY" | "SELL";
2085
+ currentWeight: number;
2086
+ targetWeight: number;
2087
+ }[];
2088
+ driftPct: number;
2089
+ notionalUsd: number;
2090
+ configId: string;
2091
+ positionId: string;
2092
+ positionKey: string;
2093
+ connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
2094
+ weightSource: "INITIAL_WEIGHT" | "LIVE_BETA";
2095
+ type: "auto_rebalance_executed";
2096
+ } | {
2097
+ legs: {
2098
+ id: string;
2099
+ symbol: string;
2100
+ side: "BUY" | "SELL";
2101
+ currentWeight: number;
2102
+ targetWeight: number;
2103
+ }[];
2104
+ driftPct: number;
2105
+ reason: string;
2106
+ configId: string;
2107
+ positionId: string;
2108
+ positionKey: string;
2109
+ connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
2110
+ weightSource: "INITIAL_WEIGHT" | "LIVE_BETA";
2111
+ type: "auto_rebalance_failed";
2112
+ } | {
2113
+ legs: {
2114
+ id: string;
2115
+ symbol: string;
2116
+ side: "BUY" | "SELL";
2117
+ }[];
2118
+ pausedReason: "POSITION_CHANGED" | "REPEATED_FAILURES" | "INVALID_LIVE_BETA_EXPOSURE";
2119
+ configId: string;
2120
+ positionId: string;
2121
+ positionKey: string;
2122
+ connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
2123
+ weightSource: "INITIAL_WEIGHT" | "LIVE_BETA";
2124
+ type: "auto_rebalance_paused";
2043
2125
  };
2044
2126
  isRead: boolean;
2045
2127
  createdAt: string;
@@ -2096,6 +2178,83 @@ declare class Core {
2096
2178
  connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
2097
2179
  }[];
2098
2180
  }>;
2181
+ /**
2182
+ * Closed-trade history, newest close first, composed server-side.
2183
+ *
2184
+ * A page may hold fewer than `limit` trades and still return a `nextCursor` —
2185
+ * page until `nextCursor` is absent, never until a page comes back short.
2186
+ */
2187
+ closed: (query?: HttpTypes.ClosedPositionListParamsInput, headers?: ClientHeaders) => Promise<{
2188
+ limit: number;
2189
+ trades: {
2190
+ positionId: string;
2191
+ connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
2192
+ openedAt: string;
2193
+ closedAt: string;
2194
+ origin: "PARTIAL" | "PEAR" | "EXTERNAL";
2195
+ grossPnl: `-${string}` | `+${string}`;
2196
+ netPnl: `-${string}` | `+${string}`;
2197
+ totalFees: `-${string}` | `+${string}`;
2198
+ tradeFees: `-${string}` | `+${string}`;
2199
+ pearFees: `-${string}` | `+${string}`;
2200
+ totalFunding: `-${string}` | `+${string}`;
2201
+ entryNotional: string;
2202
+ exitNotional: string;
2203
+ exitNotionalComplete: boolean;
2204
+ hasSyntheticFills: boolean;
2205
+ unstableHistoricalData: boolean;
2206
+ longAssets: string[];
2207
+ shortAssets: string[];
2208
+ legs: {
2209
+ asset: string;
2210
+ side: "LONG" | "SHORT";
2211
+ grossPnl: `-${string}` | `+${string}`;
2212
+ netPnl: `-${string}` | `+${string}`;
2213
+ totalFees: `-${string}` | `+${string}`;
2214
+ tradeFees: `-${string}` | `+${string}`;
2215
+ pearFees: `-${string}` | `+${string}`;
2216
+ funding: `-${string}` | `+${string}`;
2217
+ entryNotional: string;
2218
+ exitQuantity: string;
2219
+ undeterminedSize: string;
2220
+ entryVwap?: string | undefined;
2221
+ exitVwap?: string | undefined;
2222
+ }[];
2223
+ closedReason?: "USER" | "NETTED" | "LIQUIDATED" | undefined;
2224
+ steps?: {
2225
+ at: string;
2226
+ grossPnl: `-${string}` | `+${string}`;
2227
+ legs: ({
2228
+ kind: "INCREASE";
2229
+ asset: string;
2230
+ side: "BUY" | "SELL";
2231
+ quantity: string;
2232
+ price: string;
2233
+ tradeFee: `-${string}` | `+${string}`;
2234
+ pearFee: `-${string}` | `+${string}`;
2235
+ } | {
2236
+ kind: "REDUCE";
2237
+ asset: string;
2238
+ side: "BUY" | "SELL";
2239
+ quantity: string;
2240
+ price: string;
2241
+ entryBasis: string;
2242
+ grossPnl: `-${string}` | `+${string}`;
2243
+ tradeFee: `-${string}` | `+${string}`;
2244
+ pearFee: `-${string}` | `+${string}`;
2245
+ } | {
2246
+ kind: "REDUCE_UNPRICED";
2247
+ asset: string;
2248
+ side: "BUY" | "SELL";
2249
+ quantity: string;
2250
+ tradeFee: `-${string}` | `+${string}`;
2251
+ pearFee: `-${string}` | `+${string}`;
2252
+ })[];
2253
+ executionId?: string | undefined;
2254
+ }[] | undefined;
2255
+ }[];
2256
+ nextCursor?: string | undefined;
2257
+ }>;
2099
2258
  };
2100
2259
  portfolio: {
2101
2260
  overview: (query?: HttpTypes.PortfolioQueryInput, headers?: ClientHeaders) => Promise<{
@@ -2296,17 +2455,38 @@ declare class Core {
2296
2455
  auto: {
2297
2456
  list: (query?: HttpTypes.AutoRebalanceListParamsInput, headers?: ClientHeaders) => Promise<{
2298
2457
  limit: number;
2299
- items: {
2458
+ items: ({
2300
2459
  id: string;
2301
2460
  positionId: string;
2302
2461
  status: "ACTIVE" | "PAUSED";
2303
- weightSource: "INITIAL_WEIGHT" | "LIVE_BETA";
2304
2462
  minimumDriftPct: string;
2305
2463
  createdAt: string;
2306
2464
  updatedAt: string;
2307
- pausedReason?: "USER" | "POSITION_CHANGED" | "REPEATED_FAILURES" | undefined;
2308
- timeframe?: "1d" | "1h" | "4h" | undefined;
2309
- }[];
2465
+ weightSource: "INITIAL_WEIGHT";
2466
+ pausedReason?: "USER" | "POSITION_CHANGED" | "REPEATED_FAILURES" | "INVALID_LIVE_BETA_EXPOSURE" | undefined;
2467
+ } | {
2468
+ id: string;
2469
+ positionId: string;
2470
+ status: "ACTIVE" | "PAUSED";
2471
+ minimumDriftPct: string;
2472
+ createdAt: string;
2473
+ updatedAt: string;
2474
+ weightSource: "LIVE_BETA";
2475
+ timeframe: "1d" | "1h" | "4h";
2476
+ beta: {
2477
+ state: "PENDING";
2478
+ } | {
2479
+ state: "BASELINED";
2480
+ impliedEntryBeta: string;
2481
+ } | {
2482
+ state: "TRACKING";
2483
+ impliedEntryBeta: string;
2484
+ lastDerivedBeta: string;
2485
+ lastProcessedBetaTime: string;
2486
+ driftPct?: string | undefined;
2487
+ };
2488
+ pausedReason?: "USER" | "POSITION_CHANGED" | "REPEATED_FAILURES" | "INVALID_LIVE_BETA_EXPOSURE" | undefined;
2489
+ })[];
2310
2490
  nextCursor?: string | undefined;
2311
2491
  }>;
2312
2492
  create: (body: HttpTypes.CreateAutoRebalanceConfig, headers?: ClientHeaders) => Promise<{
@@ -2314,12 +2494,33 @@ declare class Core {
2314
2494
  id: string;
2315
2495
  positionId: string;
2316
2496
  status: "ACTIVE" | "PAUSED";
2317
- weightSource: "INITIAL_WEIGHT" | "LIVE_BETA";
2318
2497
  minimumDriftPct: string;
2319
2498
  createdAt: string;
2320
2499
  updatedAt: string;
2321
- pausedReason?: "USER" | "POSITION_CHANGED" | "REPEATED_FAILURES" | undefined;
2322
- timeframe?: "1d" | "1h" | "4h" | undefined;
2500
+ weightSource: "INITIAL_WEIGHT";
2501
+ pausedReason?: "USER" | "POSITION_CHANGED" | "REPEATED_FAILURES" | "INVALID_LIVE_BETA_EXPOSURE" | undefined;
2502
+ } | {
2503
+ id: string;
2504
+ positionId: string;
2505
+ status: "ACTIVE" | "PAUSED";
2506
+ minimumDriftPct: string;
2507
+ createdAt: string;
2508
+ updatedAt: string;
2509
+ weightSource: "LIVE_BETA";
2510
+ timeframe: "1d" | "1h" | "4h";
2511
+ beta: {
2512
+ state: "PENDING";
2513
+ } | {
2514
+ state: "BASELINED";
2515
+ impliedEntryBeta: string;
2516
+ } | {
2517
+ state: "TRACKING";
2518
+ impliedEntryBeta: string;
2519
+ lastDerivedBeta: string;
2520
+ lastProcessedBetaTime: string;
2521
+ driftPct?: string | undefined;
2522
+ };
2523
+ pausedReason?: "USER" | "POSITION_CHANGED" | "REPEATED_FAILURES" | "INVALID_LIVE_BETA_EXPOSURE" | undefined;
2323
2524
  };
2324
2525
  }>;
2325
2526
  update: (id: string, body: HttpTypes.UpdateAutoRebalanceConfig, headers?: ClientHeaders) => Promise<{
@@ -2327,12 +2528,33 @@ declare class Core {
2327
2528
  id: string;
2328
2529
  positionId: string;
2329
2530
  status: "ACTIVE" | "PAUSED";
2330
- weightSource: "INITIAL_WEIGHT" | "LIVE_BETA";
2331
2531
  minimumDriftPct: string;
2332
2532
  createdAt: string;
2333
2533
  updatedAt: string;
2334
- pausedReason?: "USER" | "POSITION_CHANGED" | "REPEATED_FAILURES" | undefined;
2335
- timeframe?: "1d" | "1h" | "4h" | undefined;
2534
+ weightSource: "INITIAL_WEIGHT";
2535
+ pausedReason?: "USER" | "POSITION_CHANGED" | "REPEATED_FAILURES" | "INVALID_LIVE_BETA_EXPOSURE" | undefined;
2536
+ } | {
2537
+ id: string;
2538
+ positionId: string;
2539
+ status: "ACTIVE" | "PAUSED";
2540
+ minimumDriftPct: string;
2541
+ createdAt: string;
2542
+ updatedAt: string;
2543
+ weightSource: "LIVE_BETA";
2544
+ timeframe: "1d" | "1h" | "4h";
2545
+ beta: {
2546
+ state: "PENDING";
2547
+ } | {
2548
+ state: "BASELINED";
2549
+ impliedEntryBeta: string;
2550
+ } | {
2551
+ state: "TRACKING";
2552
+ impliedEntryBeta: string;
2553
+ lastDerivedBeta: string;
2554
+ lastProcessedBetaTime: string;
2555
+ driftPct?: string | undefined;
2556
+ };
2557
+ pausedReason?: "USER" | "POSITION_CHANGED" | "REPEATED_FAILURES" | "INVALID_LIVE_BETA_EXPOSURE" | undefined;
2336
2558
  };
2337
2559
  }>;
2338
2560
  replace: (id: string, body: HttpTypes.ReplaceAutoRebalanceConfig, headers?: ClientHeaders) => Promise<{
@@ -2340,12 +2562,33 @@ declare class Core {
2340
2562
  id: string;
2341
2563
  positionId: string;
2342
2564
  status: "ACTIVE" | "PAUSED";
2343
- weightSource: "INITIAL_WEIGHT" | "LIVE_BETA";
2344
2565
  minimumDriftPct: string;
2345
2566
  createdAt: string;
2346
2567
  updatedAt: string;
2347
- pausedReason?: "USER" | "POSITION_CHANGED" | "REPEATED_FAILURES" | undefined;
2348
- timeframe?: "1d" | "1h" | "4h" | undefined;
2568
+ weightSource: "INITIAL_WEIGHT";
2569
+ pausedReason?: "USER" | "POSITION_CHANGED" | "REPEATED_FAILURES" | "INVALID_LIVE_BETA_EXPOSURE" | undefined;
2570
+ } | {
2571
+ id: string;
2572
+ positionId: string;
2573
+ status: "ACTIVE" | "PAUSED";
2574
+ minimumDriftPct: string;
2575
+ createdAt: string;
2576
+ updatedAt: string;
2577
+ weightSource: "LIVE_BETA";
2578
+ timeframe: "1d" | "1h" | "4h";
2579
+ beta: {
2580
+ state: "PENDING";
2581
+ } | {
2582
+ state: "BASELINED";
2583
+ impliedEntryBeta: string;
2584
+ } | {
2585
+ state: "TRACKING";
2586
+ impliedEntryBeta: string;
2587
+ lastDerivedBeta: string;
2588
+ lastProcessedBetaTime: string;
2589
+ driftPct?: string | undefined;
2590
+ };
2591
+ pausedReason?: "USER" | "POSITION_CHANGED" | "REPEATED_FAILURES" | "INVALID_LIVE_BETA_EXPOSURE" | undefined;
2349
2592
  };
2350
2593
  }>;
2351
2594
  cancel: (id: string, headers?: ClientHeaders) => Promise<void>;
@@ -2367,6 +2610,17 @@ declare class Core {
2367
2610
  nextCursor?: string | undefined;
2368
2611
  }>;
2369
2612
  };
2613
+ referrals: {
2614
+ /** Issue an immutable referral code to the authenticated user. */
2615
+ create: (body: HttpTypes.CreateReferralCode, headers?: ClientHeaders) => Promise<void>;
2616
+ /** Permanently bind the authenticated user to an existing referral code. */
2617
+ bind: (body: HttpTypes.BindReferralCode, headers?: ClientHeaders) => Promise<void>;
2618
+ /** Return referral codes owned by the authenticated user and their referrer. */
2619
+ status: (headers?: ClientHeaders) => Promise<{
2620
+ ownedCodes: string[];
2621
+ referrerUserId?: string | undefined;
2622
+ }>;
2623
+ };
2370
2624
  savedBaskets: {
2371
2625
  list: (headers?: ClientHeaders) => Promise<{
2372
2626
  baskets: {
@@ -2640,6 +2894,7 @@ declare class Core {
2640
2894
  since: (body: HttpTypes.SyncFillsSinceRequest, headers?: ClientHeaders) => Promise<{
2641
2895
  sinceMs: number;
2642
2896
  neverSynced: boolean;
2897
+ firstSyncStartedAt?: number | undefined;
2643
2898
  confirmedExchangeFillIds?: string[] | undefined;
2644
2899
  }>;
2645
2900
  reconcile: (body: HttpTypes.ReconcileFillsRequest, headers?: ClientHeaders) => Promise<Record<string, never>>;
@@ -207,6 +207,13 @@ class Core {
207
207
  headers,
208
208
  query
209
209
  });
210
+ },
211
+ basketPositions: async (body, headers) => {
212
+ return await this.client.fetch(`/markets/baskets/positions`, {
213
+ method: "POST",
214
+ headers,
215
+ body
216
+ });
210
217
  }
211
218
  };
212
219
  notifications = {
@@ -253,6 +260,19 @@ class Core {
253
260
  method: "GET",
254
261
  headers
255
262
  });
263
+ },
264
+ /**
265
+ * Closed-trade history, newest close first, composed server-side.
266
+ *
267
+ * A page may hold fewer than `limit` trades and still return a `nextCursor` —
268
+ * page until `nextCursor` is absent, never until a page comes back short.
269
+ */
270
+ closed: async (query, headers) => {
271
+ return await this.client.fetch(`/positions/closed`, {
272
+ method: "GET",
273
+ headers,
274
+ query
275
+ });
256
276
  }
257
277
  };
258
278
  portfolio = {
@@ -332,6 +352,31 @@ class Core {
332
352
  });
333
353
  }
334
354
  };
355
+ referrals = {
356
+ /** Issue an immutable referral code to the authenticated user. */
357
+ create: async (body, headers) => {
358
+ return await this.client.fetch(`/referrals/create`, {
359
+ method: "POST",
360
+ headers,
361
+ body
362
+ });
363
+ },
364
+ /** Permanently bind the authenticated user to an existing referral code. */
365
+ bind: async (body, headers) => {
366
+ return await this.client.fetch(`/referrals/bind`, {
367
+ method: "POST",
368
+ headers,
369
+ body
370
+ });
371
+ },
372
+ /** Return referral codes owned by the authenticated user and their referrer. */
373
+ status: async (headers) => {
374
+ return await this.client.fetch(`/referrals/status`, {
375
+ method: "GET",
376
+ headers
377
+ });
378
+ }
379
+ };
335
380
  savedBaskets = {
336
381
  list: async (headers) => {
337
382
  return await this.client.fetch(`/saved-baskets`, {
package/dist/utils.d.ts CHANGED
@@ -4,7 +4,7 @@ import '@pear-protocol/utils';
4
4
 
5
5
  declare function getBaseUrl(passedBaseUrl: string): string;
6
6
  declare function normalizeRequest(init: FetchArgs | undefined, headers: Headers, authMode: AuthMode): RequestInit | undefined;
7
- declare function normalizeResponseData(resp: Response, reqHeaders: Headers): Promise<any>;
7
+ declare function normalizeResponseData(resp: Response, reqHeaders: Headers): Promise<unknown>;
8
8
  declare class FetchError extends Error {
9
9
  status: number | undefined;
10
10
  statusText: string | undefined;
package/dist/utils.js CHANGED
@@ -33,7 +33,14 @@ async function normalizeResponseData(resp, reqHeaders) {
33
33
  return null;
34
34
  }
35
35
  const isJsonRequest = reqHeaders.get("accept")?.includes("application/json");
36
- return isJsonRequest ? await resp.json() : resp;
36
+ if (!isJsonRequest) {
37
+ return resp;
38
+ }
39
+ const responseText = await resp.text();
40
+ if (responseText.length === 0) {
41
+ return null;
42
+ }
43
+ return JSON.parse(responseText);
37
44
  }
38
45
  class FetchError extends Error {
39
46
  status;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/core-sdk",
3
- "version": "1.12.1",
3
+ "version": "1.13.0",
4
4
  "description": "Pear Protocol Core SDK",
5
5
  "private": false,
6
6
  "type": "module",
@@ -25,8 +25,8 @@
25
25
  "typecheck": "tsc --noEmit"
26
26
  },
27
27
  "dependencies": {
28
- "@pear-protocol/types": "^1.15.0",
29
- "@pear-protocol/utils": "^0.4.0",
28
+ "@pear-protocol/types": "^1.17.0",
29
+ "@pear-protocol/utils": "^0.5.0",
30
30
  "qs": "^6.14.0"
31
31
  },
32
32
  "devDependencies": {