MT4 REST API Documentation
New demo environment and documentation
Introduction
All method you can test on API with address http://mt4.mtapi.be.
Next articles examples reference to this instance.
Examples tested with well-known utility SOAPUI, which has free version.
Login to MT4 server
If you try to connect without token you will get «Unauthorized».
You should add header with name «Authorization» and value «Bearer <token>» (with space).
GET http://mt4.mtapi.be/connect?user=10184600&password=fldv04&host=mt4-sto-london-02.mt4proxy.com&port=443
API return response with login_id (keep this id) of MT4 server connection and some data.
If something goes wrong with API you will get Error. E.x. wrong login
Login to MT4 server via proxy
Some MT4 servers deny more than several connection from one IP.
In this case you should find free SOCKS5 proxy or build yourself.
Find free socks5 proxy is hard task. So we will build ourselves for example.
Now method exist, but proxy doesn’t.
http://rest.mtapi.online/MT4/newviaproxy?user=10184600&password=fldv04&host=mt4-sto-london-02.mt4proxy.com&port=443&proxyHost=117.57.242.124&proxyPort=1080
Get login info
If you logged to MT4 server, API would keep that connection. You can check connection existing by user_id returned by method “new”.
http://rest.mtapi.online/MT4/connected?id=1
Get quote
Get quote from connection by user id and tiker
http://rest.mtapi.online/MT4/quote/?id=1&symbol=EURUSD
Open orders
Open orders from connection
http://rest.mtapi.online/MT4/openedorders/?id=1
Get order history
http://rest.mtapi.online/MT4/orderhistory/?id=1&from=2018-04-01-12-10-00&to=2018-04-10-12-10-00
Please, use exactly exampled datetime format
Order send
You should see properly exception, because market was closed, when I am writing this document
http://rest.mtapi.online/MT4/ordersend/?id=1&symbol=EURUSD.&operation=Buy&volume=0.1&price=1.2176&slippage=0&stoploss=0.0&takeprofit=0.0
But when it switched on, you will see like this
Order close
http://rest.mtapi.online/MT4/orderclose/?id=1&ticket=24528191&symbol=EURUSD.&volume=0.1&price=1.21774&slippage=0
Close connection to MT4 server
When you work is done, you should disconnect by user id
If connection was closed earlier