[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-77721":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":16,"stars30d":17,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":18,"rankGlobal":10,"rankLanguage":10,"license":10,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":21,"hasPages":19,"topics":22,"createdAt":10,"pushedAt":10,"updatedAt":43,"readmeContent":44,"aiSummary":45,"trendingCount":16,"starSnapshotCount":16,"syncStatus":46,"lastSyncTime":47,"discoverSource":48},77721,"solana-wallet-pnl-profit-and-loss-api","vybenetwork\u002Fsolana-wallet-pnl-profit-and-loss-api","vybenetwork","Solana Wallet PnL API: This repo demonstrates how to use Vybe Solana wallet PnL APIs to fetch, filter, and analyze per-wallet profit and loss (PnL), related wallets, trades, and SPL\u002FToken-2022 token metadata. Use it as a reference or starter kit for analytics dashboards, PnL leaderboards, related-wallet discovery, and similar data products.","https:\u002F\u002Fdocs.vybenetwork.com",null,"TypeScript",212,80,104,5,0,77,50.43,false,"main",true,[23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42],"chain-analysis","gmgn","holders","kolscan","nansen","pnl-analysis-tool","pnl-tracker","pnl-visualization","profit-and-loss","pumpfun","pumpswap","raydium","solana","solana-api","solscan","spl","token-2022","traders","wallet","wallet-analytics","2026-06-12 04:01:22","# Solana Wallet PnL Profit & Loss API\n\n**Solana Wallet PnL API:** This repository demonstrates how to use the Vybe Solana wallet PnL APIs to fetch, explore, and analyze **per-wallet profit and loss (PnL)** together with **related wallets** ranked by realized PnL, including trades, program labels, and token metadata for SPL and Token-2022 activity. It ships as a production-ready Node.js backend and browser UI so you can search wallets (address or partial name via `ilikeFilter`), load wallet-scoped PnL, and browse the related-wallets leaderboard with the same parameters you would send to Vybe. Use this project as a reference implementation or starter kit for building data products such as wallet analytics dashboards, PnL leaderboards, related-wallet discovery, and more.\n\nTry the live demo: https:\u002F\u002Fsolana-wallet-pnl-profit-and-loss-api.vybenetwork.com\n\n![Solana wallet PnL and related wallets demo](screenshots\u002Fsolana-wallet-pnl-profit-and-loss-api.png)\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"screenshots\u002Fwallet-pnl-api-profit-and-loss-solana.png\" alt=\"Wallet PnL API Profit and Loss\" width=\"360\" style=\"min-width:360px;max-width:360px;margin-right:10px;\" \u002F>\n  \u003Cimg src=\"screenshots\u002Fsolana-wallet-pnl-historical-data-api.png\" alt=\"Solana Wallet PnL Historical Data API\" width=\"272\" style=\"min-width:272px;max-width:272px\" \u002F>\n\u003C\u002Fp>\n\n\n---\n\n**[Try the LIVE demo →](https:\u002F\u002Fsolana-wallet-pnl-profit-and-loss-api.vybenetwork.com)**\n\n**[Get your free Vybe API key →](https:\u002F\u002Fvybe.fyi\u002Fapi-pricing)**\n\n**[Vybe quick start →](https:\u002F\u002Fdocs.vybenetwork.com\u002Fdocs\u002Fquick-start)**\n\n---\n\n## Prerequisites\n\n- **Node.js** ≥ 20 (LTS recommended)\n- **npm** ≥ 10 (or equivalent)\n\n## Quick Start\n\nGet from clone to running app in a few commands:\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fvybenetwork\u002Fsolana-wallet-pnl-profit-and-loss-api.git\ncd solana-wallet-pnl-profit-and-loss-api\nnpm install\ncp .env.example .env\n# Edit .env and set VYBE_API_KEY=your_api_key_here\nnpm start\n```\n\nThen open **http:\u002F\u002Flocalhost:3000**, enter a **wallet address or name** (mapped to Vybe `ilikeFilter` when not a full address), tune **resolution** and sort controls if needed, and click **Load wallet PnL** to fetch wallet PnL and related wallets.\n\n## Environment Variables\n\n| Variable          | Required | Description                                                                 | Example                                   |\n|-------------------|----------|-----------------------------------------------------------------------------|-------------------------------------------|\n| `VYBE_API_KEY`    | Yes      | Vybe API key used for all Vybe requests                                     | `your_api_key_here`                       |\n| `SOLANA_RPC_URL`  | No       | RPC endpoint for Metaplex symbol lookup (token-symbol fallback)             | `https:\u002F\u002Fapi.mainnet-beta.solana.com`     |\n| `PORT`            | No       | HTTP server port                                                            | `3000`                                    |\n| `TUNNEL`          | No       | Set to `1` to run behind a Cloudflare Tunnel                                | `1`                                       |\n| `TRADES_LOG`      | No       | Set to `1` to append `\u002Fapi\u002Ftrades` request lines to `trades-requests.log`   | `0`                                       |\n\nGet your API key at `https:\u002F\u002Fvybe.fyi\u002Fapi-pricing`.\n\n---\n\n## What This Repo Provides\n\n- **Wallet PnL and related-wallets proxy**\n  - Express server that proxies Vybe:\n    - `GET \u002Fv4\u002Fwallets\u002F{ownerAddress}\u002Fpnl` (per-wallet token-level PnL for a resolution window)\n    - `GET \u002Fv4\u002Fwallets\u002Ftop-traders` (related wallets \u002F leaderboard for `mintAddress` or `ilikeFilter`)\n    - `GET \u002Fv4\u002Ftokens\u002F{mintAddress}\u002Ftop-pnl-traders` (token-scoped top PnL traders; used when the UI is in token-oriented flows)\n    - `GET \u002Fv4\u002Ftrades` (supporting trade context where the UI requests it)\n    - `GET \u002Fv4\u002Fprograms\u002Flabeled-program-accounts` (program labels)\n    - `GET \u002Fv4\u002Ftokens\u002F{mintAddress}` (token metadata for optional token panels)\n- **Wallet PnL web UI**\n  - Single-page GUI (no frameworks) built from `src\u002Ffrontend\u002Fapp.ts` into `public\u002Fapp.js` (`npm start` runs `prestart` → `npm run build:frontend`).\n  - **Realtime** flow: wallet search, resolution (1d \u002F 7d \u002F 30d), optional `mintAddress` filter on PnL, sort field and direction, pagination, and a **Related wallets** grid driven by top-traders.\n- **Remote filters (Vybe query params)**\n  - Controls at the top and second row map directly to Vybe query params (`ilikeFilter`, `resolution`, `label`, `sortByAsc` \u002F `sortByDesc`, `limit`, `page`, optional `mintAddress` on wallet PnL).\n- **Retries and errors**\n  - Shared HTTP client (`src\u002Fapi\u002Fclient.ts`) with timeouts, retries, and human-readable error messages for failed Vybe calls.\n\n---\n\n### Solana API docs for these endpoints\n\n- **Related wallets \u002F top traders (`GET \u002Fv4\u002Fwallets\u002Ftop-traders`)**:\n  - [https:\u002F\u002Fdocs.vybenetwork.com\u002Freference\u002Fget_top_traders_v4](https:\u002F\u002Fdocs.vybenetwork.com\u002Freference\u002Fget_top_traders_v4)\n- **Wallet PnL (`GET \u002Fv4\u002Fwallets\u002F{ownerAddress}\u002Fpnl`)**:\n  - [https:\u002F\u002Fdocs.vybenetwork.com\u002Freference](https:\u002F\u002Fdocs.vybenetwork.com\u002Freference) (wallet PnL lives alongside wallet endpoints in the Vybe reference)\n- **Trade data (`GET \u002Fv4\u002Ftrades`)**:\n  - [https:\u002F\u002Fdocs.vybenetwork.com\u002Freference\u002Fget_trade_data_program_v4](https:\u002F\u002Fdocs.vybenetwork.com\u002Freference\u002Fget_trade_data_program_v4)\n- **Token details (`GET \u002Fv4\u002Ftokens\u002F{mintAddress}`)**:\n  - [https:\u002F\u002Fdocs.vybenetwork.com\u002Freference\u002Fget_token_details_v4](https:\u002F\u002Fdocs.vybenetwork.com\u002Freference\u002Fget_token_details_v4)\n- **Token top PnL traders (`GET \u002Fv4\u002Ftokens\u002F{mintAddress}\u002Ftop-pnl-traders`)**:\n  - [https:\u002F\u002Fdocs.vybenetwork.com\u002Freference](https:\u002F\u002Fdocs.vybenetwork.com\u002Freference)\n- **Labeled programs (`GET \u002Fv4\u002Fprograms\u002Flabeled-program-accounts`)**:\n  - [https:\u002F\u002Fdocs.vybenetwork.com\u002Freference\u002Fget_known_program_accounts_v4](https:\u002F\u002Fdocs.vybenetwork.com\u002Freference\u002Fget_known_program_accounts_v4)\n\n---\n\n## Why Wallet PnL & Related Wallets Matter\n\nWallet-level PnL and related-wallet discovery are useful for:\n\n- **Trader intelligence**: see realized and unrealized PnL, trade counts, and win rate for a wallet over a chosen window.\n- **Network effects**: surface wallets with similar behavior or peer performance via **top traders** for the same filter and resolution.\n- **Product UX**: ship a credible wallet dashboard without operating your own indexer—Vybe aggregates trades and PnL across Solana venues.\n\nThis repo shows how to wire a **practical wallet explorer** on top of Vybe’s wallet PnL and top-traders endpoints.\n\n---\n\n## Frontend Overview (Wallet PnL UI)\n\nThe wallet UI is implemented in `src\u002Ffrontend\u002Fapp.ts` and compiled to `public\u002Fapp.js` via `npm run build:frontend` (also run automatically before `npm start`).\n\n### Sections\n\n- **Remote filters (wallet + endpoint row)**\n  - **Endpoint mode**: Realtime vs Historical switch (Historical is disabled in the current UI until the timeseries section ships).\n  - **Wallet address or name** (`ilikeFilter` \u002F owner resolution), **Resolution** (1d, 7d, 30d), **Wallet PnL sort** and related controls that map to Vybe query params.\n\n- **Wallet PnL summary and token rows**\n  - After **Load wallet PnL**, the UI renders wallet PnL metadata, per-token metrics (where returned), charts\u002Fcards depending on payload, and links or copy-friendly addresses.\n\n- **Related wallets (top traders)**\n  - Grid of wallets returned by `GET \u002Fv4\u002Fwallets\u002Ftop-traders` for the same scope, sorted by realized PnL for the selected resolution.\n\n- **Second-row controls (pagination and filters)**\n  - **Wallet traders label** (`label`), optional **Wallet PnL mint** (`mintAddress`), **Sort direction**, **limit**, **page**, and loading indicator beside **Load wallet PnL**.\n\n- **Token stats & token-mode panels** (when enabled in the build)\n  - Optional sections for token metadata, supply charts, and token top PnL traders—wired to the same proxy routes when those panels are visible.\n\n---\n\n## Filters & Workflow\n\n### Remote filters (Vybe query params)\n\n![Remote filters row mapping to Vybe wallet params](screenshots\u002Fsolana-wallet-pnl-api-search-filters.png)\n\nThe top of the UI controls the requests sent to the API:\n\n- **Wallet search** — full address or partial name; forwarded as `mintAddress` or `ilikeFilter` per Vybe rules for top-traders and as the owner for wallet PnL.\n- **Resolution** — `1d`, `7d`, or `30d` for both wallet PnL and related wallets where applicable.\n- **Wallet PnL sort** — `sortByDesc` \u002F `sortByAsc` field for per-wallet token rows (e.g. `realizedPnlUsd`).\n- **Label** — `label=all|kol` style filter for top-traders when exposed in the UI.\n- **limit \u002F page** — pagination for wallet PnL and related wallet queries.\n\nThese map to the proxy routes in `src\u002Fserver.ts` and are forwarded to Vybe with your `VYBE_API_KEY`.\n\n### Second-row wallet controls\n\nAfter the primary row, optional controls refine the same Vybe calls:\n\n- **Wallet traders label** — forwarded as `label` on top-traders when Vybe expects it (UI omits invalid combinations such as `label=all` where the API rejects it).\n- **Wallet PnL mint** — optional `mintAddress` filter on `GET \u002Fv4\u002Fwallets\u002F{owner}\u002Fpnl`.\n- **Sort direction, limit, page** — standard pagination and sort order for wallet PnL and related lists.\n\nChanging these and clicking **Load wallet PnL** refetches from the proxy.\n\n---\n\n## Historical mode (UI roadmap)\n\nThe UI may show a **Historical** path for wallet PnL **timeseries** in the future. In the current repository, **Historical is disabled in the browser** while that section is implemented; the Express server focuses on **realtime** wallet PnL (`GET \u002Fv4\u002Fwallets\u002F{ownerAddress}\u002Fpnl`) and **related wallets** (`GET \u002Fv4\u002Fwallets\u002Ftop-traders`). When Historical ships, this README will document the matching proxy route (for example `GET \u002Fapi\u002Fwallets\u002F:owner\u002Fpnl-ts` → Vybe `pnl-ts`) alongside the UI.\n\n---\n\n## Server Proxy Routes\n\nThe Express server in `src\u002Fserver.ts` exposes:\n\n- **`GET \u002Fapi\u002Fwallets\u002Ftop-traders`**\n  - Proxies to Vybe `GET \u002Fv4\u002Fwallets\u002Ftop-traders` with query params: `mintAddress` or `ilikeFilter`, `resolution`, `label`, `sortByAsc` \u002F `sortByDesc`, `limit`, `page`.\n- **`GET \u002Fapi\u002Fwallets\u002F:ownerAddress\u002Fpnl`**\n  - Proxies to Vybe `GET \u002Fv4\u002Fwallets\u002F{ownerAddress}\u002Fpnl` with `resolution`, optional `mintAddress`, sort fields, `limit`, `page`.\n- **`GET \u002Fapi\u002Ftokens\u002F:mint\u002Ftop-pnl-traders`**\n  - Proxies to Vybe `GET \u002Fv4\u002Ftokens\u002F{mintAddress}\u002Ftop-pnl-traders` with resolution and sort pagination.\n- **`GET \u002Fapi\u002Ftokens\u002F:mint`**\n  - Proxies to Vybe `GET \u002Fv4\u002Ftokens\u002F{mintAddress}` for token metadata.\n- **`GET \u002Fapi\u002Ftokens\u002F:mint\u002Ftop-holders`**\n  - Proxies to Vybe top holders for the mint (optional UI).\n- **`GET \u002Fapi\u002Ftrades`**\n  - Proxies to Vybe `GET \u002Fv4\u002Ftrades` with `mintAddress`, `limit`, `page`, `sortByDesc`, optional `timeStart` \u002F `timeEnd`.\n- **`GET \u002Fapi\u002Fprograms\u002Flabeled-program-account?programAddress=…`**\n  - Proxies to Vybe labeled program lookup; responses cached on disk (`data\u002F`).\n- **`POST \u002Fapi\u002Fprograms\u002Flabeled-program-accounts`**\n  - Batch labeled programs; merges with on-disk cache.\n- **`GET \u002Fapi\u002Ftoken-symbol\u002F:mint`** and **`POST \u002Fapi\u002Ftoken-symbols`**\n  - Symbol resolution (Metaplex \u002F Vybe fallback); cached under `data\u002F`.\n\nAll Vybe requests use a shared client (`src\u002Fapi\u002Findex.ts`) with timeouts, retries, and `toHumanReadableError`. Symbol and program-label caches are JSON files in the **`data\u002F`** directory (created on demand).\n\n---\n\n## How to Run\n\n### 1. Clone the repository\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fvybenetwork\u002Fsolana-wallet-pnl-profit-and-loss-api.git\ncd solana-wallet-pnl-profit-and-loss-api\n```\n\n### 2. Install dependencies\n\n```bash\nnpm install\n```\n\n### 3. Set your API key\n\n```bash\ncp .env.example .env\n# Add your VYBE_API_KEY to .env\n```\n\n### 4. Run the server + web app\n\n```bash\nnpm start\n```\n\nThen open **http:\u002F\u002Flocalhost:3000**. The UI loads **wallet PnL** and **related wallets** for the search and resolution you choose; use **Load wallet PnL** after changing remote filters.\n\n### 5. (Optional) Run with Cloudflare Tunnel\n\nTo expose the app on a public URL (e.g. for sharing or testing from another device), enable a tunnel (requires `cloudflared` installed):\n\n```bash\nTUNNEL=1 npm start\n```\n\nOr use the npm script:\n\n```bash\nnpm run dev:tunnel\n```\n\nThe console will print a **Cloudflare Tunnel URL** when `cloudflared` starts successfully.\n\n---\n\n## Project Structure\n\n```text\nsolana-wallet-pnl-profit-and-loss-api\u002F\n├── .env.example           # Copy to .env, fill in VYBE_API_KEY (and optional SOLANA_RPC_URL, PORT, TUNNEL, TRADES_LOG)\n├── tsconfig.json          # TypeScript config for backend (tsx runs src\u002Fserver.ts)\n├── tsconfig.frontend.json # TypeScript config for frontend (builds public\u002Fapp.js)\n├── package.json           # Scripts and pinned dependencies\n├── README.md\n├── screenshots\u002F           # Screenshots referenced in this README (same filenames as template; you replace images)\n├── public\u002F                # Web GUI (HTML, CSS, built JS)\n│   ├── index.html\n│   ├── app.js             # Generated by `npm run build:frontend` from src\u002Ffrontend\u002Fapp.ts\n│   └── app.css\n└── src\u002F\n    ├── server.ts          # Express server; proxies Vybe API and serves public\u002F\n    ├── config.ts          # Env loading, API base URL, timeouts, PUBLIC_DIR\n    ├── cache.ts           # On-disk caches (symbol, program-label) in data\u002F\n    ├── types\u002F\n    │   └── api.ts         # Interfaces matching Vybe API response shapes\n    ├── utils\u002F\n    │   └── formatters.ts  # Shared formatting helpers\n    ├── api\u002F\n    │   ├── index.ts       # createClient(apiKey) — wires all API methods\n    │   ├── client.ts      # Axios wrapper, retries, human-readable errors\n    │   ├── tokens.ts      # GET \u002Fv4\u002Ftokens\u002F{mintAddress}\n    │   ├── holders.ts     # GET \u002Fv4\u002Ftokens\u002F{mint}\u002Ftop-holders\n    │   ├── trades.ts      # Trades, top-traders, wallet Pnl, token top PnL traders\n    │   └── token-symbol.ts # Token symbol fallback (Metaplex, WSOL\u002FUSDC hardcoded)\n    └── frontend\u002F\n        └── app.ts         # Wallet PnL UI → builds to public\u002Fapp.js\n```\n\n---\n\n## Direct API Usage Example\n\nIf you want to bypass the UI and call Vybe directly for wallet PnL and related wallets:\n\n```typescript\nimport axios from 'axios';\n\nconst API = 'https:\u002F\u002Fapi.vybenetwork.xyz';\nconst headers = { 'X-API-KEY': process.env.VYBE_API_KEY!, Accept: 'application\u002Fjson' };\n\nasync function fetchWalletPnl(ownerAddress: string, resolution = '7d') {\n  const { data } = await axios.get(`${API}\u002Fv4\u002Fwallets\u002F${encodeURIComponent(ownerAddress)}\u002Fpnl`, {\n    params: { resolution, limit: 100, sortByDesc: 'realizedPnlUsd' },\n    headers,\n  });\n  return data;\n}\n\nasync function fetchRelatedWallets(ilikeFilter: string, resolution = '7d') {\n  const { data } = await axios.get(`${API}\u002Fv4\u002Fwallets\u002Ftop-traders`, {\n    params: { ilikeFilter, resolution, limit: 100, sortByDesc: 'realizedPnlUsd' },\n    headers,\n  });\n  return data;\n}\n\nconst owner = 'CyaE1VxvBrahnPWkqm5VsdCvyS2QmNht2UFrKJHga54o';\n\nPromise.all([fetchWalletPnl(owner), fetchRelatedWallets(owner)])\n  .then(([pnl, related]) => {\n    console.log('Wallet PnL payload keys:', pnl && typeof pnl === 'object' ? Object.keys(pnl) : pnl);\n    console.log('Related wallets rows:', Array.isArray((related as { data?: unknown[] })?.data) ? (related as { data: unknown[] }).data.length : related);\n  })\n  .catch((err) => console.error(err.response?.data ?? err.message));\n```\n\n---\n\n## Troubleshooting\n\n| Issue                         | What to do |\n|-------------------------------|------------|\n| **403 Forbidden**             | Verify `VYBE_API_KEY` in `.env` is correct and has access to wallet and top-traders endpoints. If the key works locally but not on a server, it may be IP-restricted — contact Vybe to allow your server IP. |\n| **Slow responses \u002F timeouts** | The app uses a 60s timeout for Vybe requests with retries (`VYBE_TIMEOUT_MS`, `VYBE_MAX_RETRIES`, `VYBE_RETRY_DELAY_MS` in `src\u002Fconfig.ts`). Retry later if Vybe is under load. |\n| **Missing env vars**          | Copy `.env.example` to `.env` and set `VYBE_API_KEY`. On start you should see `VYBE_API_KEY loaded` in the server logs. |\n\n---\n\n## Support\n\n- **Telegram:** [Vybe community](https:\u002F\u002Ft.me\u002Fvybenetwork)\n- **Support ticket:** [Submit a ticket via vybenetwork.xyz](https:\u002F\u002Fvybenetwork.com)\n","该项目提供了一个Solana钱包利润与亏损（PnL）API的示例，展示了如何使用Vybe Solana钱包PnL API来获取、过滤和分析单个钱包的盈亏情况及相关钱包信息。核心功能包括按实际盈亏排名的钱包搜索、交易记录查询以及SPL\u002FToken-2022代币元数据展示。技术上采用TypeScript编写，并提供了一个生产就绪的Node.js后端及浏览器界面。适用于构建钱包分析仪表板、盈亏排行榜、关联钱包发现等数据分析产品场景。",2,"2026-06-11 03:55:58","CREATED_QUERY"]