Package: pymt5
PyMT5Provides simplified, multithreaded, socket-based Python interfaces to MT5 gateways. PyMT5 requires aDevCartel MT5 gatewayinstalled on the MT5 platform to work with PyMT5.InstallationPyMT5 supports both Python 2 and 3. Simply install fromPyPIusingpip:pip install pymt5Exampleimportpymt5defonData(data):client=data.get('client_id')# Loginifdata.get('type')=='1':# Send heartbeatm.send(client,{'ver':'3','type':'6'})# Send login OK responsem.send(client,{'ver':'3','type':'1','login':data.get('login'),'password':data.get('password'),'res':'0'})m=pymt5.PyMT5()m.onConnected=onConnectedm.onDisconnected=onDisconnectedm.onData=onDataCheckout more messageexamples.APIpymt5.PyMT5([host=''], [port=16838])host: strport: int➥return: objectStarts a PyMT5 server and listening on a port defined byport.>> m = pymt5.PyMT5()Upon incoming connection from a gateway, PyMT5 stores client information inpymt5.requestsin dict format aspymt5.stop()Disconnects all MT5 gateway connections and stop the server.>> m.stop()pymt5.broadcast(data)data: dictSends a message to all connected gateways. Consider using this when sending market data.>> #send a tick
>> m.broadcast({'ver':'3','type':'4','symbol':'EURUSD.TEST','bank':'dc','bid':'1.2661','ask':'1.2665','last':'1.2665','volume':'1','datetime':'0'})pymt5.send(client_id,data)client_id: intdata: dictSends a message to a connected gateway.>> #send heartbeat
>> m.send(123145536110592, {'ver':'3','type':'6'})pymt5.disconnect(client_id)client_id: intTerminates a connection.>> m.disconnect(123145536110592)pymt5.onConnected(client_info)client_info: dictA callbackonConnected, if assigned, is called upon a successful connection from a client. Client information can be accessed fromclient_info's values asclient_id,client_addressandclient_port.>> def onConnected(client_info):
>>     print(str(client_info))
>>     # print {'client_port': 64941, 'client_address': '127.0.0.1', 'client_id': 123145536110592}
>>
>> m = pymt5.PyMT5()
>> m.onConnected = onConnectedpymt5.onDisconnected(client_info)client_info: dictA callbackonDisconnected, if assigned, is called upon a disconnection from a client. Client information can be accessed fromclient_info's values asclient_id,client_addressandclient_port.>> def onDisonnected(client_info):
>>     print(str(client_info))
>>
>> m = pymt5.PyMT5()
>> m.onDisconnected = onDisconnectedpymt5.onData(data)data: dictA callbackonData, if assigned, is called upon receiving messages from gateways. SeeData Formatfor more information.>> def onData(data):
>>     print(json.dumps(data))
>>
>> m = pymt5.PyMT5()
>> m.onData = onDataData FormatData is to be composed as a dict with key/value defined below to be sent and received from a gateway.Data typeHeaderTagsLogin'ver':'3','type':1''login','password','res'Logout'ver':'3','type':2'NoneSymbol'ver':'3','type':3''index','symbol','path','description','page','currency_base','currency_profit','currency_margin','digits','tick_flags','calc_mode','exec_mode','chart_mode','fill_flags','expir_flags','tick_value','tick_size','contract_size','volume_min','volume_max','volume_step','market_depth','margin_flags','margin_initial','margin_maintenance','margin_long','margin_short','margin_limit','margin_stop','margin_stop_limit','settlement_price','price_limit_max','price_limit_min','time_start','time_expiration','trade_mode'Tick'ver':'3','type':4''symbol','bank','bid','ask','last','volume','datetime'Order'ver':'3','type':5''symbol','bank','bid','ask','last','volume','datetime','order_action','state','order','exchange_id','custom_data','request_id','symbol','login','type_order','type_time','type_fill','action','price_order','price_sl','price_tp','price_tick_bid','price_tick_ask','volume','expiration_time','result'Heartbeat'ver':'3','type':6'NoneDeal'ver':'3','type':7''exchange_id','order','symbol','login','type_deal','volume','volume_rem','price','position'External Deal'ver':'3','type':50''exchange_id','order','symbol','login','type_deal','volume','volume_rem','price','datetime','comment'SupportGet aDevCartel MT5 Gatewayin order to work with PyMT5Report an issue inissue trackerChangelog1.4.030 October 2022Fix potential data loss due to data fragmentation1.3.08 August 2021Fix parsing data buffer1.2.08 July 2019Support for Python 3.7Update support linksAdd examples1.1.021 April 2018Released on PyPIAdded README1.0.013 April 2018Initial release