Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 1, 2025

This PR adds a graceful close connection function to the BinaryOptionsTools-v2 WebSocket client, addressing the need for proper connection management.

Changes Made

Core WebSocket Client (crates/core/src/general/client.rs)

  • Added shutdown_sender: Sender<()> field to WebSocketInnerClient for signaling shutdown
  • Modified event loop to check for shutdown signals and send WebSocket close frames
  • Added close() method that gracefully terminates the connection:
    pub async fn close(&self) -> BinaryOptionsResult<()>

PocketOption Client (crates/binary_options_tools/src/pocketoption/pocket_client.rs)

  • Added public close() method that delegates to the underlying WebSocket client
  • Comprehensive documentation with usage examples
  • Basic test coverage to verify functionality

Usage

Users can now gracefully close connections:

let client = PocketOption::new("your-ssid").await?;
// ... perform trading operations ...
client.close().await?; // Gracefully close the connection

Implementation Details

  • Graceful shutdown: Sends proper WebSocket close frame to remote peer
  • Clean termination: Signals event loop to stop processing without abrupt disconnection
  • Non-breaking: All existing functionality remains intact
  • Thread-safe: Uses async channels for safe cross-task communication

The implementation follows the existing patterns in the codebase and maintains backward compatibility while adding the requested close connection capability.

Fixes #16.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • demo-api-eu.po.market
    • Triggering command: /home/REDACTED/work/BinaryOptionsTools-v2/BinaryOptionsTools-v2/target/debug/deps/binary_options_tools-bf0e6b2adb8abbb6 test_close_connection (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@theshadow76
Copy link
Contributor

Nothing changed

@theshadow76 theshadow76 marked this pull request as ready for review July 1, 2025 20:41
@theshadow76 theshadow76 merged commit ca2e94f into master Jul 1, 2025
5 of 20 checks passed
Copilot AI changed the title [WIP] add close connection Add close connection functionality to WebSocket client Jul 1, 2025
Copilot AI requested a review from theshadow76 July 1, 2025 20:52
Copilot finished work on behalf of theshadow76 July 1, 2025 20:52
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.

add close connection

2 participants