MetaRpcMT4 0.0.337__tar.gz → 0.0.339__tar.gz

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.
Files changed (43) hide show
  1. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_account.py +390 -23
  2. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4.egg-info/PKG-INFO +1 -1
  3. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/PKG-INFO +1 -1
  4. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/pyproject.toml +6 -3
  5. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/__init__.py +0 -0
  6. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mrpc_mt4_error_pb2.py +0 -0
  7. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mrpc_mt4_error_pb2_grpc.py +0 -0
  8. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_account_helper_pb2.py +0 -0
  9. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_account_helper_pb2_grpc.py +0 -0
  10. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_accounts_pb2.py +0 -0
  11. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_accounts_pb2_grpc.py +0 -0
  12. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_admin_pb2.py +0 -0
  13. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_admin_pb2_grpc.py +0 -0
  14. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_connection_pb2.py +0 -0
  15. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_connection_pb2_grpc.py +0 -0
  16. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_demo_account_pb2.py +0 -0
  17. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_demo_account_pb2_grpc.py +0 -0
  18. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_gui_pb2.py +0 -0
  19. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_gui_pb2_grpc.py +0 -0
  20. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_health_check_pb2.py +0 -0
  21. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_health_check_pb2_grpc.py +0 -0
  22. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_internal_charts_pb2.py +0 -0
  23. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_internal_charts_pb2_grpc.py +0 -0
  24. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_market_info_pb2.py +0 -0
  25. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_market_info_pb2_grpc.py +0 -0
  26. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_public_account_pb2.py +0 -0
  27. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_public_account_pb2_grpc.py +0 -0
  28. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_quote_history_pb2.py +0 -0
  29. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_quote_history_pb2_grpc.py +0 -0
  30. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_server_timezone_pb2.py +0 -0
  31. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_server_timezone_pb2_grpc.py +0 -0
  32. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_subscriptions_pb2.py +0 -0
  33. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_subscriptions_pb2_grpc.py +0 -0
  34. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_trade_stats_pb2.py +0 -0
  35. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_trade_stats_pb2_grpc.py +0 -0
  36. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_trading_helper_pb2.py +0 -0
  37. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4/mt4_term_api_trading_helper_pb2_grpc.py +0 -0
  38. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4.egg-info/SOURCES.txt +0 -0
  39. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4.egg-info/dependency_links.txt +0 -0
  40. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4.egg-info/requires.txt +0 -0
  41. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/MetaRpcMT4.egg-info/top_level.txt +0 -0
  42. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/setup.cfg +0 -0
  43. {metarpcmt4-0.0.337 → metarpcmt4-0.0.339}/tests/test.py +0 -0
@@ -17,6 +17,10 @@ import MetaRpcMT4.mt4_term_api_market_info_pb2 as market_info_pb2
17
17
  import MetaRpcMT4.mt4_term_api_market_info_pb2_grpc as market_info_pb2_grpc
18
18
  import MetaRpcMT4.mt4_term_api_subscriptions_pb2 as subscriptions_pb2
19
19
  import MetaRpcMT4.mt4_term_api_subscriptions_pb2_grpc as subscriptions_pb2_grpc
20
+ import MetaRpcMT4.mt4_term_api_trade_stats_pb2 as trade_stats_pb2
21
+ import MetaRpcMT4.mt4_term_api_trade_stats_pb2_grpc as trade_stats_pb2_grpc
22
+ import MetaRpcMT4.mt4_term_api_server_timezone_pb2 as server_timezone_pb2
23
+ import MetaRpcMT4.mt4_term_api_server_timezone_pb2_grpc as server_timezone_pb2_grpc
20
24
  import MetaRpcMT4.mt4_term_api_market_info_pb2 as market_info_pb2
21
25
  import MetaRpcMT4.mt4_term_api_market_info_pb2_grpc as market_info_pb2_grpc
22
26
 
@@ -41,6 +45,7 @@ class MT4Account:
41
45
  self.grpc_server = grpc_server or "mt4.mrpc.pro:443" # default server
42
46
  self.id = id_
