opentool 0.18.0 → 0.19.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/adapters/polymarket/index.d.ts +150 -10
- package/dist/adapters/polymarket/index.js +321 -33
- package/dist/adapters/polymarket/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +321 -33
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/templates/base/package.json +1 -1
- package/templates/polymarket-simple-trade/README.md +24 -0
- package/templates/polymarket-simple-trade/metadata.ts +12 -0
- package/templates/polymarket-simple-trade/package.json +23 -0
- package/templates/polymarket-simple-trade/tools/place-polymarket-order.ts +122 -0
- package/templates/polymarket-simple-trade/tsconfig.json +14 -0
|
@@ -187,20 +187,16 @@ interface PolymarketPlaceOrderResponse {
|
|
|
187
187
|
message?: string;
|
|
188
188
|
[key: string]: unknown;
|
|
189
189
|
}
|
|
190
|
-
|
|
190
|
+
interface PolymarketApiKeyRequestArgs {
|
|
191
191
|
wallet: WalletFullContext;
|
|
192
192
|
environment?: PolymarketEnvironment;
|
|
193
193
|
timestamp?: number;
|
|
194
194
|
nonce?: number;
|
|
195
195
|
message?: string;
|
|
196
|
-
}
|
|
197
|
-
declare function
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
timestamp?: number;
|
|
201
|
-
nonce?: number;
|
|
202
|
-
message?: string;
|
|
203
|
-
}): Promise<PolymarketApiKeyResponse>;
|
|
196
|
+
}
|
|
197
|
+
declare function createPolymarketApiKey(args: PolymarketApiKeyRequestArgs): Promise<PolymarketApiKeyResponse>;
|
|
198
|
+
declare function derivePolymarketApiKey(args: PolymarketApiKeyRequestArgs): Promise<PolymarketApiKeyResponse>;
|
|
199
|
+
declare function createOrDerivePolymarketApiKey(args: PolymarketApiKeyRequestArgs): Promise<PolymarketApiKeyResponse>;
|
|
204
200
|
declare function placePolymarketOrder(args: {
|
|
205
201
|
wallet: WalletFullContext;
|
|
206
202
|
credentials?: PolymarketApiCredentials;
|
|
@@ -253,6 +249,8 @@ declare class PolymarketExchangeClient {
|
|
|
253
249
|
cancelMarket(tokenId: string): Promise<Record<string, unknown>>;
|
|
254
250
|
}
|
|
255
251
|
|
|
252
|
+
type CsvStringInput = string | string[];
|
|
253
|
+
type CsvNumberInput = number | number[];
|
|
256
254
|
type FetchParams = {
|
|
257
255
|
environment?: PolymarketEnvironment;
|
|
258
256
|
limit?: number;
|
|
@@ -267,6 +265,135 @@ type FetchParams = {
|
|
|
267
265
|
active?: boolean;
|
|
268
266
|
closed?: boolean;
|
|
269
267
|
};
|
|
268
|
+
interface PolymarketUserPosition {
|
|
269
|
+
proxyWallet?: string | null;
|
|
270
|
+
asset?: string | null;
|
|
271
|
+
conditionId?: string | null;
|
|
272
|
+
size?: number | null;
|
|
273
|
+
avgPrice?: number | null;
|
|
274
|
+
initialValue?: number | null;
|
|
275
|
+
currentValue?: number | null;
|
|
276
|
+
cashPnl?: number | null;
|
|
277
|
+
percentPnl?: number | null;
|
|
278
|
+
totalBought?: number | null;
|
|
279
|
+
realizedPnl?: number | null;
|
|
280
|
+
percentRealizedPnl?: number | null;
|
|
281
|
+
curPrice?: number | null;
|
|
282
|
+
redeemable?: boolean;
|
|
283
|
+
mergeable?: boolean;
|
|
284
|
+
title?: string | null;
|
|
285
|
+
slug?: string | null;
|
|
286
|
+
icon?: string | null;
|
|
287
|
+
eventSlug?: string | null;
|
|
288
|
+
outcome?: string | null;
|
|
289
|
+
outcomeIndex?: number | null;
|
|
290
|
+
oppositeOutcome?: string | null;
|
|
291
|
+
oppositeAsset?: string | null;
|
|
292
|
+
endDate?: string | null;
|
|
293
|
+
negativeRisk?: boolean;
|
|
294
|
+
}
|
|
295
|
+
interface PolymarketClosedPosition {
|
|
296
|
+
proxyWallet?: string | null;
|
|
297
|
+
asset?: string | null;
|
|
298
|
+
conditionId?: string | null;
|
|
299
|
+
avgPrice?: number | null;
|
|
300
|
+
totalBought?: number | null;
|
|
301
|
+
realizedPnl?: number | null;
|
|
302
|
+
curPrice?: number | null;
|
|
303
|
+
timestamp?: number | null;
|
|
304
|
+
title?: string | null;
|
|
305
|
+
slug?: string | null;
|
|
306
|
+
icon?: string | null;
|
|
307
|
+
eventSlug?: string | null;
|
|
308
|
+
outcome?: string | null;
|
|
309
|
+
outcomeIndex?: number | null;
|
|
310
|
+
oppositeOutcome?: string | null;
|
|
311
|
+
oppositeAsset?: string | null;
|
|
312
|
+
endDate?: string | null;
|
|
313
|
+
}
|
|
314
|
+
type PolymarketActivityType = "TRADE" | "SPLIT" | "MERGE" | "REDEEM" | "REWARD" | "CONVERSION" | "MAKER_REBATE";
|
|
315
|
+
interface PolymarketUserActivity {
|
|
316
|
+
proxyWallet?: string | null;
|
|
317
|
+
timestamp?: number | null;
|
|
318
|
+
conditionId?: string | null;
|
|
319
|
+
type?: PolymarketActivityType | null;
|
|
320
|
+
size?: number | null;
|
|
321
|
+
usdcSize?: number | null;
|
|
322
|
+
transactionHash?: string | null;
|
|
323
|
+
price?: number | null;
|
|
324
|
+
asset?: string | null;
|
|
325
|
+
side?: "BUY" | "SELL" | null;
|
|
326
|
+
outcomeIndex?: number | null;
|
|
327
|
+
title?: string | null;
|
|
328
|
+
slug?: string | null;
|
|
329
|
+
icon?: string | null;
|
|
330
|
+
eventSlug?: string | null;
|
|
331
|
+
outcome?: string | null;
|
|
332
|
+
name?: string | null;
|
|
333
|
+
pseudonym?: string | null;
|
|
334
|
+
bio?: string | null;
|
|
335
|
+
profileImage?: string | null;
|
|
336
|
+
profileImageOptimized?: string | null;
|
|
337
|
+
}
|
|
338
|
+
interface PolymarketPositionValue {
|
|
339
|
+
user?: string | null;
|
|
340
|
+
value?: number | null;
|
|
341
|
+
}
|
|
342
|
+
interface PolymarketPublicProfileUser {
|
|
343
|
+
id?: string | null;
|
|
344
|
+
creator?: boolean;
|
|
345
|
+
mod?: boolean;
|
|
346
|
+
}
|
|
347
|
+
interface PolymarketPublicProfile {
|
|
348
|
+
createdAt?: string | null;
|
|
349
|
+
proxyWallet?: string | null;
|
|
350
|
+
profileImage?: string | null;
|
|
351
|
+
displayUsernamePublic?: boolean | null;
|
|
352
|
+
bio?: string | null;
|
|
353
|
+
pseudonym?: string | null;
|
|
354
|
+
name?: string | null;
|
|
355
|
+
users?: PolymarketPublicProfileUser[] | null;
|
|
356
|
+
xUsername?: string | null;
|
|
357
|
+
verifiedBadge?: boolean | null;
|
|
358
|
+
}
|
|
359
|
+
interface PolymarketUserQueryBase {
|
|
360
|
+
user: string;
|
|
361
|
+
environment?: PolymarketEnvironment;
|
|
362
|
+
market?: CsvStringInput;
|
|
363
|
+
eventId?: CsvNumberInput;
|
|
364
|
+
}
|
|
365
|
+
interface PolymarketUserPositionParams extends PolymarketUserQueryBase {
|
|
366
|
+
sizeThreshold?: number;
|
|
367
|
+
redeemable?: boolean;
|
|
368
|
+
mergeable?: boolean;
|
|
369
|
+
limit?: number;
|
|
370
|
+
offset?: number;
|
|
371
|
+
sortBy?: "CURRENT" | "INITIAL" | "TOKENS" | "CASHPNL" | "PERCENTPNL" | "TITLE" | "RESOLVING" | "PRICE" | "AVGPRICE";
|
|
372
|
+
sortDirection?: "ASC" | "DESC";
|
|
373
|
+
title?: string;
|
|
374
|
+
}
|
|
375
|
+
interface PolymarketClosedPositionParams extends PolymarketUserQueryBase {
|
|
376
|
+
limit?: number;
|
|
377
|
+
offset?: number;
|
|
378
|
+
sortBy?: "REALIZEDPNL" | "TITLE" | "PRICE" | "AVGPRICE" | "TIMESTAMP";
|
|
379
|
+
sortDirection?: "ASC" | "DESC";
|
|
380
|
+
title?: string;
|
|
381
|
+
}
|
|
382
|
+
interface PolymarketUserActivityParams extends PolymarketUserQueryBase {
|
|
383
|
+
limit?: number;
|
|
384
|
+
offset?: number;
|
|
385
|
+
type?: PolymarketActivityType | PolymarketActivityType[];
|
|
386
|
+
start?: number;
|
|
387
|
+
end?: number;
|
|
388
|
+
sortBy?: "TIMESTAMP" | "TOKENS" | "CASH";
|
|
389
|
+
sortDirection?: "ASC" | "DESC";
|
|
390
|
+
side?: "BUY" | "SELL";
|
|
391
|
+
}
|
|
392
|
+
interface PolymarketPositionValueParams {
|
|
393
|
+
user: string;
|
|
394
|
+
environment?: PolymarketEnvironment;
|
|
395
|
+
market?: CsvStringInput;
|
|
396
|
+
}
|
|
270
397
|
declare class PolymarketInfoClient {
|
|
271
398
|
private readonly environment;
|
|
272
399
|
constructor(environment?: PolymarketEnvironment);
|
|
@@ -286,6 +413,11 @@ declare class PolymarketInfoClient {
|
|
|
286
413
|
interval?: string;
|
|
287
414
|
fidelity?: number;
|
|
288
415
|
}): Promise<PolymarketPriceHistoryPoint[]>;
|
|
416
|
+
positions(params: Omit<PolymarketUserPositionParams, "environment">): Promise<PolymarketUserPosition[]>;
|
|
417
|
+
closedPositions(params: Omit<PolymarketClosedPositionParams, "environment">): Promise<PolymarketClosedPosition[]>;
|
|
418
|
+
activity(params: Omit<PolymarketUserActivityParams, "environment">): Promise<PolymarketUserActivity[]>;
|
|
419
|
+
positionValue(params: Omit<PolymarketPositionValueParams, "environment">): Promise<PolymarketPositionValue[]>;
|
|
420
|
+
publicProfile(address: string): Promise<PolymarketPublicProfile | null>;
|
|
289
421
|
}
|
|
290
422
|
declare function fetchPolymarketMarkets(params?: FetchParams): Promise<PolymarketMarket[]>;
|
|
291
423
|
declare function fetchPolymarketMarket(params: {
|
|
@@ -315,5 +447,13 @@ declare function fetchPolymarketPriceHistory(params: {
|
|
|
315
447
|
fidelity?: number;
|
|
316
448
|
environment?: PolymarketEnvironment;
|
|
317
449
|
}): Promise<PolymarketPriceHistoryPoint[]>;
|
|
450
|
+
declare function fetchPolymarketPositions(params: PolymarketUserPositionParams): Promise<PolymarketUserPosition[]>;
|
|
451
|
+
declare function fetchPolymarketClosedPositions(params: PolymarketClosedPositionParams): Promise<PolymarketClosedPosition[]>;
|
|
452
|
+
declare function fetchPolymarketActivity(params: PolymarketUserActivityParams): Promise<PolymarketUserActivity[]>;
|
|
453
|
+
declare function fetchPolymarketPositionValue(params: PolymarketPositionValueParams): Promise<PolymarketPositionValue[]>;
|
|
454
|
+
declare function fetchPolymarketPublicProfile(params: {
|
|
455
|
+
address: string;
|
|
456
|
+
environment?: PolymarketEnvironment;
|
|
457
|
+
}): Promise<PolymarketPublicProfile | null>;
|
|
318
458
|
|
|
319
|
-
export { POLYMARKET_CHAIN_ID, POLYMARKET_CLOB_AUTH_DOMAIN, POLYMARKET_CLOB_DOMAIN, POLYMARKET_ENDPOINTS, POLYMARKET_EXCHANGE_ADDRESSES, type PolymarketApiCredentials, PolymarketApiError, type PolymarketApiKeyResponse, PolymarketAuthError, type PolymarketEnvironment, PolymarketExchangeClient, PolymarketInfoClient, type PolymarketMarket, type PolymarketOrderIntent, type PolymarketOrderType, type PolymarketOrderbook, type PolymarketPlaceOrderResponse, type PolymarketPriceHistoryPoint, type PolymarketSide, type PolymarketSignatureType, type PolymarketSignedOrderPayload, buildHmacSignature, buildL1Headers, buildL2Headers, buildPolymarketOrderAmounts, buildSignedOrderPayload, cancelAllPolymarketOrders, cancelMarketPolymarketOrders, cancelPolymarketOrder, cancelPolymarketOrders, createPolymarketApiKey, derivePolymarketApiKey, fetchPolymarketMarket, fetchPolymarketMarkets, fetchPolymarketMidpoint, fetchPolymarketOrderbook, fetchPolymarketPrice, fetchPolymarketPriceHistory, normalizeNumberArrayish, normalizeStringArrayish, placePolymarketOrder, resolveExchangeAddress, resolvePolymarketBaseUrl };
|
|
459
|
+
export { POLYMARKET_CHAIN_ID, POLYMARKET_CLOB_AUTH_DOMAIN, POLYMARKET_CLOB_DOMAIN, POLYMARKET_ENDPOINTS, POLYMARKET_EXCHANGE_ADDRESSES, type PolymarketActivityType, type PolymarketApiCredentials, PolymarketApiError, type PolymarketApiKeyResponse, PolymarketAuthError, type PolymarketClosedPosition, type PolymarketClosedPositionParams, type PolymarketEnvironment, PolymarketExchangeClient, PolymarketInfoClient, type PolymarketMarket, type PolymarketOrderIntent, type PolymarketOrderType, type PolymarketOrderbook, type PolymarketPlaceOrderResponse, type PolymarketPositionValue, type PolymarketPositionValueParams, type PolymarketPriceHistoryPoint, type PolymarketPublicProfile, type PolymarketPublicProfileUser, type PolymarketSide, type PolymarketSignatureType, type PolymarketSignedOrderPayload, type PolymarketUserActivity, type PolymarketUserActivityParams, type PolymarketUserPosition, type PolymarketUserPositionParams, buildHmacSignature, buildL1Headers, buildL2Headers, buildPolymarketOrderAmounts, buildSignedOrderPayload, cancelAllPolymarketOrders, cancelMarketPolymarketOrders, cancelPolymarketOrder, cancelPolymarketOrders, createOrDerivePolymarketApiKey, createPolymarketApiKey, derivePolymarketApiKey, fetchPolymarketActivity, fetchPolymarketClosedPositions, fetchPolymarketMarket, fetchPolymarketMarkets, fetchPolymarketMidpoint, fetchPolymarketOrderbook, fetchPolymarketPositionValue, fetchPolymarketPositions, fetchPolymarketPrice, fetchPolymarketPriceHistory, fetchPolymarketPublicProfile, normalizeNumberArrayish, normalizeStringArrayish, placePolymarketOrder, resolveExchangeAddress, resolvePolymarketBaseUrl };
|
|
@@ -315,7 +315,7 @@ async function buildSignedOrderPayload(args) {
|
|
|
315
315
|
// src/adapters/polymarket/exchange.ts
|
|
316
316
|
async function resolveAuthContext(args) {
|
|
317
317
|
if (args.wallet) {
|
|
318
|
-
const credentials = args.credentials ?? await
|
|
318
|
+
const credentials = args.credentials ?? await createOrDerivePolymarketApiKey({
|
|
319
319
|
wallet: args.wallet,
|
|
320
320
|
...args.environment ? { environment: args.environment } : {}
|
|
321
321
|
});
|
|
@@ -352,27 +352,9 @@ function resolvePath(url) {
|
|
|
352
352
|
const parsed = new URL(url);
|
|
353
353
|
return `${parsed.pathname}${parsed.search}`;
|
|
354
354
|
}
|
|
355
|
-
|
|
356
|
-
const environment = args.environment ?? "mainnet";
|
|
357
|
-
const baseUrl = resolvePolymarketBaseUrl("clob", environment);
|
|
358
|
-
const url = `${baseUrl}/auth/api-key`;
|
|
359
|
-
const headers = await buildL1Headers({
|
|
360
|
-
wallet: args.wallet,
|
|
361
|
-
environment,
|
|
362
|
-
...args.timestamp !== void 0 ? { timestamp: args.timestamp } : {},
|
|
363
|
-
...args.nonce !== void 0 ? { nonce: args.nonce } : {},
|
|
364
|
-
...args.message !== void 0 ? { message: args.message } : {}
|
|
365
|
-
});
|
|
366
|
-
const data = await requestJson(url, {
|
|
367
|
-
method: "POST",
|
|
368
|
-
headers: {
|
|
369
|
-
"content-type": "application/json",
|
|
370
|
-
...headers
|
|
371
|
-
},
|
|
372
|
-
body: JSON.stringify({})
|
|
373
|
-
});
|
|
355
|
+
function normalizeApiKeyResponse(data) {
|
|
374
356
|
if (!data?.apiKey || !data?.secret || !data?.passphrase) {
|
|
375
|
-
|
|
357
|
+
return null;
|
|
376
358
|
}
|
|
377
359
|
return {
|
|
378
360
|
apiKey: data.apiKey,
|
|
@@ -380,10 +362,10 @@ async function createPolymarketApiKey(args) {
|
|
|
380
362
|
passphrase: data.passphrase
|
|
381
363
|
};
|
|
382
364
|
}
|
|
383
|
-
async function
|
|
365
|
+
async function requestPolymarketApiKey(args) {
|
|
384
366
|
const environment = args.environment ?? "mainnet";
|
|
385
367
|
const baseUrl = resolvePolymarketBaseUrl("clob", environment);
|
|
386
|
-
const url = `${baseUrl}/auth/derive-api-key`;
|
|
368
|
+
const url = args.mode === "create" ? `${baseUrl}/auth/api-key` : `${baseUrl}/auth/derive-api-key`;
|
|
387
369
|
const headers = await buildL1Headers({
|
|
388
370
|
wallet: args.wallet,
|
|
389
371
|
environment,
|
|
@@ -391,21 +373,41 @@ async function derivePolymarketApiKey(args) {
|
|
|
391
373
|
...args.nonce !== void 0 ? { nonce: args.nonce } : {},
|
|
392
374
|
...args.message !== void 0 ? { message: args.message } : {}
|
|
393
375
|
});
|
|
394
|
-
|
|
395
|
-
method: "GET",
|
|
376
|
+
return await requestJson(url, {
|
|
377
|
+
method: args.mode === "create" ? "POST" : "GET",
|
|
396
378
|
headers: {
|
|
397
379
|
"content-type": "application/json",
|
|
398
380
|
...headers
|
|
399
|
-
}
|
|
381
|
+
},
|
|
382
|
+
...args.mode === "create" ? { body: JSON.stringify({}) } : {}
|
|
400
383
|
});
|
|
401
|
-
|
|
384
|
+
}
|
|
385
|
+
async function createPolymarketApiKey(args) {
|
|
386
|
+
const normalized = normalizeApiKeyResponse(
|
|
387
|
+
await requestPolymarketApiKey({ ...args, mode: "create" })
|
|
388
|
+
);
|
|
389
|
+
if (!normalized) {
|
|
390
|
+
throw new PolymarketAuthError("Failed to create Polymarket API key.");
|
|
391
|
+
}
|
|
392
|
+
return normalized;
|
|
393
|
+
}
|
|
394
|
+
async function derivePolymarketApiKey(args) {
|
|
395
|
+
const normalized = normalizeApiKeyResponse(
|
|
396
|
+
await requestPolymarketApiKey({ ...args, mode: "derive" })
|
|
397
|
+
);
|
|
398
|
+
if (!normalized) {
|
|
402
399
|
throw new PolymarketAuthError("Failed to derive Polymarket API key.");
|
|
403
400
|
}
|
|
404
|
-
return
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
401
|
+
return normalized;
|
|
402
|
+
}
|
|
403
|
+
async function createOrDerivePolymarketApiKey(args) {
|
|
404
|
+
const created = normalizeApiKeyResponse(
|
|
405
|
+
await requestPolymarketApiKey({ ...args, mode: "create" })
|
|
406
|
+
);
|
|
407
|
+
if (created) {
|
|
408
|
+
return created;
|
|
409
|
+
}
|
|
410
|
+
return derivePolymarketApiKey(args);
|
|
409
411
|
}
|
|
410
412
|
async function placePolymarketOrder(args) {
|
|
411
413
|
const environment = args.environment ?? "mainnet";
|
|
@@ -634,6 +636,61 @@ function getString(value) {
|
|
|
634
636
|
const str = String(value).trim();
|
|
635
637
|
return str.length ? str : null;
|
|
636
638
|
}
|
|
639
|
+
function getNumber(value) {
|
|
640
|
+
const numeric = Number(value);
|
|
641
|
+
return Number.isFinite(numeric) ? numeric : null;
|
|
642
|
+
}
|
|
643
|
+
function getInteger(value) {
|
|
644
|
+
const numeric = getNumber(value);
|
|
645
|
+
return numeric == null ? null : Math.trunc(numeric);
|
|
646
|
+
}
|
|
647
|
+
function getBoolean(value) {
|
|
648
|
+
if (typeof value === "boolean") return value;
|
|
649
|
+
if (typeof value === "string") {
|
|
650
|
+
const normalized = value.trim().toLowerCase();
|
|
651
|
+
if (normalized === "true") return true;
|
|
652
|
+
if (normalized === "false") return false;
|
|
653
|
+
}
|
|
654
|
+
return null;
|
|
655
|
+
}
|
|
656
|
+
function normalizeCsvStringInput(value) {
|
|
657
|
+
if (Array.isArray(value)) {
|
|
658
|
+
return value.flatMap((entry) => String(entry).split(",")).map((entry) => entry.trim()).filter((entry) => entry.length > 0);
|
|
659
|
+
}
|
|
660
|
+
if (typeof value === "string") {
|
|
661
|
+
return value.split(",").map((entry) => entry.trim()).filter((entry) => entry.length > 0);
|
|
662
|
+
}
|
|
663
|
+
return [];
|
|
664
|
+
}
|
|
665
|
+
function normalizeCsvNumberInput(value) {
|
|
666
|
+
if (Array.isArray(value)) {
|
|
667
|
+
return value.filter((entry) => Number.isFinite(entry));
|
|
668
|
+
}
|
|
669
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
670
|
+
return [value];
|
|
671
|
+
}
|
|
672
|
+
return [];
|
|
673
|
+
}
|
|
674
|
+
function appendCsvParam(url, key, values) {
|
|
675
|
+
if (values.length > 0) {
|
|
676
|
+
url.searchParams.set(key, values.join(","));
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
function appendNumberParam(url, key, value) {
|
|
680
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
681
|
+
url.searchParams.set(key, String(value));
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
function appendBooleanParam(url, key, value) {
|
|
685
|
+
if (typeof value === "boolean") {
|
|
686
|
+
url.searchParams.set(key, value ? "true" : "false");
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
function assertMutuallyExclusiveMarketScope(market, eventIds) {
|
|
690
|
+
if (market.length > 0 && eventIds.length > 0) {
|
|
691
|
+
throw new Error("market and eventId are mutually exclusive.");
|
|
692
|
+
}
|
|
693
|
+
}
|
|
637
694
|
function normalizeOrderbookLevels(raw) {
|
|
638
695
|
if (!Array.isArray(raw)) return [];
|
|
639
696
|
return raw.map((entry) => {
|
|
@@ -697,6 +754,132 @@ function normalizeGammaMarket(market, event) {
|
|
|
697
754
|
}
|
|
698
755
|
return normalized;
|
|
699
756
|
}
|
|
757
|
+
function normalizeUserPosition(raw) {
|
|
758
|
+
const record = raw && typeof raw === "object" ? raw : {};
|
|
759
|
+
const normalized = {
|
|
760
|
+
proxyWallet: getString(record.proxyWallet),
|
|
761
|
+
asset: getString(record.asset),
|
|
762
|
+
conditionId: getString(record.conditionId),
|
|
763
|
+
size: getNumber(record.size),
|
|
764
|
+
avgPrice: getNumber(record.avgPrice),
|
|
765
|
+
initialValue: getNumber(record.initialValue),
|
|
766
|
+
currentValue: getNumber(record.currentValue),
|
|
767
|
+
cashPnl: getNumber(record.cashPnl),
|
|
768
|
+
percentPnl: getNumber(record.percentPnl),
|
|
769
|
+
totalBought: getNumber(record.totalBought),
|
|
770
|
+
realizedPnl: getNumber(record.realizedPnl),
|
|
771
|
+
percentRealizedPnl: getNumber(record.percentRealizedPnl),
|
|
772
|
+
curPrice: getNumber(record.curPrice),
|
|
773
|
+
title: getString(record.title),
|
|
774
|
+
slug: getString(record.slug),
|
|
775
|
+
icon: getString(record.icon),
|
|
776
|
+
eventSlug: getString(record.eventSlug),
|
|
777
|
+
outcome: getString(record.outcome),
|
|
778
|
+
outcomeIndex: getInteger(record.outcomeIndex),
|
|
779
|
+
oppositeOutcome: getString(record.oppositeOutcome),
|
|
780
|
+
oppositeAsset: getString(record.oppositeAsset),
|
|
781
|
+
endDate: parseOptionalDate(record.endDate)
|
|
782
|
+
};
|
|
783
|
+
const redeemable = getBoolean(record.redeemable);
|
|
784
|
+
if (redeemable != null) normalized.redeemable = redeemable;
|
|
785
|
+
const mergeable = getBoolean(record.mergeable);
|
|
786
|
+
if (mergeable != null) normalized.mergeable = mergeable;
|
|
787
|
+
const negativeRisk = getBoolean(record.negativeRisk);
|
|
788
|
+
if (negativeRisk != null) normalized.negativeRisk = negativeRisk;
|
|
789
|
+
return normalized;
|
|
790
|
+
}
|
|
791
|
+
function normalizeClosedPosition(raw) {
|
|
792
|
+
const record = raw && typeof raw === "object" ? raw : {};
|
|
793
|
+
return {
|
|
794
|
+
proxyWallet: getString(record.proxyWallet),
|
|
795
|
+
asset: getString(record.asset),
|
|
796
|
+
conditionId: getString(record.conditionId),
|
|
797
|
+
avgPrice: getNumber(record.avgPrice),
|
|
798
|
+
totalBought: getNumber(record.totalBought),
|
|
799
|
+
realizedPnl: getNumber(record.realizedPnl),
|
|
800
|
+
curPrice: getNumber(record.curPrice),
|
|
801
|
+
timestamp: getInteger(record.timestamp),
|
|
802
|
+
title: getString(record.title),
|
|
803
|
+
slug: getString(record.slug),
|
|
804
|
+
icon: getString(record.icon),
|
|
805
|
+
eventSlug: getString(record.eventSlug),
|
|
806
|
+
outcome: getString(record.outcome),
|
|
807
|
+
outcomeIndex: getInteger(record.outcomeIndex),
|
|
808
|
+
oppositeOutcome: getString(record.oppositeOutcome),
|
|
809
|
+
oppositeAsset: getString(record.oppositeAsset),
|
|
810
|
+
endDate: parseOptionalDate(record.endDate)
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
function normalizeUserActivity(raw) {
|
|
814
|
+
const record = raw && typeof raw === "object" ? raw : {};
|
|
815
|
+
return {
|
|
816
|
+
proxyWallet: getString(record.proxyWallet),
|
|
817
|
+
timestamp: getInteger(record.timestamp),
|
|
818
|
+
conditionId: getString(record.conditionId),
|
|
819
|
+
type: getString(record.type),
|
|
820
|
+
size: getNumber(record.size),
|
|
821
|
+
usdcSize: getNumber(record.usdcSize),
|
|
822
|
+
transactionHash: getString(record.transactionHash),
|
|
823
|
+
price: getNumber(record.price),
|
|
824
|
+
asset: getString(record.asset),
|
|
825
|
+
side: getString(record.side),
|
|
826
|
+
outcomeIndex: getInteger(record.outcomeIndex),
|
|
827
|
+
title: getString(record.title),
|
|
828
|
+
slug: getString(record.slug),
|
|
829
|
+
icon: getString(record.icon),
|
|
830
|
+
eventSlug: getString(record.eventSlug),
|
|
831
|
+
outcome: getString(record.outcome),
|
|
832
|
+
name: getString(record.name),
|
|
833
|
+
pseudonym: getString(record.pseudonym),
|
|
834
|
+
bio: getString(record.bio),
|
|
835
|
+
profileImage: getString(record.profileImage),
|
|
836
|
+
profileImageOptimized: getString(record.profileImageOptimized)
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
function normalizePositionValue(raw) {
|
|
840
|
+
const record = raw && typeof raw === "object" ? raw : {};
|
|
841
|
+
return {
|
|
842
|
+
user: getString(record.user),
|
|
843
|
+
value: getNumber(record.value)
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
function normalizeProfileUsers(raw) {
|
|
847
|
+
if (!Array.isArray(raw)) return null;
|
|
848
|
+
return raw.map((entry) => {
|
|
849
|
+
const record = entry && typeof entry === "object" ? entry : {};
|
|
850
|
+
const normalized = {
|
|
851
|
+
id: getString(record.id)
|
|
852
|
+
};
|
|
853
|
+
const creator = getBoolean(record.creator);
|
|
854
|
+
if (creator != null) normalized.creator = creator;
|
|
855
|
+
const mod = getBoolean(record.mod);
|
|
856
|
+
if (mod != null) normalized.mod = mod;
|
|
857
|
+
return normalized;
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
function normalizePublicProfile(raw) {
|
|
861
|
+
if (!raw || typeof raw !== "object") return null;
|
|
862
|
+
const record = raw;
|
|
863
|
+
const normalized = {
|
|
864
|
+
createdAt: parseOptionalDate(record.createdAt),
|
|
865
|
+
proxyWallet: getString(record.proxyWallet),
|
|
866
|
+
profileImage: getString(record.profileImage),
|
|
867
|
+
bio: getString(record.bio),
|
|
868
|
+
pseudonym: getString(record.pseudonym),
|
|
869
|
+
name: getString(record.name),
|
|
870
|
+
users: normalizeProfileUsers(record.users),
|
|
871
|
+
xUsername: getString(record.xUsername)
|
|
872
|
+
};
|
|
873
|
+
const displayUsernamePublic = getBoolean(record.displayUsernamePublic);
|
|
874
|
+
if (displayUsernamePublic != null) {
|
|
875
|
+
normalized.displayUsernamePublic = displayUsernamePublic;
|
|
876
|
+
}
|
|
877
|
+
const verifiedBadge = getBoolean(record.verifiedBadge);
|
|
878
|
+
if (verifiedBadge != null) {
|
|
879
|
+
normalized.verifiedBadge = verifiedBadge;
|
|
880
|
+
}
|
|
881
|
+
return normalized;
|
|
882
|
+
}
|
|
700
883
|
var PolymarketInfoClient = class {
|
|
701
884
|
constructor(environment = "mainnet") {
|
|
702
885
|
this.environment = environment;
|
|
@@ -719,6 +902,21 @@ var PolymarketInfoClient = class {
|
|
|
719
902
|
priceHistory(params) {
|
|
720
903
|
return fetchPolymarketPriceHistory({ ...params, environment: this.environment });
|
|
721
904
|
}
|
|
905
|
+
positions(params) {
|
|
906
|
+
return fetchPolymarketPositions({ ...params, environment: this.environment });
|
|
907
|
+
}
|
|
908
|
+
closedPositions(params) {
|
|
909
|
+
return fetchPolymarketClosedPositions({ ...params, environment: this.environment });
|
|
910
|
+
}
|
|
911
|
+
activity(params) {
|
|
912
|
+
return fetchPolymarketActivity({ ...params, environment: this.environment });
|
|
913
|
+
}
|
|
914
|
+
positionValue(params) {
|
|
915
|
+
return fetchPolymarketPositionValue({ ...params, environment: this.environment });
|
|
916
|
+
}
|
|
917
|
+
publicProfile(address) {
|
|
918
|
+
return fetchPolymarketPublicProfile({ address, environment: this.environment });
|
|
919
|
+
}
|
|
722
920
|
};
|
|
723
921
|
async function fetchPolymarketMarkets(params = {}) {
|
|
724
922
|
if (params.active !== void 0 && params.active !== true) {
|
|
@@ -825,7 +1023,97 @@ async function fetchPolymarketPriceHistory(params) {
|
|
|
825
1023
|
p: Number(point.p)
|
|
826
1024
|
})).filter((point) => Number.isFinite(point.t) && Number.isFinite(point.p));
|
|
827
1025
|
}
|
|
1026
|
+
async function fetchPolymarketPositions(params) {
|
|
1027
|
+
const environment = params.environment ?? "mainnet";
|
|
1028
|
+
const market = normalizeCsvStringInput(params.market);
|
|
1029
|
+
const eventIds = normalizeCsvNumberInput(params.eventId);
|
|
1030
|
+
assertMutuallyExclusiveMarketScope(market, eventIds);
|
|
1031
|
+
const baseUrl = resolvePolymarketBaseUrl("data", environment);
|
|
1032
|
+
const url = new URL("/positions", baseUrl);
|
|
1033
|
+
url.searchParams.set("user", params.user);
|
|
1034
|
+
appendCsvParam(url, "market", market);
|
|
1035
|
+
appendCsvParam(
|
|
1036
|
+
url,
|
|
1037
|
+
"eventId",
|
|
1038
|
+
eventIds.map((entry) => String(entry))
|
|
1039
|
+
);
|
|
1040
|
+
appendNumberParam(url, "sizeThreshold", params.sizeThreshold);
|
|
1041
|
+
appendBooleanParam(url, "redeemable", params.redeemable);
|
|
1042
|
+
appendBooleanParam(url, "mergeable", params.mergeable);
|
|
1043
|
+
appendNumberParam(url, "limit", params.limit);
|
|
1044
|
+
appendNumberParam(url, "offset", params.offset);
|
|
1045
|
+
if (params.sortBy) url.searchParams.set("sortBy", params.sortBy);
|
|
1046
|
+
if (params.sortDirection) url.searchParams.set("sortDirection", params.sortDirection);
|
|
1047
|
+
if (params.title) url.searchParams.set("title", params.title);
|
|
1048
|
+
const data = await requestJson2(url.toString());
|
|
1049
|
+
return Array.isArray(data) ? data.map((entry) => normalizeUserPosition(entry)) : [];
|
|
1050
|
+
}
|
|
1051
|
+
async function fetchPolymarketClosedPositions(params) {
|
|
1052
|
+
const environment = params.environment ?? "mainnet";
|
|
1053
|
+
const market = normalizeCsvStringInput(params.market);
|
|
1054
|
+
const eventIds = normalizeCsvNumberInput(params.eventId);
|
|
1055
|
+
assertMutuallyExclusiveMarketScope(market, eventIds);
|
|
1056
|
+
const baseUrl = resolvePolymarketBaseUrl("data", environment);
|
|
1057
|
+
const url = new URL("/closed-positions", baseUrl);
|
|
1058
|
+
url.searchParams.set("user", params.user);
|
|
1059
|
+
appendCsvParam(url, "market", market);
|
|
1060
|
+
appendCsvParam(
|
|
1061
|
+
url,
|
|
1062
|
+
"eventId",
|
|
1063
|
+
eventIds.map((entry) => String(entry))
|
|
1064
|
+
);
|
|
1065
|
+
appendNumberParam(url, "limit", params.limit);
|
|
1066
|
+
appendNumberParam(url, "offset", params.offset);
|
|
1067
|
+
if (params.sortBy) url.searchParams.set("sortBy", params.sortBy);
|
|
1068
|
+
if (params.sortDirection) url.searchParams.set("sortDirection", params.sortDirection);
|
|
1069
|
+
if (params.title) url.searchParams.set("title", params.title);
|
|
1070
|
+
const data = await requestJson2(url.toString());
|
|
1071
|
+
return Array.isArray(data) ? data.map((entry) => normalizeClosedPosition(entry)) : [];
|
|
1072
|
+
}
|
|
1073
|
+
async function fetchPolymarketActivity(params) {
|
|
1074
|
+
const environment = params.environment ?? "mainnet";
|
|
1075
|
+
const market = normalizeCsvStringInput(params.market);
|
|
1076
|
+
const eventIds = normalizeCsvNumberInput(params.eventId);
|
|
1077
|
+
assertMutuallyExclusiveMarketScope(market, eventIds);
|
|
1078
|
+
const types = Array.isArray(params.type) ? params.type : params.type ? [params.type] : [];
|
|
1079
|
+
const baseUrl = resolvePolymarketBaseUrl("data", environment);
|
|
1080
|
+
const url = new URL("/activity", baseUrl);
|
|
1081
|
+
url.searchParams.set("user", params.user);
|
|
1082
|
+
appendCsvParam(url, "market", market);
|
|
1083
|
+
appendCsvParam(
|
|
1084
|
+
url,
|
|
1085
|
+
"eventId",
|
|
1086
|
+
eventIds.map((entry) => String(entry))
|
|
1087
|
+
);
|
|
1088
|
+
appendCsvParam(url, "type", types);
|
|
1089
|
+
appendNumberParam(url, "start", params.start);
|
|
1090
|
+
appendNumberParam(url, "end", params.end);
|
|
1091
|
+
appendNumberParam(url, "limit", params.limit);
|
|
1092
|
+
appendNumberParam(url, "offset", params.offset);
|
|
1093
|
+
if (params.sortBy) url.searchParams.set("sortBy", params.sortBy);
|
|
1094
|
+
if (params.sortDirection) url.searchParams.set("sortDirection", params.sortDirection);
|
|
1095
|
+
if (params.side) url.searchParams.set("side", params.side);
|
|
1096
|
+
const data = await requestJson2(url.toString());
|
|
1097
|
+
return Array.isArray(data) ? data.map((entry) => normalizeUserActivity(entry)) : [];
|
|
1098
|
+
}
|
|
1099
|
+
async function fetchPolymarketPositionValue(params) {
|
|
1100
|
+
const environment = params.environment ?? "mainnet";
|
|
1101
|
+
const baseUrl = resolvePolymarketBaseUrl("data", environment);
|
|
1102
|
+
const url = new URL("/value", baseUrl);
|
|
1103
|
+
url.searchParams.set("user", params.user);
|
|
1104
|
+
appendCsvParam(url, "market", normalizeCsvStringInput(params.market));
|
|
1105
|
+
const data = await requestJson2(url.toString());
|
|
1106
|
+
return Array.isArray(data) ? data.map((entry) => normalizePositionValue(entry)) : [];
|
|
1107
|
+
}
|
|
1108
|
+
async function fetchPolymarketPublicProfile(params) {
|
|
1109
|
+
const environment = params.environment ?? "mainnet";
|
|
1110
|
+
const baseUrl = resolvePolymarketBaseUrl("gamma", environment);
|
|
1111
|
+
const url = new URL("/public-profile", baseUrl);
|
|
1112
|
+
url.searchParams.set("address", params.address);
|
|
1113
|
+
const data = await requestJson2(url.toString());
|
|
1114
|
+
return normalizePublicProfile(data);
|
|
1115
|
+
}
|
|
828
1116
|
|
|
829
|
-
export { POLYMARKET_CHAIN_ID, POLYMARKET_CLOB_AUTH_DOMAIN, POLYMARKET_CLOB_DOMAIN, POLYMARKET_ENDPOINTS, POLYMARKET_EXCHANGE_ADDRESSES, PolymarketApiError, PolymarketAuthError, PolymarketExchangeClient, PolymarketInfoClient, buildHmacSignature, buildL1Headers, buildL2Headers, buildPolymarketOrderAmounts, buildSignedOrderPayload, cancelAllPolymarketOrders, cancelMarketPolymarketOrders, cancelPolymarketOrder, cancelPolymarketOrders, createPolymarketApiKey, derivePolymarketApiKey, fetchPolymarketMarket, fetchPolymarketMarkets, fetchPolymarketMidpoint, fetchPolymarketOrderbook, fetchPolymarketPrice, fetchPolymarketPriceHistory, normalizeNumberArrayish, normalizeStringArrayish, placePolymarketOrder, resolveExchangeAddress, resolvePolymarketBaseUrl };
|
|
1117
|
+
export { POLYMARKET_CHAIN_ID, POLYMARKET_CLOB_AUTH_DOMAIN, POLYMARKET_CLOB_DOMAIN, POLYMARKET_ENDPOINTS, POLYMARKET_EXCHANGE_ADDRESSES, PolymarketApiError, PolymarketAuthError, PolymarketExchangeClient, PolymarketInfoClient, buildHmacSignature, buildL1Headers, buildL2Headers, buildPolymarketOrderAmounts, buildSignedOrderPayload, cancelAllPolymarketOrders, cancelMarketPolymarketOrders, cancelPolymarketOrder, cancelPolymarketOrders, createOrDerivePolymarketApiKey, createPolymarketApiKey, derivePolymarketApiKey, fetchPolymarketActivity, fetchPolymarketClosedPositions, fetchPolymarketMarket, fetchPolymarketMarkets, fetchPolymarketMidpoint, fetchPolymarketOrderbook, fetchPolymarketPositionValue, fetchPolymarketPositions, fetchPolymarketPrice, fetchPolymarketPriceHistory, fetchPolymarketPublicProfile, normalizeNumberArrayish, normalizeStringArrayish, placePolymarketOrder, resolveExchangeAddress, resolvePolymarketBaseUrl };
|
|
830
1118
|
//# sourceMappingURL=index.js.map
|
|
831
1119
|
//# sourceMappingURL=index.js.map
|