Files
simstudioai--sim/apps/sim/tools/polymarket/get_leaderboard.ts
T
wehub-resource-sync d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

145 lines
4.4 KiB
TypeScript

import type { PolymarketLeaderboardEntry } from '@/tools/polymarket/types'
import { buildDataUrl, handlePolymarketError } from '@/tools/polymarket/types'
import type { ToolConfig } from '@/tools/types'
export interface PolymarketGetLeaderboardParams {
category?: string
timePeriod?: string
orderBy?: string
limit?: string
offset?: string
user?: string
userName?: string
}
export interface PolymarketGetLeaderboardResponse {
success: boolean
output: {
leaderboard: PolymarketLeaderboardEntry[]
}
}
export const polymarketGetLeaderboardTool: ToolConfig<
PolymarketGetLeaderboardParams,
PolymarketGetLeaderboardResponse
> = {
id: 'polymarket_get_leaderboard',
name: 'Get Leaderboard from Polymarket',
description: 'Retrieve trader leaderboard rankings by profit/loss or volume',
version: '1.0.0',
params: {
category: {
type: 'string',
required: false,
description:
'Category filter: OVERALL, POLITICS, SPORTS, CRYPTO, CULTURE, MENTIONS, WEATHER, ECONOMICS, TECH, FINANCE (default: OVERALL)',
visibility: 'user-or-llm',
},
timePeriod: {
type: 'string',
required: false,
description: 'Time period: DAY, WEEK, MONTH, ALL (default: DAY)',
visibility: 'user-or-llm',
},
orderBy: {
type: 'string',
required: false,
description: 'Order by: PNL or VOL (default: PNL)',
visibility: 'user-or-llm',
},
limit: {
type: 'string',
required: false,
description: 'Number of results to return (e.g., "10"). Range: 1-50, default: 25.',
visibility: 'user-or-llm',
},
offset: {
type: 'string',
required: false,
description:
'Number of results to skip for pagination (e.g., "25"). Range: 0-1000, default: 0.',
visibility: 'user-or-llm',
},
user: {
type: 'string',
required: false,
description: 'Filter by specific user wallet address',
visibility: 'user-or-llm',
},
userName: {
type: 'string',
required: false,
description: 'Filter by username',
visibility: 'user-or-llm',
},
},
request: {
url: (params) => {
const queryParams = new URLSearchParams()
if (params.category) queryParams.append('category', params.category)
if (params.timePeriod) queryParams.append('timePeriod', params.timePeriod)
if (params.orderBy) queryParams.append('orderBy', params.orderBy)
if (params.limit) queryParams.append('limit', params.limit)
if (params.offset) queryParams.append('offset', params.offset)
if (params.user) queryParams.append('user', params.user)
if (params.userName) queryParams.append('userName', params.userName)
const query = queryParams.toString()
return query ? `${buildDataUrl('/v1/leaderboard')}?${query}` : buildDataUrl('/v1/leaderboard')
},
method: 'GET',
headers: () => ({
'Content-Type': 'application/json',
}),
},
transformResponse: async (response: Response) => {
const data = await response.json()
if (!response.ok) {
handlePolymarketError(data, response.status, 'get_leaderboard')
}
const entries = Array.isArray(data) ? data : []
const leaderboard: PolymarketLeaderboardEntry[] = entries.map((entry: any) => ({
rank: entry.rank ?? '',
proxyWallet: entry.proxyWallet ?? '',
userName: entry.userName ?? null,
vol: entry.vol ?? 0,
pnl: entry.pnl ?? 0,
profileImage: entry.profileImage ?? null,
xUsername: entry.xUsername ?? null,
verifiedBadge: entry.verifiedBadge ?? false,
}))
return {
success: true,
output: {
leaderboard,
},
}
},
outputs: {
leaderboard: {
type: 'array',
description: 'Array of leaderboard entries',
items: {
type: 'object',
properties: {
rank: { type: 'string', description: 'Leaderboard rank position' },
proxyWallet: { type: 'string', description: 'User proxy wallet address' },
userName: { type: 'string', description: 'User display name' },
vol: { type: 'number', description: 'Trading volume' },
pnl: { type: 'number', description: 'Profit and loss' },
profileImage: { type: 'string', description: 'User profile image URL' },
xUsername: { type: 'string', description: 'Twitter/X username' },
verifiedBadge: { type: 'boolean', description: 'Whether user has verified badge' },
},
},
},
},
}