跳转到内容
本页面的翻译由 LLM 生成。如果你发现翻译有误,请在 GitHub 上提交 issue 告诉我们。

费用 API 参考

查询交易费用、每日统计和协议、交易者汇总。

按 ID 获取费用交易。

签名:

feeTransaction(id: ID!): FeeTransaction

参数:

  • id:字符串交易 ID。

返回: FeeTransaction 或 null。

示例:

query GetFeeTransaction {
fee {
feeTransaction(id: "abc123") {
id
traderAddress
feeType
totalFeeCharged
govFee
vaultFee
referrerAllocation
triggerFee
collateralDenom
blockHeight
blockTime
}
}
}

列出费用交易,支持筛选和分页。

签名:

feeTransactions(
filter: FeeTransactionFilter
limit: Int = 100
offset: Int = 0
): [FeeTransaction!]!

参数:

  • filter:可选筛选。
    • traderAddress:交易者。
    • collateralDenom:抵押代币。
    • feeType:OPENING 或 CLOSING。
    • fromDate:开始日期,RFC3339。
    • toDate:结束日期,RFC3339。
    • minAmount:最低费用。
    • maxAmount:最高费用。
  • limit:最大数量,默认 100。
  • offset:跳过数量,默认 0。

返回: FeeTransaction 数组。

示例:获取用户费用

query GetUserFees($trader: String!) {
fee {
feeTransactions(
filter: { traderAddress: $trader }
limit: 50
) {
id
feeType
totalFeeCharged
govFee
vaultFee
referrerAllocation
triggerFee
blockTime
tradeId
orderType
}
}
}

示例:按日期范围筛选

query GetFeesInRange {
fee {
feeTransactions(
filter: {
fromDate: "2024-01-01T00:00:00Z"
toDate: "2024-01-31T23:59:59Z"
feeType: OPENING
}
limit: 100
) {
id
traderAddress
totalFeeCharged
blockTime
}
}
}

示例:仅大额费用

query GetLargeFees {
fee {
feeTransactions(
filter: {
minAmount: 1000000 # Filter fees > 1,000,000
}
limit: 20
) {
id
traderAddress
totalFeeCharged
feeType
}
}
}

应用场景:

  • 用户费用历史。
  • 协议费用监控。
  • 大额交易追踪。
  • 按时段分析费用。

获取每日费用汇总。

签名:

feeDailyStats(
filter: FeeDailyStatsFilter
limit: Int = 30
offset: Int = 0
): [FeeDailyStats!]!

参数:

  • filter:可选筛选。
    • traderAddress:交易者。
    • collateralDenom:抵押代币。
    • fromDate、toDate:起止日期。
    • protocolWide:true 时查询整个协议。
  • limit:最大数量,默认 30。
  • offset:跳过数量,默认 0。

返回: FeeDailyStats 数组。

示例:协议每日统计

query GetProtocolDailyStats {
fee {
feeDailyStats(
filter: { protocolWide: true }
limit: 30
) {
date
collateralDenom
openingFeeCount
openingFeeTotal
openingGovFee
openingReferrerFee
openingVaultFee
closingFeeCount
closingFeeTotal
closingGovFee
closingReferrerFee
closingVaultFee
closingTriggerFee
totalBadDebt
updatedAt
}
}
}

示例:交易者每日统计

query GetTraderDailyStats($trader: String!) {
fee {
feeDailyStats(
filter: {
traderAddress: $trader
fromDate: "2024-01-01T00:00:00Z"
}
limit: 90
) {
date
openingFeeTotal
closingFeeTotal
totalBadDebt
}
}
}

应用场景:

  • 每日费用图表。
  • 历史费用分析。
  • 收益追踪。
  • 交易者费用明细。

获取包含附加指标的增强费用分析。

签名:

feeAnalytics(
filter: FeeDailyStatsFilter
limit: Int = 30
offset: Int = 0
): [FeeAnalytics!]!

参数: 与 feeDailyStats 相同。

返回: FeeAnalytics 数组。

示例:

