MT4 Client gRPC example for Python

easy direct connection to any MT4 and MT5 server

MT4 Client gRPC example for Python

Firstly need to download python libraries at the same folder with your *.py file:

git clone https://git.gendocu.com/mtapiio/mt4grpc.git --branch master  mt4grpc 

Or download like zip:
https://git.gendocu.com/mtapiio/mt4grpc/archive/master.zip

After that you can run this simple example.

from mt4grpc.sdk.python3 import mt4_pb2_grpc
from mt4grpc.sdk.python3.mt4_pb2 import *
from mt4grpc.sdk.python3.mt4_pb2_grpc import *

channel = grpc.secure_channel('mt4grpc.mtapi.io:443', grpc.ssl_channel_credentials())
service = mt4_pb2_grpc.ServiceStub(channel)
mt4 = mt4_pb2_grpc.MT4Stub(channel)
trading = mt4_pb2_grpc.TradingStub(channel)
connection = mt4_pb2_grpc.ConnectionStub(channel)

req = ConnectRequest(
    user = 500476959,
    password = 'ehj4bod',
    host="mt4-demo.roboforex.com", 
    port=443)
res = connection.Connect(req)
if res.error.message:
    print(res.error)
    exit()
token = res.result
print(token)

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

Leave a Reply