binaryoptionstoolsv2 0.2.8__cp313-cp313-win32.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,155 @@
1
+ from typing import Any, Callable, List, Optional
2
+
3
+ class PyConfig:
4
+ def __init__(
5
+ self,
6
+ max_allowed_loops: int = 10,
7
+ sleep_interval: int = 100,
8
+ reconnect_time: int = 5,
9
+ connection_initialization_timeout: float = 30.0,
10
+ timeout: float = 10.0,
11
+ urls: List[str] = [],
12
+ ) -> None: ...
13
+
14
+ class RawValidator:
15
+ @staticmethod
16
+ def new() -> "RawValidator": ...
17
+ @staticmethod
18
+ def regex(pattern: str) -> "RawValidator": ...
19
+ @staticmethod
20
+ def contains(pattern: str) -> "RawValidator": ...
21
+ @staticmethod
22
+ def starts_with(pattern: str) -> "RawValidator": ...
23
+ @staticmethod
24
+ def ends_with(pattern: str) -> "RawValidator": ...
25
+ @staticmethod
26
+ def ne(validator: "RawValidator") -> "RawValidator": ...
27
+ @staticmethod
28
+ def all(validators: List["RawValidator"]) -> "RawValidator": ...
29
+ @staticmethod
30
+ def any(validators: List["RawValidator"]) -> "RawValidator": ...
31
+ @staticmethod
32
+ def custom(func: Callable[[str], bool]) -> "RawValidator": ...
33
+ def check(self, msg: str) -> bool: ...
34
+
35
+ class StreamIterator:
36
+ def __aiter__(self) -> "StreamIterator": ...
37
+ def __anext__(self) -> str: ...
38
+ def __iter__(self) -> "StreamIterator": ...
39
+ def __next__(self) -> str: ...
40
+
41
+ class RawStreamIterator:
42
+ def __aiter__(self) -> "RawStreamIterator": ...
43
+ def __anext__(self) -> str: ...
44
+ def __iter__(self) -> "RawStreamIterator": ...
45
+ def __next__(self) -> str: ...
46
+
47
+ class RawHandler:
48
+ def id(self) -> str: ...
49
+ async def send_text(self, text: str) -> None: ...
50
+ async def send_binary(self, data: bytes) -> None: ...
51
+ async def send_and_wait(self, message: str) -> str: ...
52
+ async def wait_next(self) -> str: ...
53
+ async def subscribe(self) -> RawStreamIterator: ...
54
+
55
+ class RawHandle:
56
+ async def create(self, validator: RawValidator, keep_alive_message: Optional[str]) -> RawHandler: ...
57
+ async def remove(self, id: str) -> bool: ...
58
+
59
+ class RawPocketOption:
60
+ def __init__(self, ssid: str) -> None: ...
61
+ @staticmethod
62
+ async def create(ssid: str) -> "RawPocketOption": ...
63
+ @staticmethod
64
+ def new_with_url(ssid: str, url: str) -> "RawPocketOption": ...
65
+ @staticmethod
66
+ async def create_with_url(ssid: str, url: str) -> "RawPocketOption": ...
67
+ @staticmethod
68
+ def new_with_config(ssid: str, config: PyConfig) -> "RawPocketOption": ...
69
+ @staticmethod
70
+ async def create_with_config(ssid: str, config: PyConfig) -> "RawPocketOption": ...
71
+ async def wait_for_assets(self, timeout_secs: float) -> None: ...
72
+ def is_demo(self) -> bool: ...
73
+ async def buy(self, asset: str, amount: float, time: int) -> List[str]: ...
74
+ async def sell(self, asset: str, amount: float, time: int) -> List[str]: ...
75
+ async def check_win(self, trade_id: str) -> str: ...
76
+ async def get_deal_end_time(self, trade_id: str) -> Optional[int]: ...
77
+ async def candles(self, asset: str, period: int) -> str: ...
78
+ async def get_candles(self, asset: str, period: int, offset: int) -> str: ...
79
+ async def get_candles_advanced(self, asset: str, period: int, offset: int, time: int) -> str: ...
80
+ async def balance(self) -> float: ...
81
+ async def open_pending_order(
82
+ self,
83
+ open_type: int,
84
+ amount: float,
85
+ asset: str,
86
+ open_time: int,
87
+ open_price: float,
88
+ timeframe: int,
89
+ min_payout: int,
90
+ command: int,
91
+ ) -> str: ...
92
+ async def closed_deals(self) -> str: ...
93
+ async def clear_closed_deals(self) -> None: ...
94
+ async def opened_deals(self) -> str: ...
95
+ async def payout(self) -> str: ...
96
+ async def history(self, asset: str, period: int) -> str: ...
97
+ async def compile_candles(self, asset: str, custom_period: int, lookback_period: int) -> str: ...
98
+ async def subscribe_symbol(self, symbol: str) -> StreamIterator: ...
99
+ async def subscribe_symbol_chuncked(self, symbol: str, chunck_size: int) -> StreamIterator: ...
100
+ async def subscribe_symbol_timed(self, symbol: str, time: Any) -> StreamIterator: ...
101
+ async def subscribe_symbol_time_aligned(self, symbol: str, time: Any) -> StreamIterator: ...
102
+ async def send_raw_message(self, message: str) -> None: ...
103
+ async def create_raw_order(self, message: str, validator: RawValidator) -> str: ...
104
+ async def create_raw_order_with_timeout(self, message: str, validator: RawValidator, timeout: Any) -> str: ...
105
+ async def create_raw_order_with_timeout_and_retry(
106
+ self, message: str, validator: RawValidator, timeout: Any
107
+ ) -> str: ...
108
+ async def create_raw_iterator(
109
+ self, message: str, validator: RawValidator, timeout: Optional[Any]
110
+ ) -> RawStreamIterator: ...
111
+ async def get_server_time(self) -> int: ...
112
+ async def disconnect(self) -> None: ...
113
+ async def connect(self) -> None: ...
114
+ async def reconnect(self) -> None: ...
115
+ async def unsubscribe(self, asset: str) -> None: ...
116
+ async def create_raw_handler(self, validator: RawValidator, keep_alive: Optional[str]) -> RawHandler: ...
117
+
118
+ class Logger:
119
+ def __init__(self) -> None: ...
120
+ def debug(self, message: str) -> None: ...
121
+ def info(self, message: str) -> None: ...
122
+ def warn(self, message: str) -> None: ...
123
+ def error(self, message: str) -> None: ...
124
+
125
+ class LogBuilder:
126
+ def __init__(self) -> None: ...
127
+ def create_logs_iterator(self, level: str, timeout: Optional[Any]) -> Any: ...
128
+ def log_file(self, path: str, level: str) -> None: ...
129
+ def terminal(self, level: str) -> None: ...
130
+ def build(self) -> None: ...
131
+
132
+ class StreamLogsLayer: ...
133
+ class StreamLogsIterator: ...
134
+
135
+ class PyContext:
136
+ async def buy(self, asset: str, amount: float, time: int) -> List[str]: ...
137
+ async def balance(self) -> float: ...
138
+
139
+ class PyVirtualMarket:
140
+ def __init__(self, initial_balance: float) -> None: ...
141
+ async def update_price(self, asset: str, price: float) -> None: ...
142
+
143
+ class PyStrategy:
144
+ def __init__(self) -> None: ...
145
+ def on_start(self, ctx: PyContext) -> None: ...
146
+ def on_candle(self, ctx: PyContext, asset: str, candle_json: str) -> None: ...
147
+
148
+ class PyBot:
149
+ def __init__(
150
+ self, client: RawPocketOption, strategy: PyStrategy, virtual_market: Optional[PyVirtualMarket] = None
151
+ ) -> None: ...
152
+ def add_asset(self, asset: str, period: int) -> None: ...
153
+ async def run(self) -> None: ...
154
+
155
+ def start_tracing(path: str, level: str, terminal: bool, layers: List[StreamLogsLayer]) -> None: ...
@@ -0,0 +1,54 @@
1
+ import importlib
2
+ import os
3
+ import sys
4
+
5
+ # Import the Rust module and re-export its attributes
6
+ try:
7
+ _rust_module = importlib.import_module(".BinaryOptionsToolsV2", __package__)
8
+ except (ImportError, ValueError):
9
+ try:
10
+ # Fallback for when it's not in the package
11
+ _rust_module = importlib.import_module("BinaryOptionsToolsV2")
12
+ # Ensure we didn't just import the package itself
13
+ if _rust_module is sys.modules.get(__package__):
14
+ _rust_module = None
15
+ except ImportError:
16
+ _rust_module = None
17
+
18
+ if _rust_module:
19
+ # Update globals with Rust module attributes
20
+ globals().update({k: v for k, v in _rust_module.__dict__.items() if not k.startswith("_")})
21
+ else:
22
+ # This is often okay during development/type checking, but bad for tests
23
+ if os.environ.get("PYTEST_CURRENT_TEST"):
24
+ print(f"[ERROR] Rust extension module 'BinaryOptionsToolsV2' not found! __package__={__package__}")
25
+ print(f"[DEBUG] sys.path: {sys.path}")
26
+
27
+ # Import submodules for re-export
28
+ from . import tracing as tracing # noqa: E402
29
+ from . import validator as validator # noqa: E402
30
+ from .pocketoption import * # noqa: F403, E402
31
+ from .pocketoption import __all__ as __pocket_all__ # noqa: E402
32
+
33
+ # Collect all core attributes for __all__
34
+ _core_names = [
35
+ "RawPocketOption",
36
+ "RawValidator",
37
+ "RawHandler",
38
+ "RawHandle",
39
+ "Logger",
40
+ "LogBuilder",
41
+ "PyConfig",
42
+ "PyBot",
43
+ "PyStrategy",
44
+ "PyContext",
45
+ "PyVirtualMarket",
46
+ "StreamLogsIterator",
47
+ "StreamLogsLayer",
48
+ "StreamIterator",
49
+ "RawStreamIterator",
50
+ "start_tracing",
51
+ ]
52
+ __core_all__ = [name for name in _core_names if name in globals()]
53
+
54
+ __all__ = list(set(__pocket_all__ + ["tracing", "validator"] + __core_all__))
@@ -0,0 +1,143 @@
1
+ import json
2
+ from dataclasses import dataclass, field
3
+ from typing import Any, Dict, List
4
+
5
+
6
+ def _get_pyconfig():
7
+ try:
8
+ from .BinaryOptionsToolsV2 import PyConfig
9
+
10
+ return PyConfig
11
+ except ImportError:
12
+ import BinaryOptionsToolsV2
13
+
14
+ return getattr(BinaryOptionsToolsV2, "PyConfig")
15
+
16
+
17
+ @dataclass
18
+ class Config:
19
+ """
20
+ Python wrapper around PyConfig that provides additional functionality
21
+ for configuration management.
22
+ """
23
+
24
+ max_allowed_loops: int = 100
25
+ sleep_interval: int = 100
26
+ reconnect_time: int = 5
27
+ connection_initialization_timeout_secs: int = 60
28
+ timeout_secs: int = 30
29
+ urls: List[str] = field(default_factory=list)
30
+
31
+ # Logging configuration
32
+ terminal_logging: bool = False
33
+ log_level: str = "INFO"
34
+
35
+ # Extra duration, used by functions like `check_win`
36
+ extra_duration: int = 5
37
+
38
+ def __post_init__(self):
39
+ self.urls = self.urls or []
40
+ self._pyconfig = None
41
+ self._locked = False
42
+
43
+ def __setattr__(self, name: str, value: Any) -> None:
44
+ """Override setattr to check for locked state"""
45
+ # Allow setting private attributes and during initialization
46
+ if name.startswith("_") or not hasattr(self, "_locked") or not self._locked:
47
+ super().__setattr__(name, value)
48
+ else:
49
+ raise RuntimeError("Configuration is locked and cannot be modified after being used")
50
+
51
+ @property
52
+ def pyconfig(self) -> Any:
53
+ """
54
+ Returns the PyConfig instance for use in Rust code.
55
+ Once this is accessed, the configuration becomes locked.
56
+ """
57
+ if self._pyconfig is None:
58
+ self._pyconfig = _get_pyconfig()()
59
+ self._update_pyconfig()
60
+ self._locked = True
61
+ return self._pyconfig
62
+
63
+ def _update_pyconfig(self):
64
+ """Updates the internal PyConfig with current values"""
65
+ if self._locked:
66
+ raise RuntimeError("Configuration is locked and cannot be modified after being used")
67
+
68
+ if self._pyconfig is None:
69
+ self._pyconfig = _get_pyconfig()()
70
+
71
+ self._pyconfig.max_allowed_loops = self.max_allowed_loops
72
+ self._pyconfig.sleep_interval = self.sleep_interval
73
+ self._pyconfig.reconnect_time = self.reconnect_time
74
+ self._pyconfig.connection_initialization_timeout_secs = self.connection_initialization_timeout_secs
75
+ self._pyconfig.timeout_secs = self.timeout_secs
76
+ self._pyconfig.urls = self.urls
77
+
78
+ @classmethod
79
+ def from_dict(cls, config_dict: Dict[str, Any]) -> "Config":
80
+ """
81
+ Creates a Config instance from a dictionary.
82
+
83
+ Args:
84
+ config_dict: Dictionary containing configuration values
85
+
86
+ Returns:
87
+ Config instance
88
+ """
89
+ return cls(**{k: v for k, v in config_dict.items() if k in Config.__dataclass_fields__})
90
+
91
+ @classmethod
92
+ def from_json(cls, json_str: str) -> "Config":
93
+ """
94
+ Creates a Config instance from a JSON string.
95
+
96
+ Args:
97
+ json_str: JSON string containing configuration values
98
+
99
+ Returns:
100
+ Config instance
101
+ """
102
+ return cls.from_dict(json.loads(json_str))
103
+
104
+ def to_dict(self) -> Dict[str, Any]:
105
+ """
106
+ Converts the configuration to a dictionary.
107
+
108
+ Returns:
109
+ Dictionary containing all configuration values
110
+ """
111
+ return {
112
+ "max_allowed_loops": self.max_allowed_loops,
113
+ "sleep_interval": self.sleep_interval,
114
+ "reconnect_time": self.reconnect_time,
115
+ "connection_initialization_timeout_secs": self.connection_initialization_timeout_secs,
116
+ "timeout_secs": self.timeout_secs,
117
+ "urls": self.urls,
118
+ "terminal_logging": self.terminal_logging,
119
+ "log_level": self.log_level,
120
+ }
121
+
122
+ def to_json(self) -> str:
123
+ """
124
+ Converts the configuration to a JSON string.
125
+
126
+ Returns:
127
+ JSON string containing all configuration values
128
+ """
129
+ return json.dumps(self.to_dict())
130
+
131
+ def update(self, config_dict: Dict[str, Any]) -> None:
132
+ """
133
+ Updates the configuration with values from a dictionary.
134
+
135
+ Args:
136
+ config_dict: Dictionary containing new configuration values
137
+ """
138
+ if self._locked:
139
+ raise RuntimeError("Configuration is locked and cannot be modified after being used")
140
+
141
+ for key, value in config_dict.items():
142
+ if hasattr(self, key):
143
+ setattr(self, key, value)
@@ -0,0 +1,19 @@
1
+ """
2
+ Module for Pocket Option related functionality.
3
+
4
+ Contains asynchronous and synchronous clients,
5
+ as well as specific classes for Pocket Option trading.
6
+ """
7
+
8
+ __all__ = [
9
+ "asynchronous",
10
+ "synchronous",
11
+ "PocketOptionAsync",
12
+ "PocketOption",
13
+ "RawHandler",
14
+ "RawHandlerSync",
15
+ ]
16
+
17
+ from . import asynchronous, synchronous
18
+ from .asynchronous import PocketOptionAsync, RawHandler
19
+ from .synchronous import PocketOption, RawHandlerSync