query GetFeeAnalytics {
fee {
feeAnalytics(
filter: { protocolWide: true }
limit: 30
) {
date
collateralDenom
openingCount
openingTotal
openingGov
openingReferrer
openingVault
openingTrigger
closingCount
closingTotal
closingGov
closingReferrer
closingVault
closingTrigger
totalFeesAll
avgFeeMultiplier
totalBadDebt
traderAddress
}
}
}

与 feeDailyStats 的区别:

  • 包含 avgFeeMultiplier。
  • 包含开平仓合计 totalFeesAll。
  • 更细的触发费用明细。

应用场景:

  • 高级分析面板。
  • 费用乘数追踪。
  • 完整费用报告。

获取指定时段的协议费用汇总。

签名:

protocolFeeSummary(
collateralDenom: String
fromDate: Time
toDate: Time
): ProtocolFeeSummary!

参数:

  • collateralDenom:可选抵押资产筛选。
  • fromDate、toDate:可选起止日期。

返回: ProtocolFeeSummary。

示例:协议全时段汇总

query GetProtocolSummary {
fee {
protocolFeeSummary {
period {
fromDate
toDate
}
totalFees
totalOpeningFees
totalClosingFees
totalGovFees
totalVaultFees
totalReferrerFees
totalTriggerFees
totalBadDebt
openingCount
closingCount
uniqueTraders
avgFeeMultiplier
}
}
}

示例:月度汇总

query GetMonthlySummary {
fee {
protocolFeeSummary(
fromDate: "2024-01-01T00:00:00Z"
toDate: "2024-01-31T23:59:59Z"
) {
totalFees
totalOpeningFees
totalClosingFees
uniqueTraders
openingCount
closingCount
}
}
}

示例:按抵押资产汇总

query GetCollateralSummary {
fee {
protocolFeeSummary(
collateralDenom: "uusdc"
fromDate: "2024-01-01T00:00:00Z"
) {
totalFees
totalVaultFees
totalGovFees
uniqueTraders
}
}
}

应用场景:

  • 协议收益报告。
  • KPI 追踪。
  • 表现指标。
  • 时段比较。

获取指定交易者费用汇总。

签名:

traderFeeSummary(
traderAddress: String!
collateralDenom: String
fromDate: Time
toDate: Time
): TraderFeeSummary!

参数:

  • traderAddress:必填地址。
  • collateralDenom:可选抵押资产筛选。
  • fromDate、toDate:可选起止日期。

返回: TraderFeeSummary。

示例:交易者全时段汇总

query GetTraderSummary($trader: String!) {
fee {
traderFeeSummary(traderAddress: $trader) {
traderAddress
period {
fromDate
toDate
}
totalFees
totalOpeningFees
totalClosingFees
totalReferrerAllocation
totalBadDebt
openingCount
closingCount
avgFeeMultiplier
}
}
}

示例:交易者月度汇总

query GetTraderMonthlySummary($trader: String!) {
fee {
traderFeeSummary(
traderAddress: $trader
fromDate: "2024-01-01T00:00:00Z"
toDate: "2024-01-31T23:59:59Z"
) {
totalFees
openingCount
closingCount
avgFeeMultiplier
}
}
}

应用场景:

  • 用户面板。
  • 交易成本分析。
  • 费用优化分析。
  • 推荐追踪。

完整费用交易详情。

type FeeTransaction {
id: ID!
traderAddress: String!
tradeId: Int!
tradeIndex: Int!
feeType: FeeType!
collateralDenom: String!
totalFeeCharged: Int!
govFee: Int!
netGovFee: Int!
vaultFee: Int!
referrerAllocation: Int!
triggerFee: Int!
openFeeComponent: Int
triggerFeeComponent: Int
triggererReward: Int
collateralLeft: Int
badDebt: Int!
feeMultiplier: Float!
orderType: String
catalystAddress: String
blockHeight: Int!
blockTime: Time!
createdAt: Time!
}

主要字段:

  • totalFeeCharged:交易者支付总额。
  • govFee:治理费用。
  • vaultFee:LP 金库费用。
  • referrerAllocation:推荐人分配。
  • triggerFee:订单触发执行者费用。
  • badDebt:抵押不足强平的坏账。
  • feeMultiplier:适用动态乘数。

