mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-13 10:48:08 +00:00
Compare commits
20
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be8a17c0fd | ||
|
|
5c6751de9b | ||
|
|
83776f8b7a | ||
|
|
f1c1df1e00 | ||
|
|
d6640300f5 | ||
|
|
c9c188f697 | ||
|
|
3a4f561836 | ||
|
|
bdb30edee3 | ||
|
|
29f501b055 | ||
|
|
521d7ea2c0 | ||
|
|
0e5bb40a6f | ||
|
|
14079dc3c1 | ||
|
|
3600a86971 | ||
|
|
83e62fbff7 | ||
|
|
5c96aeb2fd | ||
|
|
a238e5eb36 | ||
|
|
11fd5b7527 | ||
|
|
cbe75cfbf6 | ||
|
|
9581431a9f | ||
|
|
acf0c12531 |
@@ -8,6 +8,50 @@ using log4net.Repository.Hierarchy;
|
|||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
{
|
{
|
||||||
|
public class MtLog
|
||||||
|
{
|
||||||
|
#region ctor
|
||||||
|
internal MtLog(Type type)
|
||||||
|
{
|
||||||
|
_log = LogManager.GetLogger(type);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public
|
||||||
|
|
||||||
|
public void Debug(object message)
|
||||||
|
{
|
||||||
|
_log.Debug(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Error(object message)
|
||||||
|
{
|
||||||
|
_log.Error(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Fatal(object message)
|
||||||
|
{
|
||||||
|
_log.Fatal(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Info(object message)
|
||||||
|
{
|
||||||
|
_log.Info(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Warn(object message)
|
||||||
|
{
|
||||||
|
_log.Warn(message);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Private
|
||||||
|
|
||||||
|
private readonly ILog _log;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
public class LogConfigurator
|
public class LogConfigurator
|
||||||
{
|
{
|
||||||
private const string LogFileNameExtension = "txt";
|
private const string LogFileNameExtension = "txt";
|
||||||
@@ -48,5 +92,13 @@ namespace MTApiService
|
|||||||
#endif
|
#endif
|
||||||
hierarchy.Configured = true;
|
hierarchy.Configured = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MtLog GetLogger(Type type)
|
||||||
|
{
|
||||||
|
if (type == null)
|
||||||
|
throw new ArgumentNullException(nameof(type));
|
||||||
|
|
||||||
|
return new MtLog(type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.28.0")]
|
[assembly: AssemblyVersion("1.0.29.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.28.0")]
|
[assembly: AssemblyFileVersion("1.0.29.0")]
|
||||||
@@ -994,6 +994,12 @@ namespace MtApi
|
|||||||
return MtApiTimeConverter.ConvertFromMtTime(commandResponse);
|
return MtApiTimeConverter.ConvertFromMtTime(commandResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DateTime TimeGMT()
|
||||||
|
{
|
||||||
|
var commandResponse = SendCommand<int>(MtCommandType.TimeGMT, null);
|
||||||
|
return MtApiTimeConverter.ConvertFromMtTime(commandResponse);
|
||||||
|
}
|
||||||
|
|
||||||
public int TimeDay(DateTime date)
|
public int TimeDay(DateTime date)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { MtApiTimeConverter.ConvertToMtTime(date) };
|
var commandParameters = new ArrayList { MtApiTimeConverter.ConvertToMtTime(date) };
|
||||||
|
|||||||
@@ -111,6 +111,7 @@
|
|||||||
TimeSeconds = 86,
|
TimeSeconds = 86,
|
||||||
TimeYear = 87,
|
TimeYear = 87,
|
||||||
Year = 88,
|
Year = 88,
|
||||||
|
TimeGMT = 281,
|
||||||
|
|
||||||
//Global Variables
|
//Global Variables
|
||||||
GlobalVariableCheck = 89,
|
GlobalVariableCheck = 89,
|
||||||
|
|||||||
+3
-1
@@ -1,4 +1,6 @@
|
|||||||
namespace MtApi
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
|
namespace MtApi
|
||||||
{
|
{
|
||||||
public enum ENUM_TERMINAL_INFO_STRING
|
public enum ENUM_TERMINAL_INFO_STRING
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.39.0")]
|
[assembly: AssemblyVersion("1.0.40.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.39.0")]
|
[assembly: AssemblyFileVersion("1.0.40.0")]
|
||||||
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
// ReSharper disable InconsistentNaming
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
// ReSharper disable InconsistentNaming
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
namespace MtApi5
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
public class MqlTradeCheckResult
|
public class MqlTradeCheckResult
|
||||||
{
|
{
|
||||||
public uint Retcode { get; private set; } // Reply code
|
public uint Retcode { get; } // Reply code
|
||||||
public double Balance { get; private set; } // Balance after the execution of the deal
|
public double Balance { get; } // Balance after the execution of the deal
|
||||||
public double Equity { get; private set; } // Equity after the execution of the deal
|
public double Equity { get; } // Equity after the execution of the deal
|
||||||
public double Profit { get; private set; } // Floating profit
|
public double Profit { get; } // Floating profit
|
||||||
public double Margin { get; private set; } // Margin requirements
|
public double Margin { get; } // Margin requirements
|
||||||
public double Margin_free { get; private set; } // Free margin
|
public double Margin_free { get; } // Free margin
|
||||||
public double Margin_level { get; private set; } // Margin level
|
public double Margin_level { get; } // Margin level
|
||||||
public string Comment { get; private set; } // Comment to the reply code (description of the error)
|
public string Comment { get; } // Comment to the reply code (description of the error)
|
||||||
|
|
||||||
public MqlTradeCheckResult(uint retcode
|
public MqlTradeCheckResult(uint retcode
|
||||||
, double balance
|
, double balance
|
||||||
@@ -29,5 +31,10 @@
|
|||||||
Margin_level = margin_level;
|
Margin_level = margin_level;
|
||||||
Comment = comment;
|
Comment = comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"Retcode={Retcode}; Comment={Comment}; Balance={Balance}; Equity={Equity}; Profit={Profit}; Margin={Margin}; Margin_free={Margin_free}; Margin_level={Margin_level}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
// ReSharper disable InconsistentNaming
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
@@ -21,5 +22,12 @@ namespace MtApi5
|
|||||||
public string Comment { get; set; } // Order comment
|
public string Comment { get; set; } // Order comment
|
||||||
public ulong Position { get; set; } // Position ticket
|
public ulong Position { get; set; } // Position ticket
|
||||||
public ulong PositionBy { get; set; } // The ticket of an opposite position
|
public ulong PositionBy { get; set; } // The ticket of an opposite position
|
||||||
|
|
||||||
|
public int MtExpiration => Mt5TimeConverter.ConvertToMtTime(Expiration);
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"{Symbol}|{Volume}|{Price}|{Volume}|{Action}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-11
@@ -1,4 +1,6 @@
|
|||||||
namespace MtApi5
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
public class MqlTradeResult
|
public class MqlTradeResult
|
||||||
{
|
{
|
||||||
@@ -15,19 +17,32 @@
|
|||||||
Request_id = request_id;
|
Request_id = request_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public uint Retcode { get; private set; } // Operation return code
|
internal MqlTradeResult(MqlTradeResult o)
|
||||||
public ulong Deal { get; private set; } // Deal ticket, if it is performed
|
{
|
||||||
public ulong Order { get; private set; } // Order ticket, if it is placed
|
Retcode = o.Retcode;
|
||||||
public double Volume { get; private set; } // Deal volume, confirmed by broker
|
Deal = o.Deal;
|
||||||
public double Price { get; private set; } // Deal price, confirmed by broker
|
Order = o.Order;
|
||||||
public double Bid { get; private set; } // Current Bid price
|
Volume = o.Volume;
|
||||||
public double Ask { get; private set; } // Current Ask price
|
Price = o.Price;
|
||||||
public string Comment { get; private set; } // Broker comment to operation (by default it is filled by the operation description)
|
Bid = o.Bid;
|
||||||
public uint Request_id { get; private set; } // Request ID set by the terminal during the dispatch
|
Ask = o.Ask;
|
||||||
|
Comment = o.Comment;
|
||||||
|
Request_id = o.Request_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public uint Retcode { get; } // Operation return code
|
||||||
|
public ulong Deal { get; } // Deal ticket, if it is performed
|
||||||
|
public ulong Order { get; } // Order ticket, if it is placed
|
||||||
|
public double Volume { get; } // Deal volume, confirmed by broker
|
||||||
|
public double Price { get; } // Deal price, confirmed by broker
|
||||||
|
public double Bid { get; } // Current Bid price
|
||||||
|
public double Ask { get; } // Current Ask price
|
||||||
|
public string Comment { get; } // Broker comment to operation (by default it is filled by the operation description)
|
||||||
|
public uint Request_id { get; } // Request ID set by the terminal during the dispatch
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"Retcode={Retcode}; Deal={Deal}; Order={Order}; Volume={Volume}; Price={Price}; Bid={Bid}; Ask={Ask}; Comment={Comment}; Request_id={Request_id}";
|
return $"Retcode={Retcode}; Comment={Comment}; Deal={Deal}; Order={Order}; Volume={Volume}; Price={Price}; Bid={Bid}; Ask={Ask}; Request_id={Request_id}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
namespace MtApi5
|
// ReSharper disable InconsistentNaming
|
||||||
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
internal enum Mt5CommandType
|
internal enum Mt5CommandType
|
||||||
{
|
{
|
||||||
//NoCommand = 0
|
//NoCommand = 0
|
||||||
|
|
||||||
//trade operations
|
//trade operations
|
||||||
OrderSend = 1,
|
//OrderSend = 1,
|
||||||
OrderCalcMargin = 2,
|
OrderCalcMargin = 2,
|
||||||
OrderCalcProfit = 3,
|
OrderCalcProfit = 3,
|
||||||
OrderCheck = 4,
|
//OrderCheck = 4,
|
||||||
//OrderSendAsync = 5,
|
//OrderSendAsync = 5,
|
||||||
PositionsTotal = 6,
|
PositionsTotal = 6,
|
||||||
PositionGetSymbol = 7,
|
PositionGetSymbol = 7,
|
||||||
@@ -100,7 +101,7 @@
|
|||||||
//CTrade
|
//CTrade
|
||||||
PositionClose = 64,
|
PositionClose = 64,
|
||||||
PositionOpen = 65,
|
PositionOpen = 65,
|
||||||
PositionOpenWithResult = 1065,
|
//PositionOpenWithResult = 1065,
|
||||||
|
|
||||||
//Backtesting
|
//Backtesting
|
||||||
BacktestingReady = 66,
|
BacktestingReady = 66,
|
||||||
@@ -170,6 +171,12 @@
|
|||||||
iTriX = 123,
|
iTriX = 123,
|
||||||
iWPR = 124,
|
iWPR = 124,
|
||||||
iVIDyA = 125,
|
iVIDyA = 125,
|
||||||
iVolumes = 126
|
iVolumes = 126,
|
||||||
|
|
||||||
|
//Date and Time
|
||||||
|
TimeCurrent = 127,
|
||||||
|
TimeTradeServer = 128,
|
||||||
|
TimeLocal = 129,
|
||||||
|
TimeGMT = 130
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ namespace MtApi5
|
|||||||
{
|
{
|
||||||
public class Mt5ConnectionEventArgs: EventArgs
|
public class Mt5ConnectionEventArgs: EventArgs
|
||||||
{
|
{
|
||||||
public Mt5ConnectionState Status { get; private set; }
|
public Mt5ConnectionState Status { get; }
|
||||||
public string ConnectionMessage { get; private set; }
|
public string ConnectionMessage { get; }
|
||||||
|
|
||||||
public Mt5ConnectionEventArgs(Mt5ConnectionState status, string message)
|
public Mt5ConnectionEventArgs(Mt5ConnectionState status, string message)
|
||||||
{
|
{
|
||||||
|
|||||||
+3
-1
@@ -1,4 +1,6 @@
|
|||||||
namespace MtApi5
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
|
|
||||||
// Chart Constants:
|
// Chart Constants:
|
||||||
|
|||||||
+4
-9
@@ -1,15 +1,10 @@
|
|||||||
using System;
|
namespace MtApi5
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace MtApi5
|
|
||||||
{
|
{
|
||||||
public class Mt5Quote
|
public class Mt5Quote
|
||||||
{
|
{
|
||||||
public string Instrument { get; private set; }
|
public string Instrument { get; }
|
||||||
public double Bid { get; private set; }
|
public double Bid { get; }
|
||||||
public double Ask { get; private set; }
|
public double Ask { get; }
|
||||||
|
|
||||||
public Mt5Quote(string instrument, double bid, double ask)
|
public Mt5Quote(string instrument, double bid, double ask)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
public class Mt5QuoteEventArgs: EventArgs
|
public class Mt5QuoteEventArgs: EventArgs
|
||||||
{
|
{
|
||||||
public Mt5Quote Quote { get; private set; }
|
public Mt5Quote Quote { get; }
|
||||||
|
|
||||||
public Mt5QuoteEventArgs(Mt5Quote quote)
|
public Mt5QuoteEventArgs(Mt5Quote quote)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,32 +1,27 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
class Mt5TimeConverter
|
internal class Mt5TimeConverter
|
||||||
{
|
{
|
||||||
public static DateTime ConvertFromMtTime(int time)
|
public static DateTime ConvertFromMtTime(int time)
|
||||||
{
|
{
|
||||||
DateTime tmpTime = new DateTime(1970, 1, 1);
|
var tmpTime = new DateTime(1970, 1, 1);
|
||||||
return new DateTime(tmpTime.Ticks + (time * 0x989680L));
|
return new DateTime(tmpTime.Ticks + (time * 0x989680L));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DateTime ConvertFromMtTime(long time)
|
public static DateTime ConvertFromMtTime(long time)
|
||||||
{
|
{
|
||||||
DateTime tmpTime = new DateTime(1970, 1, 1);
|
var tmpTime = new DateTime(1970, 1, 1);
|
||||||
return new DateTime(tmpTime.Ticks + (time * 0x989680L));
|
return new DateTime(tmpTime.Ticks + (time * 0x989680L));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int ConvertToMtTime(DateTime time)
|
public static int ConvertToMtTime(DateTime time)
|
||||||
{
|
{
|
||||||
int result = 0;
|
var result = 0;
|
||||||
if (time != DateTime.MinValue)
|
if (time == DateTime.MinValue) return result;
|
||||||
{
|
var tmpTime = new DateTime(1970, 1, 1);
|
||||||
DateTime tmpTime = new DateTime(1970, 1, 1);
|
result = (int)((time.Ticks - tmpTime.Ticks) / 0x989680L);
|
||||||
result = (int)((time.Ticks - tmpTime.Ticks) / 0x989680L);
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,11 +68,14 @@
|
|||||||
<Compile Include="Mt5Quote.cs" />
|
<Compile Include="Mt5Quote.cs" />
|
||||||
<Compile Include="Requests\CopyTicksRequest.cs" />
|
<Compile Include="Requests\CopyTicksRequest.cs" />
|
||||||
<Compile Include="Requests\ICustomRequest.cs" />
|
<Compile Include="Requests\ICustomRequest.cs" />
|
||||||
|
<Compile Include="Requests\OrderCheckRequest.cs" />
|
||||||
|
<Compile Include="Requests\OrderCheckResult.cs" />
|
||||||
|
<Compile Include="Requests\OrderSendRequest.cs" />
|
||||||
|
<Compile Include="Requests\PositionOpenRequest.cs" />
|
||||||
<Compile Include="Requests\RequestBase.cs" />
|
<Compile Include="Requests\RequestBase.cs" />
|
||||||
<Compile Include="Requests\RequestType.cs" />
|
<Compile Include="Requests\RequestType.cs" />
|
||||||
<Compile Include="Responses\CopyTicksResponse.cs" />
|
<Compile Include="Requests\OrderSendResult.cs" />
|
||||||
<Compile Include="Responses\ICustomResponse.cs" />
|
<Compile Include="Requests\Response.cs" />
|
||||||
<Compile Include="Responses\ResponseBase.cs" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\MTApiService\MTApiService.csproj">
|
<ProjectReference Include="..\MTApiService\MTApiService.csproj">
|
||||||
@@ -83,6 +86,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup />
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
|||||||
+165
-36
@@ -1,11 +1,11 @@
|
|||||||
using System;
|
// ReSharper disable InconsistentNaming
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using MTApiService;
|
using MTApiService;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.ServiceModel;
|
using System.ServiceModel;
|
||||||
using MtApi5.Requests;
|
using MtApi5.Requests;
|
||||||
using MtApi5.Responses;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@@ -32,9 +32,11 @@ namespace MtApi5
|
|||||||
|
|
||||||
|
|
||||||
#region Private Fields
|
#region Private Fields
|
||||||
|
private static readonly MtLog Log = LogConfigurator.GetLogger(typeof(MtApi5Client));
|
||||||
|
|
||||||
private MtClient _client;
|
private MtClient _client;
|
||||||
private readonly object _locker = new object();
|
private readonly object _locker = new object();
|
||||||
private volatile bool _isBacktestingMode = false;
|
private volatile bool _isBacktestingMode;
|
||||||
private Mt5ConnectionState _connectionState = Mt5ConnectionState.Disconnected;
|
private Mt5ConnectionState _connectionState = Mt5ConnectionState.Disconnected;
|
||||||
private int _executorHandle;
|
private int _executorHandle;
|
||||||
#endregion
|
#endregion
|
||||||
@@ -78,8 +80,8 @@ namespace MtApi5
|
|||||||
public IEnumerable<Mt5Quote> GetQuotes()
|
public IEnumerable<Mt5Quote> GetQuotes()
|
||||||
{
|
{
|
||||||
var client = Client;
|
var client = Client;
|
||||||
var quotes = client != null ? client.GetQuotes() : null;
|
var quotes = client?.GetQuotes();
|
||||||
return quotes?.Select(q => q.Parse());
|
return quotes?.Select(q => q.Convert());
|
||||||
}
|
}
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
@@ -104,17 +106,22 @@ namespace MtApi5
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public bool OrderSend(MqlTradeRequest request, out MqlTradeResult result)
|
public bool OrderSend(MqlTradeRequest request, out MqlTradeResult result)
|
||||||
{
|
{
|
||||||
|
Log.Debug($"OrderSend: request = {request}");
|
||||||
|
|
||||||
if (request == null)
|
if (request == null)
|
||||||
{
|
{
|
||||||
|
Log.Warn("OrderSend: request is not defined!");
|
||||||
result = null;
|
result = null;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var commandParameters = request.ToArrayList();
|
var response = SendRequest<OrderSendResult>(new OrderSendRequest
|
||||||
|
{
|
||||||
|
TradeRequest = request
|
||||||
|
});
|
||||||
|
|
||||||
var strResult = SendCommand<string>(Mt5CommandType.OrderSend, commandParameters);
|
result = response?.TradeResult;
|
||||||
|
return response != null && response.RetVal;
|
||||||
return strResult.ParseResult(ParamSeparator, out result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
@@ -180,17 +187,22 @@ namespace MtApi5
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public bool OrderCheck(MqlTradeRequest request, out MqlTradeCheckResult result)
|
public bool OrderCheck(MqlTradeRequest request, out MqlTradeCheckResult result)
|
||||||
{
|
{
|
||||||
|
Log.Debug($"OrderCheck: request = {request}");
|
||||||
|
|
||||||
if (request == null)
|
if (request == null)
|
||||||
{
|
{
|
||||||
|
Log.Warn("OrderCheck: request is not defined!");
|
||||||
result = null;
|
result = null;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var commandParameters = request.ToArrayList();
|
var response = SendRequest<OrderCheckResult>(new OrderCheckRequest
|
||||||
|
{
|
||||||
|
TradeRequest = request
|
||||||
|
});
|
||||||
|
|
||||||
var strResult = SendCommand<string>(Mt5CommandType.OrderSend, commandParameters);
|
result = response?.TradeCheckResult;
|
||||||
|
return response != null && response.RetVal;
|
||||||
return strResult.ParseResult(ParamSeparator, out result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
@@ -533,13 +545,25 @@ namespace MtApi5
|
|||||||
/// <param name="sl">Stop Loss price</param>
|
/// <param name="sl">Stop Loss price</param>
|
||||||
/// <param name="tp">Take Profit price</param>
|
/// <param name="tp">Take Profit price</param>
|
||||||
/// <param name="comment">comment</param>
|
/// <param name="comment">comment</param>
|
||||||
|
/// <param name="result">output result</param>
|
||||||
/// <returns>true - successful check of the basic structures, otherwise - false.</returns>
|
/// <returns>true - successful check of the basic structures, otherwise - false.</returns>
|
||||||
public bool PositionOpen(string symbol, ENUM_ORDER_TYPE orderType, double volume, double price, double sl, double tp, string comment , out MqlTradeResult result)
|
public bool PositionOpen(string symbol, ENUM_ORDER_TYPE orderType, double volume, double price, double sl, double tp, string comment , out MqlTradeResult result)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { symbol, (int)orderType, volume, price, sl, tp, comment };
|
Log.Debug($"PositionOpen: symbol = {symbol}, orderType = {orderType}, volume = {volume}, price = {price}, sl = {sl}, tp = {tp}, comment = {comment}");
|
||||||
|
|
||||||
var strResult = SendCommand<string>(Mt5CommandType.PositionOpenWithResult, commandParameters);
|
var response = SendRequest<OrderSendResult>(new PositionOpenRequest
|
||||||
return strResult.ParseResult(ParamSeparator, out result);
|
{
|
||||||
|
Symbol = symbol,
|
||||||
|
OrderType = orderType,
|
||||||
|
Volume = volume,
|
||||||
|
Price = price,
|
||||||
|
Sl = sl,
|
||||||
|
Tp = tp,
|
||||||
|
Comment = comment
|
||||||
|
});
|
||||||
|
|
||||||
|
result = response?.TradeResult;
|
||||||
|
return response != null && response.RetVal;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -711,7 +735,7 @@ namespace MtApi5
|
|||||||
|
|
||||||
return ratesArray?.Length ?? 0;
|
return ratesArray?.Length ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
///Gets history data of MqlRates structure of a specified symbol-period in specified quantity into the ratesArray array. The elements ordering of the copied data is from present to the past, i.e., starting position of 0 means the current bar.
|
///Gets history data of MqlRates structure of a specified symbol-period in specified quantity into the ratesArray array. The elements ordering of the copied data is from present to the past, i.e., starting position of 0 means the current bar.
|
||||||
///</summary>
|
///</summary>
|
||||||
@@ -1229,11 +1253,14 @@ namespace MtApi5
|
|||||||
///<see href="https://www.mql5.com/en/docs/series/copyticks"/>
|
///<see href="https://www.mql5.com/en/docs/series/copyticks"/>
|
||||||
public List<MqlTick> CopyTicks(string symbolName, CopyTicksFlag flags = CopyTicksFlag.All, ulong from = 0, uint count = 0)
|
public List<MqlTick> CopyTicks(string symbolName, CopyTicksFlag flags = CopyTicksFlag.All, ulong from = 0, uint count = 0)
|
||||||
{
|
{
|
||||||
var response = SendRequest<CopyTicksResponse>(new CopyTicksRequest
|
var response = SendRequest<List<MqlTick>>(new CopyTicksRequest
|
||||||
{
|
{
|
||||||
SymbolName = symbolName, Flags = (int)flags, From = from, Count = count
|
SymbolName = symbolName,
|
||||||
|
Flags = (int)flags,
|
||||||
|
From = from,
|
||||||
|
Count = count
|
||||||
});
|
});
|
||||||
return response.Ticks;
|
return response;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -1640,8 +1667,6 @@ namespace MtApi5
|
|||||||
|
|
||||||
#region Technical Indicators
|
#region Technical Indicators
|
||||||
|
|
||||||
#endregion //Technical Indicators
|
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
///The function creates Accelerator Oscillator in a global cache of the client terminal and returns its handle.
|
///The function creates Accelerator Oscillator in a global cache of the client terminal and returns its handle.
|
||||||
///</summary>
|
///</summary>
|
||||||
@@ -2169,7 +2194,8 @@ namespace MtApi5
|
|||||||
///<param name="parameters">input-parameters of a custom indicator. If there is no parameters specified, then default values will be used.</param>
|
///<param name="parameters">input-parameters of a custom indicator. If there is no parameters specified, then default values will be used.</param>
|
||||||
public int iCustom(string symbol, ENUM_TIMEFRAMES period, string name, double[] parameters)
|
public int iCustom(string symbol, ENUM_TIMEFRAMES period, string name, double[] parameters)
|
||||||
{
|
{
|
||||||
var response = SendRequest<ICustomResponse>(new ICustomRequest
|
Log.Debug("iCustom: called.");
|
||||||
|
var response = SendRequest<int>(new ICustomRequest
|
||||||
{
|
{
|
||||||
Symbol = symbol,
|
Symbol = symbol,
|
||||||
Timeframe = (int)period,
|
Timeframe = (int)period,
|
||||||
@@ -2177,7 +2203,8 @@ namespace MtApi5
|
|||||||
Params = new ArrayList(parameters),
|
Params = new ArrayList(parameters),
|
||||||
ParamsType = ICustomRequest.ParametersType.Double
|
ParamsType = ICustomRequest.ParametersType.Double
|
||||||
});
|
});
|
||||||
return response?.Value ?? 0;
|
Log.Debug($"iCustom: response = {response}.");
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
@@ -2189,7 +2216,8 @@ namespace MtApi5
|
|||||||
///<param name="parameters">input-parameters of a custom indicator. If there is no parameters specified, then default values will be used.</param>
|
///<param name="parameters">input-parameters of a custom indicator. If there is no parameters specified, then default values will be used.</param>
|
||||||
public int iCustom(string symbol, ENUM_TIMEFRAMES period, string name, int[] parameters)
|
public int iCustom(string symbol, ENUM_TIMEFRAMES period, string name, int[] parameters)
|
||||||
{
|
{
|
||||||
var response = SendRequest<ICustomResponse>(new ICustomRequest
|
Log.Debug("iCustom: called.");
|
||||||
|
var response = SendRequest<int>(new ICustomRequest
|
||||||
{
|
{
|
||||||
Symbol = symbol,
|
Symbol = symbol,
|
||||||
Timeframe = (int)period,
|
Timeframe = (int)period,
|
||||||
@@ -2197,9 +2225,104 @@ namespace MtApi5
|
|||||||
Params = new ArrayList(parameters),
|
Params = new ArrayList(parameters),
|
||||||
ParamsType = ICustomRequest.ParametersType.Int
|
ParamsType = ICustomRequest.ParametersType.Int
|
||||||
});
|
});
|
||||||
return response?.Value ?? 0;
|
Log.Debug($"iCustom: response = {response}.");
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
///The function returns the handle of the Volumes indicator.
|
||||||
|
///</summary>
|
||||||
|
///<param name="symbol">The symbol name of the security, the data of which should be used to calculate the indicator.</param>
|
||||||
|
///<param name="period">The value of the period can be one of the ENUM_TIMEFRAMES enumeration values, 0 means the current timeframe.</param>
|
||||||
|
///<param name="name">The name of the custom indicator, with path relative to the root directory of indicators (MQL5/Indicators/). If an indicator is located in a subdirectory, for example, in MQL5/Indicators/Examples, its name must be specified like: "Examples\\indicator_name" (it is necessary to use a double slash instead of the single slash as a separator).</param>
|
||||||
|
///<param name="parameters">input-parameters of a custom indicator. If there is no parameters specified, then default values will be used.</param>
|
||||||
|
public int iCustom(string symbol, ENUM_TIMEFRAMES period, string name, string[] parameters)
|
||||||
|
{
|
||||||
|
Log.Debug("iCustom: called.");
|
||||||
|
var response = SendRequest<int>(new ICustomRequest
|
||||||
|
{
|
||||||
|
Symbol = symbol,
|
||||||
|
Timeframe = (int)period,
|
||||||
|
Name = name,
|
||||||
|
Params = new ArrayList(parameters),
|
||||||
|
ParamsType = ICustomRequest.ParametersType.Int
|
||||||
|
});
|
||||||
|
Log.Debug($"iCustom: response = {response}.");
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
///The function returns the handle of the Volumes indicator.
|
||||||
|
///</summary>
|
||||||
|
///<param name="symbol">The symbol name of the security, the data of which should be used to calculate the indicator.</param>
|
||||||
|
///<param name="period">The value of the period can be one of the ENUM_TIMEFRAMES enumeration values, 0 means the current timeframe.</param>
|
||||||
|
///<param name="name">The name of the custom indicator, with path relative to the root directory of indicators (MQL5/Indicators/). If an indicator is located in a subdirectory, for example, in MQL5/Indicators/Examples, its name must be specified like: "Examples\\indicator_name" (it is necessary to use a double slash instead of the single slash as a separator).</param>
|
||||||
|
///<param name="parameters">input-parameters of a custom indicator. If there is no parameters specified, then default values will be used.</param>
|
||||||
|
public int iCustom(string symbol, ENUM_TIMEFRAMES period, string name, bool[] parameters)
|
||||||
|
{
|
||||||
|
Log.Debug("iCustom: called.");
|
||||||
|
var response = SendRequest<int>(new ICustomRequest
|
||||||
|
{
|
||||||
|
Symbol = symbol,
|
||||||
|
Timeframe = (int)period,
|
||||||
|
Name = name,
|
||||||
|
Params = new ArrayList(parameters),
|
||||||
|
ParamsType = ICustomRequest.ParametersType.Int
|
||||||
|
});
|
||||||
|
Log.Debug($"iCustom: response = {response}.");
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion //Technical Indicators
|
||||||
|
|
||||||
|
#region Date and Time
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
///Returns the last known server time, time of the last quote receipt for one of the symbols selected in the "Market Watch" window.
|
||||||
|
///</summary>
|
||||||
|
public DateTime TimeCurrent()
|
||||||
|
{
|
||||||
|
Log.Debug("TimeCurrent: called.");
|
||||||
|
var response = SendCommand<long>(Mt5CommandType.TimeCurrent, null);
|
||||||
|
Log.Debug($"TimeCurrent: response = {response}.");
|
||||||
|
return Mt5TimeConverter.ConvertFromMtTime(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
///Returns the calculated current time of the trade server. Unlike TimeCurrent(), the calculation of the time value is performed in the client terminal and depends on the time settings on your computer.
|
||||||
|
///</summary>
|
||||||
|
public DateTime TimeTradeServer()
|
||||||
|
{
|
||||||
|
Log.Debug("TimeTradeServer: called.");
|
||||||
|
var response = SendCommand<long>(Mt5CommandType.TimeTradeServer, null);
|
||||||
|
Log.Debug($"TimeTradeServer: response = {response}.");
|
||||||
|
return Mt5TimeConverter.ConvertFromMtTime(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
///Returns the local time of a computer, where the client terminal is running.
|
||||||
|
///</summary>
|
||||||
|
public DateTime TimeLocal()
|
||||||
|
{
|
||||||
|
Log.Debug("TimeLocal: called.");
|
||||||
|
var response = SendCommand<long>(Mt5CommandType.TimeLocal, null);
|
||||||
|
Log.Debug($"TimeLocal: response = {response}.");
|
||||||
|
return Mt5TimeConverter.ConvertFromMtTime(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
///Returns the GMT, which is calculated taking into account the DST switch by the local time on the computer where the client terminal is running.
|
||||||
|
///</summary>
|
||||||
|
public DateTime TimeGMT()
|
||||||
|
{
|
||||||
|
Log.Debug("TimeGMT: called.");
|
||||||
|
var response = SendCommand<long>(Mt5CommandType.TimeGMT, null);
|
||||||
|
Log.Debug($"TimeGMT: response = {response}.");
|
||||||
|
return Mt5TimeConverter.ConvertFromMtTime(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion //Date and Time
|
||||||
|
|
||||||
#endregion // Public Methods
|
#endregion // Public Methods
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
@@ -2241,6 +2364,7 @@ namespace MtApi5
|
|||||||
|
|
||||||
#region Events
|
#region Events
|
||||||
public event QuoteHandler QuoteUpdated;
|
public event QuoteHandler QuoteUpdated;
|
||||||
|
public event EventHandler<Mt5QuoteEventArgs> QuoteUpdate;
|
||||||
public event EventHandler<Mt5QuoteEventArgs> QuoteAdded;
|
public event EventHandler<Mt5QuoteEventArgs> QuoteAdded;
|
||||||
public event EventHandler<Mt5QuoteEventArgs> QuoteRemoved;
|
public event EventHandler<Mt5QuoteEventArgs> QuoteRemoved;
|
||||||
public event EventHandler<Mt5ConnectionEventArgs> ConnectionStateChanged;
|
public event EventHandler<Mt5ConnectionEventArgs> ConnectionStateChanged;
|
||||||
@@ -2388,10 +2512,10 @@ namespace MtApi5
|
|||||||
}
|
}
|
||||||
|
|
||||||
var responseValue = response.GetValue();
|
var responseValue = response.GetValue();
|
||||||
return responseValue != null ? (T)responseValue : default(T);
|
return (T) responseValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private T SendRequest<T>(RequestBase request) where T : ResponseBase, new()
|
private T SendRequest<T>(RequestBase request)
|
||||||
{
|
{
|
||||||
if (request == null)
|
if (request == null)
|
||||||
return default(T);
|
return default(T);
|
||||||
@@ -2410,22 +2534,21 @@ namespace MtApi5
|
|||||||
throw new ExecutionException(ErrorCode.ErrCustom, "Response from MetaTrader is null");
|
throw new ExecutionException(ErrorCode.ErrCustom, "Response from MetaTrader is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
var response = JsonConvert.DeserializeObject<T>(res);
|
var response = JsonConvert.DeserializeObject<Response<T>>(res);
|
||||||
if (response.ErrorCode != 0)
|
if (response.ErrorCode != 0)
|
||||||
{
|
{
|
||||||
throw new ExecutionException((ErrorCode)response.ErrorCode, response.ErrorMessage);
|
throw new ExecutionException((ErrorCode)response.ErrorCode, response.ErrorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void _client_QuoteUpdated(MtQuote quote)
|
private void _client_QuoteUpdated(MtQuote quote)
|
||||||
{
|
{
|
||||||
if (quote != null)
|
if (quote == null) return;
|
||||||
{
|
QuoteUpdate?.Invoke(this, new Mt5QuoteEventArgs(new Mt5Quote(quote.Instrument, quote.Bid, quote.Ask)));
|
||||||
QuoteUpdated?.Invoke(this, quote.Instrument, quote.Bid, quote.Ask);
|
QuoteUpdated?.Invoke(this, quote.Instrument, quote.Bid, quote.Ask);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _client_ServerDisconnected(object sender, EventArgs e)
|
private void _client_ServerDisconnected(object sender, EventArgs e)
|
||||||
@@ -2440,12 +2563,18 @@ namespace MtApi5
|
|||||||
|
|
||||||
private void _client_QuoteRemoved(MtQuote quote)
|
private void _client_QuoteRemoved(MtQuote quote)
|
||||||
{
|
{
|
||||||
QuoteRemoved?.Invoke(this, new Mt5QuoteEventArgs(quote.Parse()));
|
if (quote != null)
|
||||||
|
{
|
||||||
|
QuoteRemoved?.Invoke(this, new Mt5QuoteEventArgs(new Mt5Quote(quote.Instrument, quote.Bid, quote.Ask)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _client_QuoteAdded(MtQuote quote)
|
private void _client_QuoteAdded(MtQuote quote)
|
||||||
{
|
{
|
||||||
QuoteAdded?.Invoke(this, new Mt5QuoteEventArgs(quote.Parse()));
|
if (quote != null)
|
||||||
|
{
|
||||||
|
QuoteAdded?.Invoke(this, new Mt5QuoteEventArgs(new Mt5Quote(quote.Instrument, quote.Bid, quote.Ask)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnConnected()
|
private void OnConnected()
|
||||||
|
|||||||
+20
-74
@@ -6,84 +6,18 @@ namespace MtApi5
|
|||||||
{
|
{
|
||||||
internal static class MtConverters
|
internal static class MtConverters
|
||||||
{
|
{
|
||||||
|
private static readonly MtLog Log = LogConfigurator.GetLogger(typeof(MtConverters));
|
||||||
|
|
||||||
#region Values Converters
|
#region Values Converters
|
||||||
public static Mt5Quote Parse(this MtQuote quote)
|
public static Mt5Quote Convert(this MtQuote quote)
|
||||||
{
|
{
|
||||||
return (quote != null) ? new Mt5Quote(quote.Instrument, quote.Bid, quote.Ask) : null;
|
return quote != null ? new Mt5Quote(quote.Instrument, quote.Bid, quote.Ask) : null;
|
||||||
}
|
|
||||||
|
|
||||||
public static bool ParseResult(this string inputString, char separator, out MqlTradeResult result)
|
|
||||||
{
|
|
||||||
var retVal = false;
|
|
||||||
result = null;
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(inputString) == false)
|
|
||||||
{
|
|
||||||
var values = inputString.Split(separator);
|
|
||||||
if (values.Length == 10)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
retVal = int.Parse(values[0]) != 0;
|
|
||||||
|
|
||||||
var retcode = uint.Parse(values[1]);
|
|
||||||
var deal = ulong.Parse(values[2]);
|
|
||||||
var order = ulong.Parse(values[3]);
|
|
||||||
var volume = double.Parse(values[4]);
|
|
||||||
var price = double.Parse(values[5]);
|
|
||||||
var bid = double.Parse(values[6]);
|
|
||||||
var ask = double.Parse(values[7]);
|
|
||||||
var comment = values[8];
|
|
||||||
var requestId = uint.Parse(values[9]);
|
|
||||||
|
|
||||||
result = new MqlTradeResult(retcode, deal, order, volume, price, bid, ask, comment, requestId);
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return retVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool ParseResult(this string inputString, char separator, out MqlTradeCheckResult result)
|
|
||||||
{
|
|
||||||
var retVal = false;
|
|
||||||
result = null;
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(inputString) == false)
|
|
||||||
{
|
|
||||||
var values = inputString.Split(separator);
|
|
||||||
if (values.Length == 10)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
retVal = int.Parse(values[0]) != 0;
|
|
||||||
|
|
||||||
var retcode = uint.Parse(values[1]);
|
|
||||||
var balance = double.Parse(values[2]);
|
|
||||||
var equity = double.Parse(values[3]);
|
|
||||||
var profit = double.Parse(values[4]);
|
|
||||||
var margin = double.Parse(values[5]);
|
|
||||||
var marginFree = double.Parse(values[6]);
|
|
||||||
var marginLevel = double.Parse(values[7]);
|
|
||||||
var comment = values[8];
|
|
||||||
|
|
||||||
result = new MqlTradeCheckResult(retcode, balance, equity, profit, margin, marginFree, marginLevel, comment);
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
retVal = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return retVal;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool ParseResult(this string inputString, char separator, out double result)
|
public static bool ParseResult(this string inputString, char separator, out double result)
|
||||||
{
|
{
|
||||||
|
Log.Debug($"ParseResult: inputString = {inputString}, separator = {separator}");
|
||||||
|
|
||||||
var retVal = false;
|
var retVal = false;
|
||||||
result = 0;
|
result = 0;
|
||||||
|
|
||||||
@@ -98,18 +32,25 @@ namespace MtApi5
|
|||||||
|
|
||||||
result = double.Parse(values[1]);
|
result = double.Parse(values[1]);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
retVal = false;
|
retVal = false;
|
||||||
|
Log.Error($"ParseResult: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.Warn("ParseResult: input srting is null or empty!");
|
||||||
|
}
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool ParseResult(this string inputString, char separator, out DateTime from, out DateTime to)
|
public static bool ParseResult(this string inputString, char separator, out DateTime from, out DateTime to)
|
||||||
{
|
{
|
||||||
|
Log.Debug($"ParseResult: inputString = {inputString}, separator = {separator}");
|
||||||
|
|
||||||
var retVal = false;
|
var retVal = false;
|
||||||
|
|
||||||
from = new DateTime();
|
from = new DateTime();
|
||||||
@@ -130,12 +71,17 @@ namespace MtApi5
|
|||||||
var iTo= int.Parse(values[2]);
|
var iTo= int.Parse(values[2]);
|
||||||
to = Mt5TimeConverter.ConvertFromMtTime(iTo);
|
to = Mt5TimeConverter.ConvertFromMtTime(iTo);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
retVal = false;
|
retVal = false;
|
||||||
|
Log.Error($"ParseResult: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.Warn("ParseResult: input srting is null or empty!");
|
||||||
|
}
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.14")]
|
[assembly: AssemblyVersion("1.0.16")]
|
||||||
[assembly: AssemblyFileVersion("1.0.14")]
|
[assembly: AssemblyFileVersion("1.0.16")]
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
namespace MtApi5.Requests
|
||||||
|
{
|
||||||
|
internal class OrderCheckRequest: RequestBase
|
||||||
|
{
|
||||||
|
public override RequestType RequestType => RequestType.OrderCheck;
|
||||||
|
|
||||||
|
public MqlTradeRequest TradeRequest { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace MtApi5.Requests
|
||||||
|
{
|
||||||
|
public class OrderCheckResult
|
||||||
|
{
|
||||||
|
public bool RetVal { get; set; }
|
||||||
|
public MqlTradeCheckResult TradeCheckResult { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace MtApi5.Requests
|
||||||
|
{
|
||||||
|
internal class OrderSendRequest: RequestBase
|
||||||
|
{
|
||||||
|
public override RequestType RequestType => RequestType.OrderSend;
|
||||||
|
|
||||||
|
public MqlTradeRequest TradeRequest { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace MtApi5.Requests
|
||||||
|
{
|
||||||
|
internal class OrderSendResult
|
||||||
|
{
|
||||||
|
public bool RetVal { get; set; }
|
||||||
|
public MqlTradeResult TradeResult { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
namespace MtApi5.Requests
|
||||||
|
{
|
||||||
|
internal class PositionOpenRequest: RequestBase
|
||||||
|
{
|
||||||
|
public override RequestType RequestType => RequestType.PositionOpen;
|
||||||
|
|
||||||
|
public string Symbol { get; set; }
|
||||||
|
public ENUM_ORDER_TYPE OrderType { get; set; }
|
||||||
|
public double Volume { get; set; }
|
||||||
|
public double Price { get; set; }
|
||||||
|
public double Sl { get; set; }
|
||||||
|
public double Tp { get; set; }
|
||||||
|
public string Comment { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,14 @@
|
|||||||
namespace MtApi5.Requests
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
|
namespace MtApi5.Requests
|
||||||
{
|
{
|
||||||
internal enum RequestType
|
internal enum RequestType
|
||||||
{
|
{
|
||||||
Unknown = 0,
|
Unknown = 0,
|
||||||
CopyTicks = 1,
|
CopyTicks = 1,
|
||||||
iCustom = 2
|
iCustom = 2,
|
||||||
|
OrderSend = 3,
|
||||||
|
PositionOpen = 4,
|
||||||
|
OrderCheck = 5
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Executable → Regular
+4
-2
@@ -1,8 +1,10 @@
|
|||||||
namespace MtApi5.Responses
|
namespace MtApi5.Requests
|
||||||
{
|
{
|
||||||
internal class ResponseBase
|
internal class Response<T>
|
||||||
{
|
{
|
||||||
public int ErrorCode { get; set; }
|
public int ErrorCode { get; set; }
|
||||||
public string ErrorMessage { get; set; }
|
public string ErrorMessage { get; set; }
|
||||||
|
|
||||||
|
public T Value { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace MtApi5.Responses
|
|
||||||
{
|
|
||||||
internal class CopyTicksResponse: ResponseBase
|
|
||||||
{
|
|
||||||
public List<MqlTick> Ticks { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace MtApi5.Responses
|
|
||||||
{
|
|
||||||
internal class ICustomResponse: ResponseBase
|
|
||||||
{
|
|
||||||
public int Value { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
xmlns:mtapi5="clr-namespace:MtApi5;assembly=MtApi5"
|
xmlns:mtapi5="clr-namespace:MtApi5;assembly=MtApi5"
|
||||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||||
xmlns:mtApi5TestClient="clr-namespace:MtApi5TestClient"
|
xmlns:mtApi5TestClient="clr-namespace:MtApi5TestClient"
|
||||||
Title="MainWindow" Height="700" Width="650"
|
Title="MainWindow" Height="700" Width="700"
|
||||||
Closing="Window_Closing">
|
Closing="Window_Closing">
|
||||||
<Window.Resources>
|
<Window.Resources>
|
||||||
<DataTemplate x:Key="ConnectionTextBlockTemplate" DataType="{x:Type mtapi5:Mt5ConnectionState}">
|
<DataTemplate x:Key="ConnectionTextBlockTemplate" DataType="{x:Type mtapi5:Mt5ConnectionState}">
|
||||||
@@ -100,58 +100,33 @@
|
|||||||
<ColumnDefinition Width="*"/>
|
<ColumnDefinition Width="*"/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
<Expander ExpandDirection="Right" IsExpanded="True"
|
<Grid Margin="10">
|
||||||
Grid.Row="0" Grid.Column="0" Margin="5">
|
<Grid.RowDefinitions>
|
||||||
<Expander.Header>
|
<RowDefinition Height="Auto"/>
|
||||||
<TextBlock Text="Connection" RenderTransformOrigin="0.5,0.5" Margin="0,0,0,0" Width="Auto">
|
<RowDefinition Height="Auto"/>
|
||||||
<TextBlock.LayoutTransform>
|
<RowDefinition Height="Auto"/>
|
||||||
<TransformGroup>
|
</Grid.RowDefinitions>
|
||||||
<ScaleTransform ScaleX="1" ScaleY="1"/>
|
|
||||||
<SkewTransform AngleX="0" AngleY="0"/>
|
|
||||||
<RotateTransform Angle="-90"/>
|
|
||||||
<TranslateTransform X="0" Y="0"/>
|
|
||||||
</TransformGroup>
|
|
||||||
</TextBlock.LayoutTransform>
|
|
||||||
<TextBlock.RenderTransform>
|
|
||||||
<TransformGroup>
|
|
||||||
<ScaleTransform ScaleX="1" ScaleY="1"/>
|
|
||||||
<SkewTransform AngleX="0" AngleY="0"/>
|
|
||||||
<RotateTransform Angle="0"/>
|
|
||||||
<TranslateTransform X="0" Y="0"/>
|
|
||||||
</TransformGroup>
|
|
||||||
</TextBlock.RenderTransform>
|
|
||||||
</TextBlock>
|
|
||||||
</Expander.Header>
|
|
||||||
<Expander.Content>
|
|
||||||
<Grid Margin="10">
|
|
||||||
<Grid.RowDefinitions>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
</Grid.RowDefinitions>
|
|
||||||
|
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="Auto"/>
|
<ColumnDefinition Width="Auto"/>
|
||||||
<ColumnDefinition Width="150"/>
|
<ColumnDefinition Width="150"/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
<TextBlock Grid.Row="0" Grid.Column="0" Text="Host"/>
|
<TextBlock Grid.Row="0" Grid.Column="0" Text="Host"/>
|
||||||
<TextBox Grid.Row="0" Grid.Column="1"
|
<TextBox Grid.Row="0" Grid.Column="1"
|
||||||
Margin="5,0,0,0"
|
Margin="5,0,0,0"
|
||||||
Text="{Binding Host, UpdateSourceTrigger=PropertyChanged}"/>
|
Text="{Binding Host, UpdateSourceTrigger=PropertyChanged}"/>
|
||||||
|
|
||||||
<TextBlock Grid.Row="1" Grid.Column="0" Text="Port"/>
|
<TextBlock Grid.Row="1" Grid.Column="0" Text="Port"/>
|
||||||
<TextBox Grid.Row="1" Grid.Column="1"
|
<TextBox Grid.Row="1" Grid.Column="1"
|
||||||
Margin="5,0,0,0"
|
Margin="5,0,0,0"
|
||||||
Text="{Binding Port, UpdateSourceTrigger=PropertyChanged}"/>
|
Text="{Binding Port, UpdateSourceTrigger=PropertyChanged}"/>
|
||||||
|
|
||||||
<StackPanel Grid.Row="2" Grid.ColumnSpan="2" Margin="5" Orientation="Horizontal">
|
<StackPanel Grid.Row="2" Grid.ColumnSpan="2" Margin="5" Orientation="Horizontal">
|
||||||
<Button Content="Connect" Width="70" Command="{Binding ConnectCommand}" />
|
<Button Content="Connect" Width="70" Command="{Binding ConnectCommand}" />
|
||||||
<Button Margin="5,0,0,0" Width="70" Content="Disconnect" Command="{Binding DisconnectCommand}" />
|
<Button Margin="5,0,0,0" Width="70" Content="Disconnect" Command="{Binding DisconnectCommand}" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Expander.Content>
|
|
||||||
</Expander>
|
|
||||||
|
|
||||||
<ListView Grid.Row="0" Grid.Column="1"
|
<ListView Grid.Row="0" Grid.Column="1"
|
||||||
ItemsSource="{Binding Quotes}"
|
ItemsSource="{Binding Quotes}"
|
||||||
@@ -247,18 +222,26 @@
|
|||||||
SelectedItem="{Binding TradeRequest.Type_time}" Margin="5,0,0,0"/>
|
SelectedItem="{Binding TradeRequest.Type_time}" Margin="5,0,0,0"/>
|
||||||
|
|
||||||
<TextBlock Grid.Column="2" Grid.Row="6" Text="Expiration" Margin="10,0,0,0"/>
|
<TextBlock Grid.Column="2" Grid.Row="6" Text="Expiration" Margin="10,0,0,0"/>
|
||||||
<TextBox Grid.Column="3" Grid.Row="6" Text="{Binding TradeRequest}" Margin="5,0,0,0"/>
|
<TextBox Grid.Column="3" Grid.Row="6" Text="{Binding TradeRequest.Expiration}" Margin="5,0,0,0"/>
|
||||||
|
|
||||||
<TextBlock Grid.Column="0" Grid.Row="7" Text="Comment"/>
|
<TextBlock Grid.Column="0" Grid.Row="7" Text="Comment"/>
|
||||||
<TextBox Grid.Column="1" Grid.Row="7" Grid.ColumnSpan="3" Text="{Binding TradeRequest}" Margin="5,0,0,0"/>
|
<TextBox Grid.Column="1" Grid.Row="7" Grid.ColumnSpan="3" Text="{Binding TradeRequest.Comment}" Margin="5,0,0,0"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Expander>
|
</Expander>
|
||||||
|
|
||||||
<StackPanel Grid.Row="1" Orientation="Vertical">
|
<StackPanel Grid.Row="1" Orientation="Vertical">
|
||||||
<Button Content="OrderSend" Command="{Binding OrderSendCommand}" Width="100" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
<StackPanel Orientation="Horizontal">
|
||||||
<Button Content="HistoryDealGetDouble" Command="{Binding HistoryDealGetDoubleCommand}" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
<Button Content="OrderSend" Command="{Binding OrderSendCommand}" Width="100" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||||
<Button Content="HistoryDealGetInteger" Command="{Binding HistoryDealGetIntegerCommand}" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
<Button Content="OrderCheck" Command="{Binding OrderCheckCommand}" Width="100" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||||
<Button Content="HistoryDealGetString" Command="{Binding HistoryDealGetStringCommand}" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
</StackPanel>
|
||||||
|
|
||||||
|
<WrapPanel>
|
||||||
|
<Button Content="HistoryDealGetDouble" Command="{Binding HistoryDealGetDoubleCommand}" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||||
|
<Button Content="HistoryDealGetInteger" Command="{Binding HistoryDealGetIntegerCommand}" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||||
|
<Button Content="HistoryDealGetString" Command="{Binding HistoryDealGetStringCommand}" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||||
|
<Button Content="HistoryOrderGetInteger" Command="{Binding HistoryOrderGetIntegerCommand}" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||||
|
<Button Content="HistoryDealMethods" Command="{Binding HistoryDealMethodsCommand}" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||||
|
</WrapPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
@@ -400,10 +383,25 @@
|
|||||||
<Button Command="{Binding PositionOpenCommand}" Content="PositionOpen" Margin="2"/>
|
<Button Command="{Binding PositionOpenCommand}" Content="PositionOpen" Margin="2"/>
|
||||||
</WrapPanel>
|
</WrapPanel>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
||||||
|
<TabItem Header="Indicators">
|
||||||
|
<WrapPanel VerticalAlignment="Top" Margin="5">
|
||||||
|
<Button Command="{Binding iCustomCommand}" Content="iCustom" Margin="2"/>
|
||||||
|
</WrapPanel>
|
||||||
|
</TabItem>
|
||||||
|
|
||||||
|
<TabItem Header="Time and Date">
|
||||||
|
<WrapPanel VerticalAlignment="Top" Margin="5">
|
||||||
|
<Button Command="{Binding TimeCurrentCommand}" Content="TimeCurrent" Margin="2"/>
|
||||||
|
<Button Command="{Binding TimeTradeServerCommand}" Content="TimeTradeServer" Margin="2"/>
|
||||||
|
<Button Command="{Binding TimeLocalCommand}" Content="TimeLocal" Margin="2"/>
|
||||||
|
<Button Command="{Binding TimeGMTCommand}" Content="TimeGMT" Margin="2"/>
|
||||||
|
</WrapPanel>
|
||||||
|
</TabItem>
|
||||||
</TabControl>
|
</TabControl>
|
||||||
|
|
||||||
<Expander Grid.Row="2" Header="History" IsExpanded="True">
|
<Expander Grid.Row="2" Header="Console" IsExpanded="True">
|
||||||
<ListBox mtApi5TestClient:ListBoxBehavior.ScrollOnNewItem="true" Height="200" ItemsSource="{Binding History}"/>
|
<ListBox mtApi5TestClient:ListBoxBehavior.ScrollOnNewItem="true" Height="180" ItemsSource="{Binding History}"/>
|
||||||
</Expander>
|
</Expander>
|
||||||
|
|
||||||
<StatusBar Grid.Row="3">
|
<StatusBar Grid.Row="3">
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
// ReSharper disable InconsistentNaming
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
@@ -16,9 +17,13 @@ namespace MtApi5TestClient
|
|||||||
public DelegateCommand DisconnectCommand { get; private set; }
|
public DelegateCommand DisconnectCommand { get; private set; }
|
||||||
|
|
||||||
public DelegateCommand OrderSendCommand { get; private set; }
|
public DelegateCommand OrderSendCommand { get; private set; }
|
||||||
|
public DelegateCommand OrderCheckCommand { get; private set; }
|
||||||
|
|
||||||
|
public DelegateCommand HistoryOrderGetIntegerCommand { get; private set; }
|
||||||
public DelegateCommand HistoryDealGetDoubleCommand { get; private set; }
|
public DelegateCommand HistoryDealGetDoubleCommand { get; private set; }
|
||||||
public DelegateCommand HistoryDealGetIntegerCommand { get; private set; }
|
public DelegateCommand HistoryDealGetIntegerCommand { get; private set; }
|
||||||
public DelegateCommand HistoryDealGetStringCommand { get; private set; }
|
public DelegateCommand HistoryDealGetStringCommand { get; private set; }
|
||||||
|
public DelegateCommand HistoryDealMethodsCommand { get; private set; }
|
||||||
|
|
||||||
public DelegateCommand AccountInfoDoubleCommand { get; private set; }
|
public DelegateCommand AccountInfoDoubleCommand { get; private set; }
|
||||||
public DelegateCommand AccountInfoIntegerCommand { get; private set; }
|
public DelegateCommand AccountInfoIntegerCommand { get; private set; }
|
||||||
@@ -53,6 +58,13 @@ namespace MtApi5TestClient
|
|||||||
public DelegateCommand PositionOpenCommand { get; private set; }
|
public DelegateCommand PositionOpenCommand { get; private set; }
|
||||||
|
|
||||||
public DelegateCommand PrintCommand { get; private set; }
|
public DelegateCommand PrintCommand { get; private set; }
|
||||||
|
|
||||||
|
public DelegateCommand iCustomCommand { get; private set; }
|
||||||
|
|
||||||
|
public DelegateCommand TimeCurrentCommand { get; private set; }
|
||||||
|
public DelegateCommand TimeTradeServerCommand { get; private set; }
|
||||||
|
public DelegateCommand TimeLocalCommand { get; private set; }
|
||||||
|
public DelegateCommand TimeGMTCommand { get; private set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
@@ -196,9 +208,13 @@ namespace MtApi5TestClient
|
|||||||
DisconnectCommand = new DelegateCommand(ExecuteDisconnect, CanExecuteDisconnect);
|
DisconnectCommand = new DelegateCommand(ExecuteDisconnect, CanExecuteDisconnect);
|
||||||
|
|
||||||
OrderSendCommand = new DelegateCommand(ExecuteOrderSend);
|
OrderSendCommand = new DelegateCommand(ExecuteOrderSend);
|
||||||
|
OrderCheckCommand = new DelegateCommand(ExecuteOrderCheck);
|
||||||
|
|
||||||
|
HistoryOrderGetIntegerCommand = new DelegateCommand(ExecuteHistoryOrderGetInteger);
|
||||||
HistoryDealGetDoubleCommand = new DelegateCommand(ExecuteHistoryDealGetDouble);
|
HistoryDealGetDoubleCommand = new DelegateCommand(ExecuteHistoryDealGetDouble);
|
||||||
HistoryDealGetIntegerCommand = new DelegateCommand(ExecuteHistoryDealGetInteger);
|
HistoryDealGetIntegerCommand = new DelegateCommand(ExecuteHistoryDealGetInteger);
|
||||||
HistoryDealGetStringCommand = new DelegateCommand(ExecuteHistoryDealGetString);
|
HistoryDealGetStringCommand = new DelegateCommand(ExecuteHistoryDealGetString);
|
||||||
|
HistoryDealMethodsCommand = new DelegateCommand(ExecuteHistoryDealMethods);
|
||||||
|
|
||||||
AccountInfoDoubleCommand = new DelegateCommand(ExecuteAccountInfoDouble);
|
AccountInfoDoubleCommand = new DelegateCommand(ExecuteAccountInfoDouble);
|
||||||
AccountInfoIntegerCommand = new DelegateCommand(ExecuteAccountInfoInteger);
|
AccountInfoIntegerCommand = new DelegateCommand(ExecuteAccountInfoInteger);
|
||||||
@@ -233,6 +249,13 @@ namespace MtApi5TestClient
|
|||||||
PositionOpenCommand = new DelegateCommand(ExecutePositionOpen);
|
PositionOpenCommand = new DelegateCommand(ExecutePositionOpen);
|
||||||
|
|
||||||
PrintCommand = new DelegateCommand(ExecutePrint);
|
PrintCommand = new DelegateCommand(ExecutePrint);
|
||||||
|
|
||||||
|
iCustomCommand = new DelegateCommand(ExecuteICustom);
|
||||||
|
|
||||||
|
TimeCurrentCommand = new DelegateCommand(ExecuteTimeCurrent);
|
||||||
|
TimeTradeServerCommand = new DelegateCommand(ExecuteTimeTradeServer);
|
||||||
|
TimeLocalCommand = new DelegateCommand(ExecuteTimeLocal);
|
||||||
|
TimeGMTCommand = new DelegateCommand(ExecuteTimeGMT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CanExecuteConnect(object o)
|
private bool CanExecuteConnect(object o)
|
||||||
@@ -265,18 +288,42 @@ namespace MtApi5TestClient
|
|||||||
private async void ExecuteOrderSend(object o)
|
private async void ExecuteOrderSend(object o)
|
||||||
{
|
{
|
||||||
var request = TradeRequest.GetMqlTradeRequest();
|
var request = TradeRequest.GetMqlTradeRequest();
|
||||||
|
MqlTradeResult result = null;
|
||||||
var retVal = await Execute(() =>
|
var retVal = await Execute(() =>
|
||||||
{
|
{
|
||||||
MqlTradeResult result;
|
|
||||||
var ok = _mtApiClient.OrderSend(request, out result);
|
var ok = _mtApiClient.OrderSend(request, out result);
|
||||||
return ok ? result : null;
|
return ok;
|
||||||
});
|
});
|
||||||
|
|
||||||
var message = retVal != null ? $"OrderSend successed. {MqlTradeResultToString(retVal)}" : "OrderSend failed.";
|
var message = retVal ? $"OrderSend: success. {result}" : $"OrderSend: fail. {result}";
|
||||||
AddLog(message);
|
AddLog(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private async void ExecuteOrderCheck(object obj)
|
||||||
|
{
|
||||||
|
var request = TradeRequest.GetMqlTradeRequest();
|
||||||
|
MqlTradeCheckResult result = null;
|
||||||
|
var retVal = await Execute(() =>
|
||||||
|
{
|
||||||
|
var ok = _mtApiClient.OrderCheck(request, out result);
|
||||||
|
return ok;
|
||||||
|
});
|
||||||
|
|
||||||
|
var message = retVal ? $"OrderCheck: success. {result}" : $"OrderCheck: fail. {result}";
|
||||||
|
AddLog(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ExecuteHistoryOrderGetInteger(object o)
|
||||||
|
{
|
||||||
|
const ulong ticket = 12345;
|
||||||
|
const ENUM_ORDER_PROPERTY_INTEGER propertyId = ENUM_ORDER_PROPERTY_INTEGER.ORDER_POSITION_ID;
|
||||||
|
|
||||||
|
var retVal = await Execute(() => _mtApiClient.HistoryOrderGetInteger(ticket, propertyId));
|
||||||
|
|
||||||
|
AddLog($"HistoryOrderGetInteger: {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
private async void ExecuteHistoryDealGetDouble(object o)
|
private async void ExecuteHistoryDealGetDouble(object o)
|
||||||
{
|
{
|
||||||
const ulong ticket = 12345;
|
const ulong ticket = 12345;
|
||||||
@@ -307,6 +354,25 @@ namespace MtApi5TestClient
|
|||||||
AddLog($"HistoryDealGetString: {retVal}");
|
AddLog($"HistoryDealGetString: {retVal}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void ExecuteHistoryDealMethods(object o)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var posId = await Execute(() => _mtApiClient.PositionGetInteger(ENUM_POSITION_PROPERTY_INTEGER.POSITION_IDENTIFIER));
|
||||||
|
var history = await Execute(() => _mtApiClient.HistorySelectByPosition(posId));
|
||||||
|
var historyDealsTotal = await Execute(() => _mtApiClient.HistoryDealsTotal());
|
||||||
|
var histDealTicket = await Execute(() => _mtApiClient.HistoryDealGetTicket(0));
|
||||||
|
var histDealPrice = await Execute(() => _mtApiClient.HistoryDealGetDouble(histDealTicket, ENUM_DEAL_PROPERTY_DOUBLE.DEAL_PRICE));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
AddLog(ex.Message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AddLog("ExecuteHistoryDealMethods: success.");
|
||||||
|
}
|
||||||
|
|
||||||
private async void ExecuteAccountInfoDouble(object o)
|
private async void ExecuteAccountInfoDouble(object o)
|
||||||
{
|
{
|
||||||
var result = await Execute(() => _mtApiClient.AccountInfoDouble(AccountInfoDoublePropertyId));
|
var result = await Execute(() => _mtApiClient.AccountInfoDouble(AccountInfoDoublePropertyId));
|
||||||
@@ -799,6 +865,41 @@ namespace MtApi5TestClient
|
|||||||
AddLog($"Print: message print in MetaTrader - {retVal}");
|
AddLog($"Print: message print in MetaTrader - {retVal}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void ExecuteICustom(object o)
|
||||||
|
{
|
||||||
|
const string symbol = "EURUSD";
|
||||||
|
const ENUM_TIMEFRAMES timeframe = ENUM_TIMEFRAMES.PERIOD_H1;
|
||||||
|
const string name = @"Examples\Custom Moving Average";
|
||||||
|
int[] parameters = { 0, 21, (int)ENUM_APPLIED_PRICE.PRICE_CLOSE };
|
||||||
|
|
||||||
|
var retVal = await Execute(() => _mtApiClient.iCustom(symbol, timeframe, name, parameters));
|
||||||
|
AddLog($"Custom Moving Average: result - {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ExecuteTimeCurrent(object o)
|
||||||
|
{
|
||||||
|
var retVal = await Execute(() => _mtApiClient.TimeCurrent());
|
||||||
|
AddLog($"TimeCurrent: {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ExecuteTimeTradeServer(object o)
|
||||||
|
{
|
||||||
|
var retVal = await Execute(() => _mtApiClient.TimeTradeServer());
|
||||||
|
AddLog($"TimeTradeServer: {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ExecuteTimeLocal(object o)
|
||||||
|
{
|
||||||
|
var retVal = await Execute(() => _mtApiClient.TimeLocal());
|
||||||
|
AddLog($"TimeLocal: {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void ExecuteTimeGMT(object o)
|
||||||
|
{
|
||||||
|
var retVal = await Execute(() => _mtApiClient.TimeGMT());
|
||||||
|
AddLog($"TimeGMT: {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
private static void RunOnUiThread(Action action)
|
private static void RunOnUiThread(Action action)
|
||||||
{
|
{
|
||||||
Application.Current?.Dispatcher.Invoke(action);
|
Application.Current?.Dispatcher.Invoke(action);
|
||||||
@@ -921,20 +1022,6 @@ namespace MtApi5TestClient
|
|||||||
Quotes.Clear();
|
Quotes.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string MqlTradeResultToString(MqlTradeResult result)
|
|
||||||
{
|
|
||||||
return result != null ?
|
|
||||||
"Retcode = " + result.Retcode + ";"
|
|
||||||
+ " Comment = " + result.Comment + ";"
|
|
||||||
+ " Order = " + result.Order + ";"
|
|
||||||
+ " Volume = " + result.Volume + ";"
|
|
||||||
+ " Price = " + result.Price + ";"
|
|
||||||
+ " Deal = " + result.Deal + ";"
|
|
||||||
+ " Request_id = " + result.Request_id + ";"
|
|
||||||
+ " Bid = " + result.Bid + ";"
|
|
||||||
+ " Ask = " + result.Ask + ";" : string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnSelectedQuoteChanged()
|
private void OnSelectedQuoteChanged()
|
||||||
{
|
{
|
||||||
if (SelectedQuote == null) return;
|
if (SelectedQuote == null) return;
|
||||||
|
|||||||
+40
-2
@@ -143,6 +143,8 @@
|
|||||||
this.label23 = new System.Windows.Forms.Label();
|
this.label23 = new System.Windows.Forms.Label();
|
||||||
this.textBoxAccountInfoSymbol = new System.Windows.Forms.TextBox();
|
this.textBoxAccountInfoSymbol = new System.Windows.Forms.TextBox();
|
||||||
this.tabPage4 = new System.Windows.Forms.TabPage();
|
this.tabPage4 = new System.Windows.Forms.TabPage();
|
||||||
|
this.comboBox12 = new System.Windows.Forms.ComboBox();
|
||||||
|
this.button72 = new System.Windows.Forms.Button();
|
||||||
this.button36 = new System.Windows.Forms.Button();
|
this.button36 = new System.Windows.Forms.Button();
|
||||||
this.comboBox10 = new System.Windows.Forms.ComboBox();
|
this.comboBox10 = new System.Windows.Forms.ComboBox();
|
||||||
this.comboBox9 = new System.Windows.Forms.ComboBox();
|
this.comboBox9 = new System.Windows.Forms.ComboBox();
|
||||||
@@ -210,6 +212,7 @@
|
|||||||
this.button4 = new System.Windows.Forms.Button();
|
this.button4 = new System.Windows.Forms.Button();
|
||||||
this.tabPage11 = new System.Windows.Forms.TabPage();
|
this.tabPage11 = new System.Windows.Forms.TabPage();
|
||||||
this.button69 = new System.Windows.Forms.Button();
|
this.button69 = new System.Windows.Forms.Button();
|
||||||
|
this.button73 = new System.Windows.Forms.Button();
|
||||||
this.groupBox1.SuspendLayout();
|
this.groupBox1.SuspendLayout();
|
||||||
this.statusStrip1.SuspendLayout();
|
this.statusStrip1.SuspendLayout();
|
||||||
this.groupBox2.SuspendLayout();
|
this.groupBox2.SuspendLayout();
|
||||||
@@ -1427,6 +1430,8 @@
|
|||||||
//
|
//
|
||||||
// tabPage4
|
// tabPage4
|
||||||
//
|
//
|
||||||
|
this.tabPage4.Controls.Add(this.comboBox12);
|
||||||
|
this.tabPage4.Controls.Add(this.button72);
|
||||||
this.tabPage4.Controls.Add(this.button36);
|
this.tabPage4.Controls.Add(this.button36);
|
||||||
this.tabPage4.Controls.Add(this.comboBox10);
|
this.tabPage4.Controls.Add(this.comboBox10);
|
||||||
this.tabPage4.Controls.Add(this.comboBox9);
|
this.tabPage4.Controls.Add(this.comboBox9);
|
||||||
@@ -1450,6 +1455,25 @@
|
|||||||
this.tabPage4.Text = "MarketInfo";
|
this.tabPage4.Text = "MarketInfo";
|
||||||
this.tabPage4.UseVisualStyleBackColor = true;
|
this.tabPage4.UseVisualStyleBackColor = true;
|
||||||
//
|
//
|
||||||
|
// comboBox12
|
||||||
|
//
|
||||||
|
this.comboBox12.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||||
|
this.comboBox12.FormattingEnabled = true;
|
||||||
|
this.comboBox12.Location = new System.Drawing.Point(13, 188);
|
||||||
|
this.comboBox12.Name = "comboBox12";
|
||||||
|
this.comboBox12.Size = new System.Drawing.Size(186, 21);
|
||||||
|
this.comboBox12.TabIndex = 38;
|
||||||
|
//
|
||||||
|
// button72
|
||||||
|
//
|
||||||
|
this.button72.Location = new System.Drawing.Point(208, 186);
|
||||||
|
this.button72.Name = "button72";
|
||||||
|
this.button72.Size = new System.Drawing.Size(111, 23);
|
||||||
|
this.button72.TabIndex = 37;
|
||||||
|
this.button72.Text = "TerminalInfoString";
|
||||||
|
this.button72.UseVisualStyleBackColor = true;
|
||||||
|
this.button72.Click += new System.EventHandler(this.button72_Click);
|
||||||
|
//
|
||||||
// button36
|
// button36
|
||||||
//
|
//
|
||||||
this.button36.Location = new System.Drawing.Point(208, 157);
|
this.button36.Location = new System.Drawing.Point(208, 157);
|
||||||
@@ -1844,6 +1868,7 @@
|
|||||||
//
|
//
|
||||||
// tabPage6
|
// tabPage6
|
||||||
//
|
//
|
||||||
|
this.tabPage6.Controls.Add(this.button73);
|
||||||
this.tabPage6.Controls.Add(this.textBoxPrint);
|
this.tabPage6.Controls.Add(this.textBoxPrint);
|
||||||
this.tabPage6.Controls.Add(this.button27);
|
this.tabPage6.Controls.Add(this.button27);
|
||||||
this.tabPage6.Controls.Add(this.button14);
|
this.tabPage6.Controls.Add(this.button14);
|
||||||
@@ -1858,14 +1883,14 @@
|
|||||||
//
|
//
|
||||||
// textBoxPrint
|
// textBoxPrint
|
||||||
//
|
//
|
||||||
this.textBoxPrint.Location = new System.Drawing.Point(13, 86);
|
this.textBoxPrint.Location = new System.Drawing.Point(13, 108);
|
||||||
this.textBoxPrint.Name = "textBoxPrint";
|
this.textBoxPrint.Name = "textBoxPrint";
|
||||||
this.textBoxPrint.Size = new System.Drawing.Size(386, 20);
|
this.textBoxPrint.Size = new System.Drawing.Size(386, 20);
|
||||||
this.textBoxPrint.TabIndex = 3;
|
this.textBoxPrint.TabIndex = 3;
|
||||||
//
|
//
|
||||||
// button27
|
// button27
|
||||||
//
|
//
|
||||||
this.button27.Location = new System.Drawing.Point(405, 84);
|
this.button27.Location = new System.Drawing.Point(405, 106);
|
||||||
this.button27.Name = "button27";
|
this.button27.Name = "button27";
|
||||||
this.button27.Size = new System.Drawing.Size(75, 23);
|
this.button27.Size = new System.Drawing.Size(75, 23);
|
||||||
this.button27.TabIndex = 2;
|
this.button27.TabIndex = 2;
|
||||||
@@ -2146,6 +2171,16 @@
|
|||||||
this.button69.UseVisualStyleBackColor = true;
|
this.button69.UseVisualStyleBackColor = true;
|
||||||
this.button69.Click += new System.EventHandler(this.button69_Click);
|
this.button69.Click += new System.EventHandler(this.button69_Click);
|
||||||
//
|
//
|
||||||
|
// button73
|
||||||
|
//
|
||||||
|
this.button73.Location = new System.Drawing.Point(13, 74);
|
||||||
|
this.button73.Name = "button73";
|
||||||
|
this.button73.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.button73.TabIndex = 4;
|
||||||
|
this.button73.Text = "TimeGMT";
|
||||||
|
this.button73.UseVisualStyleBackColor = true;
|
||||||
|
this.button73.Click += new System.EventHandler(this.button73_Click);
|
||||||
|
//
|
||||||
// Form1
|
// Form1
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
@@ -2379,6 +2414,9 @@
|
|||||||
private System.Windows.Forms.TextBox textBoxAccountLogin;
|
private System.Windows.Forms.TextBox textBoxAccountLogin;
|
||||||
private System.Windows.Forms.Button button70;
|
private System.Windows.Forms.Button button70;
|
||||||
private System.Windows.Forms.Button button71;
|
private System.Windows.Forms.Button button71;
|
||||||
|
private System.Windows.Forms.ComboBox comboBox12;
|
||||||
|
private System.Windows.Forms.Button button72;
|
||||||
|
private System.Windows.Forms.Button button73;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ namespace TestApiClientUI
|
|||||||
comboBox9.DataSource = Enum.GetNames(typeof(EnumTerminalInfoInteger));
|
comboBox9.DataSource = Enum.GetNames(typeof(EnumTerminalInfoInteger));
|
||||||
comboBox10.DataSource = Enum.GetNames(typeof(EnumTerminalInfoDouble));
|
comboBox10.DataSource = Enum.GetNames(typeof(EnumTerminalInfoDouble));
|
||||||
comboBox11.DataSource = Enum.GetNames(typeof(EnumObject));
|
comboBox11.DataSource = Enum.GetNames(typeof(EnumObject));
|
||||||
|
comboBox12.DataSource = Enum.GetNames(typeof(ENUM_TERMINAL_INFO_STRING));
|
||||||
comboBoxAccountInfoCmd.DataSource = Enum.GetNames(typeof(TradeOperation));
|
comboBoxAccountInfoCmd.DataSource = Enum.GetNames(typeof(TradeOperation));
|
||||||
|
|
||||||
_apiClient.QuoteUpdated += apiClient_QuoteUpdated;
|
_apiClient.QuoteUpdated += apiClient_QuoteUpdated;
|
||||||
@@ -615,18 +616,28 @@ namespace TestApiClientUI
|
|||||||
listBoxProceHistory.DataSource = items;
|
listBoxProceHistory.DataSource = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TimeCurrent
|
||||||
private void button13_Click(object sender, EventArgs e)
|
private void button13_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var retVal = _apiClient.TimeCurrent();
|
var retVal = _apiClient.TimeCurrent();
|
||||||
PrintLog($"TimeCurrent result: {retVal}");
|
PrintLog($"TimeCurrent result: {retVal}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TimeLocal
|
||||||
private void button14_Click(object sender, EventArgs e)
|
private void button14_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var retVal = _apiClient.TimeLocal();
|
var retVal = _apiClient.TimeLocal();
|
||||||
PrintLog($"TimeLocal result: {retVal}");
|
PrintLog($"TimeLocal result: {retVal}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TimeGMT
|
||||||
|
private void button73_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var retVal = _apiClient.TimeGMT();
|
||||||
|
PrintLog($"TimeGMT result: {retVal}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//RefreshRates
|
||||||
private void buttonRefreshRates_Click(object sender, EventArgs e)
|
private void buttonRefreshRates_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var retVal = _apiClient.RefreshRates();
|
var retVal = _apiClient.RefreshRates();
|
||||||
@@ -1129,6 +1140,16 @@ namespace TestApiClientUI
|
|||||||
PrintLog($"TerminalInfoDouble: result = {result}");
|
PrintLog($"TerminalInfoDouble: result = {result}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TerminalInfoString
|
||||||
|
private async void button72_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
ENUM_TERMINAL_INFO_STRING propId;
|
||||||
|
Enum.TryParse(comboBox12.Text, out propId);
|
||||||
|
|
||||||
|
var result = await Execute(() => _apiClient.TerminalInfoString(propId));
|
||||||
|
PrintLog($"TerminalInfoString: result = {result}");
|
||||||
|
}
|
||||||
|
|
||||||
private void checkBox2_CheckedChanged(object sender, EventArgs e)
|
private void checkBox2_CheckedChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var checkbox = sender as CheckBox;
|
var checkbox = sender as CheckBox;
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
+284
-11
@@ -1,7 +1,7 @@
|
|||||||
#property copyright "Vyacheslav Demidyuk"
|
#property copyright "Vyacheslav Demidyuk"
|
||||||
#property link ""
|
#property link ""
|
||||||
|
|
||||||
#property version "1.3"
|
#property version "1.4"
|
||||||
#property description "MtApi (MT5) connection expert"
|
#property description "MtApi (MT5) connection expert"
|
||||||
|
|
||||||
#include <json.mqh>
|
#include <json.mqh>
|
||||||
@@ -39,6 +39,8 @@
|
|||||||
bool getBooleanValue(int expertHandle, int paramIndex, bool& res, string& err);
|
bool getBooleanValue(int expertHandle, int paramIndex, bool& res, string& err);
|
||||||
#import
|
#import
|
||||||
|
|
||||||
|
//#define __DEBUG_LOG__
|
||||||
|
|
||||||
input int Port = 8228;
|
input int Port = 8228;
|
||||||
|
|
||||||
int ExpertHandle;
|
int ExpertHandle;
|
||||||
@@ -72,6 +74,7 @@ void OnDeinit(const int reason)
|
|||||||
void OnTick()
|
void OnTick()
|
||||||
{
|
{
|
||||||
start();
|
start();
|
||||||
|
if (IsTesting()) OnTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
int preinit()
|
int preinit()
|
||||||
@@ -92,7 +95,6 @@ bool IsDemo()
|
|||||||
bool IsTesting()
|
bool IsTesting()
|
||||||
{
|
{
|
||||||
bool isTesting = MQLInfoInteger(MQL_TESTER);
|
bool isTesting = MQLInfoInteger(MQL_TESTER);
|
||||||
PrintFormat("IsTesting: %s", isTesting ? "true" : "false");
|
|
||||||
return isTesting;
|
return isTesting;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +143,10 @@ int init()
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __DEBUG_LOG__
|
||||||
PrintFormat("Expert Handle = %d", ExpertHandle);
|
PrintFormat("Expert Handle = %d", ExpertHandle);
|
||||||
|
PrintFormat("IsTesting: %s", IsTesting() ? "true" : "false");
|
||||||
|
#endif
|
||||||
|
|
||||||
//--- Backtesting mode
|
//--- Backtesting mode
|
||||||
if (IsTesting())
|
if (IsTesting())
|
||||||
@@ -219,10 +224,12 @@ int executeCommand()
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __DEBUG_LOG__
|
||||||
if (commandType > 0)
|
if (commandType > 0)
|
||||||
{
|
{
|
||||||
Print("executeCommand: commnad type = ", commandType);
|
Print("executeCommand: commnad type = ", commandType);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
switch (commandType)
|
switch (commandType)
|
||||||
{
|
{
|
||||||
@@ -481,9 +488,9 @@ int executeCommand()
|
|||||||
case 65: //PositionOpen
|
case 65: //PositionOpen
|
||||||
Execute_PositionOpen(false);
|
Execute_PositionOpen(false);
|
||||||
break;
|
break;
|
||||||
case 1065: //PositionOpenWithResult
|
// case 1065: //PositionOpenWithResult
|
||||||
Execute_PositionOpen(true);
|
// Execute_PositionOpen(true);
|
||||||
break;
|
// break;
|
||||||
case 66: //BacktestingReady
|
case 66: //BacktestingReady
|
||||||
Execute_BacktestingReady();
|
Execute_BacktestingReady();
|
||||||
break;
|
break;
|
||||||
@@ -657,6 +664,18 @@ int executeCommand()
|
|||||||
case 126: //iVolumes
|
case 126: //iVolumes
|
||||||
Execute_iVolumes();
|
Execute_iVolumes();
|
||||||
break;
|
break;
|
||||||
|
case 127: //TimeCurrent
|
||||||
|
Execute_TimeCurrent();
|
||||||
|
break;
|
||||||
|
case 128: //TimeTradeServer
|
||||||
|
Execute_TimeTradeServer();
|
||||||
|
break;
|
||||||
|
case 129: //TimeLocal
|
||||||
|
Execute_TimeLocal();
|
||||||
|
break;
|
||||||
|
case 130: //TimeGMT
|
||||||
|
Execute_TimeGMT();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Print("Unknown command type = ", commandType);
|
Print("Unknown command type = ", commandType);
|
||||||
sendVoidResponse(ExpertHandle, _response_error);
|
sendVoidResponse(ExpertHandle, _response_error);
|
||||||
@@ -681,7 +700,9 @@ void Execute_Request()
|
|||||||
string response = "";
|
string response = "";
|
||||||
if (request != "")
|
if (request != "")
|
||||||
{
|
{
|
||||||
|
#ifdef __DEBUG_LOG__
|
||||||
Print("Execute_Request: incoming request = ", request);
|
Print("Execute_Request: incoming request = ", request);
|
||||||
|
#endif
|
||||||
response = OnRequest(request);
|
response = OnRequest(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1151,7 +1172,7 @@ void Execute_HistoryOrderGetInteger()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sendULongResponse(ExpertHandle, HistoryOrderGetInteger(ticket_number, (ENUM_ORDER_PROPERTY_INTEGER)property_id), _response_error))
|
if (!sendLongResponse(ExpertHandle, HistoryOrderGetInteger(ticket_number, (ENUM_ORDER_PROPERTY_INTEGER)property_id), _response_error))
|
||||||
{
|
{
|
||||||
PrintResponseError("HistoryOrderGetInteger", _response_error);
|
PrintResponseError("HistoryOrderGetInteger", _response_error);
|
||||||
}
|
}
|
||||||
@@ -3102,8 +3123,11 @@ void Execute_PositionOpen(bool isTradeResultRequired)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintFormat("Execute_PositionOpen: symbol = %s, order_type = %d, volume = %f, price = %f, sl = %f, tp = %f, comment = %s",
|
|
||||||
symbol, order_type, volume, price, sl, tp, comment);
|
#ifdef __DEBUG_LOG__
|
||||||
|
PrintFormat("%s: symbol = %s, order_type = %d, volume = %f, price = %f, sl = %f, tp = %f, comment = %s",
|
||||||
|
__FUNCTION__, symbol, order_type, volume, price, sl, tp, comment);
|
||||||
|
#endif
|
||||||
|
|
||||||
CTrade trade;
|
CTrade trade;
|
||||||
bool ok = trade.PositionOpen(symbol, (ENUM_ORDER_TYPE)order_type, volume, price, sl, tp, comment);
|
bool ok = trade.PositionOpen(symbol, (ENUM_ORDER_TYPE)order_type, volume, price, sl, tp, comment);
|
||||||
@@ -5414,6 +5438,38 @@ void Execute_iVolumes()
|
|||||||
PrintResponseError("iVolumes", _response_error);
|
PrintResponseError("iVolumes", _response_error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Execute_TimeCurrent()
|
||||||
|
{
|
||||||
|
if (!sendLongResponse(ExpertHandle, TimeCurrent(), _response_error))
|
||||||
|
{
|
||||||
|
PrintResponseError("TimeCurrent", _response_error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Execute_TimeTradeServer()
|
||||||
|
{
|
||||||
|
if (!sendLongResponse(ExpertHandle, TimeTradeServer(), _response_error))
|
||||||
|
{
|
||||||
|
PrintResponseError("TimeTradeServer", _response_error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Execute_TimeLocal()
|
||||||
|
{
|
||||||
|
if (!sendLongResponse(ExpertHandle, TimeLocal(), _response_error))
|
||||||
|
{
|
||||||
|
PrintResponseError("TimeLocal", _response_error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Execute_TimeGMT()
|
||||||
|
{
|
||||||
|
if (!sendLongResponse(ExpertHandle, TimeGMT(), _response_error))
|
||||||
|
{
|
||||||
|
PrintResponseError("TimeGMT", _response_error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PrintParamError(string paramName)
|
void PrintParamError(string paramName)
|
||||||
{
|
{
|
||||||
@@ -5552,7 +5608,7 @@ string OnRequest(string json)
|
|||||||
|
|
||||||
if(jv == NULL)
|
if(jv == NULL)
|
||||||
{
|
{
|
||||||
PrintFormat("OnRequest [ERROR]: %d - %s", (string)parser.getErrorCode(), parser.getErrorMessage());
|
PrintFormat("%s [ERROR]: %d - %s", __FUNCTION__, (string)parser.getErrorCode(), parser.getErrorMessage());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -5569,8 +5625,17 @@ string OnRequest(string json)
|
|||||||
case 2: //iCustom
|
case 2: //iCustom
|
||||||
response = ExecuteRequest_iCustom(jo);
|
response = ExecuteRequest_iCustom(jo);
|
||||||
break;
|
break;
|
||||||
|
case 3: //OrderSend
|
||||||
|
response = ExecuteRequest_OrderSend(jo);
|
||||||
|
break;
|
||||||
|
case 4: //PositionOpen
|
||||||
|
response = ExecuteRequest_PositionOpen(jo);
|
||||||
|
break;
|
||||||
|
case 5: //OrderCheck
|
||||||
|
response = ExecuteRequest_OrderCheck(jo);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
PrintFormat("OnRequest [WARNING]: Unknown request type %d", requestType);
|
PrintFormat("%s [WARNING]: Unknown request type %d", __FUNCTION__, requestType);
|
||||||
response = CreateErrorResponse(-1, "Unknown request type");
|
response = CreateErrorResponse(-1, "Unknown request type");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -5654,7 +5719,7 @@ string ExecuteRequest_CopyTicks(JSONObject *jo)
|
|||||||
jaTicks.put(i, Serialize(ticks[i]));
|
jaTicks.put(i, Serialize(ticks[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
return CreateSuccessResponse("Ticks", jaTicks);;
|
return CreateSuccessResponse("Value", jaTicks);;
|
||||||
}
|
}
|
||||||
|
|
||||||
string ExecuteRequest_iCustom(JSONObject *jo)
|
string ExecuteRequest_iCustom(JSONObject *jo)
|
||||||
@@ -5760,4 +5825,212 @@ int iCustomT(string symbol, ENUM_TIMEFRAMES timeframe, string name, T &p[], int
|
|||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define PRINT_MSG_AND_RETURN_VALUE(msg,value) PrintFormat("%s: %s",__FUNCTION__,msg);return value
|
||||||
|
#define CHECK_JSON_VALUE(jo, name_value, return_fail_result) if (jo.getValue(name_value) == NULL) { PRINT_MSG_AND_RETURN_VALUE(StringFormat("failed to get %s from JSON!", name_value), return_fail_result); }
|
||||||
|
|
||||||
|
bool JsonToMqlTradeRequest(JSONObject *jo, MqlTradeRequest& request)
|
||||||
|
{
|
||||||
|
//Action
|
||||||
|
CHECK_JSON_VALUE(jo, "Action", false);
|
||||||
|
request.action = (ENUM_TRADE_REQUEST_ACTIONS) jo.getInt("Action");
|
||||||
|
|
||||||
|
//Magic
|
||||||
|
CHECK_JSON_VALUE(jo, "Magic", false);
|
||||||
|
request.magic = jo.getLong("Magic");
|
||||||
|
|
||||||
|
//Order
|
||||||
|
CHECK_JSON_VALUE(jo, "Order", false);
|
||||||
|
request.order = jo.getLong("Magic");
|
||||||
|
|
||||||
|
//Symbol
|
||||||
|
CHECK_JSON_VALUE(jo, "Symbol", false);
|
||||||
|
StringInit(request.symbol, 100, 0);
|
||||||
|
request.symbol = jo.getString("Symbol");
|
||||||
|
|
||||||
|
//Volume
|
||||||
|
CHECK_JSON_VALUE(jo, "Volume", false);
|
||||||
|
request.volume = jo.getDouble("Volume");
|
||||||
|
|
||||||
|
//Price
|
||||||
|
CHECK_JSON_VALUE(jo, "Price", false);
|
||||||
|
request.price = jo.getDouble("Price");
|
||||||
|
|
||||||
|
//Stoplimit
|
||||||
|
CHECK_JSON_VALUE(jo, "Stoplimit", false);
|
||||||
|
request.stoplimit = jo.getDouble("Stoplimit");
|
||||||
|
|
||||||
|
//Sl
|
||||||
|
CHECK_JSON_VALUE(jo, "Sl", false);
|
||||||
|
request.sl = jo.getDouble("Sl");
|
||||||
|
|
||||||
|
//Tp
|
||||||
|
CHECK_JSON_VALUE(jo, "Tp", false);
|
||||||
|
request.tp = jo.getDouble("Tp");
|
||||||
|
|
||||||
|
//Deviation
|
||||||
|
CHECK_JSON_VALUE(jo, "Deviation", false);
|
||||||
|
request.deviation = jo.getLong("Deviation");
|
||||||
|
|
||||||
|
//Type
|
||||||
|
CHECK_JSON_VALUE(jo, "Type", false);
|
||||||
|
request.type = (ENUM_ORDER_TYPE)jo.getInt("Type");
|
||||||
|
|
||||||
|
//Type_filling
|
||||||
|
CHECK_JSON_VALUE(jo, "Type_filling", false);
|
||||||
|
request.type_filling = (ENUM_ORDER_TYPE_FILLING)jo.getInt("Type_filling");
|
||||||
|
|
||||||
|
//Type_time
|
||||||
|
CHECK_JSON_VALUE(jo, "Type_time", false);
|
||||||
|
request.type_time = (ENUM_ORDER_TYPE_TIME)jo.getInt("Type_time");
|
||||||
|
|
||||||
|
//MtExpiration
|
||||||
|
CHECK_JSON_VALUE(jo, "MtExpiration", false);
|
||||||
|
request.expiration = (datetime)jo.getInt("MtExpiration");
|
||||||
|
|
||||||
|
//Comment
|
||||||
|
if (jo.getValue("Comment") != NULL)
|
||||||
|
{
|
||||||
|
StringInit(request.comment, 1000, 0);
|
||||||
|
request.comment = jo.getString("Comment");
|
||||||
|
}
|
||||||
|
|
||||||
|
//Position
|
||||||
|
CHECK_JSON_VALUE(jo, "Position", false);
|
||||||
|
request.position = jo.getLong("Position");
|
||||||
|
|
||||||
|
//PositionBy
|
||||||
|
CHECK_JSON_VALUE(jo, "PositionBy", false);
|
||||||
|
request.position_by = jo.getLong("PositionBy");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONObject* MqlTradeResultToJson(MqlTradeResult& result)
|
||||||
|
{
|
||||||
|
JSONObject* jo = new JSONObject();
|
||||||
|
|
||||||
|
jo.put("Retcode", new JSONNumber(result.retcode));
|
||||||
|
jo.put("Deal", new JSONNumber(result.deal));
|
||||||
|
jo.put("Order", new JSONNumber(result.order));
|
||||||
|
jo.put("Volume", new JSONNumber(result.volume));
|
||||||
|
jo.put("Price", new JSONNumber(result.price));
|
||||||
|
jo.put("Bid", new JSONNumber(result.bid));
|
||||||
|
jo.put("Ask", new JSONNumber(result.ask));
|
||||||
|
jo.put("Comment", new JSONString(result.comment));
|
||||||
|
jo.put("Request_id", new JSONNumber(result.request_id));
|
||||||
|
|
||||||
|
return jo;
|
||||||
|
}
|
||||||
|
|
||||||
|
string ExecuteRequest_OrderSend(JSONObject *jo)
|
||||||
|
{
|
||||||
|
CHECK_JSON_VALUE(jo, "TradeRequest", CreateErrorResponse(-1, "Undefinded mandatory parameter TradeRequest"));
|
||||||
|
JSONObject* trade_request_jo = jo.getObject("TradeRequest");
|
||||||
|
|
||||||
|
MqlTradeRequest trade_request = {0};
|
||||||
|
JsonToMqlTradeRequest(trade_request_jo, trade_request);
|
||||||
|
|
||||||
|
MqlTradeResult trade_result = {0};
|
||||||
|
bool ok = OrderSend(trade_request, trade_result);
|
||||||
|
|
||||||
|
JSONObject* result_value_jo = new JSONObject();
|
||||||
|
result_value_jo.put("RetVal", new JSONBool(ok));
|
||||||
|
result_value_jo.put("TradeResult", MqlTradeResultToJson(trade_result));
|
||||||
|
|
||||||
|
#ifdef __DEBUG_LOG__
|
||||||
|
PrintFormat("%s: return value = %s", __FUNCTION__, ok ? "true" : "false");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return CreateSuccessResponse("Value", result_value_jo);
|
||||||
|
}
|
||||||
|
|
||||||
|
string ExecuteRequest_PositionOpen(JSONObject *jo)
|
||||||
|
{
|
||||||
|
//Symbol
|
||||||
|
CHECK_JSON_VALUE(jo, "Symbol", CreateErrorResponse(-1, "Undefinded mandatory parameter Symbol"));
|
||||||
|
string symbol = jo.getString("Symbol");
|
||||||
|
|
||||||
|
//OrderType
|
||||||
|
CHECK_JSON_VALUE(jo, "OrderType", CreateErrorResponse(-1, "Undefinded mandatory parameter OrderType"));
|
||||||
|
ENUM_ORDER_TYPE order_type = (ENUM_ORDER_TYPE) jo.getInt("OrderType");
|
||||||
|
|
||||||
|
//Volume
|
||||||
|
CHECK_JSON_VALUE(jo, "Volume", CreateErrorResponse(-1, "Undefinded mandatory parameter Volume"));
|
||||||
|
double volume = jo.getDouble("Volume");
|
||||||
|
|
||||||
|
//Price
|
||||||
|
CHECK_JSON_VALUE(jo, "Price", CreateErrorResponse(-1, "Undefinded mandatory parameter Price"));
|
||||||
|
double price = jo.getDouble("Price");
|
||||||
|
|
||||||
|
//Sl
|
||||||
|
CHECK_JSON_VALUE(jo, "Sl", CreateErrorResponse(-1, "Undefinded mandatory parameter Sl"));
|
||||||
|
double sl = jo.getDouble("Sl");
|
||||||
|
|
||||||
|
//Tp
|
||||||
|
CHECK_JSON_VALUE(jo, "Tp", CreateErrorResponse(-1, "Undefinded mandatory parameter Tp"));
|
||||||
|
double tp = jo.getDouble("Tp");
|
||||||
|
|
||||||
|
//Comment
|
||||||
|
string comment;
|
||||||
|
if (jo.getValue("Comment") != NULL)
|
||||||
|
{
|
||||||
|
comment = jo.getString("Comment");
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __DEBUG_LOG__
|
||||||
|
PrintFormat("%s: symbol = %s, order_type = %d, volume = %f, price = %f, sl = %f, tp = %f, comment = %s",
|
||||||
|
__FUNCTION__, symbol, order_type, volume, price, sl, tp, comment);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
CTrade trade;
|
||||||
|
bool ok = trade.PositionOpen(symbol, order_type, volume, price, sl, tp, comment);
|
||||||
|
|
||||||
|
MqlTradeResult trade_result={0};
|
||||||
|
trade.Result(trade_result);
|
||||||
|
|
||||||
|
JSONObject* result_value_jo = new JSONObject();
|
||||||
|
result_value_jo.put("RetVal", new JSONBool(ok));
|
||||||
|
result_value_jo.put("TradeResult", MqlTradeResultToJson(trade_result));
|
||||||
|
|
||||||
|
return CreateSuccessResponse("Value", result_value_jo);
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONObject* MqlTradeCheckResultToJson(MqlTradeCheckResult& result)
|
||||||
|
{
|
||||||
|
JSONObject* jo = new JSONObject();
|
||||||
|
|
||||||
|
jo.put("Retcode", new JSONNumber(result.retcode));
|
||||||
|
jo.put("Balance", new JSONNumber(result.balance));
|
||||||
|
jo.put("Equity", new JSONNumber(result.equity));
|
||||||
|
jo.put("Profit", new JSONNumber(result.profit));
|
||||||
|
jo.put("Margin", new JSONNumber(result.margin));
|
||||||
|
jo.put("Margin_free", new JSONNumber(result.margin_free));
|
||||||
|
jo.put("Margin_level", new JSONNumber(result.margin_level));
|
||||||
|
jo.put("Comment", new JSONString(result.comment));
|
||||||
|
|
||||||
|
return jo;
|
||||||
|
}
|
||||||
|
|
||||||
|
string ExecuteRequest_OrderCheck(JSONObject *jo)
|
||||||
|
{
|
||||||
|
CHECK_JSON_VALUE(jo, "TradeRequest", CreateErrorResponse(-1, "Undefinded mandatory parameter TradeRequest"));
|
||||||
|
JSONObject* trade_request_jo = jo.getObject("TradeRequest");
|
||||||
|
|
||||||
|
MqlTradeRequest trade_request = {0};
|
||||||
|
JsonToMqlTradeRequest(trade_request_jo, trade_request);
|
||||||
|
|
||||||
|
MqlTradeCheckResult trade_check_result = {0};
|
||||||
|
bool ok = OrderCheck(trade_request, trade_check_result);
|
||||||
|
|
||||||
|
#ifdef __DEBUG_LOG__
|
||||||
|
PrintFormat("%s: return value = %s", __FUNCTION__, ok ? "true" : "false");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
JSONObject* result_value_jo = new JSONObject();
|
||||||
|
result_value_jo.put("RetVal", new JSONBool(ok));
|
||||||
|
result_value_jo.put("TradeCheckResult", MqlTradeCheckResultToJson(trade_check_result));
|
||||||
|
|
||||||
|
return CreateSuccessResponse("Value", result_value_jo);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user