43
47
  self.api_key = api_key or "TRIAL"
48
+ self.name = None
44
49
 
45
50
  # Async gRPC secure channel (TLS)
46
51
  self.channel = grpc.aio.secure_channel(
@@ -54,6 +59,8 @@ class MT4Account:
54
59
  self.account_client = account_helper_pb2_grpc.AccountHelperStub(self.channel)
55
60
  self.trade_client = trading_helper_pb2_grpc.TradingHelperStub(self.channel)
56
61
  self.market_info_client = market_info_pb2_grpc.MarketInfoStub(self.channel)
62
+ self.trade_stats_client = trade_stats_pb2_grpc.TradeStatsStub(self.channel)
63
+ self.server_timezone_client = server_timezone_pb2_grpc.ServerTimezoneStub(self.channel)
57
64
 
58
65
  # Connection state
59
66
  self.host = None
@@ -70,13 +77,13 @@ class MT4Account:
70
77
  headers.append(("apikey", str(getattr(self, "api_key", None) or "TRIAL")))
71
78
  return headers
72
79
 
73
- async def disconnect(self):
80
+ async def disconnect(self, delete: bool = False):
74
81
  """
75
82
  Disconnect from MT4 server by sending Disconnect request, then close the gRPC channel.
76
83
  """
77
84
  try:
78
85
  if hasattr(self, 'connection_client') and self.connection_client:
79
- request = connection_pb2.DisconnectRequest()
86
+ request = connection_pb2.DisconnectRequest(delete=delete)
80
87
  await self.connection_client.Disconnect(request, metadata=self.get_headers(), timeout=10)
81
88
  except Exception:
82
89
  pass
@@ -95,10 +102,11 @@ class MT4Account:
95
102
 
96
103
  # === Utility: reconnect ===
97
104
  async def reconnect(self, deadline: Optional[datetime] = None):
105
+ name = getattr(self, "name", None)
98
106
  if self.server_name:
99
- await self.connect_by_server_name(self.server_name, True, self.connect_timeout_seconds, deadline)
107
+ await self.connect_by_server_name(self.server_name, True, self.connect_timeout_seconds, deadline, name=name)
100
108
  elif self.host:
101
- await self.connect_by_host_port(self.host, self.port or 443, True, self.connect_timeout_seconds, deadline)
109
+ await self.connect_by_host_port(self.host, self.port or 443, True, self.connect_timeout_seconds, deadline, name=name)
102
110
 
103
111
  # === Core retry wrapper ===
104
112
  async def execute_with_reconnect(
@@ -141,9 +149,17 @@ class MT4Account:
141
149
  timeout_seconds: int = 30,
142
150
  deadline: Optional[datetime] = None,
143
151
  base_chart_symbol: Optional[str] = None,
152
+ name: Optional[str] = None,
153
+ expiration: Optional[int] = None,
144
154
  *args,
145
155
  **kwargs,
146
156
  ):
157
+ """
158
+ Connects by broker host:port. `name` is the human-readable terminal label shown in
159
+ the MRPC portal / `Accounts` list; `expiration` is an optional terminal lifetime in
160
+ seconds. The `id` (terminal instance guid) and `apikey` headers are always sent, so a
161
+ stable `id_` passed to the constructor re-attaches to the same terminal on every run.
162
+ """
147
163
  if isinstance(wait_for_terminal_is_alive, str):
148
164
  wait_for_terminal_is_alive = True
149
165
 
@@ -155,17 +171,18 @@ class MT4Account:
155
171
  port=port,
156
172
  timeout_seconds=timeout_seconds,
157
173
  )
174
+ if name:
175
+ request.name = name
176
+ self.name = name
177
+ if expiration is not None:
178
+ request.expiration = int(expiration)
158
179
 
159
- headers = []
160
- if self.id:
161
- headers.append(("id", str(self.id)))
162
-
163
180
  res = await self.connection_client.Connect(
164
181
  request,
165
- metadata=headers,
166
- timeout=30.0 if deadline is None else (deadline - datetime.utcnow()).total_seconds(),
182
+ metadata=self.get_headers(),
183
+ timeout=float(timeout_seconds) + 30.0 if deadline is None else (deadline - datetime.utcnow()).total_seconds(),
167
184
  )
