12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- import { AsterWsConfig, AsterAuthConfig } from '../adapters/exchanges/aster/types'
- export interface AsterConfig {
- // WebSocket 配置
- ws: {
- url: string
- pingInterval: number
- pongTimeout: number
- reconnectInterval: number
- maxReconnectAttempts: number
- }
- // HTTP API 配置
- http: {
- baseUrl: string
- }
- // 鉴权配置
- auth: {
- user: string
- signer: string
- privateKey: string
- }
- // 订阅配置
- subscribe: {
- symbols: string[]
- }
- // 日志配置
- log: {
- level: string
- }
- }
- /**
- * 从环境变量读取 Aster DEX 配置
- */
- export function loadAsterConfig(): AsterConfig {
- const required = ['ASTER_WS_URL', 'ASTER_ORDER_USER', 'ASTER_ORDER_SIGNER', 'PRIVATE_KEY']
- for (const key of required) {
- if (!process.env[key]) {
- throw new Error(`缺少必需的环境变量: ${key}`)
- }
- }
- return {
- ws: {
- url: process.env.ASTER_WS_URL!,
- pingInterval: parseInt(process.env.ASTER_WS_PING_INTERVAL || '30000'),
- pongTimeout: parseInt(process.env.ASTER_WS_PONG_TIMEOUT || '10000'),
- reconnectInterval: parseInt(process.env.ASTER_WS_RECONNECT_INTERVAL || '5000'),
- maxReconnectAttempts: parseInt(process.env.ASTER_WS_MAX_RECONNECT_ATTEMPTS || '10'),
- },
- http: {
- baseUrl: process.env.ASTER_HTTP_BASE || 'https://fapi.asterdex.com',
- },
- auth: {
- user: process.env.ASTER_ORDER_USER!,
- signer: process.env.ASTER_ORDER_SIGNER!,
- privateKey: process.env.PRIVATE_KEY!,
- },
- subscribe: {
- symbols: (process.env.ASTER_SUBSCRIBE_SYMBOLS || 'BTCUSDT,ETHUSDT').split(',').map(s => s.trim()),
- },
- log: {
- level: process.env.LOG_LEVEL || 'info',
- },
- }
- }
- /**
- * 转换为 AsterWsConfig
- */
- export function toAsterWsConfig(config: AsterConfig): AsterWsConfig {
- return {
- wsUrl: config.ws.url,
- pingIntervalMs: config.ws.pingInterval,
- pongTimeoutMs: config.ws.pongTimeout,
- autoReconnect: true,
- reconnectIntervalMs: config.ws.reconnectInterval,
- }
- }
- /**
- * 转换为 AsterAuthConfig
- */
- export function toAsterAuthConfig(config: AsterConfig): AsterAuthConfig {
- return {
- type: 'signer',
- user: config.auth.user,
- signer: config.auth.signer,
- privateKey: config.auth.privateKey,
- loginMethod: 'login',
- }
- }
|