Giter Club home page Giter Club logo

mt5-rest's Introduction

Turns Metatrader5 into REST API server.

Note: make sure you have VSredist: https://www.microsoft.com/en-ie/download/details.aspx?id=48145

time_setup, time is MQL5 datetime, check docs at: https://www.mql5.com/en/docs/basis/types/integer/datetime

check "error" for /trade command on that page: https://www.mql5.com/en/docs/constants/errorswarnings/enum_trade_return_codes

for enums check that page: https://www.mql5.com/en/docs/constants

how to compile

clone repo to any folder on our PC.

Copy MQL5 folder to Data folder of mt5 (how to get where is Data folder is localted, open mt5, click File->Open Data Folder or just click Ctrl+Shft+D). In MT5 Navigator (to show Naavigator click Ctrl+N) select Expert Advisors->Advisors. Right click on RestApi, select Modify. Editor will be opened, press F7 to compile. Done.

To compile C++ dll use Visual Studio 2017. Use .sln file to open solution in VS, select Realease x64 and press Ctrl+Shft+b to build dll file. Output is located under /x64 folder.

Commands

POST /sub - setup web hook. options: callback_url and callback_format (json or x-form)

GET /symbols/{name} - get symbol informaiton including ask/bid prices.

GET /info - get account details, number of orders, number of positions

GET /positions - returns list of positions

GET /positions/{id} - return position by id

GET /deals?offset={offset}&limit={limit} - returns list of deals/transactions

GET /deals/{id} - return deal by id

GET /orders - returns list of orders

GET /orders/{id} - return order by id

GET /history - returns list of history orders

GET /history/{id} - return order history by id

POST /trade - open position, details in POST body

Example of POST body for trade command

Open Buy

{ 
  "symbol":"EURUSD", 
  "actionType": "ORDER_TYPE_BUY", 
  "volume": 0.1, 
  "stoploss": 1.3455, 
  "takeprofit": 1.33333, 
  "comment": "test buy"
}

Open Sell

{ 
  "symbol":"EURUSD", 
  "actionType": "ORDER_TYPE_SELL", 
  "volume": 0.1, 
  "stoploss": 1.3455, 
  "takeprofit": 1.33333, 
  "comment": "test buy"
}

Open Buy Limit

{ 
  "symbol":"EURUSD", 
  "actionType": "ORDER_TYPE_BUY_LIMIT", 
  "price": 1.4444, 
  "volume": 0.1, 
  "stoploss": 1.3455, 
  "takeprofit": 1.33333, 
  "comment": "test buy limit"
}

Open Sell Limit

{ 
  "symbol":"EURUSD", 
  "actionType": "ORDER_TYPE_SELL_LIMIT", 
  "price": 1.4444,
  "volume": 0.1, 
  "stoploss": 1.3455, 
  "takeprofit": 1.33333, 
  "comment": "test sell limit"
}

Open Buy Stop

{ 
  "symbol":"EURUSD", 
  "actionType": 
  "ORDER_TYPE_BUY_STOP", 
  "price": 1.4444, 
  "volume": 0.1, 
  "stoploss": 1.3455, 
  "takeprofit": 1.33333, 
  "comment": "test buy stop"
}

Open Sell Stop

{ 
  "symbol":"EURUSD", 
  "actionType": "ORDER_TYPE_SELL_STOP", 
  "price": 1.4444, 
  "volume": 0.1, 
  "stoploss": 1.3455, 
  "takeprofit": 1.33333, 
  "comment": "test sell stop"
}  

Position Close by ID

{ "actionType": "POSITION_CLOSE_ID", "id": 1212121 }

Order Cancel

{ "actionType": "ORDER_CANCEL", "id": 1212121 }

Order Cancel

{ "actionType": "POSITION_PARTIAL", "id": 1212121, "volume": 0.1 }

Examples of /trade output

{
    "error": 10018,
    "desription": "TRADE_RETCODE_MARKET_CLOSED",
    "order_id": 0,
    "volume": 0,
    "price": 0,
    "bid": 0,
    "ask": 0,
    "function": "CRestApi::tradingModule"
}
{
    "error": 10009,
    "desription": "TRADE_RETCODE_DONE",
    "order_id": 405895526,
    "volume": 0.1,
    "price": 1.13047,
    "bid": 1.13038,
    "ask": 1.13047,
    "function": "CRestApi::tradingModule"
}

mt5-rest's People

Contributors

mikha-dev avatar romankisilenko avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.