MT4 REST API Documentation

easy direct connection to any MT4 and MT5 server

MT4 REST API Documentation

Introduction

All method you can test on API with address http://rest.mtapi.online.

Next articles examples reference to this instance.

Examples tested with well-known utility SOAPUI, which has free version.

Authorization

We are using token authorization.

When username and password is right, service will return access token which live length is 15 minutes

POST http://rest.mtapi.online/token?username=Login1&password=LoginPassword1

If login or password is incorrect

If token has expired, get new

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://rest.mtapi.online/MT4/new?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

Leave a Reply