有两种配置方式可选:
Two configuration methods available:
一次配置,所有接口可用!/ Configure once, use everywhere!
- 编辑根目录的
shared-config.js
Editshared-config.jsin root directory
cd "/Users/user/Desktop/api demo"
nano shared-config.js # 或使用任何编辑器 / or use any editor- 填写您的凭证
Fill in your credentials
module.exports = {
// API凭证 / API Credentials
API_KEY: '您的API密钥',
SECRET_KEY: '您的密钥',
// 钱包凭证(钱包签名接口需要)/ Wallet (for signature endpoints)
PRIVATE_KEY: '0x您的私钥...',
WALLET_ADDRESS: '0x您的地址...',
// 其他配置已预设,无需修改 / Other configs are preset
};- 运行同步脚本
Run sync script
node sync-config.js这会自动将配置同步到所有目录!
This will automatically sync config to all directories!
分别为每个目录配置(更灵活但需要多次配置)
Configure each directory separately (more flexible but requires multiple setups)
# 1. Spot API / 现货API
cd spot-demo
cp config.example.js config.js
nano config.js
# 2. Futures API / 期货API
cd ../futures-demo
nano config.js
# 3. Futures V3 API / 期货V3 API
cd ../futures-v3-demo
nano config.js| 配置项 / Config Item | spot-demo | futures-demo | futures-v3-demo |
|---|---|---|---|
| BASE_URL | https://sapi.asterdex.com | https://fapi.asterdex.com | https://fapi.asterdex.com |
| API_KEY | ✅ 需要 / Required | ✅ 需要 / Required | ✅ 需要 / Required |
| SECRET_KEY | ✅ 需要 / Required | ✅ 需要 / Required | ✅ 需要 / Required |
| PRIVATE_KEY | ❌ 不需要 / Not needed | ❌ 不需要 / Not needed | |
| WALLET_ADDRESS | ❌ 不需要 / Not needed | ❌ 不需要 / Not needed |
- ✅ API_KEY - API密钥
- ✅ SECRET_KEY - 密钥
22_sendToAddress.js- 发送到地址 / Send to address26_createApiKey.js- 创建API密钥 / Create API key
如果您不使用这两个接口,可以不配置钱包相关内容。
If you don't use these two endpoints, you can skip wallet configuration.
- ✅ 您想要简单快速的配置 / You want simple and fast setup
- ✅ 所有API使用相同的凭证 / All APIs use same credentials
- ✅ 您会使用多个API类型 / You'll use multiple API types
- ✅ 不同API需要不同的凭证 / Different APIs need different credentials
- ✅ 您只使用一个API类型 / You only use one API type
- ✅ 您需要更灵活的配置 / You need more flexible configuration
Minimal Config (REST API only, no wallet features)
// shared-config.js
module.exports = {
API_KEY: 'abc123...',
SECRET_KEY: 'xyz789...',
// 以下可以保持默认 / Following can keep defaults
PRIVATE_KEY: '0x0000...',
WALLET_ADDRESS: '0x0000...',
};可用接口 / Available Endpoints:
- ✅ 所有Spot REST API(除了22, 26)
- ✅ 所有Futures REST API
- ✅ 所有Futures V3 REST API
- ✅ 所有WebSocket流
不可用接口 / Unavailable Endpoints:
- ❌
spot-demo/22_sendToAddress.js - ❌
spot-demo/26_createApiKey.js
Full Config (with wallet features)
// shared-config.js
module.exports = {
API_KEY: 'abc123...',
SECRET_KEY: 'xyz789...',
PRIVATE_KEY: '0x1234567890abcdef...', // 真实私钥 / Real private key
WALLET_ADDRESS: '0xAbCdEf...', // 真实地址 / Real address
};可用接口 / Available Endpoints:
- ✅ 所有接口!/ All endpoints!
# 使用方法 / Usage:
node sync-config.js
# 输出示例 / Output example:
✓ Synced to spot-demo/config.js
✓ Synced to futures-demo/config.js
✓ Synced to futures-v3-demo/config.js
✓ All configurations synced! / 所有配置已同步!不论使用哪种方法,请确保:
Regardless of which method, please ensure:
- ✅ 将
shared-config.js和所有config.js添加到.gitignore - ✅ 永远不要提交包含真实凭证的文件
- ✅ 使用测试凭证进行测试
- ✅ 定期更换API密钥
配置前检查 / Before Configuration:
- 已获取API密钥和密钥 / Obtained API key and secret
- 已准备好钱包私钥(如需要)/ Wallet private key ready (if needed)
- 已阅读安全须知 / Read security notice
配置后检查 / After Configuration:
- API_KEY 不是默认值 / API_KEY is not default
- SECRET_KEY 不是默认值 / SECRET_KEY is not default
- 已添加到 .gitignore / Added to .gitignore
- 测试一个简单接口(如 ping)/ Test a simple endpoint (like ping)
配置完成后,测试是否正常:
After configuration, test if it works:
# 测试 Spot API / Test Spot API
cd spot-demo
node 01_ping.js
# 测试 Futures API / Test Futures API
cd ../futures-demo
node 01_ping.js
# 测试 Futures V3 API / Test Futures V3 API
cd ../futures-v3-demo
node 01_ping.js如果看到 "✓ Connection successful!",说明配置正确!
If you see "✓ Connection successful!", configuration is correct!
A: 不是。只有使用 22_sendToAddress.js 和 26_createApiKey.js 时才需要。其他接口只需要API密钥。
A: 可以!同一个API密钥可以用于Spot、Futures和Futures V3 API。
A: 可以!如果您只使用Spot API,只需配置 spot-demo/config.js。
A: 是的。它只是复制配置,不会发送到网络。而且 shared-config.js 已在 .gitignore 中。
A: 运行 node 01_ping.js 测试连接。如果成功,配置就正确了。
# 1. 编辑 shared-config.js
nano shared-config.js
# 2. 重新同步
node sync-config.js# 分别编辑每个 config.js
nano spot-demo/config.js
nano futures-demo/config.js
nano futures-v3-demo/config.js如果配置遇到问题:
If you encounter configuration issues:
- 检查
.gitignore是否包含config.js - 确认API密钥格式正确
- 运行
ping接口测试连接 - 查看错误消息获取详细信息
配置完成后,所有接口示例都可以使用了!
After configuration, all endpoint examples are ready to use!