Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 11, 2025

Summary

Implements a timer-based subscription restart mechanism to address issue #183 where trades subscription was broken after 17 days of uptime.

Changes Made

  • Added SubscriptionTimeoutInterval constant set to 5 minutes
  • Added tracking fields for last data received time: LastTradesDataTicks and LastMarketDataTicks
  • Implemented timeout monitoring methods: CheckTradesTimeout and CheckMarketDataTimeout
  • Updated both subscription loops (ReceiveTradesLoop and SendOrdersLoop) to:
    • Run subscription tasks concurrently with timeout monitoring
    • Automatically restart subscriptions when no data is received within the timeout period
    • Log warnings when timeouts are detected for debugging purposes
  • Fixed existing Task.Delay calls to properly handle cancellation tokens

Technical Details

  • Each subscription stream now updates its respective timestamp when data is received
  • Timeout monitoring runs every 30 seconds and checks if data hasn't been received for over 5 minutes
  • When a timeout is detected, the subscription is cancelled and automatically restarted
  • The mechanism is transparent to the trading logic and maintains all existing functionality

Test Plan

  • Code compiles successfully with no errors
  • Existing warnings remain unchanged (all pre-existing)
  • CI build workflow validates the changes
  • Manual testing with subscription timeout simulation (recommended for production deployment)

This fix ensures the trader bot maintains reliable data streams and automatically recovers from silent subscription failures that previously required manual restarts.

🤖 Generated with Claude Code


Resolves #183

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #183
@konard konard self-assigned this Sep 11, 2025
konard and others added 2 commits September 11, 2025 13:18
- Add SubscriptionTimeoutInterval (5 minutes) to detect silent subscription failures
- Track LastTradesDataTicks and LastMarketDataTicks for both subscription streams
- Implement CheckTradesTimeout and CheckMarketDataTimeout methods to monitor data flow
- Update ReceiveTradesLoop and SendOrdersLoop to restart subscriptions when no data received
- Fix existing Task.Delay calls to properly handle cancellation tokens

Fixes issue where trades subscription was broken after 17 days of uptime.
The bot now proactively restarts subscriptions if no data is received within the timeout period.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Trader: add a timer to restart subscriptions if no data is received for a period of time Trader: add timer to restart subscriptions if no data received Sep 11, 2025
@konard konard marked this pull request as ready for review September 11, 2025 10:24
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.

Trader: add a timer to restart subscriptions if no data is received for a period of time

2 participants