### ModifiedOrdersMonitor Usage Example
Source: https://github.com/vdemydiuk/mtapi/blob/master/MtApi/Monitors/readme.md
Shows how to instantiate and use the `ModifiedOrdersMonitor` to track order modifications. It includes subscribing to the `OrdersModified` event and starting the monitor.
```csharp
var orderModifyMonitor = new ModifiedOrdersMonitor(
_apiClient,
new MtApi.Monitors.Triggers.TimeElapsedTrigger(TimeSpan.FromSeconds(1)),
OrderModifiedTypes.All,
true
);
orderModifyMonitor.OrdersModified += OrderModifyMonitor_OrdersModified;
orderModifyMonitor.Start();
private void OrderModifyMonitor_OrdersModified(object sender, ModifiedOrdersEventArgs e)
{
//Receives the event
}
```
--------------------------------
### Asynchronous Connection Example
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/README.md
Demonstrates how to establish an asynchronous connection to the trading platform and handle connection state changes.
```csharp
client.BeginConnect("localhost", 8222);
// Wait for ConnectionStateChanged event with Connected status
client.ConnectionStateChanged += (sender, e) =>
{
if (e.Status == Mt5ConnectionState.Connected)
{
// Perform trading operations
}
};
```
--------------------------------
### Synchronous Connection Example
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/README.md
Shows how to establish a synchronous connection to the trading platform using await and includes basic error handling.
```csharp
try
{
await client.Connect("localhost", 8222);
// Connection established
}
catch (Exception ex)
{
Console.WriteLine($"Connection failed: {ex.Message}");
}
```
--------------------------------
### Get Ask Price
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Gets the current ask price for a specified symbol. Requires the symbol as a string parameter.
```csharp
public double GetAsk(string symbol)
```
--------------------------------
### Get Bid Price
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Gets the current bid price for a specified symbol. Requires the symbol as a string parameter.
```csharp
public double GetBid(string symbol)
```
```csharp
double bid = client.GetBid("EURUSD");
```
--------------------------------
### Initiate Asynchronous Connection
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Start connecting to the MetaTrader 5 API on localhost using the default port. Listen for the ConnectionStateChanged event to confirm connection.
```csharp
client.BeginConnect("localhost", 8222);
// Listen for ConnectionStateChanged event to know when connected
```
--------------------------------
### Get Lot Size Step
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Retrieves the increment step for lot sizes.
```csharp
public double GetStepLot()
```
--------------------------------
### Configure Project File for Dependencies
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/configuration.md
Example of how to configure your project file (.csproj) to include the Newtonsoft.Json NuGet package and reference the MtApi5 and MtClient DLLs. This is useful for non-SDK style projects or specific build configurations.
```xml
../bin/MtApi5.dll
../bin/MtClient.dll
```
--------------------------------
### Get Last Bid Price
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Gets the last recorded bid price for a specified symbol. Requires the symbol as a string parameter.
```csharp
public double GetLastBid(string symbol)
```
--------------------------------
### Get Account Information
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/quickstart.md
This snippet shows how to retrieve key account information such as balance, equity, and free margin using the MT API.
```csharp
Console.WriteLine($"Balance: {client.GetAccountBalance()}");
Console.WriteLine($"Equity: {client.GetAccountEquity()}");
Console.WriteLine($"Free Margin: {client.GetAccountFreeMargin()}");
```
--------------------------------
### Example: Copy Rates for Symbol
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Demonstrates how to copy the last 100 hourly bars for the EURUSD symbol and print their open and close prices. Ensure the symbol and timeframe are valid.
```csharp
if (client.CopyRates("EURUSD", ENUM_TIMEFRAMES.PERIOD_H1, 0, 100, out var rates))
{
foreach (var rate in rates)
{
Console.WriteLine($"O={{rate.open}}, C={{rate.close}}");
}
}
```
--------------------------------
### Example: Retrieve History for Date Range
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Demonstrates how to retrieve historical trading data for the last 30 days. Ensure that the client object is properly initialized before calling this method.
```csharp
var from = DateTime.Now.AddDays(-30);
var to = DateTime.Now;
if (client.HistorySelect(from, to))
{
// Can now retrieve history orders and deals
}
```
--------------------------------
### Get Account Server
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Retrieves the name of the trading server the account is connected to. Returns a string or null.
```csharp
public string? GetAccountServer()
```
--------------------------------
### Get Minimum Lot Size
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Retrieves the minimum allowed order size (lot).
```csharp
public double GetMinLot()
```
--------------------------------
### Connect and Send Trade Operation (MT4 Specific)
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/configuration.md
Demonstrates connecting to MT4 and sending a trade operation using the TradeOperation enum. This example shows a basic buy order with stop loss and take profit.
```csharp
using MtApi;
var client = new MtApiClient();
// Same connection pattern
client.BeginConnect(8222);
// MT4 uses TradeOperation enum
int ticket = client.OrderSend(
symbol: "EURUSD",
cmd: TradeOperation.OP_BUY,
volume: 0.1,
price: 1.1000,
slippage: 10,
stoploss: 1.0900,
takeprofit: 1.1100
);
```
--------------------------------
### Get Account Leverage
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Retrieves the leverage ratio for the account, e.g., 100 for 1:100 leverage. Returns an integer.
```csharp
public int GetAccountLeverage()
```
--------------------------------
### Get Total Number of History Deals
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Returns the total count of deals available in the trading history.
```csharp
public int HistoryDealsTotal()
```
--------------------------------
### GetStepLot
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Gets the lot size step, which is the increment by which lot sizes can be adjusted during order placement.
```APIDOC
## GetStepLot
### Description
Gets lot size step. Retrieves the increment by which lot sizes can be adjusted during order placement.
### Method
GET (Implied)
### Endpoint
/market-data/step-lot
### Parameters
None
### Response
#### Success Response (200)
- **stepLot** (double) - The lot size step
```
--------------------------------
### Get Account Name
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Retrieves the name of the account holder. Returns a string or null.
```csharp
public string? GetAccountName()
```
--------------------------------
### MtMonitorBase SyncTrigger Example
Source: https://github.com/vdemydiuk/mtapi/blob/master/MtApi/Monitors/readme.md
Demonstrates how `SyncTrigger` in `MtMonitorBase` affects trigger behavior when multiple monitors share a trigger. Setting `SyncTrigger` to true can cause shared triggers to stop all associated monitors.
```csharp
var fooTrigger = new FooTrigger();
var fooMonitor = new FooMonitor(apiClient, fooTrigger, true);
var barMonitor = new FooMonitor(apiClient, fooTrigger, false);
fooTrigger.Start();
barMonitor.Start();
fooMonitor.Start();
fooMonitor.Stop(); //Because of SyncTrigger = true in the constructor of FooMonitor, fooTrigger.Stop() were triggered as well. Therefore barMonitor will not get any further triggers.
```
--------------------------------
### Get Market Data (Rates)
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/quickstart.md
This snippet shows how to retrieve historical market data (rates) for a specified symbol and timeframe. It fetches the latest 100 hourly bars.
```csharp
// Get latest 100 hourly bars
if (client.CopyRates("EURUSD", ENUM_TIMEFRAMES.PERIOD_H1, 0, 100, out var rates))
{
foreach (var rate in rates)
{
Console.WriteLine($"{rate.time}: O={rate.open} H={rate.high} L={rate.low} C={rate.close}");
}
}
```
--------------------------------
### Add MtApi5 NuGet Package
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/configuration.md
Install the MtApi5 NuGet package using the Package Manager Console in Visual Studio. This is the recommended way to include the library in your project.
```powershell
Install-Package MtApi5
```
--------------------------------
### Add JSONlab to MATLAB Path
Source: https://github.com/vdemydiuk/mtapi/blob/master/Examples/MatLab/AdvancedExample/Slack/private/README_JSONLAB.txt
Add the JSONlab toolbox to your MATLAB or Octave path to enable its functions. This is a one-time setup step.
```matlab
addpath('/path/to/jsonlab');
```
--------------------------------
### Get Spread
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Gets the current spread in points for a specified symbol. Requires the symbol as a string parameter.
```csharp
public int GetSpread(string symbol)
```
--------------------------------
### BeginConnect(string host, int port)
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Initiates an asynchronous connection to the MetaTrader 5 API using the provided host and port.
```APIDOC
## BeginConnect(string host, int port)
### Description
Initiates an asynchronous connection to MetaTrader 5 API.
### Method
POST
### Endpoint
/connect
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **host** (string) - Yes - Host address (e.g., "192.168.1.2" or "localhost")
- **port** (int) - Yes - Connection port (default 8222 for MT5)
### Throws
- ArgumentNullException: if host is null or empty
### Example
```csharp
client.BeginConnect("localhost", 8222);
// Listen for ConnectionStateChanged event to know when connected
```
```
--------------------------------
### Get Tick Value
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Gets the value of one tick for a specified symbol. Requires the symbol as a string parameter.
```csharp
public double GetTickValue(string symbol)
```
--------------------------------
### Place a BUY Order
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/quickstart.md
This snippet demonstrates how to place a BUY order using the MT API. It requires setting up an MqlTradeRequest object with order details and then sending it.
```csharp
var request = new MqlTradeRequest
{
Action = ENUM_TRADE_REQUEST_ACTIONS.TRADE_ACTION_DEAL,
Type = ENUM_ORDER_TYPE.ORDER_TYPE_BUY,
Symbol = "EURUSD",
Volume = 0.1,
Price = 1.1000,
Comment = "My first trade"
};
if (client.OrderSend(request, out var result))
{
Console.WriteLine($"Order sent: {result?.Order}");
}
```
--------------------------------
### BeginConnect(int port)
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Initiates an asynchronous connection to the MetaTrader 5 API on localhost using the specified port.
```APIDOC
## BeginConnect(int port)
### Description
Initiates an asynchronous connection to localhost.
### Method
POST
### Endpoint
/connect
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **port** (int) - Yes - Connection port (default 8222)
### Example
```csharp
client.BeginConnect(8222);
```
```
--------------------------------
### GetAsk
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Gets the current ask price for a specified financial symbol. The ask price is the lowest price a seller is willing to accept for a security or asset.
```APIDOC
## GetAsk
### Description
Gets current ask price for a symbol. The ask price is the lowest price a seller is willing to accept for a security or asset.
### Method
GET (Implied)
### Endpoint
/market-data/ask
### Parameters
#### Query Parameters
- **symbol** (string) - Required - The financial symbol for which to retrieve the ask price.
### Response
#### Success Response (200)
- **askPrice** (double) - The current ask price
```
--------------------------------
### Get Last Tick Time
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Gets the timestamp of the last received tick for a specified symbol. Requires the symbol as a string parameter.
```csharp
public DateTime GetLastTime(string symbol)
```
--------------------------------
### Begin Connecting to Localhost
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Initiate an asynchronous connection to the MetaTrader 4 terminal on the local machine using a specified port.
```csharp
client.BeginConnect(8222);
```
--------------------------------
### Create a Basic MT5 Console Application
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/quickstart.md
This snippet demonstrates how to create a basic console application using the MT5 API. It includes connecting to the terminal, retrieving quotes, and handling connection state changes.
```csharp
using System;
using System.Threading.Tasks;
using MtApi5;
class Program
{
static async Task Main()
{
var client = new MtApi5Client();
// Subscribe to connection events
client.ConnectionStateChanged += (sender, e) =>
{
Console.WriteLine($"Connection: {e.Status}");
};
// Connect to MT5
try
{
await client.Connect("localhost", 8222);
// Get quotes
var quotes = client.GetQuotes();
foreach (var q in quotes)
{
Console.WriteLine($"{q.Instrument}: {q.Bid}/{q.Ask}");
}
// Disconnect
client.Disconnect();
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
```
--------------------------------
### Get Account Currency
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Retrieves the base currency code of the trading account (e.g., "USD"). Returns a string or null.
```csharp
public string? GetAccountCurrency()
```
--------------------------------
### Get Last Ask Price
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Gets the last recorded ask price for a specified symbol. Requires the symbol as a string parameter.
```csharp
public double GetLastAsk(string symbol)
```
--------------------------------
### Configure and Send a Basic Trade Request
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/configuration.md
Set up a standard trade request for immediate execution (deal) with specified parameters like action, type, symbol, volume, price, and magic number. Use this for market orders.
```csharp
var request = new MqlTradeRequest
{
Action = ENUM_TRADE_REQUEST_ACTIONS.TRADE_ACTION_DEAL,
Type = ENUM_ORDER_TYPE.ORDER_TYPE_BUY,
Symbol = "EURUSD",
Volume = 0.1,
Price = 1.1000,
Magic = 12345,
Comment = "My order"
};
bool success = client.OrderSend(request, out var result);
```
--------------------------------
### Get Tick Size
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Gets the minimum price change (tick size) for a specified symbol. Requires the symbol as a string parameter.
```csharp
public double GetTickSize(string symbol)
```
--------------------------------
### Copy Ticks by Start Time
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Copies tick data for a symbol starting from a specified time. The `CopyTicksFlag` parameter controls the copy mode.
```csharp
public int CopyTicks(string symbol, MqlTick[]? ticks, CopyTicksFlag flag, DateTime startTime)
```
--------------------------------
### Place a SELL Order
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/quickstart.md
This snippet demonstrates how to place a SELL order using the MT API. It requires setting up an MqlTradeRequest object with order details and then sending it.
```csharp
var request = new MqlTradeRequest
{
Action = ENUM_TRADE_REQUEST_ACTIONS.TRADE_ACTION_DEAL,
Type = ENUM_ORDER_TYPE.ORDER_TYPE_SELL,
Symbol = "EURUSD",
Volume = 0.1,
Price = 1.1000,
};
client.OrderSend(request, out var result);
```
--------------------------------
### CopyRates
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Copies historical OHLC (Open, High, Low, Close) bar data for a specified symbol and timeframe. Supports retrieval by starting position or by start and end times.
```APIDOC
## CopyRates
### Description
Copies historical OHLC (Open, High, Low, Close) bar data for a specified symbol and timeframe. Supports retrieval by starting position or by start and end times.
### Method
POST (Implied)
### Endpoint
/price-data/copy-rates
### Parameters
#### Request Body
- **symbol** (string) - Required - The financial symbol.
- **timeframe** (ENUM_TIMEFRAMES) - Required - The timeframe for the bars (e.g., PERIOD_H1).
- **startPos** (int) - Optional - The starting position for retrieving bars (0 is the current/last bar).
- **count** (int) - Required - The number of bars to retrieve.
- **startTime** (DateTime) - Optional - The start time for retrieving bars.
- **stopTime** (DateTime) - Optional - The stop time for retrieving bars.
### Response
#### Success Response (200)
- **rates** (array of MqlRates) - An array of historical OHLC bar data.
- **time** (DateTime) - Timestamp of the bar.
- **open** (double) - Opening price.
- **high** (double) - Highest price during the bar.
- **low** (double) - Lowest price during the bar.
- **close** (double) - Closing price.
- **tickVolume** (long) - Tick volume.
- **spread** (int) - Spread at the time of the bar.
- **realVolume** (long) - Real volume (if available).
#### Example Request Body (by position)
{
"symbol": "EURUSD",
"timeframe": "PERIOD_H1",
"startPos": 0,
"count": 100
}
#### Example Request Body (by time range)
{
"symbol": "EURUSD",
"timeframe": "PERIOD_H1",
"startTime": "2023-01-01T00:00:00Z",
"stopTime": "2023-01-01T12:00:00Z"
}
```
--------------------------------
### OrderGetString
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Gets a string property of the currently selected order.
```APIDOC
## OrderGetString(ENUM_ORDER_PROPERTY_STRING propertyId)
### Description
Gets string property of selected order.
### Method
Not specified (assumed to be part of a client object)
### Parameters
#### Path Parameters
- **propertyId** (ENUM_ORDER_PROPERTY_STRING) - Yes - The ID of the property to retrieve
```
--------------------------------
### OrderGetInteger
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Gets an integer property of the currently selected order.
```APIDOC
## OrderGetInteger(ENUM_ORDER_PROPERTY_INTEGER propertyId)
### Description
Gets integer property of selected order.
### Method
Not specified (assumed to be part of a client object)
### Parameters
#### Path Parameters
- **propertyId** (ENUM_ORDER_PROPERTY_INTEGER) - Yes - The ID of the property to retrieve
```
--------------------------------
### MT4 Equivalent Code for Order Sending and Account Info
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/quickstart.md
This snippet provides an equivalent code example for MT4, demonstrating how to send orders using the TradeOperation enum and retrieve account information which returns double directly.
```csharp
using MtApi;
var client = new MtApiClient();
// Connection same as MT5
await client.Connect("localhost", 8222);
// But order sending uses TradeOperation enum
int ticket = client.OrderSend(
symbol: "EURUSD",
cmd: TradeOperation.OP_BUY,
volume: 0.1,
price: 1.1000,
slippage: 10,
stoploss: 1.0900,
takeprofit: 1.1100
);
// And account methods return double directly
double balance = client.GetAccountBalance();
```
--------------------------------
### Initialize MtApi5Client
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Instantiate the MtApi5Client with an optional custom logger for debugging purposes.
```csharp
var client = new MtApi5Client();
// or with custom logger
var client = new MtApi5Client(new CustomMtLogger());
```
--------------------------------
### Test with Small Positions
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/quickstart.md
Illustrates how to set a small volume for a trade request, useful for testing purposes without risking significant capital.
```csharp
var request = new MqlTradeRequest { Volume = 0.01, /* ... */ };
```
--------------------------------
### Get Account Number
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Retrieves the account number as an integer.
```csharp
public int GetAccountNumber()
```
--------------------------------
### Connect and Handle Errors
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/quickstart.md
Demonstrates how to connect to the MT API and handle potential connection exceptions. It also shows how to check the result of a trade operation.
```csharp
try
{
await client.Connect("localhost", 8222);
}
catch (Exception ex)
{
Console.WriteLine($"Connection failed: {ex.Message}");
}
// Check trade result
var request = new MqlTradeRequest { /* ... */ };
if (client.OrderSend(request, out var result))
{
if (result?.Retcode == 0)
{
Console.WriteLine("Trade successful");
}
else
{
Console.WriteLine($"Trade failed: {result?.Retcode}");
}
}
else
{
Console.WriteLine("Trade request validation failed");
}
```
--------------------------------
### OrdersTotal
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Gets the total number of orders currently managed.
```APIDOC
## OrdersTotal
### Description
Gets the total number of orders currently managed.
### Method
`OrdersTotal`
### Returns
`int` - The total number of orders.
```
--------------------------------
### OrderGetDouble
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Gets a double-precision floating-point property of the currently selected order.
```APIDOC
## OrderGetDouble(ENUM_ORDER_PROPERTY_DOUBLE propertyId)
### Description
Gets double property of selected order.
### Method
Not specified (assumed to be part of a client object)
### Parameters
#### Path Parameters
- **propertyId** (ENUM_ORDER_PROPERTY_DOUBLE) - Yes - The ID of the property to retrieve
```
--------------------------------
### Basic Logger Usage and Levels
Source: https://github.com/vdemydiuk/mtapi/blob/master/Examples/MatLab/AdvancedExample/logging4matlab/README.md
Demonstrates creating a logger with the default INFO level and logging messages at different severity levels. Messages below the logger's level (like DEBUG) are not shown.
```matlab
>> addpath('/path/to/logging4matlab')
>> logger = logging.getLogger('mylogger') % new logger with default level INFO
>> logger.info('life is just peachy')
logging.info 2016-09-14 15:10:06,049 INFO life is just peachy
>> logger.debug('Easy as pi! (Euclid)') % produces no output
>> logger.critical('run away!')
logging.critical 2016-09-14 15:12:37,652 CRITICAL run away!
```
--------------------------------
### GetMaxLot
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Gets the maximum allowed order size (lot size) for trading.
```APIDOC
## GetMaxLot
### Description
Gets maximum order size. Retrieves the maximum allowed order size (lot size) for trading.
### Method
GET (Implied)
### Endpoint
/market-data/max-lot
### Parameters
None
### Response
#### Success Response (200)
- **maxLot** (double) - The maximum order size
```
--------------------------------
### GetMinLot
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Gets the minimum allowed order size (lot size) for trading.
```APIDOC
## GetMinLot
### Description
Gets minimum order size. Retrieves the minimum allowed order size (lot size) for trading.
### Method
GET (Implied)
### Endpoint
/market-data/min-lot
### Parameters
None
### Response
#### Success Response (200)
- **minLot** (double) - The minimum order size
```
--------------------------------
### Connect(string host, int port)
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Synchronously connects to the MetaTrader 5 API using the provided host and port. This method waits for the connection to be established.
```APIDOC
## Connect(string host, int port)
### Description
Synchronously connects to MetaTrader 5 API.
### Method
POST
### Endpoint
/connect
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **host** (string) - Yes - Host address (e.g., "192.168.1.2" or "localhost")
- **port** (int) - Yes - Connection port
### Throws
- ArgumentNullException: if host is null or empty
- Exception: if connection fails
### Example
```csharp
try
{
await client.Connect("localhost", 8222);
Console.WriteLine("Connected successfully");
}
catch (Exception ex)
{
Console.WriteLine($"Connection failed: {ex.Message}");
}
```
```
--------------------------------
### Begin Connecting to MT4
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Initiate an asynchronous connection to the MetaTrader 4 terminal. Specify the host and port for the connection.
```csharp
client.BeginConnect("localhost", 8222);
```
--------------------------------
### ConnectionState Property
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Gets the current connection state of the MtApi5Client to the MetaTrader 5 API.
```APIDOC
## ConnectionState Property
### Description
Gets the current connection state.
### Method
Property Access
### Endpoint
N/A
### Parameters
None
### Response
#### Success Response
- **ConnectionState** (Mt5ConnectionState) - Connection state: Connecting, Connected, Disconnected, or Failed
```
--------------------------------
### Get Maximum Lot Size
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Retrieves the maximum allowed order size (lot).
```csharp
public double GetMaxLot()
```
--------------------------------
### BeginDisconnect()
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Initiates an asynchronous disconnection from the MetaTrader 5 API.
```APIDOC
## BeginDisconnect()
### Description
Initiates asynchronous disconnection from MetaTrader 5 API.
### Method
POST
### Endpoint
/disconnect
### Parameters
None
### Example
```csharp
client.BeginDisconnect();
```
```
--------------------------------
### Event Loop Pattern with MTAPI
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/quickstart.md
Sets up an event-driven application using MtApi5Client. It includes connecting, subscribing to events like connection state changes, quote updates, and trade transactions, and keeping the application running.
```csharp
var client = new MtApi5Client();
// Set up event handlers
client.ConnectionStateChanged += OnConnectionChanged;
client.QuoteUpdate += OnQuoteUpdate;
client.OnTradeTransaction += OnTrade;
// Connect
client.BeginConnect(8222);
// Keep application running
Console.ReadLine();
// Cleanup
client.Disconnect();
void OnConnectionChanged(object? sender, Mt5ConnectionEventArgs e)
{
Console.WriteLine($"Connection: {e.Status}");
}
void OnQuoteUpdate(object? sender, Mt5QuoteEventArgs e)
{
Console.WriteLine($"{e.Quote.Instrument}: {e.Quote.Bid}/{e.Quote.Ask}");
}
void OnTrade(object? sender, Mt5TradeTransactionEventArgs e)
{
Console.WriteLine($"Trade: {e.Trans.Symbol} {e.Trans.Volume} @ {e.Trans.Price}");
}
```
--------------------------------
### Reference MtApi5 and MtClient DLLs
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/configuration.md
Alternatively, reference the MtApi5.dll and MtClient.dll directly from their respective bin directories if not using NuGet. Ensure the paths are correct relative to your project.
```text
- Add reference to: ../bin/MtApi5.dll
- Also reference: ../bin/MtClient.dll
```
--------------------------------
### Reuse MTAPI Client Instance for Efficiency
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/configuration.md
Demonstrates the recommended practice of reusing a single MTAPI client instance for multiple operations to improve performance and reduce overhead. Ensure the client is connected before performing operations.
```csharp
// Good: reuse single client
var client = new MtApi5Client();
await client.Connect("localhost", 8222);
// Perform multiple operations
var quotes = client.GetQuotes();
var symbols = client.GetSymbols(true);
// ... more operations
```
--------------------------------
### Get Total Number of History Orders
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Returns the total count of orders available in the trading history.
```csharp
public int HistoryOrdersTotal()
```
--------------------------------
### Initialize MtApiClient
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Instantiate the MtApiClient class. An optional custom logger can be provided for debugging purposes.
```csharp
var client = new MtApiClient();
// or with custom logger
var client = new MtApiClient(new CustomMtLogger());
```
--------------------------------
### Get Total Open Positions
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Use PositionsTotal to retrieve the current count of all open positions on the account.
```csharp
int posCount = client.PositionsTotal();
Console.WriteLine($"Total positions: {posCount}");
```
--------------------------------
### CommandTimeout Property
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Gets or sets the timeout for MetaTrader API responses in milliseconds. The default is 30 seconds.
```APIDOC
## CommandTimeout Property
### Description
Gets or sets the timeout for MetaTrader API responses (in milliseconds). Default is 30 seconds (30000 ms).
### Method
Property Access
### Endpoint
N/A
### Parameters
None
### Response
#### Success Response
- **CommandTimeout** (int) - Timeout in milliseconds. Must be greater than zero.
```
--------------------------------
### Connection Methods
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/method-reference.md
Methods for managing the connection to the MT5 terminal.
```APIDOC
## Connection Methods (MtApi5Client)
### BeginConnect
- **Description**: Asynchronously connects to the MT5 terminal.
- **Signature**: `void BeginConnect(int port)`
- **Returns**: `void`
### BeginConnect
- **Description**: Asynchronously connects to the MT5 terminal using a specified host and port.
- **Signature**: `void BeginConnect(string host, int port)`
- **Returns**: `void`
### Connect
- **Description**: Synchronously connects to the MT5 terminal.
- **Signature**: `async Task Connect(string host, int port)`
- **Returns**: `Task`
### Disconnect
- **Description**: Disconnects from the MT5 terminal.
- **Signature**: `void Disconnect()`
- **Returns**: `void`
### BeginDisconnect
- **Description**: Asynchronously disconnects from the MT5 terminal.
- **Signature**: `void BeginDisconnect()`
- **Returns**: `void`
```
--------------------------------
### Enable Logging with Custom Logger
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/quickstart.md
Shows how to enable logging by passing a custom logger instance to the MtApi5Client constructor. This is useful for debugging.
```csharp
var client = new MtApi5Client(new CustomMtLogger());
```
--------------------------------
### Get Account Company
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Retrieves the name of the broker company associated with the account. Returns a string or null.
```csharp
public string? GetAccountCompany()
```
--------------------------------
### Configure and Send a Pending Buy Limit Order
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/configuration.md
Create a pending buy limit order request. This order will be placed when the market price reaches the specified limit price, which is below the current market price. Includes stop loss and take profit levels.
```csharp
var request = new MqlTradeRequest
{
Action = ENUM_TRADE_REQUEST_ACTIONS.TRADE_ACTION_PENDING,
Type = ENUM_ORDER_TYPE.ORDER_TYPE_BUY_LIMIT,
Symbol = "EURUSD",
Volume = 0.1,
Price = 1.0900, // Limit price below market
Sl = 1.0800,
Tp = 1.1000,
Magic = 12345
};
client.OrderSend(request, out var result);
```
--------------------------------
### Get History Deal Ticket by Index
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Retrieves the ticket number of a history deal based on its index in the history.
```csharp
public ulong HistoryDealGetTicket(int index)
```
--------------------------------
### Basic MT5 Client Connection
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/configuration.md
Establishes a connection to a local MT5 terminal on the default port. Subscribes to connection state changes to monitor the connection status.
```csharp
using MtApi5;
// Create client (MT5)
var client = new MtApi5Client();
// Subscribe to connection events
client.ConnectionStateChanged += (sender, e) =>
{
Console.WriteLine($"Status: {e.Status} - {e.Message}");
};
// Connect to localhost on default port
client.BeginConnect(8222);
```
--------------------------------
### Get History Order Ticket by Index
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Retrieves the ticket number of a history order based on its index in the history.
```csharp
public ulong HistoryOrderGetTicket(int index)
```
--------------------------------
### OrderSendBuy Basic
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Sends a BUY order using basic parameters. Requires symbol, volume, and slippage.
```csharp
public int OrderSendBuy(string symbol, double volume, int slippage)
```
```csharp
int ticket = client.OrderSendBuy("EURUSD", 0.1, 10);
```
--------------------------------
### OrderSendSell Basic
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Sends a SELL order using basic parameters. Requires symbol, volume, and slippage.
```csharp
public int OrderSendSell(string symbol, double volume, int slippage)
```
--------------------------------
### ExecutorHandle Property
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Gets or sets the expert handle used for executing commands within the MetaTrader 5 API.
```APIDOC
## ExecutorHandle Property
### Description
Gets or sets the expert handle used for executing commands.
### Method
Property Access
### Endpoint
N/A
### Parameters
None
### Response
#### Success Response
- **ExecutorHandle** (int) - Expert handle identifier
```
--------------------------------
### GetSpread
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Gets the current spread in points for a specified financial symbol. The spread is the difference between the bid and ask prices.
```APIDOC
## GetSpread
### Description
Gets current spread in points for a symbol. The spread is the difference between the bid and ask prices.
### Method
GET (Implied)
### Endpoint
/market-data/spread
### Parameters
#### Query Parameters
- **symbol** (string) - Required - The financial symbol for which to retrieve the spread.
### Response
#### Success Response (200)
- **spread** (int) - The current spread in points
```
--------------------------------
### Utility Methods
Source: https://github.com/vdemydiuk/mtapi/blob/master/Examples/MatLab/AdvancedExample/logging4matlab/README.md
Utility methods for managing logger settings.
```APIDOC
## Utility Methods
### Description
Provides utility functions to configure the logger's behavior.
### Methods
* **logger.setFileName(string)**: Sets or changes the log file path.
* **logger.setCommandWindowLevel(level)**: Sets the command window log level. `level` can be a string or integer.
* **logger.setLogLevel(level)**: Sets the file log level. `level` can be a string or integer.
```
--------------------------------
### Mt5Client Constructor
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Initializes a new instance of the MtApi5Client class. An optional logger can be provided for debugging purposes.
```APIDOC
## Mt5Client Constructor
### Description
Initializes a new instance of MtApi5Client.
### Method
Constructor
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Parameters
- **log** (IMtLogger?) - Optional - Optional logger instance for debugging. If null, uses StubMtLogger.
```
--------------------------------
### Get Account Margin
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Retrieves the used margin for the trading account. Returns a double representing the used margin.
```csharp
public double GetAccountMargin()
```
--------------------------------
### Listen to Bar Close Events
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/quickstart.md
This snippet demonstrates how to subscribe to events that are triggered when a new bar is closed for a specific instrument and timeframe. It logs the closing price.
```csharp
client.OnLastTimeBar += (sender, e) =>
{
Console.WriteLine($"{e.Instrument} {e.Timeframe} bar closed");
Console.WriteLine($" Close: {e.Rates.close}");
};
```
--------------------------------
### Get Account Equity
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Retrieves the current equity of the trading account. Returns a double representing the account equity.
```csharp
public double GetAccountEquity()
```
--------------------------------
### OrderSendBuy with Stoploss and Takeprofit
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Sends a BUY order including stoploss and takeprofit levels.
```csharp
public int OrderSendBuy(string symbol, double volume, int slippage, double stoploss, double takeprofit)
```
--------------------------------
### Configure a Pending Order with Expiration
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/configuration.md
Set up a pending buy limit order that includes an expiration date. The order will be automatically canceled if not filled by the specified time. Ensure the Type_time is set to ORDER_TIME_SPECIFIED.
```csharp
var request = new MqlTradeRequest
{
Action = ENUM_TRADE_REQUEST_ACTIONS.TRADE_ACTION_PENDING,
Type = ENUM_ORDER_TYPE.ORDER_TYPE_BUY_LIMIT,
Symbol = "EURUSD",
Volume = 0.1,
Price = 1.0900,
Type_time = ENUM_ORDER_TYPE_TIME.ORDER_TIME_SPECIFIED,
Expiration = DateTime.Now.AddDays(7), // Expires in 7 days
};
client.OrderSend(request, out var result);
```
--------------------------------
### GetTickValue
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Gets the value of a single tick for a specified financial symbol. This represents the monetary value of the smallest price change.
```APIDOC
## GetTickValue
### Description
Gets value of one tick for a symbol. This represents the monetary value of the smallest price change.
### Method
GET (Implied)
### Endpoint
/market-data/tick-value
### Parameters
#### Query Parameters
- **symbol** (string) - Required - The financial symbol for which to retrieve the tick value.
### Response
#### Success Response (200)
- **tickValue** (double) - The monetary value of one tick
```
--------------------------------
### GetTickSize
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Gets the tick size for a specified financial symbol. The tick size is the minimum price movement (increment) for that symbol.
```APIDOC
## GetTickSize
### Description
Gets minimum price change (tick) for a symbol. The tick size is the minimum price movement (increment) for that symbol.
### Method
GET (Implied)
### Endpoint
/market-data/tick-size
### Parameters
#### Query Parameters
- **symbol** (string) - Required - The financial symbol for which to retrieve the tick size.
### Response
#### Success Response (200)
- **tickSize** (double) - The minimum price change (tick size)
```
--------------------------------
### MqlBookInfo Structure
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/types.md
Represents an order book entry (depth of market).
```csharp
public class MqlBookInfo
{
public ENUM_BOOK_TYPE Type { get; set; }
public double Price { get; set; }
public ulong Volume { get; set; }
}
```
--------------------------------
### Access Executor Handle
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Get or set the expert handle used for executing commands within the MetaTrader 4 terminal.
```csharp
int handle = client.ExecutorHandle;
client.ExecutorHandle = 100;
```
--------------------------------
### List Open Positions
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/quickstart.md
This snippet demonstrates how to list all open positions and retrieve their symbols and tickets. It iterates through the total number of positions available.
```csharp
int posCount = client.PositionsTotal();
Console.WriteLine($"Total positions: {posCount}");
for (int i = 0; i < posCount; i++)
{
var symbol = client.PositionGetSymbol(i);
var ticket = client.PositionGetTicket(i);
Console.WriteLine($"Position {i}: {symbol} (ticket {ticket})");
}
```
--------------------------------
### Get Symbols and Quotes
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/configuration.md
Retrieves all selected symbols and then fetches current quotes for them. Ensure the client is connected before calling these methods.
```csharp
// Get all available symbols
var selectedSymbols = client.GetSymbols(selected: true); // Symbols in MarketWatch
// Send quote event for all selected symbols
var quotes = client.GetQuotes();
foreach (var quote in quotes)
{
// Process each quote
}
```
--------------------------------
### Logging Methods
Source: https://github.com/vdemydiuk/mtapi/blob/master/Examples/MatLab/AdvancedExample/logging4matlab/README.md
Methods to log output at different severity levels.
```APIDOC
## Logging Methods
### Description
These methods are used to log messages at various severity levels.
### Methods
* **logger.trace(string)**: Logs a message at the TRACE level.
* **logger.debug(string)**: Logs a message at the DEBUG level.
* **logger.info(string)**: Logs a message at the INFO level.
* **logger.warn(string)**: Logs a message at the WARNING level.
* **logger.error(string)**: Logs a message at the ERROR level.
* **logger.critical(string)**: Logs a message at the CRITICAL level.
```
--------------------------------
### Get String Property of Selected Position
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Retrieves a string property of the currently selected position. The property is identified by an ENUM_POSITION_PROPERTY_STRING value.
```csharp
public string? PositionGetString(ENUM_POSITION_PROPERTY_STRING propertyId)
```
--------------------------------
### Synchronously Connect to MetaTrader 5
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Establish a synchronous connection to the MetaTrader 5 API. Handles potential connection failures with a try-catch block.
```csharp
try
{
await client.Connect("localhost", 8222);
Console.WriteLine("Connected successfully");
}
catch (Exception ex)
{
Console.WriteLine($"Connection failed: {ex.Message}");
}
```
--------------------------------
### Get Position Ticket by Index
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Retrieves the ticket number for a position at a specified index. This method returns the unique identifier for the position.
```csharp
public ulong PositionGetTicket(int index)
```
--------------------------------
### Retrieve Symbols
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Get a list of symbols from the MarketWatch window. Specify 'true' to retrieve only selected symbols, or 'false' for all available symbols.
```csharp
var selectedSymbols = client.GetSymbols(true);
var allSymbols = client.GetSymbols(false);
```
--------------------------------
### Get Account Profit
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Retrieves the total profit or loss for the trading account in the account's base currency. Returns a double.
```csharp
public double GetAccountProfit()
```
--------------------------------
### Get Account Free Margin
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Retrieves the available free margin for the trading account. Returns a double representing the free margin.
```csharp
public double GetAccountFreeMargin()
```
--------------------------------
### MT5 Connection State Event Handler
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/configuration.md
Sets up an event handler to monitor and react to changes in the MT5 client's connection state, including connecting, connected, disconnected, and failed states.
```csharp
client.ConnectionStateChanged += (sender, e) =>
{
switch (e.Status)
{
case Mt5ConnectionState.Connecting:
Console.WriteLine("Connecting...");
break;
case Mt5ConnectionState.Connected:
Console.WriteLine("Connected!");
break;
case Mt5ConnectionState.Disconnected:
Console.WriteLine("Disconnected");
break;
case Mt5ConnectionState.Failed:
Console.WriteLine($"Failed: {e.Message}");
break;
}
};
```
--------------------------------
### GetOrder Method
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi4-client.md
Retrieves detailed information for a specific order using its ticket.
```csharp
public MtOrder? GetOrder(int ticket)
```
```csharp
var order = client.GetOrder(12345);
if (order != null)
{
Console.WriteLine($"Type: {order.Type}, Volume: {order.Volume}, Price: {order.Price}");
}
```
--------------------------------
### Create and Send Slack Notification with Attachment
Source: https://github.com/vdemydiuk/mtapi/blob/master/Examples/MatLab/AdvancedExample/Slack/README.md
Demonstrates how to create a Slack message attachment and send it as a notification using SendSlackNotification. Requires a Slack Incoming Webhooks URL.
```matlab
% - Create a message attachment to send with a notification
% (optional; several message attachments can be sent with a single notification)
sA = MakeSlackAttachment('New open task [urgent]: ', 'Text of the notification message',
'Text that will be displayed before the message', '#0000ff',
{'Field 1 title', 'This is a field that will be shown in a table'},
{'Field 2 title', 'This is another field that will be shown in a table'});
% - Send the notification, with the attached message
SendSlackNotification('https://hooks.slack.com/services/this/is/your/webhook/url',
'I sent this notification from matlab, on behalf of @username.', '#target-channel',
'Name to post under', 'http://www.icon.com/url/to/icon/image.png', [], sA);
```
--------------------------------
### Connect to MetaTrader Asynchronously
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/quickstart.md
This snippet shows how to asynchronously connect to MetaTrader using the MT API. It includes initiating the connection and checking the connection state after a delay.
```csharp
var client = new MtApi5Client();
// Async connection
client.BeginConnect(8222);
// Wait for connection
await Task.Delay(2000);
if (client.ConnectionState == Mt5ConnectionState.Connected)
{
Console.WriteLine("Connected!");
}
```
--------------------------------
### Get String Property of Selected Order
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Retrieves a string property of the currently selected order. The property is identified by an ENUM_ORDER_PROPERTY_STRING enum value.
```csharp
public string? OrderGetString(ENUM_ORDER_PROPERTY_STRING propertyId)
```
--------------------------------
### Get Integer Property of Selected Order
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Retrieves an integer property of the currently selected order. The property is identified by an ENUM_ORDER_PROPERTY_INTEGER enum value.
```csharp
public long OrderGetInteger(ENUM_ORDER_PROPERTY_INTEGER propertyId)
```
--------------------------------
### Connect to MTAPI Client with Custom Logger
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/configuration.md
Establishes a connection to the MTAPI client, setting a custom logger and increasing the command timeout for debugging purposes. Ensure the MTAPI server is running on localhost:8222.
```csharp
var logger = new CustomMtLogger();
var client = new MtApi5Client(logger);
client.CommandTimeout = 60000; // Increase timeout for debugging
await client.Connect("localhost", 8222);
```
--------------------------------
### Get Integer Property of Selected Position
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Retrieves an integer property of the currently selected position. The specific property is identified by an ENUM_POSITION_PROPERTY_INTEGER value.
```csharp
public long PositionGetInteger(ENUM_POSITION_PROPERTY_INTEGER propertyId)
```
--------------------------------
### Properties
Source: https://github.com/vdemydiuk/mtapi/blob/master/Examples/MatLab/AdvancedExample/logging4matlab/README.md
Readable and writable properties for configuring the logger.
```APIDOC
## Properties
### Description
Allows reading and writing of logger configuration settings.
### Writable Properties
* **logger.datefmt** (string): The date/time format string for logs.
* **logger.commandWindowLevel** (string or integer): The command window log level. Returns an integer.
* **logger.logLevel** (string or integer): The file log level. Returns an integer.
### Read-Only Properties
* **logging.logging.ALL** (integer): Integer value for the ALL level (0).
* **logging.logging.TRACE** (integer): Integer value for the TRACE level (1).
* **logging.logging.DEBUG** (integer): Integer value for the DEBUG level (2).
* **logging.logging.INFO** (integer): Integer value for the INFO level (3).
* **logging.logging.WARNING** (integer): Integer value for the WARNING level (4).
* **logging.logging.ERROR** (integer): Integer value for the ERROR level (5).
* **logging.logging.CRITICAL** (integer): Integer value for the CRITICAL level (6).
* **logging.logging.OFF** (integer): Integer value for the OFF level (6).
```
--------------------------------
### Get Double Property of Selected Position
Source: https://github.com/vdemydiuk/mtapi/blob/master/_autodocs/api-reference-mtapi5-client.md
Retrieves a double-precision floating-point property of the currently selected position. Requires a position to be selected first.
```csharp
client.PositionSelect("EURUSD");
double volume = client.PositionGetDouble(ENUM_POSITION_PROPERTY_DOUBLE.POSITION_VOLUME);
double profit = client.PositionGetDouble(ENUM_POSITION_PROPERTY_DOUBLE.POSITION_PROFIT);
```