@pear-protocol/core-sdk 1.5.0 → 1.7.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/dist/admin/index.d.ts +1 -0
- package/dist/auth/index.d.ts +1 -0
- package/dist/core/index.d.ts +189 -8
- package/dist/core/index.js +13 -0
- package/dist/external/kalshi.js +4 -2
- package/dist/external/polymarket.js +4 -2
- package/dist/http.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -1
- package/dist/types.d.ts +9 -0
- package/dist/utils.d.ts +1 -0
- package/package.json +3 -3
package/dist/admin/index.d.ts
CHANGED
package/dist/auth/index.d.ts
CHANGED
package/dist/core/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { HttpTypes } from '@pear-protocol/types';
|
|
2
2
|
import { HttpClient } from '../http.js';
|
|
3
3
|
import { ClientHeaders } from '../types.js';
|
|
4
|
+
import '@pear-protocol/utils';
|
|
4
5
|
|
|
5
6
|
declare class Core {
|
|
6
7
|
private client;
|
|
@@ -204,7 +205,6 @@ declare class Core {
|
|
|
204
205
|
executions: {
|
|
205
206
|
list: (query: HttpTypes.ExecutionListParamsInput, headers?: ClientHeaders) => Promise<{
|
|
206
207
|
limit: number;
|
|
207
|
-
nextCursor: string | undefined;
|
|
208
208
|
executions: ({
|
|
209
209
|
id: string;
|
|
210
210
|
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
@@ -348,6 +348,152 @@ declare class Core {
|
|
|
348
348
|
filledPrice?: string | undefined;
|
|
349
349
|
}[] | undefined;
|
|
350
350
|
})[];
|
|
351
|
+
nextCursor?: string | undefined;
|
|
352
|
+
}>;
|
|
353
|
+
get: (id: string, headers?: ClientHeaders) => Promise<{
|
|
354
|
+
execution: {
|
|
355
|
+
id: string;
|
|
356
|
+
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
357
|
+
status: "CANCELLED" | "ACTIVE" | "COMPLETED" | "IDLE" | "FAILED";
|
|
358
|
+
createdAt: string;
|
|
359
|
+
updatedAt: string;
|
|
360
|
+
intent: "OPEN";
|
|
361
|
+
orderType: "MARKET";
|
|
362
|
+
legs: [{
|
|
363
|
+
symbol: string;
|
|
364
|
+
side: "BUY" | "SELL";
|
|
365
|
+
mode: "QUANTITY" | "USD";
|
|
366
|
+
amount: string;
|
|
367
|
+
reduceOnly: boolean;
|
|
368
|
+
}, ...{
|
|
369
|
+
symbol: string;
|
|
370
|
+
side: "BUY" | "SELL";
|
|
371
|
+
mode: "QUANTITY" | "USD";
|
|
372
|
+
amount: string;
|
|
373
|
+
reduceOnly: boolean;
|
|
374
|
+
}[]];
|
|
375
|
+
error?: string | undefined;
|
|
376
|
+
orders?: {
|
|
377
|
+
id: string;
|
|
378
|
+
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
379
|
+
status: "CANCELLED" | "PENDING" | "PARTIAL" | "FILLED" | "REJECTED";
|
|
380
|
+
createdAt: string;
|
|
381
|
+
updatedAt: string;
|
|
382
|
+
type: "MARKET";
|
|
383
|
+
symbol: string;
|
|
384
|
+
side: "BUY" | "SELL";
|
|
385
|
+
reduceOnly: boolean;
|
|
386
|
+
leverage: number;
|
|
387
|
+
quantity: string;
|
|
388
|
+
price: string;
|
|
389
|
+
filledQuantity: string;
|
|
390
|
+
error?: string | undefined;
|
|
391
|
+
filledPrice?: string | undefined;
|
|
392
|
+
}[] | undefined;
|
|
393
|
+
} | {
|
|
394
|
+
id: string;
|
|
395
|
+
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
396
|
+
status: "CANCELLED" | "ACTIVE" | "COMPLETED" | "IDLE" | "FAILED";
|
|
397
|
+
createdAt: string;
|
|
398
|
+
updatedAt: string;
|
|
399
|
+
intent: "ADJUST";
|
|
400
|
+
orderType: "MARKET";
|
|
401
|
+
position: {
|
|
402
|
+
id: string;
|
|
403
|
+
exposure: Record<string, `-${string}` | `+${string}`>;
|
|
404
|
+
};
|
|
405
|
+
legs: [{
|
|
406
|
+
symbol: string;
|
|
407
|
+
side: "BUY" | "SELL";
|
|
408
|
+
mode: "QUANTITY" | "USD";
|
|
409
|
+
amount: string;
|
|
410
|
+
reduceOnly: boolean;
|
|
411
|
+
}, ...{
|
|
412
|
+
symbol: string;
|
|
413
|
+
side: "BUY" | "SELL";
|
|
414
|
+
mode: "QUANTITY" | "USD";
|
|
415
|
+
amount: string;
|
|
416
|
+
reduceOnly: boolean;
|
|
417
|
+
}[]];
|
|
418
|
+
error?: string | undefined;
|
|
419
|
+
orders?: {
|
|
420
|
+
id: string;
|
|
421
|
+
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
422
|
+
status: "CANCELLED" | "PENDING" | "PARTIAL" | "FILLED" | "REJECTED";
|
|
423
|
+
createdAt: string;
|
|
424
|
+
updatedAt: string;
|
|
425
|
+
type: "MARKET";
|
|
426
|
+
symbol: string;
|
|
427
|
+
side: "BUY" | "SELL";
|
|
428
|
+
reduceOnly: boolean;
|
|
429
|
+
leverage: number;
|
|
430
|
+
quantity: string;
|
|
431
|
+
price: string;
|
|
432
|
+
filledQuantity: string;
|
|
433
|
+
error?: string | undefined;
|
|
434
|
+
filledPrice?: string | undefined;
|
|
435
|
+
}[] | undefined;
|
|
436
|
+
} | {
|
|
437
|
+
id: string;
|
|
438
|
+
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
439
|
+
status: "CANCELLED" | "ACTIVE" | "COMPLETED" | "IDLE" | "FAILED";
|
|
440
|
+
createdAt: string;
|
|
441
|
+
updatedAt: string;
|
|
442
|
+
intent: "CLOSE";
|
|
443
|
+
orderType: "MARKET";
|
|
444
|
+
position: {
|
|
445
|
+
id: string;
|
|
446
|
+
exposure: Record<string, `-${string}` | `+${string}`>;
|
|
447
|
+
};
|
|
448
|
+
error?: string | undefined;
|
|
449
|
+
orders?: {
|
|
450
|
+
id: string;
|
|
451
|
+
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
452
|
+
status: "CANCELLED" | "PENDING" | "PARTIAL" | "FILLED" | "REJECTED";
|
|
453
|
+
createdAt: string;
|
|
454
|
+
updatedAt: string;
|
|
455
|
+
type: "MARKET";
|
|
456
|
+
symbol: string;
|
|
457
|
+
side: "BUY" | "SELL";
|
|
458
|
+
reduceOnly: boolean;
|
|
459
|
+
leverage: number;
|
|
460
|
+
quantity: string;
|
|
461
|
+
price: string;
|
|
462
|
+
filledQuantity: string;
|
|
463
|
+
error?: string | undefined;
|
|
464
|
+
filledPrice?: string | undefined;
|
|
465
|
+
}[] | undefined;
|
|
466
|
+
} | {
|
|
467
|
+
id: string;
|
|
468
|
+
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
469
|
+
status: "CANCELLED" | "ACTIVE" | "COMPLETED" | "IDLE" | "FAILED";
|
|
470
|
+
createdAt: string;
|
|
471
|
+
updatedAt: string;
|
|
472
|
+
intent: "REVERSE";
|
|
473
|
+
orderType: "MARKET";
|
|
474
|
+
position: {
|
|
475
|
+
id: string;
|
|
476
|
+
exposure: Record<string, `-${string}` | `+${string}`>;
|
|
477
|
+
};
|
|
478
|
+
error?: string | undefined;
|
|
479
|
+
orders?: {
|
|
480
|
+
id: string;
|
|
481
|
+
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
482
|
+
status: "CANCELLED" | "PENDING" | "PARTIAL" | "FILLED" | "REJECTED";
|
|
483
|
+
createdAt: string;
|
|
484
|
+
updatedAt: string;
|
|
485
|
+
type: "MARKET";
|
|
486
|
+
symbol: string;
|
|
487
|
+
side: "BUY" | "SELL";
|
|
488
|
+
reduceOnly: boolean;
|
|
489
|
+
leverage: number;
|
|
490
|
+
quantity: string;
|
|
491
|
+
price: string;
|
|
492
|
+
filledQuantity: string;
|
|
493
|
+
error?: string | undefined;
|
|
494
|
+
filledPrice?: string | undefined;
|
|
495
|
+
}[] | undefined;
|
|
496
|
+
};
|
|
351
497
|
}>;
|
|
352
498
|
};
|
|
353
499
|
fills: {
|
|
@@ -379,7 +525,6 @@ declare class Core {
|
|
|
379
525
|
}>;
|
|
380
526
|
list: (query: HttpTypes.FillListParams, headers?: ClientHeaders) => Promise<{
|
|
381
527
|
limit: number;
|
|
382
|
-
nextCursor: string | undefined;
|
|
383
528
|
fills: {
|
|
384
529
|
id: string;
|
|
385
530
|
status: "PROVISIONAL" | "CONFIRMED" | "RECONCILED";
|
|
@@ -404,6 +549,7 @@ declare class Core {
|
|
|
404
549
|
quantity: string;
|
|
405
550
|
} | undefined;
|
|
406
551
|
}[];
|
|
552
|
+
nextCursor?: string | undefined;
|
|
407
553
|
}>;
|
|
408
554
|
provisionals: (headers?: ClientHeaders) => Promise<{
|
|
409
555
|
fills: {
|
|
@@ -426,7 +572,6 @@ declare class Core {
|
|
|
426
572
|
ladders: {
|
|
427
573
|
list: (query: HttpTypes.LadderListParamsInput, headers?: ClientHeaders) => Promise<{
|
|
428
574
|
limit: number;
|
|
429
|
-
nextCursor: string | undefined;
|
|
430
575
|
ladders: {
|
|
431
576
|
id: string;
|
|
432
577
|
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
@@ -859,6 +1004,7 @@ declare class Core {
|
|
|
859
1004
|
createdAt: string;
|
|
860
1005
|
updatedAt: string;
|
|
861
1006
|
}[];
|
|
1007
|
+
nextCursor?: string | undefined;
|
|
862
1008
|
}>;
|
|
863
1009
|
create: (body: HttpTypes.CreateLadder, headers?: ClientHeaders) => Promise<{
|
|
864
1010
|
ladder: {
|
|
@@ -1822,26 +1968,50 @@ declare class Core {
|
|
|
1822
1968
|
list: (query?: HttpTypes.NotificationListParamsInput, headers?: ClientHeaders) => Promise<{
|
|
1823
1969
|
notifications: {
|
|
1824
1970
|
id: string;
|
|
1825
|
-
category: "TAKE_PROFIT_HIT" | "STOP_LOSS_HIT" | "TRIGGER_ORDER_HIT";
|
|
1971
|
+
category: "TAKE_PROFIT_HIT" | "STOP_LOSS_HIT" | "TRIGGER_ORDER_HIT" | "TAKE_PROFIT_FAILED" | "STOP_LOSS_FAILED" | "TRIGGER_ORDER_FAILED" | "ATTACHED_TRIGGER_DISCARDED";
|
|
1826
1972
|
parameters: {
|
|
1827
1973
|
type: "take_profit";
|
|
1828
1974
|
triggerId: string;
|
|
1829
1975
|
positionId: string;
|
|
1830
1976
|
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
1977
|
+
metric?: "price" | "ratio" | "weighted_ratio" | "funding_rate" | "prediction_market" | "btc_dominance" | "notional" | "upnl" | "upnl_bps" | "ratio_trailing" | "price_trailing" | "weighted_ratio_trailing" | "notional_trailing" | "upnl_trailing" | "upnl_bps_trailing" | undefined;
|
|
1978
|
+
level?: number | undefined;
|
|
1979
|
+
reason?: string | undefined;
|
|
1831
1980
|
} | {
|
|
1832
1981
|
type: "stop_loss";
|
|
1833
1982
|
triggerId: string;
|
|
1834
1983
|
positionId: string;
|
|
1835
1984
|
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
1985
|
+
metric?: "price" | "ratio" | "weighted_ratio" | "funding_rate" | "prediction_market" | "btc_dominance" | "notional" | "upnl" | "upnl_bps" | "ratio_trailing" | "price_trailing" | "weighted_ratio_trailing" | "notional_trailing" | "upnl_trailing" | "upnl_bps_trailing" | undefined;
|
|
1986
|
+
level?: number | undefined;
|
|
1987
|
+
reason?: string | undefined;
|
|
1836
1988
|
} | {
|
|
1837
1989
|
type: "trigger_order";
|
|
1838
1990
|
triggerId: string;
|
|
1839
1991
|
positionId: string;
|
|
1840
1992
|
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
1993
|
+
metric?: "price" | "ratio" | "weighted_ratio" | "funding_rate" | "prediction_market" | "btc_dominance" | "notional" | "upnl" | "upnl_bps" | "ratio_trailing" | "price_trailing" | "weighted_ratio_trailing" | "notional_trailing" | "upnl_trailing" | "upnl_bps_trailing" | undefined;
|
|
1994
|
+
level?: number | undefined;
|
|
1995
|
+
reason?: string | undefined;
|
|
1841
1996
|
} | {
|
|
1842
1997
|
type: "default_trigger";
|
|
1843
1998
|
triggerId: string;
|
|
1844
1999
|
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
2000
|
+
metric?: "price" | "ratio" | "weighted_ratio" | "funding_rate" | "prediction_market" | "btc_dominance" | "notional" | "upnl" | "upnl_bps" | "ratio_trailing" | "price_trailing" | "weighted_ratio_trailing" | "notional_trailing" | "upnl_trailing" | "upnl_bps_trailing" | undefined;
|
|
2001
|
+
level?: number | undefined;
|
|
2002
|
+
reason?: string | undefined;
|
|
2003
|
+
} | {
|
|
2004
|
+
type: "attached_trigger_discarded";
|
|
2005
|
+
positionId: string;
|
|
2006
|
+
positionKey: string;
|
|
2007
|
+
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
2008
|
+
discarded: {
|
|
2009
|
+
bracketType: "STOP_LOSS" | "TAKE_PROFIT";
|
|
2010
|
+
metric: "price" | "ratio" | "weighted_ratio" | "funding_rate" | "prediction_market" | "btc_dominance" | "notional" | "upnl" | "upnl_bps" | "ratio_trailing" | "price_trailing" | "weighted_ratio_trailing" | "notional_trailing" | "upnl_trailing" | "upnl_bps_trailing";
|
|
2011
|
+
reason: "TRIGGER_LIMIT" | "TRAILING_ALREADY_EXISTS";
|
|
2012
|
+
level?: number | undefined;
|
|
2013
|
+
}[];
|
|
2014
|
+
activeTriggerLimit: number;
|
|
1845
2015
|
};
|
|
1846
2016
|
isRead: boolean;
|
|
1847
2017
|
createdAt: string;
|
|
@@ -1868,6 +2038,7 @@ declare class Core {
|
|
|
1868
2038
|
};
|
|
1869
2039
|
positions: {
|
|
1870
2040
|
list: (query: HttpTypes.PositionListParamsInput, headers?: ClientHeaders) => Promise<{
|
|
2041
|
+
limit: number;
|
|
1871
2042
|
positions: {
|
|
1872
2043
|
id: string;
|
|
1873
2044
|
tradeAccountId: string;
|
|
@@ -1877,11 +2048,13 @@ declare class Core {
|
|
|
1877
2048
|
exposure: Record<string, `-${string}` | `+${string}`>;
|
|
1878
2049
|
totalFundingPayment: Record<string, `-${string}` | `+${string}`>;
|
|
1879
2050
|
initialExposureUSD: Record<string, `-${string}` | `+${string}`>;
|
|
2051
|
+
entryPrices: Record<string, string>;
|
|
1880
2052
|
createdAt: string;
|
|
1881
2053
|
updatedAt: string;
|
|
1882
2054
|
closedReason?: "USER" | "NETTED" | "LIQUIDATED" | null | undefined;
|
|
1883
2055
|
closedAt?: string | null | undefined;
|
|
1884
2056
|
}[];
|
|
2057
|
+
nextCursor?: string | undefined;
|
|
1885
2058
|
}>;
|
|
1886
2059
|
openLite: (headers?: ClientHeaders) => Promise<{
|
|
1887
2060
|
positions: {
|
|
@@ -2089,7 +2262,6 @@ declare class Core {
|
|
|
2089
2262
|
auto: {
|
|
2090
2263
|
list: (query?: HttpTypes.AutoRebalanceListParamsInput, headers?: ClientHeaders) => Promise<{
|
|
2091
2264
|
limit: number;
|
|
2092
|
-
nextCursor: string | undefined;
|
|
2093
2265
|
items: {
|
|
2094
2266
|
id: string;
|
|
2095
2267
|
positionId: string;
|
|
@@ -2100,6 +2272,7 @@ declare class Core {
|
|
|
2100
2272
|
updatedAt: string;
|
|
2101
2273
|
timeframe?: "1d" | "1h" | "4h" | undefined;
|
|
2102
2274
|
}[];
|
|
2275
|
+
nextCursor?: string | undefined;
|
|
2103
2276
|
}>;
|
|
2104
2277
|
create: (body: HttpTypes.CreateAutoRebalanceConfig, headers?: ClientHeaders) => Promise<{
|
|
2105
2278
|
config: {
|
|
@@ -2129,7 +2302,6 @@ declare class Core {
|
|
|
2129
2302
|
};
|
|
2130
2303
|
listEvents: (positionId: string, query?: HttpTypes.RebalanceEventListParamsInput, headers?: ClientHeaders) => Promise<{
|
|
2131
2304
|
limit: number;
|
|
2132
|
-
nextCursor: string | undefined;
|
|
2133
2305
|
items: {
|
|
2134
2306
|
id: string;
|
|
2135
2307
|
autoRebalanceConfigId: string;
|
|
@@ -2142,6 +2314,7 @@ declare class Core {
|
|
|
2142
2314
|
createdAt: string;
|
|
2143
2315
|
error?: string | undefined;
|
|
2144
2316
|
}[];
|
|
2317
|
+
nextCursor?: string | undefined;
|
|
2145
2318
|
}>;
|
|
2146
2319
|
};
|
|
2147
2320
|
savedBaskets: {
|
|
@@ -2201,7 +2374,6 @@ declare class Core {
|
|
|
2201
2374
|
schedules: {
|
|
2202
2375
|
list: (query: HttpTypes.ScheduleListParamsInput, headers?: ClientHeaders) => Promise<{
|
|
2203
2376
|
limit: number;
|
|
2204
|
-
nextCursor: string | undefined;
|
|
2205
2377
|
schedules: ({
|
|
2206
2378
|
id: string;
|
|
2207
2379
|
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
@@ -2297,6 +2469,7 @@ declare class Core {
|
|
|
2297
2469
|
} | undefined;
|
|
2298
2470
|
}[] | undefined;
|
|
2299
2471
|
})[];
|
|
2472
|
+
nextCursor?: string | undefined;
|
|
2300
2473
|
}>;
|
|
2301
2474
|
create: (body: HttpTypes.CreateSchedule, headers?: ClientHeaders) => Promise<{
|
|
2302
2475
|
schedule: {
|
|
@@ -3153,7 +3326,6 @@ declare class Core {
|
|
|
3153
3326
|
triggers: {
|
|
3154
3327
|
list: (query: HttpTypes.TriggerListParamsInput, headers?: ClientHeaders) => Promise<{
|
|
3155
3328
|
limit: number;
|
|
3156
|
-
nextCursor: string | undefined;
|
|
3157
3329
|
triggers: ({
|
|
3158
3330
|
id: string;
|
|
3159
3331
|
tradeAccountId: string;
|
|
@@ -3572,6 +3744,7 @@ declare class Core {
|
|
|
3572
3744
|
stopBreachedAt?: number | undefined;
|
|
3573
3745
|
} | undefined;
|
|
3574
3746
|
})[];
|
|
3747
|
+
nextCursor?: string | undefined;
|
|
3575
3748
|
}>;
|
|
3576
3749
|
open: (body: HttpTypes.CreateTriggerOpen, headers?: ClientHeaders) => Promise<{
|
|
3577
3750
|
trigger: {
|
|
@@ -4485,6 +4658,14 @@ declare class Core {
|
|
|
4485
4658
|
openPositions: number;
|
|
4486
4659
|
}[];
|
|
4487
4660
|
}>;
|
|
4661
|
+
totals: (query: HttpTypes.StatisticsTotalsQueryParamsInput, headers?: ClientHeaders) => Promise<{
|
|
4662
|
+
data: {
|
|
4663
|
+
totalVolume: number;
|
|
4664
|
+
totalFees: number;
|
|
4665
|
+
totalTrades: number;
|
|
4666
|
+
totalUsers: number;
|
|
4667
|
+
};
|
|
4668
|
+
}>;
|
|
4488
4669
|
};
|
|
4489
4670
|
tca: {
|
|
4490
4671
|
execution: (executionId: string, headers?: ClientHeaders) => Promise<{
|
package/dist/core/index.js
CHANGED
|
@@ -83,6 +83,12 @@ class Core {
|
|
|
83
83
|
headers,
|
|
84
84
|
query
|
|
85
85
|
});
|
|
86
|
+
},
|
|
87
|
+
get: async (id, headers) => {
|
|
88
|
+
return await this.client.fetch(`/executions/${id}`, {
|
|
89
|
+
method: "GET",
|
|
90
|
+
headers
|
|
91
|
+
});
|
|
86
92
|
}
|
|
87
93
|
};
|
|
88
94
|
fills = {
|
|
@@ -575,6 +581,13 @@ class Core {
|
|
|
575
581
|
headers,
|
|
576
582
|
query
|
|
577
583
|
});
|
|
584
|
+
},
|
|
585
|
+
totals: async (query, headers) => {
|
|
586
|
+
return await this.client.fetch(`/statistics/totals`, {
|
|
587
|
+
method: "GET",
|
|
588
|
+
headers,
|
|
589
|
+
query
|
|
590
|
+
});
|
|
578
591
|
}
|
|
579
592
|
};
|
|
580
593
|
tca = {
|
package/dist/external/kalshi.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { proxyFetch } from '@pear-protocol/utils';
|
|
2
|
+
|
|
1
3
|
const BASE_URL = "https://api.elections.kalshi.com";
|
|
2
4
|
const BATCH_SIZE = 100;
|
|
3
5
|
async function fetchKalshiMarketNames(tickers) {
|
|
@@ -7,7 +9,7 @@ async function fetchKalshiMarketNames(tickers) {
|
|
|
7
9
|
const url = new URL(`${BASE_URL}/trade-api/v2/markets`);
|
|
8
10
|
url.searchParams.set("tickers", batch.join(","));
|
|
9
11
|
url.searchParams.set("limit", String(BATCH_SIZE));
|
|
10
|
-
const response = await
|
|
12
|
+
const response = await proxyFetch(url, { method: "GET", headers: { accept: "application/json" } });
|
|
11
13
|
if (!response.ok) throw new Error(`Kalshi API error: ${response.status} ${response.statusText}`);
|
|
12
14
|
const data = await response.json();
|
|
13
15
|
for (const m of data.markets ?? []) result.set(m.ticker, m.title);
|
|
@@ -22,7 +24,7 @@ async function searchKalshiTriggers(params = {}) {
|
|
|
22
24
|
if (params.category) url.searchParams.set("category", params.category);
|
|
23
25
|
if (params.search) url.searchParams.set("query", params.search);
|
|
24
26
|
if (params.cursor) url.searchParams.set("cursor", params.cursor);
|
|
25
|
-
const response = await
|
|
27
|
+
const response = await proxyFetch(url, { method: "GET", headers: { accept: "application/json" } });
|
|
26
28
|
if (!response.ok) return { triggers: [], nextCursor: null };
|
|
27
29
|
const data = await response.json();
|
|
28
30
|
return {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { proxyFetch } from '@pear-protocol/utils';
|
|
2
|
+
|
|
1
3
|
const BASE_URL = "https://gamma-api.polymarket.com";
|
|
2
4
|
const BATCH_SIZE = 100;
|
|
3
5
|
async function fetchPolymarketMarketNames(ids) {
|
|
@@ -7,7 +9,7 @@ async function fetchPolymarketMarketNames(ids) {
|
|
|
7
9
|
const url = new URL(`${BASE_URL}/markets`);
|
|
8
10
|
for (const id of batch) url.searchParams.append("id", id);
|
|
9
11
|
url.searchParams.set("limit", String(BATCH_SIZE));
|
|
10
|
-
const response = await
|
|
12
|
+
const response = await proxyFetch(url, { method: "GET", headers: { accept: "application/json" } });
|
|
11
13
|
if (!response.ok) throw new Error(`Polymarket API error: ${response.status} ${response.statusText}`);
|
|
12
14
|
const data = await response.json();
|
|
13
15
|
for (const m of data) result.set(m.id, m.question ?? m.groupItemTitle ?? "");
|
|
@@ -23,7 +25,7 @@ async function searchPolymarketTriggers(params = {}) {
|
|
|
23
25
|
if (params.search) url.searchParams.set("title_search", params.search);
|
|
24
26
|
if (params.category) url.searchParams.set("tag_slug", params.category);
|
|
25
27
|
if (params.cursor) url.searchParams.set("after_cursor", params.cursor);
|
|
26
|
-
const response = await
|
|
28
|
+
const response = await proxyFetch(url, { method: "GET", headers: { accept: "application/json" } });
|
|
27
29
|
if (!response.ok) return { triggers: [], nextCursor: null };
|
|
28
30
|
const data = await response.json();
|
|
29
31
|
const events = data.events ?? [];
|
package/dist/http.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { External } from './external/index.js';
|
|
|
5
5
|
import { SDKConfig } from './types.js';
|
|
6
6
|
export { ExternalTrigger, ExternalTriggerSource, HttpTypes, SearchTriggersParams, SearchTriggersResponse, TriggerOutcome } from '@pear-protocol/types';
|
|
7
7
|
export * from '@pear-protocol/utils';
|
|
8
|
+
export { FetchError } from './utils.js';
|
|
8
9
|
import './http.js';
|
|
9
10
|
|
|
10
11
|
declare class PearSDK {
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { configureProxy } from '@pear-protocol/utils';
|
|
2
|
+
export * from '@pear-protocol/utils';
|
|
1
3
|
import { Admin } from './admin';
|
|
2
4
|
import { Auth } from './auth';
|
|
3
5
|
import { Core } from './core';
|
|
@@ -5,7 +7,7 @@ import { External } from './external';
|
|
|
5
7
|
export { External } from './external';
|
|
6
8
|
import { HttpClient } from './http';
|
|
7
9
|
import { FetchError } from './utils';
|
|
8
|
-
export
|
|
10
|
+
export { FetchError } from './utils';
|
|
9
11
|
|
|
10
12
|
const SESSION_REFRESH_PATH = "/auth/session/refresh";
|
|
11
13
|
const SESSION_REFRESH_TIMEOUT_MS = 15e3;
|
|
@@ -35,6 +37,7 @@ class PearSDK {
|
|
|
35
37
|
core;
|
|
36
38
|
external;
|
|
37
39
|
constructor(config) {
|
|
40
|
+
if (config.proxy) configureProxy(config.proxy);
|
|
38
41
|
const authMode = config.auth?.type ?? "session";
|
|
39
42
|
const logger = config.logger ?? {
|
|
40
43
|
error: console.error,
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HttpTypes } from '@pear-protocol/types';
|
|
2
|
+
import { ProxyConfig } from '@pear-protocol/utils';
|
|
2
3
|
|
|
3
4
|
type AuthMode = 'session' | 'bearer' | 'apikey';
|
|
4
5
|
type SDKConfig = {
|
|
@@ -88,6 +89,14 @@ type SDKConfig = {
|
|
|
88
89
|
* Example: true
|
|
89
90
|
*/
|
|
90
91
|
debug?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Optional forward-proxy for the SDK's external HTTP calls (prediction-market data). When
|
|
94
|
+
* enabled, requests are re-pointed at `proxy.url` with the original host in `X-Proxy-Target`.
|
|
95
|
+
* Injected here because the SDK also runs in the browser, where env vars are unavailable.
|
|
96
|
+
*
|
|
97
|
+
* Example: { enabled: true, url: 'http://proxy.internal:8080' }
|
|
98
|
+
*/
|
|
99
|
+
proxy?: ProxyConfig;
|
|
91
100
|
};
|
|
92
101
|
type Logger = {
|
|
93
102
|
error: (...messages: string[]) => void;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FetchArgs, AuthMode } from './types.js';
|
|
2
2
|
import '@pear-protocol/types';
|
|
3
|
+
import '@pear-protocol/utils';
|
|
3
4
|
|
|
4
5
|
declare function getBaseUrl(passedBaseUrl: string): string;
|
|
5
6
|
declare function normalizeRequest(init: FetchArgs | undefined, headers: Headers, authMode: AuthMode): RequestInit | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pear-protocol/core-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Pear Protocol Core SDK",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"typecheck": "tsc --noEmit"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@pear-protocol/types": "^1.
|
|
31
|
-
"@pear-protocol/utils": "^0.
|
|
30
|
+
"@pear-protocol/types": "^1.9.0",
|
|
31
|
+
"@pear-protocol/utils": "^0.2.0",
|
|
32
32
|
"qs": "^6.14.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|