每日费用汇总。

type FeeDailyStats {
date: Time!
collateralDenom: String!
traderAddress: String
openingFeeCount: Int!
openingFeeTotal: Int!
openingGovFee: Int!
openingReferrerFee: Int!
openingTriggerFee: Int!
openingVaultFee: Int!
closingFeeCount: Int!
closingFeeTotal: Int!
closingGovFee: Int!
closingReferrerFee: Int!
closingTriggerFee: Int!
closingVaultFee: Int!
totalBadDebt: Int!
updatedAt: Time!
}

包含附加指标的增强分析。

type FeeAnalytics {
date: Time!
collateralDenom: String!
traderAddress: String
openingCount: Int!
openingTotal: Int!
openingGov: Int!
openingReferrer: Int!
openingTrigger: Int!
openingVault: Int!
closingCount: Int!
closingTotal: Int!
closingGov: Int!
closingReferrer: Int!
closingTrigger: Int!
closingVault: Int!
totalFeesAll: Int!
avgFeeMultiplier: Float!
totalBadDebt: Int!
}

协议费用汇总。

type ProtocolFeeSummary {
period: TimePeriod!
totalFees: Int!
totalOpeningFees: Int!
totalClosingFees: Int!
totalGovFees: Int!
totalVaultFees: Int!
totalReferrerFees: Int!
totalTriggerFees: Int!
totalBadDebt: Int!
openingCount: Int!
closingCount: Int!
uniqueTraders: Int!
avgFeeMultiplier: Float!
}

交易者费用汇总。

type TraderFeeSummary {
traderAddress: String!
period: TimePeriod!
totalFees: Int!
totalOpeningFees: Int!
totalClosingFees: Int!
totalReferrerAllocation: Int!
totalBadDebt: Int!
openingCount: Int!
closingCount: Int!
avgFeeMultiplier: Float!
}

FeeType:

  • OPENING:开仓费用。
  • CLOSING:平仓费用。

const totalRevenue = protocolFeeSummary.totalGovFees +
protocolFeeSummary.totalVaultFees
const avgOpeningFee = protocolFeeSummary.totalOpeningFees /
protocolFeeSummary.openingCount
const avgClosingFee = protocolFeeSummary.totalClosingFees /
protocolFeeSummary.closingCount
const calculateBreakdown = (summary) => {
const total = summary.totalFees
return {
govPct: (summary.totalGovFees / total) * 100,
vaultPct: (summary.totalVaultFees / total) * 100,
referrerPct: (summary.totalReferrerFees / total) * 100,
triggerPct: (summary.totalTriggerFees / total) * 100
}
}
// Fees are in smallest unit, convert to decimal
const convertFee = (feeAmount, decimals) => {
return feeAmount / (10 ** decimals)
}
// Example: USDC fees (6 decimals)
const feeUSDC = convertFee(1000000, 6) // = 1.0 USDC

// Get current month stats
const now = new Date()
const firstDay = new Date(now.getFullYear(), now.getMonth(), 1)
const lastDay = new Date(now.getFullYear(), now.getMonth() + 1, 0)
const query = `
query GetMonthlyStats {
fee {
protocolFeeSummary(
fromDate: "${firstDay.toISOString()}"
toDate: "${lastDay.toISOString()}"
) {
totalFees
uniqueTraders
}
}
}
`
// Fetch all fee transactions in batches
const fetchAllFees = async (trader, limit = 100) => {
let allFees = []
let offset = 0
let hasMore = true
while (hasMore) {
const { data } = await client.query({
query: FEE_TRANSACTIONS_QUERY,
variables: { trader, limit, offset }
})
const fees = data.fee.feeTransactions
allFees = allFees.concat(fees)
hasMore = fees.length === limit
offset += limit
}
return allFees
}
// Cache daily stats (they don't change)
const cacheDailyStats = new Map()
const getDailyStats = async (date) => {
const dateKey = date.toISOString().split('T')[0]
if (cacheDailyStats.has(dateKey)) {
return cacheDailyStats.get(dateKey)
}
const stats = await fetchDailyStats(date)
cacheDailyStats.set(dateKey, stats)
return stats
}