Skip to content

Conversation

@TaprootFreak
Copy link
Collaborator

Summary

  • Adds real-time order completion detection via CCXT Pro WebSockets for Kraken, Binance, MEXC, and XT exchanges
  • Implements event-driven pipeline continuation to eliminate polling delays
  • Adds atomic database operations to prevent race conditions between event handlers and cron jobs

Changes

New Files

  • ExchangeWebSocketService: Manages WebSocket connections to exchanges for real-time order updates
  • OrderCompletionService: Centralized order completion handling with WebSocket + polling fallback

Modified Files

  • LiquidityManagementPipelineService: Subscribes to order completion events for immediate pipeline continuation
  • LiquidityManagementOrderRepository: Atomic tryClaimForExecution and saveExecutionResult methods
  • LiquidityManagementPipelineRepository: Atomic tryContinuePipeline with pessimistic locking

Performance Improvement

Metric Before After
Delay after order completion up to 60s ~0ms (WebSocket) / ~5s (polling)
Cron frequency (fallback) 1 min 5 min

Architecture

Order completes on Exchange
         │
         ▼
WebSocket Event (CCXT Pro)
         │
         ▼
OrderCompletionService detects completion
         │
         ▼
Event emitted via RxJS Subject
         │
         ▼
PipelineService continues immediately
         │
    (Fallback: 5s polling + 5min cron)

Test plan

  • Verify WebSocket connections initialize correctly for configured exchanges
  • Test order completion detection via WebSocket for BUY orders
  • Test order completion detection via WebSocket for SELL orders
  • Verify polling fallback works when WebSocket is unavailable
  • Test race condition protection (concurrent event + cron)
  • Verify graceful shutdown closes all WebSocket connections

…ring

- Add ExchangeWebSocketService for real-time order updates via CCXT Pro
  - Supports Kraken, Binance, MEXC, XT exchanges
  - Automatic connection management and cleanup

- Add OrderCompletionService for centralized order completion handling
  - WebSocket primary with 5-second polling fallback
  - 5-minute cron as safety net
  - RxJS event stream for immediate pipeline continuation

- Update LiquidityManagementPipelineService
  - Subscribe to order completion events
  - Immediate pipeline continuation on order completion
  - Atomic pipeline transitions with pessimistic locks

- Add atomic repository methods
  - tryClaimForExecution: Prevents duplicate order execution
  - tryContinuePipeline: Race-condition-safe pipeline continuation
  - saveExecutionResult: Persists all execution fields for WebSocket

Performance improvement:
- Before: Up to 60s delay between order completion and next order
- After: Near-instant continuation (~0ms with WebSocket, ~5s with polling)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants