Python gRPC example

easy direct connection to any MT4 and MT5 server

Python gRPC example

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 

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