跳转至主要内容
返回示例应用

Hyperliquid Portfolio Tracker

Build a real-time portfolio tracker that monitors Hyperliquid perpetual positions, PnL, margin utilization, and vault holdings using Quicknode's Hyperliquid info endpoint.

前端框架/库:
React
语言:
TypeScript
构建工具/开发服务器:
Vite
示例应用预览

Introduction

As a perpetual trader on Hyperliquid, having a comprehensive portfolio tracker is essential for monitoring your positions, PnL, and margin utilization in real-time. This guide shows you how to build a powerful portfolio tracker that monitors any Hyperliquid wallet using Quicknode's Hyperliquid info endpoint.

This example app is provided for educational and demonstration purposes only.


其他资源

For an in-depth guide on implementing this portfolio tracker from scratch, check out our comprehensive guide on Quicknode


功能


  • Live Position Tracking: Real-time updates on perpetual positions with PnL
  • Portfolio Analytics: Account value, margin usage, and risk metrics
  • Vault Management: Track vault value and lock-up schedules
  • Spot Holdings: Monitor token balances and USD values
  • Search For Any Wallet: Switch between different trading accounts

Tech Stack

Frontend


  • React + TypeScript + Tailwind CSS + shadcn/ui & Radix UI
  • 在响应式界面中显示交易数据
  • 每1000毫秒查询一次数据库以获取更新
  • 通过数据库请求处理钱包切换

Backend


  • Node.js indexer with 500ms polling interval
  • 从 5 个不同的 Hyperliquid 端点获取数据
  • 将数据存储在 PostgreSQL 中,并进行正确的精度处理
  • 处理来自前端的钱包切换请求

关于投票的注意事项

本指南采用较短的轮询间隔(索引器为 500 毫秒,前端为 1000 毫秒)来演示实时更新。如有需要,您可以调整这些间隔:

  • 前端: src/Dashboard.tsx 第 260-264 行——将 1000 值位于:
    const interval = setInterval(async () => {
    await fetchData(currentWallet);
    }, 1000);
  • 索引员: src/indexer/indexer.ts 第 623-630 行——将 500 值位于:
    setInterval(async () => {
    await indexer.checkForWalletSwitch();
    await indexer.indexData();
    }, 500);

监控您的 Quicknode 和 Supabase 使用情况,以优化成本。

Database


  • Supabase PostgreSQL
  • 将交易数据以金融精度存储在 6 张表中(DECIMAL 类型)
  • 通过以下方式处理前端与索引器之间的通信: 钱包切换请求 表格
  • 使用唯一约束来防止重复条目

数据来源


  • 超流体 信息 通过 Quicknode 访问端点
  • 提供账户数据、持仓、金库持仓、现货余额和授权信息
  • 以 JSON 格式返回数据,其中数值采用字符串形式表示,以保证精度
  • 通过带有钱包地址参数的 HTTP POST 请求访问

建筑


                    ┌─────────────────┐
│ 涉案交易员 │
└─────────┬───────┘
│ 1. 输入钱包地址

┌─────────────────┐
│ React 仪表盘 │◄─────────────────┐
└─────────┬───────┘ │
│ 2. 存储请求 │ 6. 读取并显示数据
▼ │
┌─────────────────┐ │
│ Supabase │◄─────────────────┤
│ PostgreSQL │ │
└─────────┬───────┘ │
│ 3. 检测请求 │ 5. 存储数据
▼ │
┌─────────────────┐ │
│ 索引器 │──────────────────┘
│ (500毫秒轮询) │
└─────────┬───────┘
│ 4. 获取HyperCore数据

┌─────────────────┐
│ Quicknode │
│ Hyperliquid │
│ 端点 │
└─────────────────┘

该投资组合追踪器由三个组件构成,这些组件通过 PostgreSQL 数据库进行通信。索引器从 Hyperliquid 获取数据并将其存储在数据库中,前端则通过查询数据库来显示数据。


先决条件


  • Quicknode account with Hyperliquid endpoint
  • Supabase 账户
  • Node.js v20+、npm 和一个代码编辑器
  • React/TypeScript 和 REST API 的基础概念
  • SQL 基础概念
  • 可选:Hyperliquid 永续交易体验
Why Quicknode Endpoint?

Quicknode 提供了专用的 Hyperliquid API 端点,您无需再自行运行节点:

  • 预配置的端点,无需任何设置
  • 负责连接管理和故障转移
  • 无需额外基础设施即可直接访问 HyperCore 数据

快速入门

1. Clone the Repository

git clone https://github.com/quiknode-labs/qn-guide-examples.git
cd qn-guide-examples/sample-dapps/hyperliquid-portfolio-tracker

2. Setup Environment File

cp .env.example .env

3. Supabase Database Setup


  1. Create a new Supabase account or login at supabase.com

  2. Create a new project, then click the Connect button

Connect Button


  1. In the App Frameworks section, select React and change 使用Vite

Select React


  1. Copy the VITE_SUPABASE_URL 以及 VITE_SUPABASE_ANON_KEY values to your .env file 1
  2. Navigate to the SQL 编辑器, paste the content of supabase/schema.sql, then click 运行

SQL 编辑器

This creates all necessary tables and functions for storing and fetching trading data.

4. Quicknode Setup


  1. Create a free trial Quicknode account
  2. Create a Hyperliquid RPC endpoint
  3. Copy the endpoint URL and paste it to your .env 文件
Important

请务必删除现有的 /evm 并添加 /info 在您的 Quicknode 端点 URL 末尾添加此内容,即可访问 Hyperliquid 信息端点。

5. Start the Application

npm install && npm run dev:both

This runs both the frontend application and the indexer. Open your browser at http://localhost:5173 and use the demo wallet button to see the tracker in action.


故障排除


If the indexer stops responding or no data appears after wallet search, simply re-run the indexer:

npm run dev:indexer

Then search again by inputting a valid wallet address.


预览

主页

主页

Dashboard View

Dashboard View


了解更多



Future Improvements


  • Liquidation Warnings: Alert users when positions approach dangerous margin levels
  • Performance Charts: Track portfolio performance over time with Recharts
  • Price Alerts: Send notifications using your favorite notification service
  • Multi-Wallet Dashboard: Compare multiple trading accounts side-by-side

投稿与反馈
我们非常希望听到您的反馈,并欢迎大家为这个示例应用做出任何贡献!
如需报告问题或提供反馈,请在 qn-guide-示例 存储库。
如需贡献,请按照以下步骤操作:
  1. 分叉该仓库
  2. 创建一个功能分支:
    git checkout -b feature/amazing-feature
  3. 提交您的更改:
    git commit -m "添加超棒的功能"
  4. 推送您的分支:
    git push origin feature/amazing-feature
  5. 提交一个拉取请求。