官方SDK库
提供Python、JavaScript、Go和Rust的官方客户端库。通过类型化客户端、自动重试逻辑和WebSocket支持简化API集成。
Python SDK
包名: smartmoney-api
安装: pip install smartmoney-api
代码库: github.com/smartmoneyapi/python-client
Python
from smartmoney import SmartMoneyAPI
# 初始化客户端
client = SmartMoneyAPI(api_key="sk_live_abc123xyz789")
# 获取鲸鱼持仓
whales = client.whale_positions(symbol="BTCUSDT", limit=50)
for position in whales:
print(f"{position.wallet_address}: {position.position_size} BTC @ {position.entry_price}")
# 获取资金费率
funding = client.funding_rates(symbol="BTCUSDT", interval="4h", limit=24)
# 实时流式更新
with client.stream_whale_positions(["BTCUSDT", "ETHUSDT"]) as stream:
for update in stream:
print(f"持仓更新: {update}")
功能特性
- 异步/等待支持(asyncio、aiohttp)
- 指数退避自动重试
- 带自动重连的WebSocket流
- 类型提示与IDE自动补全
- 请求日志与调试
JavaScript SDK
包名: smartmoney-api
安装: npm install smartmoney-api
代码库: github.com/smartmoneyapi/js-client
JavaScript
import { SmartMoneyAPI } from "smartmoney-api";
const client = new SmartMoneyAPI({
apiKey: "sk_live_abc123xyz789"
});
// 获取鲸鱼持仓
const whales = await client.whalePositions({
symbol: "BTCUSDT",
limit: 50
});
whales.positions.forEach(pos => {
console.log(`${pos.wallet_address}: ${pos.position_size} BTC`);
});
// 实时流式更新
const stream = client.streamWhalePositions(["BTCUSDT", "ETHUSDT"]);
stream.on("data", (update) => {
console.log("持仓更新:", update);
});
stream.on("error", (err) => {
console.error("流错误:", err);
});
Go SDK
模块: github.com/smartmoneyapi/go-client
安装: go get github.com/smartmoneyapi/go-client
Go
package main
import (
"fmt"
"github.com/smartmoneyapi/go-client"
)
func main() {
// 创建客户端
client := smartmoney.NewClient("sk_live_abc123xyz789")
// 获取鲸鱼持仓
positions, err := client.WhalePositions(ctx, &smartmoney.WhalePositionsFilter{
Symbol: "BTCUSDT",
Limit: 50,
})
if err != nil {
panic(err)
}
for _, pos := range positions {
fmt.Printf("%s: %.2f BTC\n", pos.WalletAddress, pos.PositionSize)
}
}
Rust SDK
包名: smartmoney-api
安装: cargo add smartmoney-api
Rust
use smartmoney_api::Client;
#[tokio::main]
async fn main() -> Result<(), Box> {
let client = Client::new("sk_live_abc123xyz789");
// 获取鲸鱼持仓
let positions = client
.whale_positions()
.symbol("BTCUSDT")
.limit(50)
.send()
.await?;
for position in positions.iter() {
println!(
"{}: {} BTC @ {}",
position.wallet_address,
position.position_size,
position.entry_price
);
}
Ok(())
}
通用模式
错误处理
所有SDK均提供包含自动重试逻辑的丰富错误类型,含状态码、错误代码及可读消息。
请求超时
可配置请求超时(默认30秒)。为长时运行操作设置自定义超时。
速率限制处理
触发速率限制时自动指数退避,并遵循Retry-After头部。