Skip to content

API Reference

mt5_account

MT5Account

Source code in package/MetaRpcMT5/mt5_account.py
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
class MT5Account:
    def __init__(self, user: int, password: str, grpc_server: Optional[str] = None, id_: Optional[str] = None):
        self.user = user
        self.password = password
        self.grpc_server = grpc_server or "mt5.mrpc.pro:443"   # default server
        self.id = id_

        # Async gRPC secure channel (TLS)
        self.channel = grpc.aio.secure_channel(
            self.grpc_server,
            grpc.ssl_channel_credentials()
        )

        # Init stubs directly (like in C#)
        self.connection_client = connection_pb2_grpc.ConnectionStub(self.channel)
        self.subscription_client = subscriptions_pb2_grpc.SubscriptionServiceStub(self.channel)
        self.account_client = account_helper_pb2_grpc.AccountHelperStub(self.channel)
        self.trade_client = trading_helper_pb2_grpc.TradingHelperStub(self.channel)
        self.market_info_client = market_info_pb2_grpc.MarketInfoStub(self.channel)
        self.trade_functions_client = trade_functions_pb2_grpc.TradeFunctionsStub(self.channel)
        self.account_information_client = account_information_pb2_grpc.AccountInformationStub(self.channel)

        # Connection state
        self.host = None
        self.port = None
        self.server_name = None
        self.base_chart_symbol = None
        self.connect_timeout_seconds = 30


    # === Utility: headers ===
    def get_headers(self):
        return [("id", self.id)]

    # === Utility: reconnect ===
    async def reconnect(self, deadline: Optional[datetime] = None):
        if self.server_name:
            await self.connect_by_server_name(self.server_name, self.base_chart_symbol or "EURUSD",
                                              True, self.connect_timeout_seconds, deadline)
        elif self.host:
            await self.connect_by_host_port(self.host, self.port or 443,
                                            self.base_chart_symbol or "EURUSD", True,
                                            self.connect_timeout_seconds, deadline)

    # === Core retry wrapper ===
    async def execute_with_reconnect(
        self,
        grpc_call: Callable[[list[tuple[str, str]]], Awaitable[Any]],
        error_selector: Callable[[Any], Optional[Any]],
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        while cancellation_event is None or not cancellation_event.is_set():
            headers = self.get_headers()
            try:
                res = await grpc_call(headers)
            except grpc.aio.AioRpcError as ex:
                if ex.code() == grpc.StatusCode.UNAVAILABLE:
                    await asyncio.sleep(0.5)
                    await self.reconnect(deadline)
                    continue
                raise

            error = error_selector(res)
            if error and error.error_code in ("TERMINAL_INSTANCE_NOT_FOUND", "TERMINAL_REGISTRY_TERMINAL_NOT_FOUND"):
                await asyncio.sleep(0.5)
                await self.reconnect(deadline)
                continue

            if res.HasField("error") and res.error.message:
                raise ApiExceptionMT5(res.error)

            return res

        raise asyncio.CancelledError("The operation was canceled by the caller.")

    # === Connect methods ===
    async def connect_by_host_port(
        self,
        host: str,
        port: int = 443,
        base_chart_symbol: str = "EURUSD",
        wait_for_terminal_is_alive: bool = True,
        timeout_seconds: int = 30,
        deadline: Optional[datetime] = None,
    ):
        #Build connect request (from your proto)
        request = connection_pb2.ConnectRequest(
            user=self.user,
            password=self.password,
            host=host,
            port=port,
            base_chart_symbol=base_chart_symbol,
            wait_for_terminal_is_alive=wait_for_terminal_is_alive,
            terminal_readiness_waiting_timeout_seconds=timeout_seconds,
        )

        headers = []
        if self.id:
            headers.append(("id", str(self.id)))

        res = await self.connection_client.Connect(
            request,
            metadata=headers,
            timeout=30.0 if deadline is None else (deadline - datetime.utcnow()).total_seconds(),
        )

        if res.HasField("error") and res.error.message:
            raise ApiExceptionMT5(res.error)

        # Save state
        self.host = host
        self.port = port
        self.base_chart_symbol = base_chart_symbol
        self.connect_timeout_seconds = timeout_seconds
        self.id = res.data.terminalInstanceGuid

    async def connect_by_server_name(
        self,
        server_name: str,
        base_chart_symbol: str = "EURUSD",
        wait_for_terminal_is_alive: bool = True,
        timeout_seconds: int = 30,
        deadline: Optional[datetime] = None,
    ):
        # Build connect request (from your proto)
        request = connection_pb2.ConnectExRequest(
            user=self.user,
            password=self.password,
            mt_cluster_name=server_name,
            base_chart_symbol=base_chart_symbol,
            terminal_readiness_waiting_timeout_seconds=timeout_seconds,
        )

        headers = []
        if self.id:
            headers.append(("id", str(self.id)))
        res = await self.connection_client.ConnectEx(
            request,
            metadata=headers,
            timeout=30.0 if deadline is None else (deadline - datetime.utcnow()).total_seconds(),
        )

        if res.HasField("error") and res.error.message:
            raise ApiExceptionMT5(res.error)

        # Save state
        self.server_name = server_name
        self.base_chart_symbol = base_chart_symbol
        self.connect_timeout_seconds = timeout_seconds
        self.id = res.data.terminal_instance_guid

    async def account_summary(
        self,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Gets the summary information for a trading account asynchronously.

        Args:
            deadline (datetime, optional): Deadline after which the request will be canceled
                if not completed.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            AccountSummaryData: The server's response containing account summary data.

        Raises:
            ConnectExceptionMT5: If the account is not connected before calling this method.
            ApiExceptionMT5: If the server returns an error in the response.
            grpc.aio.AioRpcError: If the gRPC call fails due to communication or protocol errors.
        """
        if not (self.host or self.server_name):
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.AccountSummaryRequest()

        async def grpc_call(headers):
            timeout = None
            if deadline:
                timeout = (deadline - datetime.utcnow()).total_seconds()
                if timeout < 0:
                    timeout = 0
            return await self.account_client.AccountSummary(
                request,
                metadata=headers,
                timeout=timeout,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )

        return res.data

    async def opened_orders(
        self,
        sort_mode: account_helper_pb2.BMT5_ENUM_OPENED_ORDER_SORT_TYPE = account_helper_pb2.BMT5_ENUM_OPENED_ORDER_SORT_TYPE.BMT5_OPENED_ORDER_SORT_BY_OPEN_TIME_ASC,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Gets the currently opened orders and positions for the connected account asynchronously.

        Args:
            sort_mode (BMT5_ENUM_OPENED_ORDER_SORT_TYPE): The sort mode for the opened orders
                (0 - open time, 1 - close time, 2 - ticket ID).
            deadline (datetime, optional): Deadline after which the request will be canceled
                if not completed.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            OpenedOrdersData: The result containing opened orders and positions.

        Raises:
            ConnectExceptionMT5: If the account is not connected before calling this method.
            ApiExceptionMT5: If the server returns an error in the response.
            grpc.aio.AioRpcError: If the gRPC call fails due to communication or protocol errors.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.OpenedOrdersRequest(inputSortMode=sort_mode)

        async def grpc_call(headers):
            timeout = None
            if deadline:
                timeout = (deadline - datetime.utcnow()).total_seconds()
                if timeout < 0:
                    timeout = 0
            return await self.account_client.OpenedOrders(
                request,
                metadata=headers,
                timeout=timeout,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data


    async def order_history(
        self,
        from_dt: datetime,
        to_dt: datetime,
        sort_mode: account_helper_pb2.BMT5_ENUM_ORDER_HISTORY_SORT_TYPE = account_helper_pb2.BMT5_ENUM_ORDER_HISTORY_SORT_TYPE.BMT5_SORT_BY_CLOSE_TIME_ASC,
        page_number: int = 0,
        items_per_page: int = 0,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Gets the historical orders for the connected trading account within the specified
        time range asynchronously.

        Args:
            from_dt (datetime): The start time for the history query (server time).
            to_dt (datetime): The end time for the history query (server time).
            sort_mode (BMT5_ENUM_ORDER_HISTORY_SORT_TYPE, optional):
                The sort mode (0 - by open time, 1 - by close time, 2 - by ticket ID).
            page_number (int, optional): Page number for paginated results (default 0).
            items_per_page (int, optional): Number of items per page (default 0 = all).
            deadline (datetime, optional): Deadline after which the request will be canceled.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            OrdersHistoryData: The server's response containing paged historical order data.

        Raises:
            ConnectExceptionMT5: If the account is not connected before calling this method.
            ApiExceptionMT5: If the server returns an error in the response.
            grpc.aio.AioRpcError: If the gRPC call fails due to communication or protocol errors.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.OrderHistoryRequest(
            inputFrom=Timestamp().FromDatetime(from_dt),
            inputTo=Timestamp().FromDatetime(to_dt),
            inputSortMode=sort_mode,
            pageNumber=page_number,
            itemsPerPage=items_per_page,
        )

        async def grpc_call(headers):
            timeout = None
            if deadline:
                timeout = (deadline - datetime.utcnow()).total_seconds()
                if timeout < 0:
                    timeout = 0
            return await self.account_client.OrderHistory(
                request,
                metadata=headers,
                timeout=timeout,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data

    async def opened_orders_tickets(
        self,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Gets ticket IDs of all currently opened orders and positions asynchronously.

        Args:
            deadline (datetime, optional): Deadline after which the request will be canceled.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            OpenedOrdersTicketsData: Collection of opened order and position tickets.

        Raises:
            ConnectExceptionMT5: If the account is not connected before calling this method.
            ApiExceptionMT5: If the server returns an error in the response.
            grpc.aio.AioRpcError: If the gRPC call fails due to communication or protocol errors.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.OpenedOrdersTicketsRequest()

        async def grpc_call(headers):
            timeout = None
            if deadline:
                timeout = (deadline - datetime.utcnow()).total_seconds()
                if timeout < 0:
                    timeout = 0
            return await self.account_client.OpenedOrdersTickets(
                request,
                metadata=headers,
                timeout=timeout,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data

    async def symbol_params_many(
        self,
        request: account_helper_pb2.SymbolParamsManyRequest,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Retrieves symbol parameters for multiple instruments asynchronously.

        Args:
            request (SymbolParamsManyRequest): The request containing filters and pagination.
            deadline (datetime, optional): Deadline after which the request will be canceled.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            SymbolParamsManyData: Symbol parameter details.

        Raises:
            ConnectExceptionMT5: If the account is not connected before calling this method.
            ApiExceptionMT5: If the server returns an error in the response.
            grpc.aio.AioRpcError: If the gRPC call fails due to communication or protocol errors.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        async def grpc_call(headers):
            timeout = None
            if deadline:
                timeout = (deadline - datetime.utcnow()).total_seconds()
                if timeout < 0:
                    timeout = 0
            return await self.account_client.SymbolParamsMany(
                request,
                metadata=headers,
                timeout=timeout,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data


    async def tick_value_with_size(
        self,
        symbols: list[str],
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Gets tick value and tick size data for the given symbols asynchronously.

        Args:
            symbols (list[str]): List of symbol names.
            deadline (datetime, optional): Deadline after which the request will be canceled.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            TickValueWithSizeData: Tick value and contract size info per symbol.

        Raises:
            ConnectExceptionMT5: If the account is not connected before calling this method.
            ApiExceptionMT5: If the server returns an error in the response.
            grpc.aio.AioRpcError: If the gRPC call fails due to communication or protocol errors.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.TickValueWithSizeRequest()
        request.symbol_names.extend(symbols)

        async def grpc_call(headers):
            timeout = None
            if deadline:
                timeout = (deadline - datetime.utcnow()).total_seconds()
                if timeout < 0:
                    timeout = 0
            return await self.account_client.TickValueWithSize(
                request,
                metadata=headers,
                timeout=timeout,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data

    async def positions_history(
    self,
    sort_type: account_helper_pb2.AH_ENUM_POSITIONS_HISTORY_SORT_TYPE,
    open_from: Optional[datetime] = None,
    open_to: Optional[datetime] = None,
    page: int = 0,
    size: int = 0,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Retrieves historical positions based on filter and time range asynchronously.

        Args:
            sort_type (AH_ENUM_POSITIONS_HISTORY_SORT_TYPE): Sorting type for historical positions.
            open_from (datetime, optional): Start of open time filter (UTC).
            open_to (datetime, optional): End of open time filter (UTC).
            page (int, optional): Page number for paginated results (default 0).
            size (int, optional): Number of items per page (default 0 = all).
            deadline (datetime, optional): Deadline after which the request will be canceled.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            PositionsHistoryData: Historical position records.

        Raises:
            ConnectExceptionMT5: If the account is not connected before calling this method.
            ApiExceptionMT5: If the server returns an error in the response.
            grpc.aio.AioRpcError: If the gRPC call fails due to communication or protocol errors.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.PositionsHistoryRequest(
            sort_type=sort_type,
            pageNumber=page,
            itemsPerPage=size,
        )

        if open_from:
            request.positionOpenTimeFrom.FromDatetime(open_from)
        if open_to:
            request.positionOpenTimeTo.FromDatetime(open_to)

        async def grpc_call(headers):
            timeout = None
            if deadline:
                timeout = (deadline - datetime.utcnow()).total_seconds()
                if timeout < 0:
                    timeout = 0
            return await self.account_client.PositionsHistory(
                request,
                metadata=headers,
                timeout=timeout,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data

#
# Trading helper methods --------------------------------------------------------------------------------------------------------
#

    async def order_send(
        self,
        request: Any,  # account_helper_pb2.OrderSendRequest
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Sends a market or pending order to the trading server asynchronously.

        Args:
            request (OrderSendRequest): The order request to send.
            deadline (datetime, optional): Deadline for the operation.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            OrderSendData: Response with deal/order confirmation data.

        Raises:
            ConnectExceptionMT5: If the account is not connected.
            ApiExceptionMT5: If the server returns an error in the response.
            grpc.aio.AioRpcError: If the gRPC call fails.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        async def grpc_call(headers):
            timeout = None
            if deadline:
                timeout = (deadline - datetime.utcnow()).total_seconds()
                if timeout < 0:
                    timeout = 0
            return await self.trade_client.OrderSend(
                request,
                metadata=headers,
                timeout=timeout,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data


    async def order_modify(
        self,
        request: Any,  # OrderModifyRequest
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Modifies an existing order or position asynchronously.

        Args:
            request (OrderModifyRequest): The modification request (SL, TP, price, expiration, etc.).
            deadline (datetime, optional): Deadline for the operation.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            OrderModifyData: Response containing updated order/deal info.

        Raises:
            ConnectExceptionMT5: If the account is not connected.
            ApiExceptionMT5: If the server returns an error in the response.
            grpc.aio.AioRpcError: If the gRPC call fails.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        async def grpc_call(headers):
            timeout = None
            if deadline:
                timeout = (deadline - datetime.utcnow()).total_seconds()
                if timeout < 0:
                    timeout = 0
            return await self.trade_client.OrderModify(
                request,
                metadata=headers,
                timeout=timeout,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data

    async def order_close(
        self,
        request: Any,  # OrderCloseRequest
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Closes a market or pending order asynchronously.

        Args:
            request (OrderCloseRequest): The close request including ticket, volume, and slippage.
            deadline (datetime, optional): Deadline for the operation.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            OrderCloseData: The close result and return codes.

        Raises:
            ConnectExceptionMT5: If the account is not connected.
            ApiExceptionMT5: If the server returns an error in the response.
            grpc.aio.AioRpcError: If the gRPC call fails.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        async def grpc_call(headers):
            timeout = None
            if deadline:
                timeout = (deadline - datetime.utcnow()).total_seconds()
                if timeout < 0:
                    timeout = 0
            return await self.trade_client.OrderClose(
                request,
                metadata=headers,
                timeout=timeout,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data


#
#    Streams --------------------------------------------------------------------------------------------------------
#    

    async def execute_stream_with_reconnect(
        self,
        request: Any,
        stream_invoker: Callable[[Any, list[tuple[str, str]]], grpc.aio.StreamStreamCall],
        get_error: Callable[[Any], Optional[Any]],
        get_data: Callable[[Any], Any],
        cancellation_event: Optional[asyncio.Event] = None,
    ) -> AsyncGenerator[Any, None]:
        """
        Executes a gRPC server-streaming call with automatic reconnection logic on recoverable errors.

        Args:
            request: The request object to initiate the stream with.
            stream_invoker (Callable): A function that opens the stream. It receives the request and metadata headers,
                and returns an async streaming call.
            get_error (Callable): A function that extracts the error object (if any) from a reply.
                Return an object with .error_code == "TERMINAL_INSTANCE_NOT_FOUND" to trigger reconnect,
                or any non-null error to raise ApiExceptionMT5.
            get_data (Callable): A function that extracts the data object from a reply. If it returns None, the
                message is skipped.
            cancellation_event (asyncio.Event, optional): Event to cancel streaming and reconnection attempts.

        Yields:
            Extracted data items streamed from the server.

        Raises:
            ConnectExceptionMT5: If reconnection logic fails due to missing account context.
            ApiExceptionMT5: When the stream response contains a known API error.
            grpc.aio.AioRpcError: If a non-recoverable gRPC error occurs.
        """
        while cancellation_event is None or not cancellation_event.is_set():
            reconnect_required = False
            stream = None
            try:
                stream = stream_invoker(request, self.get_headers())
                async for reply in stream:
                    error = get_error(reply)

                    if error and error.error_code in (
                        "TERMINAL_INSTANCE_NOT_FOUND",
                        "TERMINAL_REGISTRY_TERMINAL_NOT_FOUND",
                    ):
                        reconnect_required = True
                        break

                    if error and getattr(error, "message", None):
                        raise ApiExceptionMT5(error)

                    data = get_data(reply)
                    if data is not None:
                        yield data

            except grpc.aio.AioRpcError as ex:
                if ex.code() == grpc.StatusCode.UNAVAILABLE:
                    reconnect_required = True
                else:
                    raise

            finally:
                if stream:
                    stream.cancel()  # close stream properly

            if reconnect_required:
                await asyncio.sleep(0.5)
                await self.reconnect()
            else:
                break


    async def on_symbol_tick(
        self,
        symbols: list[str],
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Subscribes to real-time tick data for specified symbols.

        Args:
            symbols (list[str]): The symbol names to subscribe to.
            cancellation_event (asyncio.Event, optional): Event to cancel streaming.

        Yields:
            OnSymbolTickData: Async stream of tick data responses.

        Raises:
            ConnectExceptionMT5: If the account is not connected before calling this method.
            ApiExceptionMT5: If the server returns an error in the stream.
            grpc.aio.AioRpcError: If the stream fails due to communication or protocol errors.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = subscriptions_pb2.OnSymbolTickRequest()
        request.symbol_names.extend(symbols)

        async for data in self.execute_stream_with_reconnect(
            request=request,
            stream_invoker=lambda req, headers: self.subscription_client.OnSymbolTick(req, metadata=headers),
            get_error=lambda reply: reply.error,
            get_data=lambda reply: reply.data,
            cancellation_event=cancellation_event,
        ):
            yield data

    async def on_trade(
        self,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Subscribes to all trade-related events: orders, deals, positions.

        Args:
            cancellation_event (asyncio.Event, optional): Event to cancel streaming.

        Yields:
            OnTradeData: Trade event data.

        Raises:
            ConnectExceptionMT5: If the account is not connected.
            ApiExceptionMT5: If the server returns a known API error.
            grpc.aio.AioRpcError: If the stream fails due to communication or protocol errors.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = subscriptions_pb2.OnTradeRequest()

        async for data in self.execute_stream_with_reconnect(
            request=request,
            stream_invoker=lambda req, headers: self.subscription_client.OnTrade(req, metadata=headers),
            get_error=lambda reply: reply.error,
            get_data=lambda reply: reply.data,
            cancellation_event=cancellation_event,
        ):
            yield data


    async def on_position_profit(
        self,
        interval_ms: int,
        ignore_empty: bool = True,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Subscribes to real-time profit updates for open positions.

        Args:
            interval_ms (int): Interval in milliseconds to poll the server.
            ignore_empty (bool, optional): Skip frames with no change.
            cancellation_event (asyncio.Event, optional): Event to cancel streaming.

        Yields:
            OnPositionProfitData: Profit update data.

        Raises:
            ConnectExceptionMT5: If the account is not connected.
            ApiExceptionMT5: If the server returns a known API error.
            grpc.aio.AioRpcError: If the stream fails due to communication or protocol errors.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = subscriptions_pb2.OnPositionProfitRequest(
            timerPeriodMilliseconds=interval_ms,
            ignoreEmptyData=ignore_empty,
        )

        async for data in self.execute_stream_with_reconnect(
            request=request,
            stream_invoker=lambda req, headers: self.subscription_client.OnPositionProfit(req, metadata=headers),
            get_error=lambda reply: reply.error,
            get_data=lambda reply: reply.data,
            cancellation_event=cancellation_event,
        ):
            yield data


    async def on_positions_and_pending_orders_tickets(
        self,
        interval_ms: int,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Subscribes to updates of position and pending order ticket IDs.

        Args:
            interval_ms (int): Polling interval in milliseconds.
            cancellation_event (asyncio.Event, optional): Event to cancel streaming.

        Yields:
            OnPositionsAndPendingOrdersTicketsData: Snapshot of tickets.

        Raises:
            ConnectExceptionMT5: If the account is not connected.
            ApiExceptionMT5: If the server returns a known API error.
            grpc.aio.AioRpcError: If the stream fails due to communication or protocol errors.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = subscriptions_pb2.OnPositionsAndPendingOrdersTicketsRequest(
            timerPeriodMilliseconds=interval_ms,
        )

        async for data in self.execute_stream_with_reconnect(
            request=request,
            stream_invoker=lambda req, headers: self.subscription_client.OnPositionsAndPendingOrdersTickets(req, metadata=headers),
            get_error=lambda reply: reply.error,
            get_data=lambda reply: reply.data,
            cancellation_event=cancellation_event,
        ):
            yield data


    async def on_trade_transaction(
        self,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Subscribes to real-time trade transaction events such as order creation, update, or execution.

        Args:
            cancellation_event (asyncio.Event, optional): Event to cancel streaming.

        Yields:
            OnTradeTransactionData: Trade transaction replies.

        Raises:
            ConnectExceptionMT5: If the account is not connected.
            ApiExceptionMT5: If the server returns a known API error.
            grpc.aio.AioRpcError: If the stream fails due to communication or protocol errors.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = subscriptions_pb2.OnTradeTransactionRequest()

        async for data in self.execute_stream_with_reconnect(
            request=request,
            stream_invoker=lambda req, headers: self.subscription_client.OnTradeTransaction(req, metadata=headers),
            get_error=lambda reply: reply.error,
            get_data=lambda reply: reply.data,
            cancellation_event=cancellation_event,
        ):
            yield data


# Trade functions --------------------------------------------------------------------------------------------------------


    async def order_calc_margin(
        self,
        request: Any,  # OrderCalcMarginRequest
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Calculates the margin required for a planned trade operation.

        Args:
            request (OrderCalcMarginRequest): The request containing symbol, order type, volume, and price.
            deadline (datetime, optional): Deadline for the gRPC call.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            OrderCalcMarginData: The required margin in account currency.

        Raises:
            ConnectExceptionMT5: If the client is not connected.
            ApiExceptionMT5: If the server returns a business error.
            grpc.aio.AioRpcError: If gRPC fails to connect or respond.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        async def grpc_call(headers):
            timeout = None
            if deadline:
                timeout = (deadline - datetime.utcnow()).total_seconds()
                timeout = max(timeout, 0)
            return await self.trade_functions_client.OrderCalcMargin(
                request,
                metadata=headers,
                timeout=timeout,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data

    async def order_check(
        self,
        request: Any,  # OrderCheckRequest
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Checks whether a trade request can be successfully executed under current market conditions.

        Args:
            request (OrderCheckRequest): The trade request to validate.
            deadline (datetime, optional): Deadline for the gRPC call.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            OrderCheckData: Result of the trade request check, including margin and balance details.

        Raises:
            ConnectExceptionMT5: If the client is not connected.
            ApiExceptionMT5: If the server returns a business error.
            grpc.aio.AioRpcError: If gRPC fails to connect or respond.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        async def grpc_call(headers):
            timeout = None
            if deadline:
                timeout = (deadline - datetime.utcnow()).total_seconds()
                timeout = max(timeout, 0)
            return await self.trade_functions_client.OrderCheck(
                request,
                metadata=headers,
                timeout=timeout,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data

    async def positions_total(
        self,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Returns the total number of open positions on the current account.

        Args:
            deadline (datetime, optional): Deadline for the gRPC call.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            PositionsTotalData: The total number of open positions.

        Raises:
            ConnectExceptionMT5: If the client is not connected.
            ApiExceptionMT5: If the server returns a business error.
            grpc.aio.AioRpcError: If gRPC fails to connect or respond.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = Empty()

        async def grpc_call(headers):
            timeout = None
            if deadline:
                timeout = (deadline - datetime.utcnow()).total_seconds()
                timeout = max(timeout, 0)
            return await self.trade_functions_client.PositionsTotal(
                request,
                metadata=headers,
                timeout=timeout,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data

    async def symbols_total(
        self,
        selected_only: bool,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Returns the total number of symbols available on the platform.

        Args:
            selected_only (bool): True to count only Market Watch symbols, false to count all.
            deadline (datetime, optional): Deadline for the gRPC call.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            SymbolsTotalData: Total symbol count data.

        Raises:
            ConnectExceptionMT5: If the client is not connected.
            ApiExceptionMT5: If the server returns a business error.
            grpc.aio.AioRpcError: If the gRPC call fails.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.SymbolsTotalRequest(mode=selected_only)

        async def grpc_call(headers):
            timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
            return await self.market_info_client.SymbolsTotal(
                request,
                metadata=headers,
                timeout=max(timeout, 0) if timeout else None,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data

    async def symbol_exist(
        self,
        symbol: str,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Checks if a symbol with the specified name exists (standard or custom).

        Args:
            symbol (str): The symbol name to check.
            deadline (datetime, optional): Deadline for the gRPC call.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            SymbolExistData: Information about symbol existence and type.

        Raises:
            ConnectExceptionMT5: If the client is not connected.
            ApiExceptionMT5: If the server returns a business error.
            grpc.aio.AioRpcError: If the gRPC call fails.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.SymbolExistRequest(name=symbol)

        async def grpc_call(headers):
            timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
            return await self.market_info_client.SymbolExist(
                request,
                metadata=headers,
                timeout=max(timeout, 0) if timeout else None,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data

    async def symbol_name(
        self,
        index: int,
        selected: bool,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Returns the name of a symbol by index.

        Args:
            index (int): Symbol index (starting at 0).
            selected (bool): True to use only Market Watch symbols.
            deadline (datetime, optional): Deadline for the gRPC call.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            SymbolNameData: The symbol name at the specified index.

        Raises:
            ConnectExceptionMT5: If the client is not connected.
            ApiExceptionMT5: If the server returns a business error.
            grpc.aio.AioRpcError: If the gRPC call fails.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.SymbolNameRequest(index=index, selected=selected)

        async def grpc_call(headers):
            timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
            return await self.market_info_client.SymbolName(
                request,
                metadata=headers,
                timeout=max(timeout, 0) if timeout else None,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data

    async def symbol_select(
        self,
        symbol: str,
        select: bool,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Adds or removes a symbol from Market Watch.

        Args:
            symbol (str): Symbol name.
            select (bool): True to add, false to remove.
            deadline (datetime, optional): Deadline for the gRPC call.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            SymbolSelectData: Success status of the operation.

        Raises:
            ConnectExceptionMT5: If the client is not connected.
            ApiExceptionMT5: If the server returns a business error.
            grpc.aio.AioRpcError: If the gRPC call fails.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.SymbolSelectRequest(symbol=symbol, select=select)

        async def grpc_call(headers):
            timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
            return await self.market_info_client.SymbolSelect(
                request,
                metadata=headers,
                timeout=max(timeout, 0) if timeout else None,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data

    async def symbol_is_synchronized(
        self,
        symbol: str,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Checks if the symbol's data is synchronized with the server.

        Args:
            symbol (str): Symbol name to check.
            deadline (datetime, optional): Deadline for the gRPC call.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            SymbolIsSynchronizedData: True if synchronized, false otherwise.

        Raises:
            ConnectExceptionMT5: If the client is not connected.
            ApiExceptionMT5: If the server returns a business error.
            grpc.aio.AioRpcError: If the gRPC call fails.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.SymbolIsSynchronizedRequest(symbol=symbol)

        async def grpc_call(headers):
            timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
            return await self.market_info_client.SymbolIsSynchronized(
                request,
                metadata=headers,
                timeout=max(timeout, 0) if timeout else None,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data

    async def symbol_info_double(
        self,
        symbol: str,
        property: market_info_pb2.SymbolInfoDoubleProperty,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Retrieves a double-precision property value of a symbol.

        Args:
            symbol (str): Symbol name.
            property (SymbolInfoDoubleProperty): The double-type property to retrieve.
            deadline (datetime, optional): Deadline for the gRPC call.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            SymbolInfoDoubleData: The double property value.

        Raises:
            ConnectExceptionMT5: If the client is not connected.
            ApiExceptionMT5: If the server returns a business error.
            grpc.aio.AioRpcError: If the gRPC call fails.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.SymbolInfoDoubleRequest(symbol=symbol, type=property)

        async def grpc_call(headers):
            timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
            return await self.market_info_client.SymbolInfoDouble(
                request,
                metadata=headers,
                timeout=max(timeout, 0) if timeout else None,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data

    async def symbol_info_integer(
        self,
        symbol: str,
        property: market_info_pb2.SymbolInfoIntegerProperty,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Retrieves an integer-type property value of a symbol.

        Args:
            symbol (str): Symbol name.
            property (SymbolInfoIntegerProperty): The integer property to query.
            deadline (datetime, optional): Deadline for the gRPC call.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            SymbolInfoIntegerData: The integer property value.

        Raises:
            ConnectExceptionMT5: If the client is not connected.
            ApiExceptionMT5: If the server returns a business error.
            grpc.aio.AioRpcError: If the gRPC call fails.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.SymbolInfoIntegerRequest(symbol=symbol, type=property)

        async def grpc_call(headers):
            timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
            return await self.market_info_client.SymbolInfoInteger(
                request,
                metadata=headers,
                timeout=max(timeout, 0) if timeout else None,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data

    async def symbol_info_string(
        self,
        symbol: str,
        property: market_info_pb2.SymbolInfoStringProperty,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Retrieves a string-type property value of a symbol.

        Args:
            symbol (str): Symbol name.
            property (SymbolInfoStringProperty): The string property to retrieve.
            deadline (datetime, optional): Deadline for the gRPC call.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            SymbolInfoStringData: The string property value.

        Raises:
            ConnectExceptionMT5: If the client is not connected.
            ApiExceptionMT5: If the server returns a business error.
            grpc.aio.AioRpcError: If the gRPC call fails.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.SymbolInfoStringRequest(symbol=symbol, type=property)

        async def grpc_call(headers):
            timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
            return await self.market_info_client.SymbolInfoString(
                request,
                metadata=headers,
                timeout=max(timeout, 0) if timeout else None,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data

    async def symbol_info_margin_rate(
        self,
        symbol: str,
        order_type: market_info_pb2.ENUM_ORDER_TYPE,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Retrieves the margin rates for a given symbol and order type.

        Args:
            symbol (str): Symbol name.
            order_type (ENUM_ORDER_TYPE): The order type (buy/sell/etc).
            deadline (datetime, optional): Deadline for the gRPC call.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            SymbolInfoMarginRateData: The initial and maintenance margin rates.

        Raises:
            ConnectExceptionMT5: If the client is not connected.
            ApiExceptionMT5: If the server returns a business error.
            grpc.aio.AioRpcError: If the gRPC call fails.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.SymbolInfoMarginRateRequest(symbol=symbol, orderType=order_type)

        async def grpc_call(headers):
            timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
            return await self.market_info_client.SymbolInfoMarginRate(
                request,
                metadata=headers,
                timeout=max(timeout, 0) if timeout else None,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data

    async def symbol_info_tick(
        self,
        symbol: str,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Retrieves the current tick data (bid, ask, last, volume) for a given symbol.

        Args:
            symbol (str): Symbol name to fetch tick info for.
            deadline (datetime, optional): Deadline for the gRPC call.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            MrpcMqlTick: The latest tick information.

        Raises:
            ConnectExceptionMT5: If the account is not connected.
            ApiExceptionMT5: If the server returns an error in the response.
            grpc.aio.AioRpcError: If the gRPC call fails.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.SymbolInfoTickRequest(symbol=symbol)

        async def grpc_call(headers):
            timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
            return await self.market_info_client.SymbolInfoTick(
                request,
                metadata=headers,
                timeout=max(timeout, 0) if timeout else None,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data

    async def symbol_info_session_quote(
        self,
        symbol: str,
        day_of_week: market_info_pb2.DayOfWeek,
        session_index: int,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Gets the quoting session start and end time for a symbol on a specific day and session index.

        Args:
            symbol (str): The symbol name.
            day_of_week (DayOfWeek): The day of the week.
            session_index (int): Index of the quoting session (starting at 0).
            deadline (datetime, optional): Deadline for the gRPC call.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            SymbolInfoSessionQuoteData: The session quote start and end time.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.SymbolInfoSessionQuoteRequest(
            symbol=symbol,
            dayOfWeek=day_of_week,
            sessionIndex=session_index,
        )

        async def grpc_call(headers):
            timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
            return await self.market_info_client.SymbolInfoSessionQuote(
                request,
                metadata=headers,
                timeout=max(timeout, 0) if timeout else None,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data

    async def symbol_info_session_trade(
        self,
        symbol: str,
        day_of_week: market_info_pb2.DayOfWeek,
        session_index: int,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Gets the trading session start and end time for a symbol on a specific day and session index.

        Args:
            symbol (str): The symbol name.
            day_of_week (DayOfWeek): The day of the week.
            session_index (int): Index of the trading session (starting at 0).
            deadline (datetime, optional): Deadline for the gRPC call.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            SymbolInfoSessionTradeData: The trading session start and end time.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.SymbolInfoSessionTradeRequest(
            symbol=symbol,
            dayOfWeek=day_of_week,
            sessionIndex=session_index,
        )

        async def grpc_call(headers):
            timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
            return await self.market_info_client.SymbolInfoSessionTrade(
                request,
                metadata=headers,
                timeout=max(timeout, 0) if timeout else None,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data

    async def market_book_add(
        self,
        symbol: str,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Opens the Depth of Market (DOM) for a symbol and subscribes to updates.

        Args:
            symbol (str): Symbol name to subscribe.
            deadline (datetime, optional): Deadline for the gRPC call.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            MarketBookAddData: True if DOM subscription was successful.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.MarketBookAddRequest(symbol=symbol)

        async def grpc_call(headers):
            timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
            return await self.market_info_client.MarketBookAdd(
                request,
                metadata=headers,
                timeout=max(timeout, 0) if timeout else None,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data

    async def market_book_release(
        self,
        symbol: str,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Releases the Depth of Market (DOM) for a symbol and stops receiving updates.

        Args:
            symbol (str): Symbol name to unsubscribe.
            deadline (datetime, optional): Deadline for the gRPC call.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            MarketBookReleaseData: True if DOM release was successful.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.MarketBookReleaseRequest(symbol=symbol)

        async def grpc_call(headers):
            timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
            return await self.market_info_client.MarketBookRelease(
                request,
                metadata=headers,
                timeout=max(timeout, 0) if timeout else None,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data

    async def market_book_get(
        self,
        symbol: str,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ):
        """
        Gets the current Depth of Market (DOM) data for a symbol.

        Args:
            symbol (str): Symbol name.
            deadline (datetime, optional): Deadline for the gRPC call.
            cancellation_event (asyncio.Event, optional): Event to cancel the request.

        Returns:
            MarketBookGetData: A list of book entries for the symbol's DOM.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.MarketBookGetRequest(symbol=symbol)

        async def grpc_call(headers):
            timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
            return await self.market_info_client.MarketBookGet(
                request,
                metadata=headers,
                timeout=max(timeout, 0) if timeout else None,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda r: getattr(r, "error", None),
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data


 # Account info --------------------------------------------------------------------------------------------------------

    async def account_info_double(
        self,
        property_id: account_info_pb2.AccountInfoDoublePropertyType,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ) -> float:
        """
        Retrieves a double-precision account property (e.g. balance, equity, margin).

        Args:
            property_id (AccountInfoDoublePropertyType): The account double property to retrieve.
            deadline (datetime, optional): Deadline after which the call will be cancelled.
            cancellation_event (asyncio.Event, optional): Event to cancel the operation.

        Returns:
            float: The double value of the requested account property.

        Raises:
            ConnectExceptionMT5: If the client is not connected.
            ApiExceptionMT5: If the server returns a business error.
            grpc.aio.AioRpcError: If the gRPC call fails.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.AccountInfoDoubleRequest(propertyId=property_id)

        async def grpc_call(headers):
            timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
            return await self.account_information_client.AccountInfoDouble(
                request,
                metadata=headers,
                timeout=max(timeout, 0) if timeout else None,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda _: None,  # no error field
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data.requestedValue

    async def account_info_integer(
        self,
        property_id: account_info_pb2.AccountInfoIntegerPropertyType,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ) -> int:
        """
        Retrieves an integer account property (e.g. login, leverage, trade mode).

        Args:
            property_id (AccountInfoIntegerPropertyType): The account integer property to retrieve.
            deadline (datetime, optional): Deadline after which the call will be cancelled.
            cancellation_event (asyncio.Event, optional): Event to cancel the operation.

        Returns:
            int: The integer value of the requested account property.

        Raises:
            ConnectExceptionMT5: If the client is not connected.
            ApiExceptionMT5: If the server returns a business error.
            grpc.aio.AioRpcError: If the gRPC call fails.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.AccountInfoIntegerRequest(propertyId=property_id)

        async def grpc_call(headers):
            timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
            return await self.account_information_client.AccountInfoInteger(
                request,
                metadata=headers,
                timeout=max(timeout, 0) if timeout else None,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda _: None,  # no error field
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data.requestedValue

    async def account_info_string(
        self,
        property_id: account_info_pb2.AccountInfoStringPropertyType,
        deadline: Optional[datetime] = None,
        cancellation_event: Optional[asyncio.Event] = None,
    ) -> str:
        """
        Retrieves a string account property (e.g. account name, currency, server).

        Args:
            property_id (AccountInfoStringPropertyType): The account string property to retrieve.
            deadline (datetime, optional): Deadline after which the call will be cancelled.
            cancellation_event (asyncio.Event, optional): Event to cancel the operation.

        Returns:
            str: The string value of the requested account property.

        Raises:
            ConnectExceptionMT5: If the client is not connected.
            ApiExceptionMT5: If the server returns a business error.
            grpc.aio.AioRpcError: If the gRPC call fails.
        """
        if not self.id:
            raise ConnectExceptionMT5("Please call connect method first")

        request = account_helper_pb2.AccountInfoStringRequest(propertyId=property_id)

        async def grpc_call(headers):
            timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
            return await self.account_information_client.AccountInfoString(
                request,
                metadata=headers,
                timeout=max(timeout, 0) if timeout else None,
            )

        res = await self.execute_with_reconnect(
            grpc_call=grpc_call,
            error_selector=lambda _: None,  # no error field
            deadline=deadline,
            cancellation_event=cancellation_event,
        )
        return res.data.requestedValue

account_summary(deadline=None, cancellation_event=None) async

Gets the summary information for a trading account asynchronously.

Parameters:

Name Type Description Default
deadline datetime

Deadline after which the request will be canceled if not completed.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
AccountSummaryData

The server's response containing account summary data.

Raises:

Type Description
ConnectExceptionMT5

If the account is not connected before calling this method.

ApiExceptionMT5

If the server returns an error in the response.

AioRpcError

If the gRPC call fails due to communication or protocol errors.

Source code in package/MetaRpcMT5/mt5_account.py
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
async def account_summary(
    self,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Gets the summary information for a trading account asynchronously.

    Args:
        deadline (datetime, optional): Deadline after which the request will be canceled
            if not completed.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        AccountSummaryData: The server's response containing account summary data.

    Raises:
        ConnectExceptionMT5: If the account is not connected before calling this method.
        ApiExceptionMT5: If the server returns an error in the response.
        grpc.aio.AioRpcError: If the gRPC call fails due to communication or protocol errors.
    """
    if not (self.host or self.server_name):
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.AccountSummaryRequest()

    async def grpc_call(headers):
        timeout = None
        if deadline:
            timeout = (deadline - datetime.utcnow()).total_seconds()
            if timeout < 0:
                timeout = 0
        return await self.account_client.AccountSummary(
            request,
            metadata=headers,
            timeout=timeout,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )

    return res.data

opened_orders(sort_mode=account_helper_pb2.BMT5_ENUM_OPENED_ORDER_SORT_TYPE.BMT5_OPENED_ORDER_SORT_BY_OPEN_TIME_ASC, deadline=None, cancellation_event=None) async

Gets the currently opened orders and positions for the connected account asynchronously.

Parameters:

Name Type Description Default
sort_mode BMT5_ENUM_OPENED_ORDER_SORT_TYPE

The sort mode for the opened orders (0 - open time, 1 - close time, 2 - ticket ID).

BMT5_OPENED_ORDER_SORT_BY_OPEN_TIME_ASC
deadline datetime

Deadline after which the request will be canceled if not completed.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
OpenedOrdersData

The result containing opened orders and positions.

Raises:

Type Description
ConnectExceptionMT5

If the account is not connected before calling this method.

ApiExceptionMT5

If the server returns an error in the response.

AioRpcError

If the gRPC call fails due to communication or protocol errors.

Source code in package/MetaRpcMT5/mt5_account.py
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
async def opened_orders(
    self,
    sort_mode: account_helper_pb2.BMT5_ENUM_OPENED_ORDER_SORT_TYPE = account_helper_pb2.BMT5_ENUM_OPENED_ORDER_SORT_TYPE.BMT5_OPENED_ORDER_SORT_BY_OPEN_TIME_ASC,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Gets the currently opened orders and positions for the connected account asynchronously.

    Args:
        sort_mode (BMT5_ENUM_OPENED_ORDER_SORT_TYPE): The sort mode for the opened orders
            (0 - open time, 1 - close time, 2 - ticket ID).
        deadline (datetime, optional): Deadline after which the request will be canceled
            if not completed.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        OpenedOrdersData: The result containing opened orders and positions.

    Raises:
        ConnectExceptionMT5: If the account is not connected before calling this method.
        ApiExceptionMT5: If the server returns an error in the response.
        grpc.aio.AioRpcError: If the gRPC call fails due to communication or protocol errors.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.OpenedOrdersRequest(inputSortMode=sort_mode)

    async def grpc_call(headers):
        timeout = None
        if deadline:
            timeout = (deadline - datetime.utcnow()).total_seconds()
            if timeout < 0:
                timeout = 0
        return await self.account_client.OpenedOrders(
            request,
            metadata=headers,
            timeout=timeout,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

order_history(from_dt, to_dt, sort_mode=account_helper_pb2.BMT5_ENUM_ORDER_HISTORY_SORT_TYPE.BMT5_SORT_BY_CLOSE_TIME_ASC, page_number=0, items_per_page=0, deadline=None, cancellation_event=None) async

Gets the historical orders for the connected trading account within the specified time range asynchronously.

Parameters:

Name Type Description Default
from_dt datetime

The start time for the history query (server time).

required
to_dt datetime

The end time for the history query (server time).

required
sort_mode BMT5_ENUM_ORDER_HISTORY_SORT_TYPE

The sort mode (0 - by open time, 1 - by close time, 2 - by ticket ID).

BMT5_SORT_BY_CLOSE_TIME_ASC
page_number int

Page number for paginated results (default 0).

0
items_per_page int

Number of items per page (default 0 = all).

0
deadline datetime

Deadline after which the request will be canceled.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
OrdersHistoryData

The server's response containing paged historical order data.

Raises:

Type Description
ConnectExceptionMT5

If the account is not connected before calling this method.

ApiExceptionMT5

If the server returns an error in the response.

AioRpcError

If the gRPC call fails due to communication or protocol errors.

Source code in package/MetaRpcMT5/mt5_account.py
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
async def order_history(
    self,
    from_dt: datetime,
    to_dt: datetime,
    sort_mode: account_helper_pb2.BMT5_ENUM_ORDER_HISTORY_SORT_TYPE = account_helper_pb2.BMT5_ENUM_ORDER_HISTORY_SORT_TYPE.BMT5_SORT_BY_CLOSE_TIME_ASC,
    page_number: int = 0,
    items_per_page: int = 0,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Gets the historical orders for the connected trading account within the specified
    time range asynchronously.

    Args:
        from_dt (datetime): The start time for the history query (server time).
        to_dt (datetime): The end time for the history query (server time).
        sort_mode (BMT5_ENUM_ORDER_HISTORY_SORT_TYPE, optional):
            The sort mode (0 - by open time, 1 - by close time, 2 - by ticket ID).
        page_number (int, optional): Page number for paginated results (default 0).
        items_per_page (int, optional): Number of items per page (default 0 = all).
        deadline (datetime, optional): Deadline after which the request will be canceled.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        OrdersHistoryData: The server's response containing paged historical order data.

    Raises:
        ConnectExceptionMT5: If the account is not connected before calling this method.
        ApiExceptionMT5: If the server returns an error in the response.
        grpc.aio.AioRpcError: If the gRPC call fails due to communication or protocol errors.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.OrderHistoryRequest(
        inputFrom=Timestamp().FromDatetime(from_dt),
        inputTo=Timestamp().FromDatetime(to_dt),
        inputSortMode=sort_mode,
        pageNumber=page_number,
        itemsPerPage=items_per_page,
    )

    async def grpc_call(headers):
        timeout = None
        if deadline:
            timeout = (deadline - datetime.utcnow()).total_seconds()
            if timeout < 0:
                timeout = 0
        return await self.account_client.OrderHistory(
            request,
            metadata=headers,
            timeout=timeout,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

opened_orders_tickets(deadline=None, cancellation_event=None) async

Gets ticket IDs of all currently opened orders and positions asynchronously.

Parameters:

Name Type Description Default
deadline datetime

Deadline after which the request will be canceled.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
OpenedOrdersTicketsData

Collection of opened order and position tickets.

Raises:

Type Description
ConnectExceptionMT5

If the account is not connected before calling this method.

ApiExceptionMT5

If the server returns an error in the response.

AioRpcError

If the gRPC call fails due to communication or protocol errors.

Source code in package/MetaRpcMT5/mt5_account.py
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
async def opened_orders_tickets(
    self,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Gets ticket IDs of all currently opened orders and positions asynchronously.

    Args:
        deadline (datetime, optional): Deadline after which the request will be canceled.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        OpenedOrdersTicketsData: Collection of opened order and position tickets.

    Raises:
        ConnectExceptionMT5: If the account is not connected before calling this method.
        ApiExceptionMT5: If the server returns an error in the response.
        grpc.aio.AioRpcError: If the gRPC call fails due to communication or protocol errors.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.OpenedOrdersTicketsRequest()

    async def grpc_call(headers):
        timeout = None
        if deadline:
            timeout = (deadline - datetime.utcnow()).total_seconds()
            if timeout < 0:
                timeout = 0
        return await self.account_client.OpenedOrdersTickets(
            request,
            metadata=headers,
            timeout=timeout,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

symbol_params_many(request, deadline=None, cancellation_event=None) async

Retrieves symbol parameters for multiple instruments asynchronously.

Parameters:

Name Type Description Default
request SymbolParamsManyRequest

The request containing filters and pagination.

required
deadline datetime

Deadline after which the request will be canceled.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
SymbolParamsManyData

Symbol parameter details.

Raises:

Type Description
ConnectExceptionMT5

If the account is not connected before calling this method.

ApiExceptionMT5

If the server returns an error in the response.

AioRpcError

If the gRPC call fails due to communication or protocol errors.

Source code in package/MetaRpcMT5/mt5_account.py
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
async def symbol_params_many(
    self,
    request: account_helper_pb2.SymbolParamsManyRequest,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Retrieves symbol parameters for multiple instruments asynchronously.

    Args:
        request (SymbolParamsManyRequest): The request containing filters and pagination.
        deadline (datetime, optional): Deadline after which the request will be canceled.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        SymbolParamsManyData: Symbol parameter details.

    Raises:
        ConnectExceptionMT5: If the account is not connected before calling this method.
        ApiExceptionMT5: If the server returns an error in the response.
        grpc.aio.AioRpcError: If the gRPC call fails due to communication or protocol errors.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    async def grpc_call(headers):
        timeout = None
        if deadline:
            timeout = (deadline - datetime.utcnow()).total_seconds()
            if timeout < 0:
                timeout = 0
        return await self.account_client.SymbolParamsMany(
            request,
            metadata=headers,
            timeout=timeout,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

tick_value_with_size(symbols, deadline=None, cancellation_event=None) async

Gets tick value and tick size data for the given symbols asynchronously.

Parameters:

Name Type Description Default
symbols list[str]

List of symbol names.

required
deadline datetime

Deadline after which the request will be canceled.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
TickValueWithSizeData

Tick value and contract size info per symbol.

Raises:

Type Description
ConnectExceptionMT5

If the account is not connected before calling this method.

ApiExceptionMT5

If the server returns an error in the response.

AioRpcError

If the gRPC call fails due to communication or protocol errors.

Source code in package/MetaRpcMT5/mt5_account.py
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
async def tick_value_with_size(
    self,
    symbols: list[str],
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Gets tick value and tick size data for the given symbols asynchronously.

    Args:
        symbols (list[str]): List of symbol names.
        deadline (datetime, optional): Deadline after which the request will be canceled.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        TickValueWithSizeData: Tick value and contract size info per symbol.

    Raises:
        ConnectExceptionMT5: If the account is not connected before calling this method.
        ApiExceptionMT5: If the server returns an error in the response.
        grpc.aio.AioRpcError: If the gRPC call fails due to communication or protocol errors.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.TickValueWithSizeRequest()
    request.symbol_names.extend(symbols)

    async def grpc_call(headers):
        timeout = None
        if deadline:
            timeout = (deadline - datetime.utcnow()).total_seconds()
            if timeout < 0:
                timeout = 0
        return await self.account_client.TickValueWithSize(
            request,
            metadata=headers,
            timeout=timeout,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

positions_history(sort_type, open_from=None, open_to=None, page=0, size=0, deadline=None, cancellation_event=None) async

Retrieves historical positions based on filter and time range asynchronously.

Parameters:

Name Type Description Default
sort_type AH_ENUM_POSITIONS_HISTORY_SORT_TYPE

Sorting type for historical positions.

required
open_from datetime

Start of open time filter (UTC).

None
open_to datetime

End of open time filter (UTC).

None
page int

Page number for paginated results (default 0).

0
size int

Number of items per page (default 0 = all).

0
deadline datetime

Deadline after which the request will be canceled.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
PositionsHistoryData

Historical position records.

Raises:

Type Description
ConnectExceptionMT5

If the account is not connected before calling this method.

ApiExceptionMT5

If the server returns an error in the response.

AioRpcError

If the gRPC call fails due to communication or protocol errors.

Source code in package/MetaRpcMT5/mt5_account.py
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
async def positions_history(
self,
sort_type: account_helper_pb2.AH_ENUM_POSITIONS_HISTORY_SORT_TYPE,
open_from: Optional[datetime] = None,
open_to: Optional[datetime] = None,
page: int = 0,
size: int = 0,
deadline: Optional[datetime] = None,
cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Retrieves historical positions based on filter and time range asynchronously.

    Args:
        sort_type (AH_ENUM_POSITIONS_HISTORY_SORT_TYPE): Sorting type for historical positions.
        open_from (datetime, optional): Start of open time filter (UTC).
        open_to (datetime, optional): End of open time filter (UTC).
        page (int, optional): Page number for paginated results (default 0).
        size (int, optional): Number of items per page (default 0 = all).
        deadline (datetime, optional): Deadline after which the request will be canceled.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        PositionsHistoryData: Historical position records.

    Raises:
        ConnectExceptionMT5: If the account is not connected before calling this method.
        ApiExceptionMT5: If the server returns an error in the response.
        grpc.aio.AioRpcError: If the gRPC call fails due to communication or protocol errors.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.PositionsHistoryRequest(
        sort_type=sort_type,
        pageNumber=page,
        itemsPerPage=size,
    )

    if open_from:
        request.positionOpenTimeFrom.FromDatetime(open_from)
    if open_to:
        request.positionOpenTimeTo.FromDatetime(open_to)

    async def grpc_call(headers):
        timeout = None
        if deadline:
            timeout = (deadline - datetime.utcnow()).total_seconds()
            if timeout < 0:
                timeout = 0
        return await self.account_client.PositionsHistory(
            request,
            metadata=headers,
            timeout=timeout,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

order_send(request, deadline=None, cancellation_event=None) async

Sends a market or pending order to the trading server asynchronously.

Parameters:

Name Type Description Default
request OrderSendRequest

The order request to send.

required
deadline datetime

Deadline for the operation.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
OrderSendData

Response with deal/order confirmation data.

Raises:

Type Description
ConnectExceptionMT5

If the account is not connected.

ApiExceptionMT5

If the server returns an error in the response.

AioRpcError

If the gRPC call fails.

Source code in package/MetaRpcMT5/mt5_account.py
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
async def order_send(
    self,
    request: Any,  # account_helper_pb2.OrderSendRequest
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Sends a market or pending order to the trading server asynchronously.

    Args:
        request (OrderSendRequest): The order request to send.
        deadline (datetime, optional): Deadline for the operation.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        OrderSendData: Response with deal/order confirmation data.

    Raises:
        ConnectExceptionMT5: If the account is not connected.
        ApiExceptionMT5: If the server returns an error in the response.
        grpc.aio.AioRpcError: If the gRPC call fails.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    async def grpc_call(headers):
        timeout = None
        if deadline:
            timeout = (deadline - datetime.utcnow()).total_seconds()
            if timeout < 0:
                timeout = 0
        return await self.trade_client.OrderSend(
            request,
            metadata=headers,
            timeout=timeout,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

order_modify(request, deadline=None, cancellation_event=None) async

Modifies an existing order or position asynchronously.

Parameters:

Name Type Description Default
request OrderModifyRequest

The modification request (SL, TP, price, expiration, etc.).

required
deadline datetime

Deadline for the operation.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
OrderModifyData

Response containing updated order/deal info.

Raises:

Type Description
ConnectExceptionMT5

If the account is not connected.

ApiExceptionMT5

If the server returns an error in the response.

AioRpcError

If the gRPC call fails.

Source code in package/MetaRpcMT5/mt5_account.py
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
async def order_modify(
    self,
    request: Any,  # OrderModifyRequest
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Modifies an existing order or position asynchronously.

    Args:
        request (OrderModifyRequest): The modification request (SL, TP, price, expiration, etc.).
        deadline (datetime, optional): Deadline for the operation.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        OrderModifyData: Response containing updated order/deal info.

    Raises:
        ConnectExceptionMT5: If the account is not connected.
        ApiExceptionMT5: If the server returns an error in the response.
        grpc.aio.AioRpcError: If the gRPC call fails.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    async def grpc_call(headers):
        timeout = None
        if deadline:
            timeout = (deadline - datetime.utcnow()).total_seconds()
            if timeout < 0:
                timeout = 0
        return await self.trade_client.OrderModify(
            request,
            metadata=headers,
            timeout=timeout,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

order_close(request, deadline=None, cancellation_event=None) async

Closes a market or pending order asynchronously.

Parameters:

Name Type Description Default
request OrderCloseRequest

The close request including ticket, volume, and slippage.

required
deadline datetime

Deadline for the operation.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
OrderCloseData

The close result and return codes.

Raises:

Type Description
ConnectExceptionMT5

If the account is not connected.

ApiExceptionMT5

If the server returns an error in the response.

AioRpcError

If the gRPC call fails.

Source code in package/MetaRpcMT5/mt5_account.py
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
async def order_close(
    self,
    request: Any,  # OrderCloseRequest
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Closes a market or pending order asynchronously.

    Args:
        request (OrderCloseRequest): The close request including ticket, volume, and slippage.
        deadline (datetime, optional): Deadline for the operation.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        OrderCloseData: The close result and return codes.

    Raises:
        ConnectExceptionMT5: If the account is not connected.
        ApiExceptionMT5: If the server returns an error in the response.
        grpc.aio.AioRpcError: If the gRPC call fails.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    async def grpc_call(headers):
        timeout = None
        if deadline:
            timeout = (deadline - datetime.utcnow()).total_seconds()
            if timeout < 0:
                timeout = 0
        return await self.trade_client.OrderClose(
            request,
            metadata=headers,
            timeout=timeout,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

execute_stream_with_reconnect(request, stream_invoker, get_error, get_data, cancellation_event=None) async

Executes a gRPC server-streaming call with automatic reconnection logic on recoverable errors.

Parameters:

Name Type Description Default
request Any

The request object to initiate the stream with.

required
stream_invoker Callable

A function that opens the stream. It receives the request and metadata headers, and returns an async streaming call.

required
get_error Callable

A function that extracts the error object (if any) from a reply. Return an object with .error_code == "TERMINAL_INSTANCE_NOT_FOUND" to trigger reconnect, or any non-null error to raise ApiExceptionMT5.

required
get_data Callable

A function that extracts the data object from a reply. If it returns None, the message is skipped.

required
cancellation_event Event

Event to cancel streaming and reconnection attempts.

None

Yields:

Type Description
AsyncGenerator[Any, None]

Extracted data items streamed from the server.

Raises:

Type Description
ConnectExceptionMT5

If reconnection logic fails due to missing account context.

ApiExceptionMT5

When the stream response contains a known API error.

AioRpcError

If a non-recoverable gRPC error occurs.

Source code in package/MetaRpcMT5/mt5_account.py
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
async def execute_stream_with_reconnect(
    self,
    request: Any,
    stream_invoker: Callable[[Any, list[tuple[str, str]]], grpc.aio.StreamStreamCall],
    get_error: Callable[[Any], Optional[Any]],
    get_data: Callable[[Any], Any],
    cancellation_event: Optional[asyncio.Event] = None,
) -> AsyncGenerator[Any, None]:
    """
    Executes a gRPC server-streaming call with automatic reconnection logic on recoverable errors.

    Args:
        request: The request object to initiate the stream with.
        stream_invoker (Callable): A function that opens the stream. It receives the request and metadata headers,
            and returns an async streaming call.
        get_error (Callable): A function that extracts the error object (if any) from a reply.
            Return an object with .error_code == "TERMINAL_INSTANCE_NOT_FOUND" to trigger reconnect,
            or any non-null error to raise ApiExceptionMT5.
        get_data (Callable): A function that extracts the data object from a reply. If it returns None, the
            message is skipped.
        cancellation_event (asyncio.Event, optional): Event to cancel streaming and reconnection attempts.

    Yields:
        Extracted data items streamed from the server.

    Raises:
        ConnectExceptionMT5: If reconnection logic fails due to missing account context.
        ApiExceptionMT5: When the stream response contains a known API error.
        grpc.aio.AioRpcError: If a non-recoverable gRPC error occurs.
    """
    while cancellation_event is None or not cancellation_event.is_set():
        reconnect_required = False
        stream = None
        try:
            stream = stream_invoker(request, self.get_headers())
            async for reply in stream:
                error = get_error(reply)

                if error and error.error_code in (
                    "TERMINAL_INSTANCE_NOT_FOUND",
                    "TERMINAL_REGISTRY_TERMINAL_NOT_FOUND",
                ):
                    reconnect_required = True
                    break

                if error and getattr(error, "message", None):
                    raise ApiExceptionMT5(error)

                data = get_data(reply)
                if data is not None:
                    yield data

        except grpc.aio.AioRpcError as ex:
            if ex.code() == grpc.StatusCode.UNAVAILABLE:
                reconnect_required = True
            else:
                raise

        finally:
            if stream:
                stream.cancel()  # close stream properly

        if reconnect_required:
            await asyncio.sleep(0.5)
            await self.reconnect()
        else:
            break

on_symbol_tick(symbols, cancellation_event=None) async

Subscribes to real-time tick data for specified symbols.

Parameters:

Name Type Description Default
symbols list[str]

The symbol names to subscribe to.

required
cancellation_event Event

Event to cancel streaming.

None

Yields:

Name Type Description
OnSymbolTickData

Async stream of tick data responses.

Raises:

Type Description
ConnectExceptionMT5

If the account is not connected before calling this method.

ApiExceptionMT5

If the server returns an error in the stream.

AioRpcError

If the stream fails due to communication or protocol errors.

Source code in package/MetaRpcMT5/mt5_account.py
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
async def on_symbol_tick(
    self,
    symbols: list[str],
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Subscribes to real-time tick data for specified symbols.

    Args:
        symbols (list[str]): The symbol names to subscribe to.
        cancellation_event (asyncio.Event, optional): Event to cancel streaming.

    Yields:
        OnSymbolTickData: Async stream of tick data responses.

    Raises:
        ConnectExceptionMT5: If the account is not connected before calling this method.
        ApiExceptionMT5: If the server returns an error in the stream.
        grpc.aio.AioRpcError: If the stream fails due to communication or protocol errors.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = subscriptions_pb2.OnSymbolTickRequest()
    request.symbol_names.extend(symbols)

    async for data in self.execute_stream_with_reconnect(
        request=request,
        stream_invoker=lambda req, headers: self.subscription_client.OnSymbolTick(req, metadata=headers),
        get_error=lambda reply: reply.error,
        get_data=lambda reply: reply.data,
        cancellation_event=cancellation_event,
    ):
        yield data

on_trade(cancellation_event=None) async

Subscribes to all trade-related events: orders, deals, positions.

Parameters:

Name Type Description Default
cancellation_event Event

Event to cancel streaming.

None

Yields:

Name Type Description
OnTradeData

Trade event data.

Raises:

Type Description
ConnectExceptionMT5

If the account is not connected.

ApiExceptionMT5

If the server returns a known API error.

AioRpcError

If the stream fails due to communication or protocol errors.

Source code in package/MetaRpcMT5/mt5_account.py
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
async def on_trade(
    self,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Subscribes to all trade-related events: orders, deals, positions.

    Args:
        cancellation_event (asyncio.Event, optional): Event to cancel streaming.

    Yields:
        OnTradeData: Trade event data.

    Raises:
        ConnectExceptionMT5: If the account is not connected.
        ApiExceptionMT5: If the server returns a known API error.
        grpc.aio.AioRpcError: If the stream fails due to communication or protocol errors.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = subscriptions_pb2.OnTradeRequest()

    async for data in self.execute_stream_with_reconnect(
        request=request,
        stream_invoker=lambda req, headers: self.subscription_client.OnTrade(req, metadata=headers),
        get_error=lambda reply: reply.error,
        get_data=lambda reply: reply.data,
        cancellation_event=cancellation_event,
    ):
        yield data

on_position_profit(interval_ms, ignore_empty=True, cancellation_event=None) async

Subscribes to real-time profit updates for open positions.

Parameters:

Name Type Description Default
interval_ms int

Interval in milliseconds to poll the server.

required
ignore_empty bool

Skip frames with no change.

True
cancellation_event Event

Event to cancel streaming.

None

Yields:

Name Type Description
OnPositionProfitData

Profit update data.

Raises:

Type Description
ConnectExceptionMT5

If the account is not connected.

ApiExceptionMT5

If the server returns a known API error.

AioRpcError

If the stream fails due to communication or protocol errors.

Source code in package/MetaRpcMT5/mt5_account.py
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
async def on_position_profit(
    self,
    interval_ms: int,
    ignore_empty: bool = True,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Subscribes to real-time profit updates for open positions.

    Args:
        interval_ms (int): Interval in milliseconds to poll the server.
        ignore_empty (bool, optional): Skip frames with no change.
        cancellation_event (asyncio.Event, optional): Event to cancel streaming.

    Yields:
        OnPositionProfitData: Profit update data.

    Raises:
        ConnectExceptionMT5: If the account is not connected.
        ApiExceptionMT5: If the server returns a known API error.
        grpc.aio.AioRpcError: If the stream fails due to communication or protocol errors.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = subscriptions_pb2.OnPositionProfitRequest(
        timerPeriodMilliseconds=interval_ms,
        ignoreEmptyData=ignore_empty,
    )

    async for data in self.execute_stream_with_reconnect(
        request=request,
        stream_invoker=lambda req, headers: self.subscription_client.OnPositionProfit(req, metadata=headers),
        get_error=lambda reply: reply.error,
        get_data=lambda reply: reply.data,
        cancellation_event=cancellation_event,
    ):
        yield data

on_positions_and_pending_orders_tickets(interval_ms, cancellation_event=None) async

Subscribes to updates of position and pending order ticket IDs.

Parameters:

Name Type Description Default
interval_ms int

Polling interval in milliseconds.

required
cancellation_event Event

Event to cancel streaming.

None

Yields:

Name Type Description
OnPositionsAndPendingOrdersTicketsData

Snapshot of tickets.

Raises:

Type Description
ConnectExceptionMT5

If the account is not connected.

ApiExceptionMT5

If the server returns a known API error.

AioRpcError

If the stream fails due to communication or protocol errors.

Source code in package/MetaRpcMT5/mt5_account.py
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
async def on_positions_and_pending_orders_tickets(
    self,
    interval_ms: int,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Subscribes to updates of position and pending order ticket IDs.

    Args:
        interval_ms (int): Polling interval in milliseconds.
        cancellation_event (asyncio.Event, optional): Event to cancel streaming.

    Yields:
        OnPositionsAndPendingOrdersTicketsData: Snapshot of tickets.

    Raises:
        ConnectExceptionMT5: If the account is not connected.
        ApiExceptionMT5: If the server returns a known API error.
        grpc.aio.AioRpcError: If the stream fails due to communication or protocol errors.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = subscriptions_pb2.OnPositionsAndPendingOrdersTicketsRequest(
        timerPeriodMilliseconds=interval_ms,
    )

    async for data in self.execute_stream_with_reconnect(
        request=request,
        stream_invoker=lambda req, headers: self.subscription_client.OnPositionsAndPendingOrdersTickets(req, metadata=headers),
        get_error=lambda reply: reply.error,
        get_data=lambda reply: reply.data,
        cancellation_event=cancellation_event,
    ):
        yield data

on_trade_transaction(cancellation_event=None) async

Subscribes to real-time trade transaction events such as order creation, update, or execution.

Parameters:

Name Type Description Default
cancellation_event Event

Event to cancel streaming.

None

Yields:

Name Type Description
OnTradeTransactionData

Trade transaction replies.

Raises:

Type Description
ConnectExceptionMT5

If the account is not connected.

ApiExceptionMT5

If the server returns a known API error.

AioRpcError

If the stream fails due to communication or protocol errors.

Source code in package/MetaRpcMT5/mt5_account.py
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
async def on_trade_transaction(
    self,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Subscribes to real-time trade transaction events such as order creation, update, or execution.

    Args:
        cancellation_event (asyncio.Event, optional): Event to cancel streaming.

    Yields:
        OnTradeTransactionData: Trade transaction replies.

    Raises:
        ConnectExceptionMT5: If the account is not connected.
        ApiExceptionMT5: If the server returns a known API error.
        grpc.aio.AioRpcError: If the stream fails due to communication or protocol errors.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = subscriptions_pb2.OnTradeTransactionRequest()

    async for data in self.execute_stream_with_reconnect(
        request=request,
        stream_invoker=lambda req, headers: self.subscription_client.OnTradeTransaction(req, metadata=headers),
        get_error=lambda reply: reply.error,
        get_data=lambda reply: reply.data,
        cancellation_event=cancellation_event,
    ):
        yield data

order_calc_margin(request, deadline=None, cancellation_event=None) async

Calculates the margin required for a planned trade operation.

Parameters:

Name Type Description Default
request OrderCalcMarginRequest

The request containing symbol, order type, volume, and price.

required
deadline datetime

Deadline for the gRPC call.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
OrderCalcMarginData

The required margin in account currency.

Raises:

Type Description
ConnectExceptionMT5

If the client is not connected.

ApiExceptionMT5

If the server returns a business error.

AioRpcError

If gRPC fails to connect or respond.

Source code in package/MetaRpcMT5/mt5_account.py
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
async def order_calc_margin(
    self,
    request: Any,  # OrderCalcMarginRequest
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Calculates the margin required for a planned trade operation.

    Args:
        request (OrderCalcMarginRequest): The request containing symbol, order type, volume, and price.
        deadline (datetime, optional): Deadline for the gRPC call.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        OrderCalcMarginData: The required margin in account currency.

    Raises:
        ConnectExceptionMT5: If the client is not connected.
        ApiExceptionMT5: If the server returns a business error.
        grpc.aio.AioRpcError: If gRPC fails to connect or respond.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    async def grpc_call(headers):
        timeout = None
        if deadline:
            timeout = (deadline - datetime.utcnow()).total_seconds()
            timeout = max(timeout, 0)
        return await self.trade_functions_client.OrderCalcMargin(
            request,
            metadata=headers,
            timeout=timeout,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

order_check(request, deadline=None, cancellation_event=None) async

Checks whether a trade request can be successfully executed under current market conditions.

Parameters:

Name Type Description Default
request OrderCheckRequest

The trade request to validate.

required
deadline datetime

Deadline for the gRPC call.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
OrderCheckData

Result of the trade request check, including margin and balance details.

Raises:

Type Description
ConnectExceptionMT5

If the client is not connected.

ApiExceptionMT5

If the server returns a business error.

AioRpcError

If gRPC fails to connect or respond.

Source code in package/MetaRpcMT5/mt5_account.py
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
async def order_check(
    self,
    request: Any,  # OrderCheckRequest
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Checks whether a trade request can be successfully executed under current market conditions.

    Args:
        request (OrderCheckRequest): The trade request to validate.
        deadline (datetime, optional): Deadline for the gRPC call.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        OrderCheckData: Result of the trade request check, including margin and balance details.

    Raises:
        ConnectExceptionMT5: If the client is not connected.
        ApiExceptionMT5: If the server returns a business error.
        grpc.aio.AioRpcError: If gRPC fails to connect or respond.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    async def grpc_call(headers):
        timeout = None
        if deadline:
            timeout = (deadline - datetime.utcnow()).total_seconds()
            timeout = max(timeout, 0)
        return await self.trade_functions_client.OrderCheck(
            request,
            metadata=headers,
            timeout=timeout,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

positions_total(deadline=None, cancellation_event=None) async

Returns the total number of open positions on the current account.

Parameters:

Name Type Description Default
deadline datetime

Deadline for the gRPC call.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
PositionsTotalData

The total number of open positions.

Raises:

Type Description
ConnectExceptionMT5

If the client is not connected.

ApiExceptionMT5

If the server returns a business error.

AioRpcError

If gRPC fails to connect or respond.

Source code in package/MetaRpcMT5/mt5_account.py
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
async def positions_total(
    self,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Returns the total number of open positions on the current account.

    Args:
        deadline (datetime, optional): Deadline for the gRPC call.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        PositionsTotalData: The total number of open positions.

    Raises:
        ConnectExceptionMT5: If the client is not connected.
        ApiExceptionMT5: If the server returns a business error.
        grpc.aio.AioRpcError: If gRPC fails to connect or respond.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = Empty()

    async def grpc_call(headers):
        timeout = None
        if deadline:
            timeout = (deadline - datetime.utcnow()).total_seconds()
            timeout = max(timeout, 0)
        return await self.trade_functions_client.PositionsTotal(
            request,
            metadata=headers,
            timeout=timeout,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

symbols_total(selected_only, deadline=None, cancellation_event=None) async

Returns the total number of symbols available on the platform.

Parameters:

Name Type Description Default
selected_only bool

True to count only Market Watch symbols, false to count all.

required
deadline datetime

Deadline for the gRPC call.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
SymbolsTotalData

Total symbol count data.

Raises:

Type Description
ConnectExceptionMT5

If the client is not connected.

ApiExceptionMT5

If the server returns a business error.

AioRpcError

If the gRPC call fails.

Source code in package/MetaRpcMT5/mt5_account.py
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
async def symbols_total(
    self,
    selected_only: bool,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Returns the total number of symbols available on the platform.

    Args:
        selected_only (bool): True to count only Market Watch symbols, false to count all.
        deadline (datetime, optional): Deadline for the gRPC call.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        SymbolsTotalData: Total symbol count data.

    Raises:
        ConnectExceptionMT5: If the client is not connected.
        ApiExceptionMT5: If the server returns a business error.
        grpc.aio.AioRpcError: If the gRPC call fails.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.SymbolsTotalRequest(mode=selected_only)

    async def grpc_call(headers):
        timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
        return await self.market_info_client.SymbolsTotal(
            request,
            metadata=headers,
            timeout=max(timeout, 0) if timeout else None,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

symbol_exist(symbol, deadline=None, cancellation_event=None) async

Checks if a symbol with the specified name exists (standard or custom).

Parameters:

Name Type Description Default
symbol str

The symbol name to check.

required
deadline datetime

Deadline for the gRPC call.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
SymbolExistData

Information about symbol existence and type.

Raises:

Type Description
ConnectExceptionMT5

If the client is not connected.

ApiExceptionMT5

If the server returns a business error.

AioRpcError

If the gRPC call fails.

Source code in package/MetaRpcMT5/mt5_account.py
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
async def symbol_exist(
    self,
    symbol: str,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Checks if a symbol with the specified name exists (standard or custom).

    Args:
        symbol (str): The symbol name to check.
        deadline (datetime, optional): Deadline for the gRPC call.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        SymbolExistData: Information about symbol existence and type.

    Raises:
        ConnectExceptionMT5: If the client is not connected.
        ApiExceptionMT5: If the server returns a business error.
        grpc.aio.AioRpcError: If the gRPC call fails.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.SymbolExistRequest(name=symbol)

    async def grpc_call(headers):
        timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
        return await self.market_info_client.SymbolExist(
            request,
            metadata=headers,
            timeout=max(timeout, 0) if timeout else None,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

symbol_name(index, selected, deadline=None, cancellation_event=None) async

Returns the name of a symbol by index.

Parameters:

Name Type Description Default
index int

Symbol index (starting at 0).

required
selected bool

True to use only Market Watch symbols.

required
deadline datetime

Deadline for the gRPC call.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
SymbolNameData

The symbol name at the specified index.

Raises:

Type Description
ConnectExceptionMT5

If the client is not connected.

ApiExceptionMT5

If the server returns a business error.

AioRpcError

If the gRPC call fails.

Source code in package/MetaRpcMT5/mt5_account.py
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
async def symbol_name(
    self,
    index: int,
    selected: bool,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Returns the name of a symbol by index.

    Args:
        index (int): Symbol index (starting at 0).
        selected (bool): True to use only Market Watch symbols.
        deadline (datetime, optional): Deadline for the gRPC call.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        SymbolNameData: The symbol name at the specified index.

    Raises:
        ConnectExceptionMT5: If the client is not connected.
        ApiExceptionMT5: If the server returns a business error.
        grpc.aio.AioRpcError: If the gRPC call fails.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.SymbolNameRequest(index=index, selected=selected)

    async def grpc_call(headers):
        timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
        return await self.market_info_client.SymbolName(
            request,
            metadata=headers,
            timeout=max(timeout, 0) if timeout else None,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

symbol_select(symbol, select, deadline=None, cancellation_event=None) async

Adds or removes a symbol from Market Watch.

Parameters:

Name Type Description Default
symbol str

Symbol name.

required
select bool

True to add, false to remove.

required
deadline datetime

Deadline for the gRPC call.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
SymbolSelectData

Success status of the operation.

Raises:

Type Description
ConnectExceptionMT5

If the client is not connected.

ApiExceptionMT5

If the server returns a business error.

AioRpcError

If the gRPC call fails.

Source code in package/MetaRpcMT5/mt5_account.py
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
async def symbol_select(
    self,
    symbol: str,
    select: bool,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Adds or removes a symbol from Market Watch.

    Args:
        symbol (str): Symbol name.
        select (bool): True to add, false to remove.
        deadline (datetime, optional): Deadline for the gRPC call.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        SymbolSelectData: Success status of the operation.

    Raises:
        ConnectExceptionMT5: If the client is not connected.
        ApiExceptionMT5: If the server returns a business error.
        grpc.aio.AioRpcError: If the gRPC call fails.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.SymbolSelectRequest(symbol=symbol, select=select)

    async def grpc_call(headers):
        timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
        return await self.market_info_client.SymbolSelect(
            request,
            metadata=headers,
            timeout=max(timeout, 0) if timeout else None,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

symbol_is_synchronized(symbol, deadline=None, cancellation_event=None) async

Checks if the symbol's data is synchronized with the server.

Parameters:

Name Type Description Default
symbol str

Symbol name to check.

required
deadline datetime

Deadline for the gRPC call.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
SymbolIsSynchronizedData

True if synchronized, false otherwise.

Raises:

Type Description
ConnectExceptionMT5

If the client is not connected.

ApiExceptionMT5

If the server returns a business error.

AioRpcError

If the gRPC call fails.

Source code in package/MetaRpcMT5/mt5_account.py
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
async def symbol_is_synchronized(
    self,
    symbol: str,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Checks if the symbol's data is synchronized with the server.

    Args:
        symbol (str): Symbol name to check.
        deadline (datetime, optional): Deadline for the gRPC call.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        SymbolIsSynchronizedData: True if synchronized, false otherwise.

    Raises:
        ConnectExceptionMT5: If the client is not connected.
        ApiExceptionMT5: If the server returns a business error.
        grpc.aio.AioRpcError: If the gRPC call fails.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.SymbolIsSynchronizedRequest(symbol=symbol)

    async def grpc_call(headers):
        timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
        return await self.market_info_client.SymbolIsSynchronized(
            request,
            metadata=headers,
            timeout=max(timeout, 0) if timeout else None,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

symbol_info_double(symbol, property, deadline=None, cancellation_event=None) async

Retrieves a double-precision property value of a symbol.

Parameters:

Name Type Description Default
symbol str

Symbol name.

required
property SymbolInfoDoubleProperty

The double-type property to retrieve.

required
deadline datetime

Deadline for the gRPC call.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
SymbolInfoDoubleData

The double property value.

Raises:

Type Description
ConnectExceptionMT5

If the client is not connected.

ApiExceptionMT5

If the server returns a business error.

AioRpcError

If the gRPC call fails.

Source code in package/MetaRpcMT5/mt5_account.py
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
async def symbol_info_double(
    self,
    symbol: str,
    property: market_info_pb2.SymbolInfoDoubleProperty,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Retrieves a double-precision property value of a symbol.

    Args:
        symbol (str): Symbol name.
        property (SymbolInfoDoubleProperty): The double-type property to retrieve.
        deadline (datetime, optional): Deadline for the gRPC call.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        SymbolInfoDoubleData: The double property value.

    Raises:
        ConnectExceptionMT5: If the client is not connected.
        ApiExceptionMT5: If the server returns a business error.
        grpc.aio.AioRpcError: If the gRPC call fails.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.SymbolInfoDoubleRequest(symbol=symbol, type=property)

    async def grpc_call(headers):
        timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
        return await self.market_info_client.SymbolInfoDouble(
            request,
            metadata=headers,
            timeout=max(timeout, 0) if timeout else None,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

symbol_info_integer(symbol, property, deadline=None, cancellation_event=None) async

Retrieves an integer-type property value of a symbol.

Parameters:

Name Type Description Default
symbol str

Symbol name.

required
property SymbolInfoIntegerProperty

The integer property to query.

required
deadline datetime

Deadline for the gRPC call.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
SymbolInfoIntegerData

The integer property value.

Raises:

Type Description
ConnectExceptionMT5

If the client is not connected.

ApiExceptionMT5

If the server returns a business error.

AioRpcError

If the gRPC call fails.

Source code in package/MetaRpcMT5/mt5_account.py
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
async def symbol_info_integer(
    self,
    symbol: str,
    property: market_info_pb2.SymbolInfoIntegerProperty,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Retrieves an integer-type property value of a symbol.

    Args:
        symbol (str): Symbol name.
        property (SymbolInfoIntegerProperty): The integer property to query.
        deadline (datetime, optional): Deadline for the gRPC call.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        SymbolInfoIntegerData: The integer property value.

    Raises:
        ConnectExceptionMT5: If the client is not connected.
        ApiExceptionMT5: If the server returns a business error.
        grpc.aio.AioRpcError: If the gRPC call fails.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.SymbolInfoIntegerRequest(symbol=symbol, type=property)

    async def grpc_call(headers):
        timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
        return await self.market_info_client.SymbolInfoInteger(
            request,
            metadata=headers,
            timeout=max(timeout, 0) if timeout else None,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

symbol_info_string(symbol, property, deadline=None, cancellation_event=None) async

Retrieves a string-type property value of a symbol.

Parameters:

Name Type Description Default
symbol str

Symbol name.

required
property SymbolInfoStringProperty

The string property to retrieve.

required
deadline datetime

Deadline for the gRPC call.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
SymbolInfoStringData

The string property value.

Raises:

Type Description
ConnectExceptionMT5

If the client is not connected.

ApiExceptionMT5

If the server returns a business error.

AioRpcError

If the gRPC call fails.

Source code in package/MetaRpcMT5/mt5_account.py
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
async def symbol_info_string(
    self,
    symbol: str,
    property: market_info_pb2.SymbolInfoStringProperty,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Retrieves a string-type property value of a symbol.

    Args:
        symbol (str): Symbol name.
        property (SymbolInfoStringProperty): The string property to retrieve.
        deadline (datetime, optional): Deadline for the gRPC call.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        SymbolInfoStringData: The string property value.

    Raises:
        ConnectExceptionMT5: If the client is not connected.
        ApiExceptionMT5: If the server returns a business error.
        grpc.aio.AioRpcError: If the gRPC call fails.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.SymbolInfoStringRequest(symbol=symbol, type=property)

    async def grpc_call(headers):
        timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
        return await self.market_info_client.SymbolInfoString(
            request,
            metadata=headers,
            timeout=max(timeout, 0) if timeout else None,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

symbol_info_margin_rate(symbol, order_type, deadline=None, cancellation_event=None) async

Retrieves the margin rates for a given symbol and order type.

Parameters:

Name Type Description Default
symbol str

Symbol name.

required
order_type ENUM_ORDER_TYPE

The order type (buy/sell/etc).

required
deadline datetime

Deadline for the gRPC call.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
SymbolInfoMarginRateData

The initial and maintenance margin rates.

Raises:

Type Description
ConnectExceptionMT5

If the client is not connected.

ApiExceptionMT5

If the server returns a business error.

AioRpcError

If the gRPC call fails.

Source code in package/MetaRpcMT5/mt5_account.py
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
async def symbol_info_margin_rate(
    self,
    symbol: str,
    order_type: market_info_pb2.ENUM_ORDER_TYPE,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Retrieves the margin rates for a given symbol and order type.

    Args:
        symbol (str): Symbol name.
        order_type (ENUM_ORDER_TYPE): The order type (buy/sell/etc).
        deadline (datetime, optional): Deadline for the gRPC call.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        SymbolInfoMarginRateData: The initial and maintenance margin rates.

    Raises:
        ConnectExceptionMT5: If the client is not connected.
        ApiExceptionMT5: If the server returns a business error.
        grpc.aio.AioRpcError: If the gRPC call fails.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.SymbolInfoMarginRateRequest(symbol=symbol, orderType=order_type)

    async def grpc_call(headers):
        timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
        return await self.market_info_client.SymbolInfoMarginRate(
            request,
            metadata=headers,
            timeout=max(timeout, 0) if timeout else None,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

symbol_info_tick(symbol, deadline=None, cancellation_event=None) async

Retrieves the current tick data (bid, ask, last, volume) for a given symbol.

Parameters:

Name Type Description Default
symbol str

Symbol name to fetch tick info for.

required
deadline datetime

Deadline for the gRPC call.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
MrpcMqlTick

The latest tick information.

Raises:

Type Description
ConnectExceptionMT5

If the account is not connected.

ApiExceptionMT5

If the server returns an error in the response.

AioRpcError

If the gRPC call fails.

Source code in package/MetaRpcMT5/mt5_account.py
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
async def symbol_info_tick(
    self,
    symbol: str,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Retrieves the current tick data (bid, ask, last, volume) for a given symbol.

    Args:
        symbol (str): Symbol name to fetch tick info for.
        deadline (datetime, optional): Deadline for the gRPC call.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        MrpcMqlTick: The latest tick information.

    Raises:
        ConnectExceptionMT5: If the account is not connected.
        ApiExceptionMT5: If the server returns an error in the response.
        grpc.aio.AioRpcError: If the gRPC call fails.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.SymbolInfoTickRequest(symbol=symbol)

    async def grpc_call(headers):
        timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
        return await self.market_info_client.SymbolInfoTick(
            request,
            metadata=headers,
            timeout=max(timeout, 0) if timeout else None,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

symbol_info_session_quote(symbol, day_of_week, session_index, deadline=None, cancellation_event=None) async

Gets the quoting session start and end time for a symbol on a specific day and session index.

Parameters:

Name Type Description Default
symbol str

The symbol name.

required
day_of_week DayOfWeek

The day of the week.

required
session_index int

Index of the quoting session (starting at 0).

required
deadline datetime

Deadline for the gRPC call.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
SymbolInfoSessionQuoteData

The session quote start and end time.

Source code in package/MetaRpcMT5/mt5_account.py
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
async def symbol_info_session_quote(
    self,
    symbol: str,
    day_of_week: market_info_pb2.DayOfWeek,
    session_index: int,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Gets the quoting session start and end time for a symbol on a specific day and session index.

    Args:
        symbol (str): The symbol name.
        day_of_week (DayOfWeek): The day of the week.
        session_index (int): Index of the quoting session (starting at 0).
        deadline (datetime, optional): Deadline for the gRPC call.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        SymbolInfoSessionQuoteData: The session quote start and end time.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.SymbolInfoSessionQuoteRequest(
        symbol=symbol,
        dayOfWeek=day_of_week,
        sessionIndex=session_index,
    )

    async def grpc_call(headers):
        timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
        return await self.market_info_client.SymbolInfoSessionQuote(
            request,
            metadata=headers,
            timeout=max(timeout, 0) if timeout else None,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

symbol_info_session_trade(symbol, day_of_week, session_index, deadline=None, cancellation_event=None) async

Gets the trading session start and end time for a symbol on a specific day and session index.

Parameters:

Name Type Description Default
symbol str

The symbol name.

required
day_of_week DayOfWeek

The day of the week.

required
session_index int

Index of the trading session (starting at 0).

required
deadline datetime

Deadline for the gRPC call.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
SymbolInfoSessionTradeData

The trading session start and end time.

Source code in package/MetaRpcMT5/mt5_account.py
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
async def symbol_info_session_trade(
    self,
    symbol: str,
    day_of_week: market_info_pb2.DayOfWeek,
    session_index: int,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Gets the trading session start and end time for a symbol on a specific day and session index.

    Args:
        symbol (str): The symbol name.
        day_of_week (DayOfWeek): The day of the week.
        session_index (int): Index of the trading session (starting at 0).
        deadline (datetime, optional): Deadline for the gRPC call.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        SymbolInfoSessionTradeData: The trading session start and end time.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.SymbolInfoSessionTradeRequest(
        symbol=symbol,
        dayOfWeek=day_of_week,
        sessionIndex=session_index,
    )

    async def grpc_call(headers):
        timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
        return await self.market_info_client.SymbolInfoSessionTrade(
            request,
            metadata=headers,
            timeout=max(timeout, 0) if timeout else None,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

market_book_add(symbol, deadline=None, cancellation_event=None) async

Opens the Depth of Market (DOM) for a symbol and subscribes to updates.

Parameters:

Name Type Description Default
symbol str

Symbol name to subscribe.

required
deadline datetime

Deadline for the gRPC call.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
MarketBookAddData

True if DOM subscription was successful.

Source code in package/MetaRpcMT5/mt5_account.py
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
async def market_book_add(
    self,
    symbol: str,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Opens the Depth of Market (DOM) for a symbol and subscribes to updates.

    Args:
        symbol (str): Symbol name to subscribe.
        deadline (datetime, optional): Deadline for the gRPC call.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        MarketBookAddData: True if DOM subscription was successful.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.MarketBookAddRequest(symbol=symbol)

    async def grpc_call(headers):
        timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
        return await self.market_info_client.MarketBookAdd(
            request,
            metadata=headers,
            timeout=max(timeout, 0) if timeout else None,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

market_book_release(symbol, deadline=None, cancellation_event=None) async

Releases the Depth of Market (DOM) for a symbol and stops receiving updates.

Parameters:

Name Type Description Default
symbol str

Symbol name to unsubscribe.

required
deadline datetime

Deadline for the gRPC call.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
MarketBookReleaseData

True if DOM release was successful.

Source code in package/MetaRpcMT5/mt5_account.py
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
async def market_book_release(
    self,
    symbol: str,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Releases the Depth of Market (DOM) for a symbol and stops receiving updates.

    Args:
        symbol (str): Symbol name to unsubscribe.
        deadline (datetime, optional): Deadline for the gRPC call.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        MarketBookReleaseData: True if DOM release was successful.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.MarketBookReleaseRequest(symbol=symbol)

    async def grpc_call(headers):
        timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
        return await self.market_info_client.MarketBookRelease(
            request,
            metadata=headers,
            timeout=max(timeout, 0) if timeout else None,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

market_book_get(symbol, deadline=None, cancellation_event=None) async

Gets the current Depth of Market (DOM) data for a symbol.

Parameters:

Name Type Description Default
symbol str

Symbol name.

required
deadline datetime

Deadline for the gRPC call.

None
cancellation_event Event

Event to cancel the request.

None

Returns:

Name Type Description
MarketBookGetData

A list of book entries for the symbol's DOM.

Source code in package/MetaRpcMT5/mt5_account.py
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
async def market_book_get(
    self,
    symbol: str,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
):
    """
    Gets the current Depth of Market (DOM) data for a symbol.

    Args:
        symbol (str): Symbol name.
        deadline (datetime, optional): Deadline for the gRPC call.
        cancellation_event (asyncio.Event, optional): Event to cancel the request.

    Returns:
        MarketBookGetData: A list of book entries for the symbol's DOM.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.MarketBookGetRequest(symbol=symbol)

    async def grpc_call(headers):
        timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
        return await self.market_info_client.MarketBookGet(
            request,
            metadata=headers,
            timeout=max(timeout, 0) if timeout else None,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda r: getattr(r, "error", None),
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data

account_info_double(property_id, deadline=None, cancellation_event=None) async

Retrieves a double-precision account property (e.g. balance, equity, margin).

Parameters:

Name Type Description Default
property_id AccountInfoDoublePropertyType

The account double property to retrieve.

required
deadline datetime

Deadline after which the call will be cancelled.

None
cancellation_event Event

Event to cancel the operation.

None

Returns:

Name Type Description
float float

The double value of the requested account property.

Raises:

Type Description
ConnectExceptionMT5

If the client is not connected.

ApiExceptionMT5

If the server returns a business error.

AioRpcError

If the gRPC call fails.

Source code in package/MetaRpcMT5/mt5_account.py
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
async def account_info_double(
    self,
    property_id: account_info_pb2.AccountInfoDoublePropertyType,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
) -> float:
    """
    Retrieves a double-precision account property (e.g. balance, equity, margin).

    Args:
        property_id (AccountInfoDoublePropertyType): The account double property to retrieve.
        deadline (datetime, optional): Deadline after which the call will be cancelled.
        cancellation_event (asyncio.Event, optional): Event to cancel the operation.

    Returns:
        float: The double value of the requested account property.

    Raises:
        ConnectExceptionMT5: If the client is not connected.
        ApiExceptionMT5: If the server returns a business error.
        grpc.aio.AioRpcError: If the gRPC call fails.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.AccountInfoDoubleRequest(propertyId=property_id)

    async def grpc_call(headers):
        timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
        return await self.account_information_client.AccountInfoDouble(
            request,
            metadata=headers,
            timeout=max(timeout, 0) if timeout else None,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda _: None,  # no error field
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data.requestedValue

account_info_integer(property_id, deadline=None, cancellation_event=None) async

Retrieves an integer account property (e.g. login, leverage, trade mode).

Parameters:

Name Type Description Default
property_id AccountInfoIntegerPropertyType

The account integer property to retrieve.

required
deadline datetime

Deadline after which the call will be cancelled.

None
cancellation_event Event

Event to cancel the operation.

None

Returns:

Name Type Description
int int

The integer value of the requested account property.

Raises:

Type Description
ConnectExceptionMT5

If the client is not connected.

ApiExceptionMT5

If the server returns a business error.

AioRpcError

If the gRPC call fails.

Source code in package/MetaRpcMT5/mt5_account.py
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
async def account_info_integer(
    self,
    property_id: account_info_pb2.AccountInfoIntegerPropertyType,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
) -> int:
    """
    Retrieves an integer account property (e.g. login, leverage, trade mode).

    Args:
        property_id (AccountInfoIntegerPropertyType): The account integer property to retrieve.
        deadline (datetime, optional): Deadline after which the call will be cancelled.
        cancellation_event (asyncio.Event, optional): Event to cancel the operation.

    Returns:
        int: The integer value of the requested account property.

    Raises:
        ConnectExceptionMT5: If the client is not connected.
        ApiExceptionMT5: If the server returns a business error.
        grpc.aio.AioRpcError: If the gRPC call fails.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.AccountInfoIntegerRequest(propertyId=property_id)

    async def grpc_call(headers):
        timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
        return await self.account_information_client.AccountInfoInteger(
            request,
            metadata=headers,
            timeout=max(timeout, 0) if timeout else None,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda _: None,  # no error field
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data.requestedValue

account_info_string(property_id, deadline=None, cancellation_event=None) async

Retrieves a string account property (e.g. account name, currency, server).

Parameters:

Name Type Description Default
property_id AccountInfoStringPropertyType

The account string property to retrieve.

required
deadline datetime

Deadline after which the call will be cancelled.

None
cancellation_event Event

Event to cancel the operation.

None

Returns:

Name Type Description
str str

The string value of the requested account property.

Raises:

Type Description
ConnectExceptionMT5

If the client is not connected.

ApiExceptionMT5

If the server returns a business error.

AioRpcError

If the gRPC call fails.

Source code in package/MetaRpcMT5/mt5_account.py
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
async def account_info_string(
    self,
    property_id: account_info_pb2.AccountInfoStringPropertyType,
    deadline: Optional[datetime] = None,
    cancellation_event: Optional[asyncio.Event] = None,
) -> str:
    """
    Retrieves a string account property (e.g. account name, currency, server).

    Args:
        property_id (AccountInfoStringPropertyType): The account string property to retrieve.
        deadline (datetime, optional): Deadline after which the call will be cancelled.
        cancellation_event (asyncio.Event, optional): Event to cancel the operation.

    Returns:
        str: The string value of the requested account property.

    Raises:
        ConnectExceptionMT5: If the client is not connected.
        ApiExceptionMT5: If the server returns a business error.
        grpc.aio.AioRpcError: If the gRPC call fails.
    """
    if not self.id:
        raise ConnectExceptionMT5("Please call connect method first")

    request = account_helper_pb2.AccountInfoStringRequest(propertyId=property_id)

    async def grpc_call(headers):
        timeout = (deadline - datetime.utcnow()).total_seconds() if deadline else None
        return await self.account_information_client.AccountInfoString(
            request,
            metadata=headers,
            timeout=max(timeout, 0) if timeout else None,
        )

    res = await self.execute_with_reconnect(
        grpc_call=grpc_call,
        error_selector=lambda _: None,  # no error field
        deadline=deadline,
        cancellation_event=cancellation_event,
    )
    return res.data.requestedValue