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