跳到主要内容

市场数据 API

市场数据 API 提供了 OtcHub 平台上的实时市场信息,包括资产价格、交易量、趋势数据等。

基础端点

获取市场统计

获取平台整体市场统计数据。

GET /api/marketplace/stats

响应示例:

{
"totalTrades": 156,
"totalVolume": "892456.78",
"activeOffers": 45,
"totalAssets": 23,
"last24hTrades": 12,
"last24hVolume": "45678.90"
}

响应字段:

  • totalTrades: 总交易数
  • totalVolume: 总交易量(美元)
  • activeOffers: 当前活跃报价数
  • totalAssets: 平台资产总数
  • last24hTrades: 过去24小时交易数
  • last24hVolume: 过去24小时交易量(美元)

获取趋势资产

获取交易量最高和最活跃的资产列表。

GET /api/marketplace/trending?limit=10

查询参数:

  • limit (可选): 返回结果数量,默认为 10

响应示例:

{
"trending": [
{
"assetUid": "asset_abc123_otchub",
"name": "USDT",
"assetType": "token",
"decimals": 6,
"currentPrice": "1.00",
"priceChange24h": "0.00",
"volume24h": "15678.90",
"totalVolume": "234567.89",
"activeOffers": 8,
"totalTrades": 45
}
]
}

资产字段说明:

  • assetUid: 资产唯一标识符
  • name: 资产名称
  • assetType: 资产类型(token、nft、custom)
  • decimals: 代币精度(仅适用于代币)
  • currentPrice: 当前价格(美元)
  • priceChange24h: 24小时价格变化(美元)
  • volume24h: 24小时交易量(美元)
  • totalVolume: 总交易量(美元)
  • activeOffers: 当前活跃报价数
  • totalTrades: 总交易次数

获取市场活动

获取最近的交易活动记录。

GET /api/marketplace/activity?limit=20

查询参数:

  • limit (可选): 返回结果数量,默认为 20

响应示例:

{
"activities": [
{
"id": "trade_789",
"type": "trade_completed",
"assetName": "USDT",
"assetType": "token",
"quantity": "1000",
"price": "1.00",
"totalValue": "1000.00",
"direction": "MakerSells",
"timestamp": "2025-01-10T15:30:00Z",
"participants": {
"maker": "0x742d35Cc6641C7FB22d02bBf5F5e2B5B3a3E5A7C",
"taker": "0x8ba1f109551bD432803012645Hac136c"
}
}
]
}

活动字段说明:

  • id: 交易唯一标识符
  • type: 活动类型(trade_completed、trade_created、offer_created)
  • assetName: 交易资产名称
  • assetType: 资产类型
  • quantity: 交易数量
  • price: 单价(美元)
  • totalValue: 交易总价值(美元)
  • direction: 交易方向
  • timestamp: 交易时间戳
  • participants: 参与方地址

获取资产分类

获取平台上所有资产分类及其统计信息。

GET /api/marketplace/categories

响应示例:

{
"categories": [
{
"name": "tokens",
"label": "代币",
"description": "ERC20 代币和其他同质化代币",
"assetCount": 15,
"totalVolume": "456789.12",
"activeOffers": 23,
"examples": ["USDT", "USDC", "ETH"]
},
{
"name": "nfts",
"label": "NFT",
"description": "非同质化代币和数字收藏品",
"assetCount": 8,
"totalVolume": "78901.23",
"activeOffers": 12,
"examples": ["CryptoPunks", "BAYC", "Azuki"]
}
]
}

分类字段说明:

  • name: 分类标识符
  • label: 分类显示名称
  • description: 分类描述
  • assetCount: 该分类下的资产数量
  • totalVolume: 该分类的总交易量
  • activeOffers: 该分类的活跃报价数
  • examples: 该分类的示例资产

资产特定端点

获取资产市场数据

获取特定资产的详细市场数据。

GET /api/assets/{assetUid}/market-data

路径参数:

  • assetUid: 资产唯一标识符

响应示例:

{
"asset": {
"assetUid": "asset_abc123_otchub",
"name": "USDT",
"assetType": "token",
"decimals": 6,
"contractAddress": "0xdAC17F958D2ee523a2206206994597C13D831ec7"
},
"marketData": {
"currentPrice": "1.00",
"priceChange24h": "0.00",
"priceChangePercent24h": "0.00%",
"volume24h": "5678.90",
"totalVolume": "123456.78",
"marketCap": "N/A",
"circulatingSupply": "N/A"
},
"trading": {
"activeOffers": 6,
"totalTrades": 28,
"avgTradeSize": "4412.30",
"lastTradeTime": "2025-01-10T14:25:00Z"
},
"priceHistory": [
{
"timestamp": "2025-01-10T10:00:00Z",
"price": "1.00",
"volume": "1234.56"
}
]
}

市场数据字段:

  • currentPrice: 当前价格
  • priceChange24h: 24小时价格变化
  • priceChangePercent24h: 24小时价格变化百分比
  • volume24h: 24小时交易量
  • totalVolume: 历史总交易量
  • marketCap: 市值(如果适用)
  • circulatingSupply: 流通供应量(如果适用)

交易数据字段:

  • activeOffers: 当前活跃报价数
  • totalTrades: 历史总交易数
  • avgTradeSize: 平均交易规模
  • lastTradeTime: 最后交易时间

错误处理

标准错误响应

{
"error": "Not Found",
"message": "Asset not found",
"code": 404
}

常见错误码

  • 400: 请求参数无效
  • 404: 资源未找到
  • 429: 请求频率过高
  • 500: 服务器内部错误

速率限制

  • 普通用户: 每分钟 100 次请求
  • 认证用户: 每分钟 300 次请求
  • API 密钥: 每分钟 1000 次请求

超过速率限制时,服务器将返回 429 状态码。

数据更新频率

  • 价格数据: 实时更新(每次交易后)
  • 统计数据: 每5分钟更新一次
  • 历史数据: 永久保存,定期归档

使用示例

JavaScript/Node.js

// 获取市场统计
async function getMarketStats() {
try {
const response = await fetch('/api/marketplace/stats');
const stats = await response.json();
console.log('总交易量:', stats.totalVolume);
} catch (error) {
console.error('获取市场统计失败:', error);
}
}

// 获取趋势资产
async function getTrendingAssets() {
try {
const response = await fetch('/api/marketplace/trending?limit=5');
const data = await response.json();
data.trending.forEach(asset => {
console.log(`${asset.name}: $${asset.currentPrice}`);
});
} catch (error) {
console.error('获取趋势资产失败:', error);
}
}

Python

import requests

def get_market_stats():
try:
response = requests.get('/api/marketplace/stats')
stats = response.json()
print(f"总交易量: ${stats['totalVolume']}")
except Exception as error:
print(f"获取市场统计失败: {error}")

def get_asset_market_data(asset_uid):
try:
response = requests.get(f'/api/assets/{asset_uid}/market-data')
data = response.json()
return data['marketData']
except Exception as error:
print(f"获取资产市场数据失败: {error}")
return None

注意事项

  1. 数据准确性: 所有价格和交易量数据基于平台上的实际交易
  2. 实时性: 某些数据可能有轻微延迟(通常少于1分钟)
  3. 隐私保护: 用户地址经过脱敏处理
  4. 数据完整性: 历史数据保证完整性和可追溯性