enhancedHedgingExecutor.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. import { EventEmitter } from 'events'
  2. import { logger } from '../../utils/logger.js'
  3. import { BasisManager, basisManager } from './basisManager.js'
  4. import { PriceConvergenceManager, priceConvergenceManager } from './priceConvergenceManager.js'
  5. import { StopLossManager, stopLossManager } from './stopLossManager.js'
  6. import { ConvergenceAlgorithm, convergenceAlgorithm } from './convergenceAlgorithm.js'
  7. import { SamePlatformHedgingManager } from './SamePlatformHedgingManager.js'
  8. import { PacificaProxyClient } from '../../exchanges/pacifica/PacificaProxyClient.js'
  9. /**
  10. * 增强型对冲执行器 - 集成基差管理、价格收敛、止盈止损等功能
  11. */
  12. export class EnhancedHedgingExecutor extends EventEmitter {
  13. private basisManager: BasisManager
  14. private convergenceManager: PriceConvergenceManager
  15. private stopLossManager: StopLossManager
  16. private convergenceAlgorithm: ConvergenceAlgorithm
  17. private platformManager: SamePlatformHedgingManager
  18. private clients: Map<string, PacificaProxyClient> = new Map()
  19. private config: EnhancedHedgingConfig
  20. private isActive: boolean = false
  21. private executionInterval?: NodeJS.Timeout
  22. private performanceMetrics: PerformanceMetrics = {
  23. totalTrades: 0,
  24. successfulTrades: 0,
  25. failedTrades: 0,
  26. totalPnl: 0,
  27. totalFees: 0,
  28. averageConvergenceTime: 0,
  29. basisRiskEvents: 0,
  30. stopLossTriggered: 0,
  31. takeProfitTriggered: 0,
  32. maxDrawdown: 0,
  33. sharpeRatio: 0,
  34. startTime: Date.now(),
  35. }
  36. constructor(config?: Partial<EnhancedHedgingConfig>) {
  37. super()
  38. this.config = {
  39. executionIntervalMs: config?.executionIntervalMs || 5000, // 5秒执行间隔
  40. enableBasisManagement: config?.enableBasisManagement ?? true,
  41. enableConvergenceManagement: config?.enableConvergenceManagement ?? true,
  42. enableStopLossManagement: config?.enableStopLossManagement ?? true,
  43. enablePerformanceTracking: config?.enablePerformanceTracking ?? true,
  44. maxDailyTrades: config?.maxDailyTrades || 100,
  45. maxConcurrentPairs: config?.maxConcurrentPairs || 10,
  46. emergencyStopThreshold: config?.emergencyStopThreshold || -0.05, // -5% 紧急停止
  47. riskLimits: {
  48. maxPositionSize: config?.riskLimits?.maxPositionSize || 1.0,
  49. maxTotalExposure: config?.riskLimits?.maxTotalExposure || 5.0,
  50. maxDailyLoss: config?.riskLimits?.maxDailyLoss || 1000,
  51. maxBasisDeviation: config?.riskLimits?.maxBasisDeviation || 200,
  52. ...config?.riskLimits,
  53. },
  54. notifications: {
  55. enableSlack: config?.notifications?.enableSlack || false,
  56. enableEmail: config?.notifications?.enableEmail || false,
  57. enableWebhook: config?.notifications?.enableWebhook || false,
  58. ...config?.notifications,
  59. },
  60. }
  61. // 初始化各个管理器
  62. this.basisManager = config?.basisManager || basisManager
  63. this.convergenceManager = config?.convergenceManager || priceConvergenceManager
  64. this.stopLossManager = config?.stopLossManager || stopLossManager
  65. this.convergenceAlgorithm = config?.convergenceAlgorithm || convergenceAlgorithm
  66. this.platformManager = new SamePlatformHedgingManager('pacifica', this.config.riskLimits)
  67. this.setupEventListeners()
  68. }
  69. /**
  70. * 设置事件监听器
  71. */
  72. private setupEventListeners(): void {
  73. // 基差管理事件
  74. this.basisManager.on('basisAlert', alert => {
  75. this.handleBasisAlert(alert)
  76. })
  77. // 收敛管理事件
  78. this.convergenceManager.on('convergenceTradeExecuted', event => {
  79. this.handleConvergenceTradeExecuted(event)
  80. })
  81. // 止损管理事件
  82. this.stopLossManager.on('stopTriggered', event => {
  83. this.handleStopTriggered(event)
  84. })
  85. // 平台管理事件
  86. this.platformManager.on('rebalanceCompleted', event => {
  87. this.handleRebalanceCompleted(event)
  88. })
  89. }
  90. /**
  91. * 添加交易对管理
  92. */
  93. async addTradingPair(
  94. pairId: string,
  95. account1Config: AccountConfig,
  96. account2Config: AccountConfig,
  97. symbol: string,
  98. options?: PairOptions,
  99. ): Promise<void> {
  100. try {
  101. // 创建交易客户端
  102. const client1 = new PacificaProxyClient({
  103. account: account1Config.account,
  104. privateKey: account1Config.privateKey,
  105. agentWallet: account1Config.agentWallet,
  106. agentPrivateKey: account1Config.agentPrivateKey,
  107. })
  108. const client2 = new PacificaProxyClient({
  109. account: account2Config.account,
  110. privateKey: account2Config.privateKey,
  111. agentWallet: account2Config.agentWallet,
  112. agentPrivateKey: account2Config.agentPrivateKey,
  113. })
  114. this.clients.set(account1Config.account, client1)
  115. this.clients.set(account2Config.account, client2)
  116. // 添加到各个管理器
  117. if (this.config.enableConvergenceManagement) {
  118. this.convergenceManager.addAccountPair(pairId, account1Config, account2Config, symbol)
  119. }
  120. if (this.config.enableStopLossManagement) {
  121. this.stopLossManager.registerClient(account1Config.account, client1)
  122. this.stopLossManager.registerClient(account2Config.account, client2)
  123. }
  124. // 添加到平台管理器
  125. this.platformManager.addAccount(account1Config.account, account1Config)
  126. this.platformManager.addAccount(account2Config.account, account2Config)
  127. this.platformManager.createHedgePair(pairId, account1Config.account, account2Config.account, symbol)
  128. logger.info('添加交易对成功', {
  129. pairId,
  130. account1: account1Config.account,
  131. account2: account2Config.account,
  132. symbol,
  133. options,
  134. })
  135. this.emit('tradingPairAdded', {
  136. pairId,
  137. account1: account1Config.account,
  138. account2: account2Config.account,
  139. symbol,
  140. })
  141. } catch (error: any) {
  142. logger.error('添加交易对失败', {
  143. pairId,
  144. error: error.message,
  145. })
  146. throw error
  147. }
  148. }
  149. /**
  150. * 开始增强对冲执行
  151. */
  152. async startEnhancedHedging(): Promise<void> {
  153. if (this.isActive) return
  154. this.isActive = true
  155. // 启动各个管理器
  156. if (this.config.enableBasisManagement) {
  157. this.basisManager.startMonitoring()
  158. }
  159. if (this.config.enableConvergenceManagement) {
  160. this.convergenceManager.startConvergenceMonitoring()
  161. }
  162. if (this.config.enableStopLossManagement) {
  163. this.stopLossManager.startMonitoring()
  164. }
  165. // 启动主执行循环
  166. this.executionInterval = setInterval(() => {
  167. this.performEnhancedExecution()
  168. }, this.config.executionIntervalMs)
  169. logger.info('增强对冲执行已启动', {
  170. enableBasisManagement: this.config.enableBasisManagement,
  171. enableConvergenceManagement: this.config.enableConvergenceManagement,
  172. enableStopLossManagement: this.config.enableStopLossManagement,
  173. executionInterval: this.config.executionIntervalMs,
  174. })
  175. this.emit('enhancedHedgingStarted')
  176. }
  177. /**
  178. * 停止增强对冲执行
  179. */
  180. async stopEnhancedHedging(): Promise<void> {
  181. if (!this.isActive) return
  182. this.isActive = false
  183. // 停止各个管理器
  184. this.basisManager.stopMonitoring()
  185. this.convergenceManager.stopConvergenceMonitoring()
  186. this.stopLossManager.stopMonitoring()
  187. // 停止主执行循环
  188. if (this.executionInterval) {
  189. clearInterval(this.executionInterval)
  190. this.executionInterval = undefined
  191. }
  192. logger.info('增强对冲执行已停止')
  193. this.emit('enhancedHedgingStopped')
  194. }
  195. /**
  196. * 执行增强对冲逻辑
  197. */
  198. private async performEnhancedExecution(): Promise<void> {
  199. try {
  200. // 检查紧急停止条件
  201. if (await this.checkEmergencyStop()) {
  202. await this.triggerEmergencyStop()
  203. return
  204. }
  205. // 更新基差数据
  206. if (this.config.enableBasisManagement) {
  207. await this.updateBasisData()
  208. }
  209. // 执行收敛检查和调整
  210. if (this.config.enableConvergenceManagement) {
  211. await this.performConvergenceExecution()
  212. }
  213. // 更新性能指标
  214. if (this.config.enablePerformanceTracking) {
  215. await this.updatePerformanceMetrics()
  216. }
  217. } catch (error: any) {
  218. logger.error('增强对冲执行失败', {
  219. error: error.message,
  220. })
  221. }
  222. }
  223. /**
  224. * 检查紧急停止条件
  225. */
  226. private async checkEmergencyStop(): Promise<boolean> {
  227. try {
  228. const dailyPnl = await this.calculateDailyPnl()
  229. const totalDrawdown = await this.calculateCurrentDrawdown()
  230. // 检查日亏损限制
  231. if (dailyPnl < -this.config.riskLimits.maxDailyLoss) {
  232. logger.warn('触发日亏损限制', {
  233. dailyPnl,
  234. maxDailyLoss: this.config.riskLimits.maxDailyLoss,
  235. })
  236. return true
  237. }
  238. // 检查回撤限制
  239. if (totalDrawdown < this.config.emergencyStopThreshold) {
  240. logger.warn('触发紧急停止阈值', {
  241. totalDrawdown,
  242. emergencyStopThreshold: this.config.emergencyStopThreshold,
  243. })
  244. return true
  245. }
  246. return false
  247. } catch (error: any) {
  248. logger.error('检查紧急停止条件失败', {
  249. error: error.message,
  250. })
  251. return false
  252. }
  253. }
  254. /**
  255. * 触发紧急停止
  256. */
  257. private async triggerEmergencyStop(): Promise<void> {
  258. logger.warn('触发紧急停止,开始平仓所有仓位')
  259. try {
  260. // 停止所有自动化执行
  261. await this.stopEnhancedHedging()
  262. // 平仓所有仓位
  263. for (const [account, client] of this.clients) {
  264. try {
  265. const positions = await client.getPositions()
  266. for (const position of positions) {
  267. if (Math.abs(parseFloat(position.size || '0')) > 0.001) {
  268. await this.emergencyClosePosition(account, position)
  269. }
  270. }
  271. } catch (error: any) {
  272. logger.error('紧急平仓失败', {
  273. account,
  274. error: error.message,
  275. })
  276. }
  277. }
  278. this.emit('emergencyStopTriggered', {
  279. reason: 'risk_limit_exceeded',
  280. timestamp: Date.now(),
  281. })
  282. // 发送通知
  283. await this.sendEmergencyNotification()
  284. } catch (error: any) {
  285. logger.error('紧急停止执行失败', {
  286. error: error.message,
  287. })
  288. }
  289. }
  290. /**
  291. * 紧急平仓
  292. */
  293. private async emergencyClosePosition(account: string, position: any): Promise<void> {
  294. const client = this.clients.get(account)
  295. if (!client) return
  296. try {
  297. const size = Math.abs(parseFloat(position.size || '0'))
  298. const isLong = parseFloat(position.size || '0') > 0
  299. const side = isLong ? 'ask' : 'bid'
  300. const payload = {
  301. account,
  302. symbol: position.symbol,
  303. amount: size.toString(),
  304. side,
  305. reduceOnly: true,
  306. slippagePercent: '2.0', // 紧急情况允许更大滑点
  307. }
  308. const result = await client.createMarketOrder(payload)
  309. logger.info('紧急平仓执行成功', {
  310. account,
  311. symbol: position.symbol,
  312. size,
  313. side,
  314. orderId: result.orderId,
  315. })
  316. } catch (error: any) {
  317. logger.error('紧急平仓执行失败', {
  318. account,
  319. position: position.symbol,
  320. error: error.message,
  321. })
  322. }
  323. }
  324. /**
  325. * 更新基差数据
  326. */
  327. private async updateBasisData(): Promise<void> {
  328. try {
  329. // 获取所有交易对的现货和期货价格
  330. const symbols = this.getMonitoredSymbols()
  331. for (const symbol of symbols) {
  332. const marketData = await this.getMarketData(symbol)
  333. if (marketData) {
  334. // 假设基差为期货价格 - 现货价格(这里简化处理)
  335. const spotPrice = marketData.price
  336. const futuresPrice = marketData.price * (1 + Math.random() * 0.002 - 0.001) // 模拟期货价格
  337. this.basisManager.updateBasis(symbol, spotPrice, futuresPrice)
  338. }
  339. }
  340. } catch (error: any) {
  341. logger.error('更新基差数据失败', {
  342. error: error.message,
  343. })
  344. }
  345. }
  346. /**
  347. * 执行收敛逻辑
  348. */
  349. private async performConvergenceExecution(): Promise<void> {
  350. try {
  351. const pairStatuses = this.convergenceManager.getAllAccountPairStatuses()
  352. for (const pairStatus of pairStatuses) {
  353. if (!pairStatus.account1Position || !pairStatus.account2Position) continue
  354. const marketData = await this.getMarketData(pairStatus.symbol)
  355. if (!marketData) continue
  356. // 使用收敛算法计算策略
  357. const strategy = this.convergenceAlgorithm.calculateConvergenceStrategy(
  358. this.convertToPositionInfo(pairStatus.account1Position, marketData),
  359. this.convertToPositionInfo(pairStatus.account2Position, marketData),
  360. marketData,
  361. )
  362. if (strategy.needsAdjustment && strategy.urgency === 'high') {
  363. await this.executeConvergenceStrategy(pairStatus.pairId, strategy)
  364. }
  365. }
  366. } catch (error: any) {
  367. logger.error('执行收敛逻辑失败', {
  368. error: error.message,
  369. })
  370. }
  371. }
  372. /**
  373. * 执行收敛策略
  374. */
  375. private async executeConvergenceStrategy(pairId: string, strategy: any): Promise<void> {
  376. try {
  377. logger.info('执行收敛策略', {
  378. pairId,
  379. strategy: strategy.strategy,
  380. confidence: strategy.confidence,
  381. reasoning: strategy.reasoning,
  382. })
  383. // 这里可以调用具体的交易执行逻辑
  384. // 暂时使用平台管理器的再平衡功能
  385. await this.platformManager.rebalanceHedgePair(pairId, 0.01)
  386. this.performanceMetrics.totalTrades++
  387. this.emit('convergenceStrategyExecuted', {
  388. pairId,
  389. strategy,
  390. timestamp: Date.now(),
  391. })
  392. } catch (error: any) {
  393. logger.error('执行收敛策略失败', {
  394. pairId,
  395. error: error.message,
  396. })
  397. this.performanceMetrics.failedTrades++
  398. }
  399. }
  400. /**
  401. * 处理基差预警
  402. */
  403. private async handleBasisAlert(alert: any): Promise<void> {
  404. logger.warn('基差预警', alert)
  405. this.performanceMetrics.basisRiskEvents++
  406. // 发送通知
  407. await this.sendNotification('basis_alert', {
  408. symbol: alert.symbol,
  409. riskLevel: alert.riskLevel,
  410. message: alert.message,
  411. })
  412. this.emit('basisRiskDetected', alert)
  413. }
  414. /**
  415. * 处理收敛交易执行
  416. */
  417. private async handleConvergenceTradeExecuted(event: any): Promise<void> {
  418. logger.info('收敛交易执行', event)
  419. this.performanceMetrics.successfulTrades++
  420. // 为新仓位设置止盈止损
  421. if (this.config.enableStopLossManagement) {
  422. await this.setStopLossForNewTrades(event)
  423. }
  424. }
  425. /**
  426. * 处理止损触发
  427. */
  428. private async handleStopTriggered(event: any): Promise<void> {
  429. logger.info('止损触发', event)
  430. if (event.execution.triggerType === 'stop_loss') {
  431. this.performanceMetrics.stopLossTriggered++
  432. } else if (event.execution.triggerType === 'take_profit') {
  433. this.performanceMetrics.takeProfitTriggered++
  434. }
  435. this.emit('stopLossTriggered', event)
  436. }
  437. /**
  438. * 处理再平衡完成
  439. */
  440. private async handleRebalanceCompleted(event: any): Promise<void> {
  441. logger.info('再平衡完成', event)
  442. this.emit('rebalanceCompleted', event)
  443. }
  444. /**
  445. * 为新交易设置止盈止损
  446. */
  447. private async setStopLossForNewTrades(event: any): Promise<void> {
  448. try {
  449. for (const result of event.results) {
  450. if (result.success && result.executedSize > 0) {
  451. await this.stopLossManager.setStopLossAndTakeProfit(
  452. result.account,
  453. event.tradeParams.symbol || 'BTC-USD',
  454. result.executedSize,
  455. result.executedPrice,
  456. result.side === 'bid', // 买入为多头
  457. )
  458. }
  459. }
  460. } catch (error: any) {
  461. logger.error('设置止盈止损失败', {
  462. error: error.message,
  463. })
  464. }
  465. }
  466. /**
  467. * 获取市场数据
  468. */
  469. private async getMarketData(symbol: string): Promise<any> {
  470. try {
  471. // 使用第一个可用的客户端获取市场数据
  472. const client = this.clients.values().next().value
  473. if (!client) return null
  474. const ticker = await client.getTicker(symbol)
  475. return {
  476. symbol,
  477. price: ticker?.price || 0,
  478. volume: ticker?.volume || 0,
  479. volatility: 0.02, // 模拟波动率
  480. trend: 'sideways',
  481. momentum: 0,
  482. }
  483. } catch (error: any) {
  484. logger.error('获取市场数据失败', {
  485. symbol,
  486. error: error.message,
  487. })
  488. return null
  489. }
  490. }
  491. /**
  492. * 转换为算法需要的仓位信息格式
  493. */
  494. private convertToPositionInfo(position: any, marketData: any): any {
  495. return {
  496. symbol: position.symbol,
  497. size: position.size,
  498. averagePrice: position.averagePrice || position.entryPrice,
  499. currentPrice: marketData.price,
  500. unrealizedPnl: position.unrealizedPnl,
  501. minOrderSize: 0.001,
  502. }
  503. }
  504. /**
  505. * 获取监控的交易对列表
  506. */
  507. private getMonitoredSymbols(): string[] {
  508. const pairStatuses = this.convergenceManager.getAllAccountPairStatuses()
  509. return pairStatuses.map(status => status.symbol)
  510. }
  511. /**
  512. * 计算日盈亏
  513. */
  514. private async calculateDailyPnl(): Promise<number> {
  515. let totalPnl = 0
  516. try {
  517. for (const [account, client] of this.clients) {
  518. const positions = await client.getPositions()
  519. for (const position of positions) {
  520. totalPnl += parseFloat(position.unrealizedPnl || '0')
  521. }
  522. }
  523. } catch (error: any) {
  524. logger.error('计算日盈亏失败', {
  525. error: error.message,
  526. })
  527. }
  528. return totalPnl
  529. }
  530. /**
  531. * 计算当前回撤
  532. */
  533. private async calculateCurrentDrawdown(): Promise<number> {
  534. // 简化实现,实际应该基于历史净值计算
  535. const currentPnl = await this.calculateDailyPnl()
  536. return Math.min(0, currentPnl / 10000) // 假设初始资金10000
  537. }
  538. /**
  539. * 更新性能指标
  540. */
  541. private async updatePerformanceMetrics(): Promise<void> {
  542. try {
  543. const currentPnl = await this.calculateDailyPnl()
  544. this.performanceMetrics.totalPnl = currentPnl
  545. const drawdown = await this.calculateCurrentDrawdown()
  546. this.performanceMetrics.maxDrawdown = Math.min(this.performanceMetrics.maxDrawdown, drawdown)
  547. // 计算成功率
  548. if (this.performanceMetrics.totalTrades > 0) {
  549. const successRate = this.performanceMetrics.successfulTrades / this.performanceMetrics.totalTrades
  550. logger.debug('性能指标更新', {
  551. totalTrades: this.performanceMetrics.totalTrades,
  552. successRate: successRate.toFixed(3),
  553. totalPnl: this.performanceMetrics.totalPnl.toFixed(2),
  554. maxDrawdown: this.performanceMetrics.maxDrawdown.toFixed(3),
  555. })
  556. }
  557. } catch (error: any) {
  558. logger.error('更新性能指标失败', {
  559. error: error.message,
  560. })
  561. }
  562. }
  563. /**
  564. * 发送通知
  565. */
  566. private async sendNotification(type: string, data: any): Promise<void> {
  567. try {
  568. if (this.config.notifications.enableWebhook) {
  569. // 发送 Webhook 通知
  570. logger.info('发送通知', { type, data })
  571. }
  572. this.emit('notification', { type, data, timestamp: Date.now() })
  573. } catch (error: any) {
  574. logger.error('发送通知失败', {
  575. error: error.message,
  576. })
  577. }
  578. }
  579. /**
  580. * 发送紧急通知
  581. */
  582. private async sendEmergencyNotification(): Promise<void> {
  583. await this.sendNotification('emergency_stop', {
  584. message: '系统触发紧急停止',
  585. performanceMetrics: this.performanceMetrics,
  586. })
  587. }
  588. /**
  589. * 获取性能指标
  590. */
  591. getPerformanceMetrics(): PerformanceMetrics {
  592. return { ...this.performanceMetrics }
  593. }
  594. /**
  595. * 获取运行状态
  596. */
  597. getStatus(): HedgingExecutorStatus {
  598. return {
  599. isActive: this.isActive,
  600. activePairs: this.convergenceManager.getAllAccountPairStatuses().length,
  601. activeStopOrders: this.stopLossManager.getActiveStopOrders().length,
  602. performanceMetrics: this.performanceMetrics,
  603. config: this.config,
  604. }
  605. }
  606. }
  607. // 类型定义
  608. export interface AccountConfig {
  609. account: string
  610. privateKey: string
  611. agentWallet?: string
  612. agentPrivateKey?: string
  613. }
  614. export interface PairOptions {
  615. maxPositionSize?: number
  616. stopLossPercent?: number
  617. takeProfitPercent?: number
  618. enableTrailingStop?: boolean
  619. }
  620. export interface EnhancedHedgingConfig {
  621. executionIntervalMs: number
  622. enableBasisManagement: boolean
  623. enableConvergenceManagement: boolean
  624. enableStopLossManagement: boolean
  625. enablePerformanceTracking: boolean
  626. maxDailyTrades: number
  627. maxConcurrentPairs: number
  628. emergencyStopThreshold: number
  629. riskLimits: {
  630. maxPositionSize: number
  631. maxTotalExposure: number
  632. maxDailyLoss: number
  633. maxBasisDeviation: number
  634. }
  635. notifications: {
  636. enableSlack: boolean
  637. enableEmail: boolean
  638. enableWebhook: boolean
  639. }
  640. basisManager?: BasisManager
  641. convergenceManager?: PriceConvergenceManager
  642. stopLossManager?: StopLossManager
  643. convergenceAlgorithm?: ConvergenceAlgorithm
  644. }
  645. export interface PerformanceMetrics {
  646. totalTrades: number
  647. successfulTrades: number
  648. failedTrades: number
  649. totalPnl: number
  650. totalFees: number
  651. averageConvergenceTime: number
  652. basisRiskEvents: number
  653. stopLossTriggered: number
  654. takeProfitTriggered: number
  655. maxDrawdown: number
  656. sharpeRatio: number
  657. startTime: number
  658. }
  659. export interface HedgingExecutorStatus {
  660. isActive: boolean
  661. activePairs: number
  662. activeStopOrders: number
  663. performanceMetrics: PerformanceMetrics
  664. config: EnhancedHedgingConfig
  665. }
  666. export const enhancedHedgingExecutor = new EnhancedHedgingExecutor()