### Open Sell Order Example Source: https://github.com/devrico003/mt5-rest-api/blob/main/README.md Example JSON payload for opening a sell order. Includes symbol, order type, volume, stop loss, take profit, and a comment. ```json { "symbol": "EURUSD", "actionType": "ORDER_TYPE_SELL", "volume": 0.1, "stoploss": 1.11000, "takeprofit": 1.09000, "comment": "Sell order" } ``` -------------------------------- ### Position Management Examples Source: https://github.com/devrico003/mt5-rest-api/blob/main/README.md Examples for managing open positions and pending orders, including closing by ID, partial volume closure, modifying stop loss/take profit, and canceling pending orders. ```json // Close position by ID { "actionType": "POSITION_CLOSE_ID", "id": 123456789 } // Partial close { "actionType": "POSITION_PARTIAL", "id": 123456789, "volume": 0.05 } // Modify position { "actionType": "POSITION_MODIFY", "id": 123456789, "stoploss": 1.08500, "takeprofit": 1.11500 } // Cancel pending order { "actionType": "ORDER_CANCEL", "id": 123456789 } ``` -------------------------------- ### Open Buy Order Example Source: https://github.com/devrico003/mt5-rest-api/blob/main/README.md Example JSON payload for opening a buy order. Includes symbol, order type, volume, stop loss, take profit, and a comment. ```json { "symbol": "EURUSD", "actionType": "ORDER_TYPE_BUY", "volume": 0.1, "stoploss": 1.09000, "takeprofit": 1.11000, "comment": "Buy order" } ``` -------------------------------- ### Initialize Swagger UI Source: https://github.com/devrico003/mt5-rest-api/blob/main/MQL5/Libraries/docs.html This snippet initializes the Swagger UI for the API. Ensure the 'swagger.json' path is correct for your setup. ```javascript function render() { var ui = SwaggerUIBundle({ url: "/swagger.json", dom_id: '#swagger-ui', presets : [ SwaggerUIBundle.presets.apis, SwaggerUIBundle.SwaggerUIStandalonePreset ] }); } ``` -------------------------------- ### Pending Order Examples Source: https://github.com/devrico003/mt5-rest-api/blob/main/README.md Examples for creating various types of pending orders: Buy Limit, Sell Limit, Buy Stop, and Sell Stop. Each includes symbol, action type, price, volume, stop loss, and take profit. ```json // Buy Limit { "symbol": "EURUSD", "actionType": "ORDER_TYPE_BUY_LIMIT", "price": 1.08000, "volume": 0.1, "stoploss": 1.07000, "takeprofit": 1.10000 } // Sell Limit { "symbol": "EURUSD", "actionType": "ORDER_TYPE_SELL_LIMIT", "price": 1.12000, "volume": 0.1, "stoploss": 1.13000, "takeprofit": 1.10000 } // Buy Stop { "symbol": "EURUSD", "actionType": "ORDER_TYPE_BUY_STOP", "price": 1.12000, "volume": 0.1, "stoploss": 1.11000, "takeprofit": 1.14000 } // Sell Stop { "symbol": "EURUSD", "actionType": "ORDER_TYPE_SELL_STOP", "price": 1.08000, "volume": 0.1, "stoploss": 1.09000, "takeprofit": 1.06000 } ``` -------------------------------- ### Trade Execution Response Example Source: https://github.com/devrico003/mt5-rest-api/blob/main/README.md Example JSON response for a trade execution. Includes error code, description, order ID, volume, price, bid, ask, and the function that processed the request. Common return codes are provided for reference. ```json { "error": 10009, "description": "TRADE_RETCODE_DONE", "order_id": 405895526, "volume": 0.1, "price": 1.13047, "bid": 1.13038, "ask": 1.13047, "function": "CRestApi::tradingModule" } ``` -------------------------------- ### Fetch Historical Candlestick Data Source: https://github.com/devrico003/mt5-rest-api/blob/main/README.md Retrieve historical candlestick data for a given symbol. Specify timeframe, count, and start position. Default timeframe is H1, default count is 100, and default start position is 0. ```bash curl -H "Authorization: your-token" "http://localhost:6542/candles/EURGBP?timeframe=H1&count=100" ``` -------------------------------- ### Compile C++ DLL for MT5 REST API Source: https://github.com/devrico003/mt5-rest-api/blob/main/README.md Instructions for compiling the C++ DLL from source using Visual Studio. Ensure to select 'Release x64' and build the solution. ```bash 1. Open `mt5-rest.sln` in Visual Studio 2017+ 2. Select `Release x64` 3. Build (`Ctrl+Shift+B`) 4. Output: `/x64/Release/mt5-rest.dll` ``` -------------------------------- ### Account & Info Endpoints Source: https://github.com/devrico003/mt5-rest-api/blob/main/README.md Retrieve account details, balance, equity, margin, and symbol information. ```APIDOC ## GET /info ### Description Retrieves account details, including balance, equity, and margin information. ### Method GET ### Endpoint /info ## GET /balance ### Description Retrieves balance, equity, and margin information for the account. ### Method GET ### Endpoint /balance ## GET /symbols/{name} ### Description Retrieves information about a specific symbol, including current ask and bid prices. ### Method GET ### Endpoint /symbols/{name} ### Parameters #### Path Parameters - **name** (string) - Required - The name of the symbol. ``` -------------------------------- ### Trading Endpoint Source: https://github.com/devrico003/mt5-rest-api/blob/main/README.md Execute various trading actions such as opening, closing, and modifying orders and positions. ```APIDOC ## POST /trade ### Description Executes trading actions, including opening new orders, closing positions, modifying orders, and canceling pending orders. ### Method POST ### Endpoint /trade ### Request Body This endpoint accepts different JSON structures based on the `actionType` field. #### Example: Open Buy Order ```json { "symbol": "EURUSD", "actionType": "ORDER_TYPE_BUY", "volume": 0.1, "stoploss": 1.09000, "takeprofit": 1.11000, "comment": "Buy order" } ``` #### Example: Open Sell Order ```json { "symbol": "EURUSD", "actionType": "ORDER_TYPE_SELL", "volume": 0.1, "stoploss": 1.11000, "takeprofit": 1.09000, "comment": "Sell order" } ``` #### Example: Pending Orders ```json // Buy Limit { "symbol": "EURUSD", "actionType": "ORDER_TYPE_BUY_LIMIT", "price": 1.08000, "volume": 0.1, "stoploss": 1.07000, "takeprofit": 1.10000 } // Sell Limit { "symbol": "EURUSD", "actionType": "ORDER_TYPE_SELL_LIMIT", "price": 1.12000, "volume": 0.1, "stoploss": 1.13000, "takeprofit": 1.10000 } // Buy Stop { "symbol": "EURUSD", "actionType": "ORDER_TYPE_BUY_STOP", "price": 1.12000, "volume": 0.1, "stoploss": 1.11000, "takeprofit": 1.14000 } // Sell Stop { "symbol": "EURUSD", "actionType": "ORDER_TYPE_SELL_STOP", "price": 1.08000, "volume": 0.1, "stoploss": 1.09000, "takeprofit": 1.06000 } ``` #### Example: Position Management ```json // Close position by ID { "actionType": "POSITION_CLOSE_ID", "id": 123456789 } // Partial close { "actionType": "POSITION_PARTIAL", "id": 123456789, "volume": 0.05 } // Modify position { "actionType": "POSITION_MODIFY", "id": 123456789, "stoploss": 1.08500, "takeprofit": 1.11500 } // Cancel pending order { "actionType": "ORDER_CANCEL", "id": 123456789 } ``` ### Response #### Success Response (200) - **error** (integer) - Error code. `10009` indicates success. - **description** (string) - Description of the result, e.g., "TRADE_RETCODE_DONE". - **order_id** (integer) - The ID of the order or position affected. - **volume** (float) - The volume of the trade. - **price** (float) - The execution price. - **bid** (float) - The current bid price. - **ask** (float) - The current ask price. - **function** (string) - The internal function that processed the request. ### Response Example ```json { "error": 10009, "description": "TRADE_RETCODE_DONE", "order_id": 405895526, "volume": 0.1, "price": 1.13047, "bid": 1.13038, "ask": 1.13047, "function": "CRestApi::tradingModule" } ``` **Common Return Codes:** - `10009` - TRADE_RETCODE_DONE (Success) - `10018` - TRADE_RETCODE_MARKET_CLOSED - `10016` - TRADE_RETCODE_INVALID_STOPS - `10019` - TRADE_RETCODE_NO_MONEY ``` -------------------------------- ### Positions & Orders Endpoints Source: https://github.com/devrico003/mt5-rest-api/blob/main/README.md Manage and retrieve information about open positions, pending orders, order history, and deals. ```APIDOC ## GET /positions ### Description Lists all currently open positions. ### Method GET ### Endpoint /positions ## GET /positions/{id} ### Description Retrieves details of a specific open position by its ID. ### Method GET ### Endpoint /positions/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the position. ## GET /orders ### Description Lists all pending orders. ### Method GET ### Endpoint /orders ## GET /orders/{id} ### Description Retrieves details of a specific pending order by its ID. ### Method GET ### Endpoint /orders/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the order. ## GET /history ### Description Lists the history of executed orders. ### Method GET ### Endpoint /history ## GET /history/{id} ### Description Retrieves details of a specific historical order by its ID. ### Method GET ### Endpoint /history/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the historical order. ## GET /deals ### Description Lists all deals. Supports offset and limit for pagination. ### Method GET ### Endpoint /deals ### Parameters #### Query Parameters - **offset** (integer) - Optional - The number of deals to skip. - **limit** (integer) - Optional - The maximum number of deals to return. ## GET /deals/{id} ### Description Retrieves details of a specific deal by its ID. ### Method GET ### Endpoint /deals/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the deal. ``` -------------------------------- ### Historical Data (OHLCV) Endpoint Source: https://github.com/devrico003/mt5-rest-api/blob/main/README.md Retrieve historical candlestick data for a given symbol and timeframe. ```APIDOC ## GET /candles/{symbol} ### Description Retrieves historical candlestick data (OHLCV) for a specified symbol. ### Method GET ### Endpoint /candles/{symbol} ### Parameters #### Path Parameters - **symbol** (string) - Required - The trading symbol (e.g., EURUSD). #### Query Parameters - **timeframe** (string) - Optional - The timeframe for the candles. Accepted values: M1, M5, M15, M30, H1, H4, D1, W1, MN1. Defaults to H1. - **count** (integer) - Optional - The number of candles to retrieve. Must be between 1 and 1000. Defaults to 100. - **start_pos** (integer) - Optional - The starting position for retrieving candles. 0 represents the current candle. Defaults to 0. ### Request Example ```bash curl -H "Authorization: your-token" "http://localhost:6542/candles/EURGBP?timeframe=H1&count=100" ``` ### Response #### Success Response (200) - **symbol** (string) - The requested symbol. - **timeframe** (string) - The requested timeframe. - **count** (integer) - The number of candles returned. - **candles** (array) - An array of candle objects. - **time** (string) - The timestamp of the candle. - **open** (float) - The opening price. - **high** (float) - The highest price during the candle period. - **low** (float) - The lowest price during the candle period. - **close** (float) - The closing price. - **tick_volume** (integer) - The tick volume. - **spread** (integer) - The spread at the time of the candle. - **real_volume** (integer) - The real volume. ### Response Example ```json { "symbol": "EURGBP", "timeframe": "H1", "count": 100, "candles": [ { "time": "2025-12-02T22:00:00.000Z", "open": 0.87971, "high": 0.87994, "low": 0.87966, "close": 0.87985, "tick_volume": 1241, "spread": 0, "real_volume": 0 } ] } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.