MT5 Client gRPC example for Python

Created with Sketch.

MT5 Client gRPC example for Python

Table of Contents

Methods browser:
https://mtapi.online/grpcdocs/mt5protoinfo.html

Ready to run example:
https://git.mtapi.io/root/grpc-proto/-/archive/main/grpc-proto-main.zip?path=mt5/pythonExample

Firstly need to download python libraries at the same folder with your *.py file:
https://git.mtapi.io/root/grpc-proto/-/archive/main/grpc-proto-main.zip?path=mt5/python

After that you can run this simple example.


from asyncio import streams
from mt5grpc import mt5_pb2_grpc
from mt5grpc.mt5_pb2 import *
from mt5grpc.mt5_pb2_grpc import *

channel = grpc.secure_channel('mt5grpc.mtapi.io:443', grpc.ssl_channel_credentials())
service = mt5_pb2_grpc.ServiceStub(channel)
mt5 = mt5_pb2_grpc.MT5Stub(channel)
trading = mt5_pb2_grpc.TradingStub(channel)
connection = mt5_pb2_grpc.ConnectionStub(channel)
streams = mt5_pb2_grpc.StreamsStub(channel)
subscriptions = mt5_pb2_grpc.SubscriptionsStub(channel)

req = ConnectRequest(
    user = 62333850,
    password = 'tecimil4',
    host="78.140.180.198", 
    port=443)
res = connection.Connect(req)
if res.error.message:
    print(res.error)
    exit()
token = res.result
print(token)

req = AccountSummaryRequest(
    id = token)
res = mt5.AccountSummary(req)
if res.error.message:
    print(res.error)
    exit()
print(res.result)

req = SubscribeRequest(
    id = token, symbol = "EURUSD")
res = subscriptions.Subscribe(req)
if res.error.message:
    print(res.error)
    exit()
print(res.result)

Leave a Reply

Your email address will not be published. Required fields are marked *