168
-
185
+
169
186
  if res.HasField("error") and res.error.error_message:
170
187
  raise ApiExceptionMT4(res.error)
171
188
 
@@ -173,7 +190,9 @@ class MT4Account:
173
190
  self.host = host
174
191
  self.port = port
175
192
  self.connect_timeout_seconds = timeout_seconds
176
- self.id = getattr(res.data, "terminal_instance_guid", getattr(res.data, "terminalInstanceGuid", None))
193
+ guid = getattr(res.data, "terminal_instance_guid", None)
194
+ if guid:
195
+ self.id = guid
177
196
 
178
197
  async def connect_by_server_name(
179
198
  self,
@@ -182,9 +201,18 @@ class MT4Account:
182
201
  timeout_seconds: int = 30,
183
202
  deadline: Optional[datetime] = None,
184
203
  base_chart_symbol: Optional[str] = None,
204
+ name: Optional[str] = None,
205
+ expiration: Optional[int] = None,
185
206
  *args,
186
207
  **kwargs,
187
208
  ):
209
+ """
210
+ Connects by broker server (cluster) name, e.g. "AMarkets-Demo" (ConnectEx).
211
+ `name` is the human-readable terminal label shown in the MRPC portal / `Accounts`
212
+ list; `expiration` is an optional terminal lifetime in seconds. The `id` (terminal
213
+ instance guid) and `apikey` headers are always sent, so a stable `id_` passed to the
214
+ constructor re-attaches to the same terminal on every run instead of creating a new one.
215
+ """
188
216
  if isinstance(wait_for_terminal_is_alive, str):
189
217
  wait_for_terminal_is_alive = True
190
218
 
@@ -195,14 +223,16 @@ class MT4Account:
195
223
  mt_cluster_name=server_name,
196
224
  timeout_seconds=timeout_seconds,
197
225
  )
226
+ if name:
227
+ request.name = name
228
+ self.name = name
229
+ if expiration is not None:
230
+ request.expiration = int(expiration)
198
231
 
199
- headers = []
200
- if self.id:
201
- headers.append(("id", str(self.id)))
202
232
  res = await self.connection_client.ConnectEx(
203
233
  request,
204
- metadata=headers,
205
- timeout=30.0 if deadline is None else (deadline - datetime.utcnow()).total_seconds(),
234
+ metadata=self.get_headers(),
235
+ timeout=float(timeout_seconds) + 30.0 if deadline is None else (deadline - datetime.utcnow()).total_seconds(),
206
236
  )
207
237
 
208
238
  if res.HasField("error") and res.error.error_message:
@@ -211,12 +241,14 @@ class MT4Account:
211
241
  # Save state
212
242
  self.server_name = server_name
213
243
  self.connect_timeout_seconds = timeout_seconds
214
- self.id = res.data.terminal_instance_guid
244
+ guid = getattr(res.data, "terminal_instance_guid", None)
245
+ if guid:
246
+ self.id = guid
215
247
 
216
248
 
217
249
  #
218
250
  # Account helper --------------------------------------------------------------------------------------------------------
219
- #
251
+ #
220
252
 
