Skip to main content

System Architecture: Project Structure

This document provides an overview of the BinaryOptionsTools project structure.

Repository Layoutโ€‹

BinaryOptionsTools-v2/
โ”œโ”€โ”€ crates/
โ”‚ โ”œโ”€โ”€ binary_options_tools/ # Core Rust crate (PocketOption integration)
โ”‚ โ”œโ”€โ”€ core/ # Core framework (client, runner, router, modules)
โ”‚ โ”œโ”€โ”€ bindings_uniffi/ # UniFFI bindings for multi-language support
โ”‚ โ”œโ”€โ”€ bindings_pyo3/ # PyO3 Python bindings
โ”‚ โ””โ”€โ”€ macros/ # Procedural macros for rule system
โ”œโ”€โ”€ python/
โ”‚ โ””โ”€โ”€ BinaryOptionsToolsV2/ # Python package
โ”œโ”€โ”€ examples/
โ”‚ โ”œโ”€โ”€ python/ # Python examples (async & sync)
โ”‚ โ”œโ”€โ”€ rust/ # Rust examples
โ”‚ โ”œโ”€โ”€ javascript/ # JavaScript/TypeScript examples
โ”‚ โ”œโ”€โ”€ swift/ # Swift examples
โ”‚ โ”œโ”€โ”€ kotlin/ # Kotlin examples
โ”‚ โ”œโ”€โ”€ go/ # Go examples
โ”‚ โ”œโ”€โ”€ ruby/ # Ruby examples
โ”‚ โ””โ”€โ”€ csharp/ # C# examples
โ”œโ”€โ”€ docs/ # Documentation (Docusaurus)
โ”œโ”€โ”€ tests/ # Integration tests
โ”œโ”€โ”€ .github/github/github/workflows/ # CI/CD pipelines
โ””โ”€โ”€ Cargo.toml # Rust workspace root

Crate Detailsโ€‹

crates/binary_options_toolsโ€‹

Main PocketOption integration crate.

src/
โ”œโ”€โ”€ lib.rs # Main exports
โ”œโ”€โ”€ error.rs # Error types
โ”œโ”€โ”€ pocket_client.rs # PocketOption client implementation
โ”œโ”€โ”€ candle.rs # Candle compilation logic
โ”œโ”€โ”€ types.rs # Shared types
โ”œโ”€โ”€ utils.rs # Utility functions
โ”œโ”€โ”€ state.rs # Connection state
โ”œโ”€โ”€ ssid.rs # SSID handling
โ”œโ”€โ”€ connect.rs # Connection logic
โ””โ”€โ”€ modules/
โ”œโ”€โ”€ mod.rs # Module exports
โ”œโ”€โ”€ subscriptions.rs # Real-time subscriptions
โ”œโ”€โ”€ trades.rs # Trade management
โ”œโ”€โ”€ deals.rs # Deal history
โ”œโ”€โ”€ get_candles.rs # Historical candles
โ”œโ”€โ”€ historical_data.rs # Historical data module
โ”œโ”€โ”€ pending_trades.rs # Pending orders
โ”œโ”€โ”€ raw.rs # Raw message handler
โ”œโ”€โ”€ balance.rs # Balance module
โ”œโ”€โ”€ assets.rs # Assets module
โ”œโ”€โ”€ server_time.rs # Server time
โ””โ”€โ”€ keep_alive.rs # Keep-alive module

crates/coreโ€‹

Core framework for building trading clients.

src/
โ”œโ”€โ”€ lib.rs # Main exports
โ”œโ”€โ”€ builder.rs # ClientBuilder for module registration
โ”œโ”€โ”€ client.rs # Client and Runner implementation
โ”œโ”€โ”€ router.rs # Message routing
โ”œโ”€โ”€ middleware.rs # Middleware stack
โ”œโ”€โ”€ traits.rs # Core traits (ApiModule, LightweightModule, etc.)
โ”œโ”€โ”€ message.rs # Message types
โ”œโ”€โ”€ statistics.rs # Statistics tracking
โ”œโ”€โ”€ rules.rs # Rule system
โ”œโ”€โ”€ signals.rs # Signal handling
โ””โ”€โ”€ utils/
โ””โ”€โ”€ stream.rs # Stream utilities

crates/bindings_uniffiโ€‹

UniFFI bindings for generating multi-language APIs.

src/
โ”œโ”€โ”€ lib.rs # Main exports
โ”œโ”€โ”€ error.rs # Error mapping
โ”œโ”€โ”€ tracing.rs # Tracing initialization
โ”œโ”€โ”€ utils.rs # Utility functions
โ”œโ”€โ”€ test.rs # Test utilities
โ””โ”€โ”€ platforms/pocketoption/
โ”œโ”€โ”€ mod.rs # Platform exports
โ”œโ”€โ”€ client.rs # PocketOption client wrapper
โ”œโ”€โ”€ validator.rs # Validator wrapper
โ”œโ”€โ”€ raw_handler.rs # Raw handler wrapper
โ”œโ”€โ”€ stream.rs # Stream wrapper
โ””โ”€โ”€ types.rs # Type conversions

crates/bindings_pyo3โ€‹

PyO3 Python bindings for native Python performance.

src/
โ”œโ”€โ”€ lib.rs # Python module entry
โ”œโ”€โ”€ pocketoption.rs # PocketOption Python class
โ”œโ”€โ”€ framework.rs # PyStrategy framework
โ”œโ”€โ”€ validator.rs # Validator Python class
โ”œโ”€โ”€ error.rs # Error mapping
โ””โ”€โ”€ logs.rs # Logging setup

crates/macrosโ€‹

Procedural macros for the rule system.

src/
โ”œโ”€โ”€ lib.rs # Macro exports
โ”œโ”€โ”€ region.rs # Region macro
โ””โ”€โ”€ doc.rs # Documentation macro

Module Architectureโ€‹

ApiModuleโ€‹

Full-featured module with commands, responses, and a Handle.

UserCode --> Handle --> CommandReceiver --> Module.run()
^ |
| v
CommandResponder <-- Response <--+

LightweightModuleโ€‹

Background task receiving routed WS messages, no command/response.

Router -- rule --> WS Msg Receiver --> Module.run()

Lightweight Handlerโ€‹

Global stateless callback receiving every WS message.

Router -- every msg --> Handler.callback()

Data Flowโ€‹

WebSocket --> Connector --> Runner --> Middleware (inbound) --> Router
|
+---------------------+---------------------+
| | |
LW Handlers LW Modules ApiModules
| | |
v v v
Callbacks Background Commands + Responses
Task

See Data Flow for detailed diagrams.

Build Systemโ€‹

  • Rust: Cargo workspace with multiple crates
  • Python: PyO3 + maturin for native bindings
  • UniFFI: Generates bindings for Kotlin, Swift, Go, Ruby, C#
  • JavaScript: wasm-bindgen or napi-rs for Node.js native module

Testingโ€‹

  • Unit tests in each crate (#[cfg(test)])
  • Integration tests in tests/ directory
  • Python tests in tests/python/
  • Examples serve as functional tests