Add connection monitor to automatically release held trades on reconnect#786
Merged
dantelrharrell-debug merged 2 commits intomainfrom Feb 21, 2026
Merged
Conversation
|
🚅 Deployed to the Nija-pr-786 environment in patient-compassion
|
Co-authored-by: dantelrharrell-debug <232652186+dantelrharrell-debug@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix execution issues for held trades
Add connection monitor to automatically release held trades on reconnect
Feb 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Trading threads were only started once at boot. If the platform account wasn't connected, user API keys were invalid, or accounts were unfunded at startup, those accounts never traded — with no retry path.
Changes
bot/independent_broker_trader.pystart_connection_monitor()/stop_connection_monitor()— starts/stops a daemon thread (NijaConnectionMonitor) automatically called at the end ofstart_independent_trading()and the start ofstop_all_trading()_connection_monitor_loop()— runs every 5 min (configurable viaNIJA_CONNECTION_RETRY_INTERVAL); invokes both retry helpers_retry_platform_connections()— for each platform broker without a running thread: callsbroker.connect(), checks funding, then starts the trading thread_retry_user_connections()— callsconnect_users_from_config()(clears failure cache for fixed credentials), then starts threads for newly-connected + funded user accounts_start_platform_thread()/_start_user_thread()— extracted thread-creation logic shared by initial startup and the monitor; guarded by the existingactive_trading_threadssingleton set to prevent duplicates_get_broker_balance()— deduplicates the Coinbase-specific zero-balance retry logic previously scattered across two methodsOnce a trading thread starts, the existing
adopt_existing_positions()call inrun_user_broker_trading_loop()(runs every 2.5-min cycle) picks up any open positions and immediately attaches stop-loss, profit targets, and trailing stops — releasing held trades without manual intervention.🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.