221
253
  async def account_summary(
222
254
  self,
@@ -446,7 +478,7 @@ class MT4Account:
446
478
 
447
479
  Returns:
448
480
  SymbolParamsManyData: The result containing symbol parameters.
449
-
481
+
450
482
  Raises:
451
483
  ConnectExceptionMT4: If the account is not connected before calling this method.
452
484
  ApiExceptionMT4: If the server returns an error in the response.
@@ -491,7 +523,7 @@ class MT4Account:
491
523
  Args:
492
524
  symbol_names (list[str]): List of symbol names.
493
525
 
494
- Returns:
526
+ Returns:
495
527
  TickValueWithSizeData: The result containing tick values and sizes.
496
528
 
497
529
  Raises:
@@ -525,9 +557,217 @@ class MT4Account:
525
557
 
526
558
  return res.data
527
559
 
560
+ async def trade_stats(
561
+ self,
562
+ from_time: Optional[datetime] = None,
563
+ deadline: Optional[datetime] = None,
564
+ cancellation_event: Optional[asyncio.Event] = None,
565
+ ):
566
+ """
567
+ Gets aggregated trade statistics (open/closed counts, profit by period, drawdowns).
568
+
569
+ Args:
570
+ from_time (datetime, optional): Start of the statistics window. Omit for full history.
571
+ deadline (datetime, optional): Deadline after which the request is canceled.
572
+ cancellation_event (asyncio.Event, optional): Event to cancel the request.
573
+
574
+ Returns:
575
+ TradeStatsData: The aggregated trade statistics.
576
+
577
+ Raises:
578
+ ConnectExceptionMT4: If the account is not connected before calling this method.
579
+ ApiExceptionMT4: If the server returns an error in the response.
580
+ grpc.aio.AioRpcError: If the gRPC call fails due to communication or protocol errors.
581
+ """
582
+ if not (self.host or self.server_name or self.id):
583
+ raise ConnectExceptionMT4("Please call connect method first")
584
+
585
+ request = trade_stats_pb2.TradeStatsRequest()
586
+ if from_time is not None:
587
+ setattr(request, "from", from_time.isoformat())
588
+
589
+ async def grpc_call(headers):
590
+ timeout = None
591
+ if deadline:
592
+ timeout = (deadline - datetime.utcnow()).total_seconds()
593
+ if timeout < 0:
594
+ timeout = 0
595
+ return await self.trade_stats_client.TradeStats(
596
+ request,
597
+ metadata=headers,
598
+ timeout=timeout,
599
+ )
600
+
601
+ res = await self.execute_with_reconnect(
602
+ grpc_call=grpc_call,
603
+ error_selector=lambda r: getattr(r, "error", None),
604
+ deadline=deadline,
605
+ cancellation_event=cancellation_event,
606
+ )
607
+
608
+ return res.data
609
+
610
+ async def trade_stats_equity_history(
611
+ self,
612
+ from_time: Optional[datetime] = None,
613
+ exclude_same_bars: Optional[bool] = None,
614
+ deadline: Optional[datetime] = None,
615
+ cancellation_event: Optional[asyncio.Event] = None,
616
+ ):
617
+ """
618
+ Gets trade statistics together with equity-chart points and the trade list in one call.
619
+
620
+ Args:
621
+ from_time (datetime, optional): Start of the window. Omit for full history.
622
+ exclude_same_bars (bool, optional): Collapse consecutive equal equity points.
623
+ deadline (datetime, optional): Deadline after which the request is canceled.
624
+ cancellation_event (asyncio.Event, optional): Event to cancel the request.
625
+
626
+ Returns:
627
+ TradeStatsEquityHistoryData: Stats + equity points + trades.
628
+
629
+ Raises:
630
+ ConnectExceptionMT4: If the account is not connected before calling this method.
631
+ ApiExceptionMT4: If the server returns an error in the response.
632
+ grpc.aio.AioRpcError: If the gRPC call fails due to communication or protocol errors.
633
+ """
634
+ if not (self.host or self.server_name or self.id):
635
+ raise ConnectExceptionMT4("Please call connect method first")
636
+
637
+ request = trade_stats_pb2.TradeStatsEquityHistoryRequest()
638
+ if from_time is not None:
639
+ setattr(request, "from", from_time.isoformat())
640
+ if exclude_same_bars is not None:
641
+ request.exclude_same_bars = exclude_same_bars
642
+
643
+ async def grpc_call(headers):
644
+ timeout = None
645
+ if deadline:
646
+ timeout = (deadline - datetime.utcnow()).total_seconds()
647
+ if timeout < 0:
648
+ timeout = 0
649
+ return await self.trade_stats_client.TradeStatsEquityHistory(
650
+ request,
651
+ metadata=headers,
652
+ timeout=timeout,
653
+ )
654
+
655
+ res = await self.execute_with_reconnect(
656
+ grpc_call=grpc_call,
657
+ error_selector=lambda r: getattr(r, "error", None),
658
+ deadline=deadline,
659
+ cancellation_event=cancellation_event,
660
+ )
661
+
662
+ return res.data
663
+
664
+ async def equity_history(
665
+ self,
666
+ from_time: Optional[datetime] = None,
667
+ exclude_same_bars: Optional[bool] = None,
668
+ deadline: Optional[datetime] = None,
669
+ cancellation_event: Optional[asyncio.Event] = None,
670
+ ):
671
+ """
672
+ Gets the equity/balance time series (equity curve) with running drawdowns.
673
+
674
+ Args:
675
+ from_time (datetime, optional): Start of the window. Omit for full history.
676
+ exclude_same_bars (bool, optional): Collapse consecutive equal equity points.
677
+ deadline (datetime, optional): Deadline after which the request is canceled.
678
+ cancellation_event (asyncio.Event, optional): Event to cancel the request.
679
+
680
+ Returns:
681
+ EquityHistoryData: The equity-curve points.
682
+
683
+ Raises:
684
+ ConnectExceptionMT4: If the account is not connected before calling this method.
685
+ ApiExceptionMT4: If the server returns an error in the response.
686
+ grpc.aio.AioRpcError: If the gRPC call fails due to communication or protocol errors.
687
+ """
688
+ if not (self.host or self.server_name or self.id):
689
+ raise ConnectExceptionMT4("Please call connect method first")
690
+
691
+ request = trade_stats_pb2.EquityHistoryRequest()
692
+ if from_time is not None:
693
+ setattr(request, "from", from_time.isoformat())
694
+ if exclude_same_bars is not None:
695
+ request.exclude_same_bars = exclude_same_bars
696
+
697
+ async def grpc_call(headers):
698
+ timeout = None
699
+ if deadline:
700
+ timeout = (deadline - datetime.utcnow()).total_seconds()
701
+ if timeout < 0:
702
+ timeout = 0
703
+ return await self.trade_stats_client.EquityHistory(
704
+ request,
705
+ metadata=headers,
706
+ timeout=timeout,
707
+ )
708
+
709
+ res = await self.execute_with_reconnect(
710
+ grpc_call=grpc_call,
711
+ error_selector=lambda r: getattr(r, "error", None),
712
+ deadline=deadline,
713
+ cancellation_event=cancellation_event,
714
+ )
715
+
716
+ return res.data
717
+
718
+ async def trade_unrealized_pl(
719
+ self,
720
+ from_time: Optional[datetime] = None,
721
+ deadline: Optional[datetime] = None,
722
+ cancellation_event: Optional[asyncio.Event] = None,
723
+ ):
724
+ """
725
+ Gets per-open-order unrealized P/L extrema (best/worst floating P/L with timestamps).
726
+
727
+ Args:
728
+ from_time (datetime, optional): Start of the window. Omit for full history.
729
+ deadline (datetime, optional): Deadline after which the request is canceled.
730
+ cancellation_event (asyncio.Event, optional): Event to cancel the request.
731
+
732
+ Returns:
733
+ TradeUnrealizedPLData: Unrealized-P/L extrema per open order.
734
+
735
+ Raises:
736
+ ConnectExceptionMT4: If the account is not connected before calling this method.
737
+ ApiExceptionMT4: If the server returns an error in the response.
738
+ grpc.aio.AioRpcError: If the gRPC call fails due to communication or protocol errors.
739
+ """
740
+ if not (self.host or self.server_name or self.id):
741
+ raise ConnectExceptionMT4("Please call connect method first")
742
+
743
+ request = trade_stats_pb2.TradeUnrealizedPLRequest()
744
+ if from_time is not None:
745
+ setattr(request, "from", from_time.isoformat())
746
+
747
+ async def grpc_call(headers):
748
+ timeout = None
749
+ if deadline:
750
+ timeout = (deadline - datetime.utcnow()).total_seconds()
751
+ if timeout < 0:
752
+ timeout = 0
753
+ return await self.trade_stats_client.TradeUnrealizedPL(
754
+ request,
755
+ metadata=headers,
756
+ timeout=timeout,
757
+ )
758
+
759
+ res = await self.execute_with_reconnect(
760
+ grpc_call=grpc_call,
761
+ error_selector=lambda r: getattr(r, "error", None),
762
+ deadline=deadline,
763
+ cancellation_event=cancellation_event,
764
+ )
765
+
766
+ return res.data
767
+
528
768
  #
529
769
  # Streams --------------------------------------------------------------------------------------------------------
530
- #
770
+ #
531
771
 
532
772
  async def execute_stream_with_reconnect(
533
773
  self,
@@ -574,7 +814,7 @@ class MT4Account:
574
814
  reconnect_required = True
575
815
  break
576
816
 
577
- if error and getattr(error, "message", None):
817
+ if error and (getattr(error, "error_message", None) or getattr(error, "error_code", None)):
578
818
  raise ApiExceptionMT4(error)
579
819
 
580
820
  data = get_data(reply)
@@ -1195,3 +1435,130 @@ class MT4Account:
1195
1435
  cancellation_event=cancellation_event,
1196
1436
  )
1197
1437
  return res.data
1438
+
1439
+ async def symbol_select(
1440
+ self,
1441
+ symbol: str,
1442
+ select: bool = True,
1443
+ deadline: Optional[datetime] = None,
1444
+ cancellation_event: Optional[asyncio.Event] = None,
1445
+ ):
1446
+ """
1447
+ Adds a symbol to (or removes it from) Market Watch.
1448
+
1449
+ Args:
1450
+ symbol (str): The symbol name.
1451
+ select (bool): True to add to Market Watch, False to remove.
1452
+ deadline (datetime, optional): Deadline after which the request is canceled.
1453
+ cancellation_event (asyncio.Event, optional): Event to cancel the request.
1454
+
1455
+ Returns:
1456
+ SymbolSelectData: The result of the select operation.
1457
+
1458
+ Raises:
1459
+ ConnectExceptionMT4: If the account is not connected before calling this method.
1460
+ ApiExceptionMT4: If the server returns an error in the response.
1461
+ grpc.aio.AioRpcError: If the gRPC call fails due to communication or protocol errors.
1462
+ """
1463
+ if not (self.host or self.server_name or self.id):
1464
+ raise ConnectExceptionMT4("Please call connect method first")
1465
+
1466
+ request = market_info_pb2.SymbolSelectRequest(symbol=symbol, select=select)
1467
+
1468
+ async def grpc_call(headers):
1469
+ timeout = None
1470
+ if deadline:
1471
+ timeout = max((deadline - datetime.utcnow()).total_seconds(), 0)
1472
+ return await self.market_info_client.SymbolSelect(
1473
+ request,
1474
+ metadata=headers,
1475
+ timeout=timeout,
1476
+ )
1477
+
1478
+ res = await self.execute_with_reconnect(
1479
+ grpc_call=grpc_call,
1480
+ error_selector=lambda r: getattr(r, "error", None),
1481
+ deadline=deadline,
1482
+ cancellation_event=cancellation_event,
1483
+ )
1484
+ return res.data
1485
+
1486
+ async def server_timezone(
1487
+ self,
1488
+ deadline: Optional[datetime] = None,
1489
+ cancellation_event: Optional[asyncio.Event] = None,
1490
+ ):
1491
+ """
1492
+ Gets the trade server timezone / UTC offset.
1493
+
1494
+ Args:
1495
+ deadline (datetime, optional): Deadline after which the request is canceled.
1496
+ cancellation_event (asyncio.Event, optional): Event to cancel the request.
1497
+
1498
+ Returns:
1499
+ ServerTimezoneData: The server timezone information.
1500
+
1501
+ Raises:
1502
+ ConnectExceptionMT4: If the account is not connected before calling this method.
1503
+ ApiExceptionMT4: If the server returns an error in the response.
1504
+ grpc.aio.AioRpcError: If the gRPC call fails due to communication or protocol errors.
1505
+ """
1506
+ if not (self.host or self.server_name or self.id):
1507
+ raise ConnectExceptionMT4("Please call connect method first")
1508
+
1509
+ request = server_timezone_pb2.ServerTimezoneRequest()
1510
+
1511
+ async def grpc_call(headers):
1512
+ timeout = None
1513
+ if deadline:
1514
+ timeout = max((deadline - datetime.utcnow()).total_seconds(), 0)
1515
+ return await self.server_timezone_client.ServerTimezone(
1516
+ request,
1517
+ metadata=headers,
1518
+ timeout=timeout,
1519
+ )
1520
+
1521
+ res = await self.execute_with_reconnect(
1522
+ grpc_call=grpc_call,
1523
+ error_selector=lambda r: getattr(r, "error", None),
1524
+ deadline=deadline,
1525
+ cancellation_event=cancellation_event,
1526
+ )
1527
+ return res.data
1528
+
1529
+ async def on_connect_state(
1530
+ self,
1531
+ terminal_ids: Optional[list[str]] = None,
1532
+ cancellation_event: Optional[asyncio.Event] = None,
1533
+ ):
1534
+ """
1535
+ Subscribes to terminal connection-state changes.
1536
+
1537
+ Args:
1538
+ terminal_ids (list[str], optional): Restrict to specific terminal ids;
1539
+ omit to use the current session.
1540
+ cancellation_event (asyncio.Event, optional): Event to cancel streaming.
1541
+
1542
+ Yields:
1543
+ OnConnectStateData: Connection-state change events.
1544
+
1545
+ Raises:
1546
+ ConnectExceptionMT4: If the account is not connected before calling this method.
1547
+ ApiExceptionMT4: If the server returns an error in the stream.
1548
+ grpc.aio.AioRpcError: If the stream fails due to communication or protocol errors.
1549
+ """
1550
+ if not self.id:
1551
+ raise ConnectExceptionMT4("Please call connect method first")
1552
+
1553
+ request = connection_pb2.OnConnectStateRequest()
1554
+ if terminal_ids:
1555
+ request.terminal_ids.extend(terminal_ids)
1556
+
1557
+ async for data in self.execute_stream_with_reconnect(
1558
+ request=request,
1559
+ stream_invoker=lambda req, headers: self.connection_client.OnConnectState(req, metadata=headers),
1560
+ get_error=lambda reply: reply.error,
1561
+ get_data=lambda reply: reply.data,
1562
+ cancellation_event=cancellation_event,
1563
+ ):
1564
+ yield data
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: MetaRpcMT4
3
- Version: 0.0.337
3
+ Version: 0.0.339
4
4
  Summary: MetaRPC MT4 gRPC Python client
5
5
  Author-email: MetaRPC <admin@mrpc.pro>
6
6
  Requires-Python: >=3.8
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: MetaRpcMT4
3
- Version: 0.0.337
3
+ Version: 0.0.339
4
4
  Summary: MetaRPC MT4 gRPC Python client
5
5
  Author-email: MetaRPC <admin@mrpc.pro>
6
6
  Requires-Python: >=3.8
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "MetaRpcMT4"
7
- version = "0.0.337"
7
+ version = "0.0.339"
8
8
  description = "MetaRPC MT4 gRPC Python client"
9
9
  authors = [{ name = "MetaRPC", email = "admin@mrpc.pro" }]
10
10
  readme = "README.md"
@@ -18,5 +18,8 @@ dependencies = [
18
18
  ]
19
19
 
20
20
  [tool.setuptools]
21
- packages = ["MetaRpcMT4"]
22
- include-package-data = true
21
+ include-package-data = true
22
+
23
+ # MetaRpcMT4 and every subpackage under it (e.g. MetaRpcMT4/helpers/, which needs an __init__.py)
24
+ [tool.setuptools.packages.find]
25
+ include = ["MetaRpcMT4*"]
File without changes
File without changes