mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-16 20:28:09 +00:00
Started version 1.0.25. Added OrderModifyRequest. Changed function OrderModify to use request pattern.
This commit is contained in:
+32
-25
@@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.ServiceModel;
|
using System.ServiceModel;
|
||||||
@@ -13,7 +11,6 @@ namespace MTApiService
|
|||||||
{
|
{
|
||||||
private static string SERVICE_NAME = "MtApiService";
|
private static string SERVICE_NAME = "MtApiService";
|
||||||
|
|
||||||
// public delegate void MtInstrumentsChangedHandler(string addedInstrument, string removedInstrument);
|
|
||||||
public delegate void MtQuoteHandler(MtQuote quote);
|
public delegate void MtQuoteHandler(MtQuote quote);
|
||||||
|
|
||||||
#region Public Methods
|
#region Public Methods
|
||||||
@@ -21,29 +18,34 @@ namespace MTApiService
|
|||||||
{
|
{
|
||||||
Debug.WriteLine("[INFO] MtClient::Open");
|
Debug.WriteLine("[INFO] MtClient::Open");
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(host) == true)
|
if (string.IsNullOrEmpty(host))
|
||||||
throw new ArgumentNullException("host", "host is null or epmty");
|
throw new ArgumentNullException("host", "host is null or empty");
|
||||||
|
|
||||||
if (port < 0 || port > 65536)
|
if (port < 0 || port > 65536)
|
||||||
throw new ArgumentOutOfRangeException("port", "port value is invalid");
|
throw new ArgumentOutOfRangeException("port", "port value is invalid");
|
||||||
|
|
||||||
string urlService = string.Format("net.tcp://{0}:{1}/{2}", host, port, SERVICE_NAME);
|
var urlService = string.Format("net.tcp://{0}:{1}/{2}", host, port, SERVICE_NAME);
|
||||||
|
|
||||||
lock (mClientLocker)
|
lock (mClientLocker)
|
||||||
{
|
{
|
||||||
if (mProxy != null)
|
if (mProxy != null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var bind = new NetTcpBinding(SecurityMode.None);
|
var bind = new NetTcpBinding(SecurityMode.None)
|
||||||
bind.MaxReceivedMessageSize = 2147483647;
|
{
|
||||||
bind.MaxBufferSize = 2147483647;
|
MaxReceivedMessageSize = 2147483647,
|
||||||
|
MaxBufferSize = 2147483647,
|
||||||
|
MaxBufferPoolSize = 2147483647,
|
||||||
|
ReaderQuotas =
|
||||||
|
{
|
||||||
|
MaxArrayLength = 2147483647,
|
||||||
|
MaxBytesPerRead = 2147483647,
|
||||||
|
MaxDepth = 2147483647,
|
||||||
|
MaxStringContentLength = 2147483647,
|
||||||
|
MaxNameTableCharCount = 2147483647
|
||||||
|
}
|
||||||
|
};
|
||||||
// Commented next statement since it is not required
|
// Commented next statement since it is not required
|
||||||
bind.MaxBufferPoolSize = 2147483647;
|
|
||||||
bind.ReaderQuotas.MaxArrayLength = 2147483647;
|
|
||||||
bind.ReaderQuotas.MaxBytesPerRead = 2147483647;
|
|
||||||
bind.ReaderQuotas.MaxDepth = 2147483647;
|
|
||||||
bind.ReaderQuotas.MaxStringContentLength = 2147483647;
|
|
||||||
bind.ReaderQuotas.MaxNameTableCharCount = 2147483647;
|
|
||||||
|
|
||||||
mProxy = new MtApiProxy(new InstanceContext(this), bind, new EndpointAddress(urlService));
|
mProxy = new MtApiProxy(new InstanceContext(this), bind, new EndpointAddress(urlService));
|
||||||
mProxy.Faulted += mProxy_Faulted;
|
mProxy.Faulted += mProxy_Faulted;
|
||||||
@@ -55,23 +57,28 @@ namespace MTApiService
|
|||||||
if (port < 0 || port > 65536)
|
if (port < 0 || port > 65536)
|
||||||
throw new ArgumentOutOfRangeException("port", "port value is invalid");
|
throw new ArgumentOutOfRangeException("port", "port value is invalid");
|
||||||
|
|
||||||
string urlService = "net.pipe://localhost/" + SERVICE_NAME + "_" + port.ToString();
|
var urlService = string.Format("net.pipe://localhost/{0}_{1}", SERVICE_NAME, port);
|
||||||
|
|
||||||
lock (mClientLocker)
|
lock (mClientLocker)
|
||||||
{
|
{
|
||||||
if (mProxy != null)
|
if (mProxy != null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var bind = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
|
var bind = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
|
||||||
bind.MaxReceivedMessageSize = 2147483647;
|
{
|
||||||
bind.MaxBufferSize = 2147483647;
|
MaxReceivedMessageSize = 2147483647,
|
||||||
|
MaxBufferSize = 2147483647,
|
||||||
|
MaxBufferPoolSize = 2147483647,
|
||||||
|
ReaderQuotas =
|
||||||
|
{
|
||||||
|
MaxArrayLength = 2147483647,
|
||||||
|
MaxBytesPerRead = 2147483647,
|
||||||
|
MaxDepth = 2147483647,
|
||||||
|
MaxStringContentLength = 2147483647,
|
||||||
|
MaxNameTableCharCount = 2147483647
|
||||||
|
}
|
||||||
|
};
|
||||||
// Commented next statement since it is not required
|
// Commented next statement since it is not required
|
||||||
bind.MaxBufferPoolSize = 2147483647;
|
|
||||||
bind.ReaderQuotas.MaxArrayLength = 2147483647;
|
|
||||||
bind.ReaderQuotas.MaxBytesPerRead = 2147483647;
|
|
||||||
bind.ReaderQuotas.MaxDepth = 2147483647;
|
|
||||||
bind.ReaderQuotas.MaxStringContentLength = 2147483647;
|
|
||||||
bind.ReaderQuotas.MaxNameTableCharCount = 2147483647;
|
|
||||||
|
|
||||||
mProxy = new MtApiProxy(new InstanceContext(this), bind, new EndpointAddress(urlService));
|
mProxy = new MtApiProxy(new InstanceContext(this), bind, new EndpointAddress(urlService));
|
||||||
mProxy.Faulted += mProxy_Faulted;
|
mProxy.Faulted += mProxy_Faulted;
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.ServiceModel;
|
using System.ServiceModel;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
namespace MTApiService
|
namespace MTApiService
|
||||||
@@ -24,6 +21,7 @@ namespace MTApiService
|
|||||||
IEnumerable<MtQuote> GetQuotes();
|
IEnumerable<MtQuote> GetQuotes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ServiceContract]
|
||||||
public interface IMtApiCallback
|
public interface IMtApiCallback
|
||||||
{
|
{
|
||||||
[OperationContract(IsOneWay = true)]
|
[OperationContract(IsOneWay = true)]
|
||||||
|
|||||||
@@ -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.18.0")]
|
[assembly: AssemblyVersion("1.0.19.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.18.0")]
|
[assembly: AssemblyFileVersion("1.0.19.0")]
|
||||||
|
|||||||
@@ -81,6 +81,7 @@
|
|||||||
<Compile Include="Requests\OrderCloseByRequest.cs" />
|
<Compile Include="Requests\OrderCloseByRequest.cs" />
|
||||||
<Compile Include="Requests\OrderCloseRequest.cs" />
|
<Compile Include="Requests\OrderCloseRequest.cs" />
|
||||||
<Compile Include="Requests\OrderDeleteRequest.cs" />
|
<Compile Include="Requests\OrderDeleteRequest.cs" />
|
||||||
|
<Compile Include="Requests\OrderModifyRequest.cs" />
|
||||||
<Compile Include="Requests\OrderSendRequest.cs" />
|
<Compile Include="Requests\OrderSendRequest.cs" />
|
||||||
<Compile Include="Requests\RequestBase.cs" />
|
<Compile Include="Requests\RequestBase.cs" />
|
||||||
<Compile Include="Requests\RequestType.cs" />
|
<Compile Include="Requests\RequestType.cs" />
|
||||||
|
|||||||
+74
-46
@@ -28,11 +28,11 @@ namespace MtApi
|
|||||||
|
|
||||||
public MtApiClient()
|
public MtApiClient()
|
||||||
{
|
{
|
||||||
mClient.QuoteAdded +=new MtClient.MtQuoteHandler(mClient_QuoteAdded);
|
_client.QuoteAdded +=new MtClient.MtQuoteHandler(mClient_QuoteAdded);
|
||||||
mClient.QuoteRemoved += new MtClient.MtQuoteHandler(mClient_QuoteRemoved);
|
_client.QuoteRemoved += new MtClient.MtQuoteHandler(mClient_QuoteRemoved);
|
||||||
mClient.QuoteUpdated += new MtClient.MtQuoteHandler(mClient_QuoteUpdated);
|
_client.QuoteUpdated += new MtClient.MtQuoteHandler(mClient_QuoteUpdated);
|
||||||
mClient.ServerDisconnected += new EventHandler(mClient_ServerDisconnected);
|
_client.ServerDisconnected += new EventHandler(mClient_ServerDisconnected);
|
||||||
mClient.ServerFailed += new EventHandler(mClient_ServerFailed);
|
_client.ServerFailed += new EventHandler(mClient_ServerFailed);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -79,16 +79,26 @@ namespace MtApi
|
|||||||
///</summary>
|
///</summary>
|
||||||
public IEnumerable<MtQuote> GetQuotes()
|
public IEnumerable<MtQuote> GetQuotes()
|
||||||
{
|
{
|
||||||
var quotes = mClient.GetQuotes();
|
var quotes = _client.GetQuotes();
|
||||||
return quotes != null ? (from q in quotes select q.Parse()) : null;
|
return quotes != null ? (from q in quotes select q.Parse()) : null;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
///Connection status of MetaTrader API.
|
///Connection status of MetaTrader API.
|
||||||
///</summary>
|
///</summary>
|
||||||
public MtConnectionState ConnectionState { get; private set; }
|
public MtConnectionState ConnectionState
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
lock (_locker)
|
||||||
|
{
|
||||||
|
return _connectionState;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
@@ -411,13 +421,29 @@ namespace MtApi
|
|||||||
|
|
||||||
public bool OrderModify(int ticket, double price, double stoploss, double takeprofit, DateTime expiration, Color arrow_color)
|
public bool OrderModify(int ticket, double price, double stoploss, double takeprofit, DateTime expiration, Color arrow_color)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { ticket, price, stoploss, takeprofit, MtApiTimeConverter.ConvertToMtTime(expiration), MtApiColorConverter.ConvertToMtColor(arrow_color) };
|
var response = SendRequest<ResponseBase>(new OrderModifyRequest
|
||||||
return SendCommand<bool>(MtCommandType.OrderModify, commandParameters);
|
{
|
||||||
|
Ticket = ticket,
|
||||||
|
Price = price,
|
||||||
|
Stoploss = stoploss,
|
||||||
|
Takeprofit = takeprofit,
|
||||||
|
Expiration = MtApiTimeConverter.ConvertToMtTime(expiration),
|
||||||
|
ArrowColor = MtApiColorConverter.ConvertToMtColor(arrow_color)
|
||||||
|
});
|
||||||
|
return response != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool OrderModify(int ticket, double price, double stoploss, double takeprofit, DateTime expiration)
|
public bool OrderModify(int ticket, double price, double stoploss, double takeprofit, DateTime expiration)
|
||||||
{
|
{
|
||||||
return OrderModify(ticket, price, stoploss, takeprofit, expiration, Color.Empty);
|
var response = SendRequest<ResponseBase>(new OrderModifyRequest
|
||||||
|
{
|
||||||
|
Ticket = ticket,
|
||||||
|
Price = price,
|
||||||
|
Stoploss = stoploss,
|
||||||
|
Takeprofit = takeprofit,
|
||||||
|
Expiration = MtApiTimeConverter.ConvertToMtTime(expiration),
|
||||||
|
});
|
||||||
|
return response != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OrderPrint()
|
public void OrderPrint()
|
||||||
@@ -1342,60 +1368,64 @@ namespace MtApi
|
|||||||
#region Private Methods
|
#region Private Methods
|
||||||
private void Connect(string host, int port)
|
private void Connect(string host, int port)
|
||||||
{
|
{
|
||||||
ConnectionState = MtConnectionState.Connecting;
|
UpdateConnectionState(MtConnectionState.Connecting, string.Format("Connecting to {0}:{1}", host, port));
|
||||||
ConnectionStateChanged.FireEvent(this
|
|
||||||
, new MtConnectionEventArgs(MtConnectionState.Connecting, "Connecting to " + host + ":" + port));
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mClient.Open(host, port);
|
_client.Open(host, port);
|
||||||
mClient.Connect();
|
_client.Connect();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
ConnectionState = MtConnectionState.Failed;
|
UpdateConnectionState(MtConnectionState.Failed, string.Format("Failed connection to {0}:{1}. {2}", host, port, e.Message));
|
||||||
ConnectionStateChanged.FireEvent(this
|
|
||||||
, new MtConnectionEventArgs(MtConnectionState.Failed, "Failed connection to " + host + ":" + port + ". " + e.Message));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionState = MtConnectionState.Connected;
|
UpdateConnectionState(MtConnectionState.Connected, string.Format("Connected to {0}:{1}", host, port));
|
||||||
ConnectionStateChanged.FireEvent(this
|
|
||||||
, new MtConnectionEventArgs(MtConnectionState.Connected, "Connected to " + host + ":" + port));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Connect(int port)
|
private void Connect(int port)
|
||||||
{
|
{
|
||||||
ConnectionState = MtConnectionState.Connecting;
|
UpdateConnectionState(MtConnectionState.Connecting, string.Format("Connecting to 'localhost':{0}", port));
|
||||||
ConnectionStateChanged.FireEvent(this
|
|
||||||
, new MtConnectionEventArgs(MtConnectionState.Connecting, "Connecting to 'localhost':" + port));
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mClient.Open(port);
|
_client.Open(port);
|
||||||
mClient.Connect();
|
_client.Connect();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
ConnectionState = MtConnectionState.Failed;
|
UpdateConnectionState(MtConnectionState.Failed, string.Format("Failed connection to 'localhost':{0}. {1}", port, e.Message));
|
||||||
ConnectionStateChanged.FireEvent(this
|
|
||||||
, new MtConnectionEventArgs(MtConnectionState.Failed, "Failed connection to 'localhost':" + port + ". " + e.Message));
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionState = MtConnectionState.Connected;
|
UpdateConnectionState(MtConnectionState.Connected, string.Format("Connected to 'localhost':{0}", port));
|
||||||
ConnectionStateChanged.FireEvent(this
|
|
||||||
, new MtConnectionEventArgs(MtConnectionState.Connected, "Connected to 'localhost':" + port));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Disconnect()
|
private void Disconnect()
|
||||||
{
|
{
|
||||||
mClient.Disconnect();
|
_client.Disconnect();
|
||||||
mClient.Close();
|
_client.Close();
|
||||||
|
|
||||||
ConnectionState = MtConnectionState.Disconnected;
|
UpdateConnectionState(MtConnectionState.Disconnected, "Disconnected");
|
||||||
ConnectionStateChanged.FireEvent(this, new MtConnectionEventArgs(MtConnectionState.Disconnected, "Disconnected"));
|
}
|
||||||
|
|
||||||
|
private void UpdateConnectionState(MtConnectionState state, string message)
|
||||||
|
{
|
||||||
|
var changed = false;
|
||||||
|
lock (_locker)
|
||||||
|
{
|
||||||
|
if (_connectionState != state)
|
||||||
|
{
|
||||||
|
_connectionState = state;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changed)
|
||||||
|
{
|
||||||
|
ConnectionStateChanged.FireEvent(this, new MtConnectionEventArgs(state, message));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private T SendCommand<T>(MtCommandType commandType, ArrayList commandParameters)
|
private T SendCommand<T>(MtCommandType commandType, ArrayList commandParameters)
|
||||||
@@ -1403,7 +1433,7 @@ namespace MtApi
|
|||||||
MtResponse response;
|
MtResponse response;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
response = mClient.SendCommand((int)commandType, commandParameters);
|
response = _client.SendCommand((int)commandType, commandParameters);
|
||||||
}
|
}
|
||||||
catch (CommunicationException ex)
|
catch (CommunicationException ex)
|
||||||
{
|
{
|
||||||
@@ -1451,7 +1481,7 @@ namespace MtApi
|
|||||||
MtResponseString res;
|
MtResponseString res;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
res = (MtResponseString)mClient.SendCommand((int)MtCommandType.MtRequest, commandParameters);
|
res = (MtResponseString)_client.SendCommand((int)MtCommandType.MtRequest, commandParameters);
|
||||||
}
|
}
|
||||||
catch (CommunicationException ex)
|
catch (CommunicationException ex)
|
||||||
{
|
{
|
||||||
@@ -1482,16 +1512,12 @@ namespace MtApi
|
|||||||
|
|
||||||
private void mClient_ServerDisconnected(object sender, EventArgs e)
|
private void mClient_ServerDisconnected(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
ConnectionState = MtConnectionState.Disconnected;
|
UpdateConnectionState(MtConnectionState.Disconnected, "MtApi is disconnected");
|
||||||
ConnectionStateChanged.FireEvent(this
|
|
||||||
, new MtConnectionEventArgs(MtConnectionState.Disconnected, "MtApi is disconnected"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mClient_ServerFailed(object sender, EventArgs e)
|
private void mClient_ServerFailed(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
ConnectionState = MtConnectionState.Failed;
|
UpdateConnectionState(MtConnectionState.Failed, "Failed connection with MtApi");
|
||||||
ConnectionStateChanged.FireEvent(this
|
|
||||||
, new MtConnectionEventArgs(MtConnectionState.Failed, "Failed connection with MtApi"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mClient_QuoteRemoved(MTApiService.MtQuote quote)
|
private void mClient_QuoteRemoved(MTApiService.MtQuote quote)
|
||||||
@@ -1513,7 +1539,9 @@ namespace MtApi
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Fields
|
#region Private Fields
|
||||||
private readonly MtClient mClient = new MtClient();
|
private readonly MtClient _client = new MtClient();
|
||||||
|
private readonly object _locker = new object();
|
||||||
|
private MtConnectionState _connectionState = MtConnectionState.Disconnected;
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ namespace MtApi
|
|||||||
public double Commission { get; set; }
|
public double Commission { get; set; }
|
||||||
public int MagicNumber { get; set; }
|
public int MagicNumber { get; set; }
|
||||||
public double Swap { get; set; }
|
public double Swap { get; set; }
|
||||||
|
public int MtExpiration { get; set; }
|
||||||
|
|
||||||
public DateTime OpenTime
|
public DateTime OpenTime
|
||||||
{
|
{
|
||||||
@@ -27,5 +28,10 @@ namespace MtApi
|
|||||||
{
|
{
|
||||||
get { return MtApiTimeConverter.ConvertFromMtTime(MtCloseTime); }
|
get { return MtApiTimeConverter.ConvertFromMtTime(MtCloseTime); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DateTime Expiration
|
||||||
|
{
|
||||||
|
get { return MtApiTimeConverter.ConvertFromMtTime(MtExpiration); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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.24.0")]
|
[assembly: AssemblyVersion("1.0.25.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.24.0")]
|
[assembly: AssemblyFileVersion("1.0.25.0")]
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
namespace MtApi.Requests
|
||||||
|
{
|
||||||
|
public class OrderModifyRequest: RequestBase
|
||||||
|
{
|
||||||
|
public int Ticket { get; set; }
|
||||||
|
public double Price { get; set; }
|
||||||
|
public double Stoploss { get; set; }
|
||||||
|
public double Takeprofit { get; set; }
|
||||||
|
public int Expiration { get; set; }
|
||||||
|
|
||||||
|
public int? ArrowColor { get; set; }
|
||||||
|
|
||||||
|
public override RequestType RequestType
|
||||||
|
{
|
||||||
|
get { return RequestType.OrderModify; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
OrderSend = 3,
|
OrderSend = 3,
|
||||||
OrderClose = 4,
|
OrderClose = 4,
|
||||||
OrderCloseBy = 5,
|
OrderCloseBy = 5,
|
||||||
OrderDelete = 6
|
OrderDelete = 6,
|
||||||
|
OrderModify = 7
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
|
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
|
||||||
<?define ProductName="MtApi" ?>
|
<?define ProductName="MtApi" ?>
|
||||||
<?define ProductVersion="1.0.24" ?>
|
<?define ProductVersion="1.0.25" ?>
|
||||||
<?define Manufacturer="DW"?>
|
<?define Manufacturer="DW"?>
|
||||||
<?define ProductPath="..\build\products\$(var.Configuration)\"?>
|
<?define ProductPath="..\build\products\$(var.Configuration)\"?>
|
||||||
|
|
||||||
|
|||||||
Generated
+13
@@ -128,6 +128,7 @@
|
|||||||
this.textBoxOppositeTicket = new System.Windows.Forms.TextBox();
|
this.textBoxOppositeTicket = new System.Windows.Forms.TextBox();
|
||||||
this.label3 = new System.Windows.Forms.Label();
|
this.label3 = new System.Windows.Forms.Label();
|
||||||
this.button21 = new System.Windows.Forms.Button();
|
this.button21 = new System.Windows.Forms.Button();
|
||||||
|
this.button22 = new System.Windows.Forms.Button();
|
||||||
this.groupBox1.SuspendLayout();
|
this.groupBox1.SuspendLayout();
|
||||||
this.statusStrip1.SuspendLayout();
|
this.statusStrip1.SuspendLayout();
|
||||||
this.groupBox2.SuspendLayout();
|
this.groupBox2.SuspendLayout();
|
||||||
@@ -308,6 +309,7 @@
|
|||||||
//
|
//
|
||||||
// tabPage2
|
// tabPage2
|
||||||
//
|
//
|
||||||
|
this.tabPage2.Controls.Add(this.button22);
|
||||||
this.tabPage2.Controls.Add(this.button21);
|
this.tabPage2.Controls.Add(this.button21);
|
||||||
this.tabPage2.Controls.Add(this.label3);
|
this.tabPage2.Controls.Add(this.label3);
|
||||||
this.tabPage2.Controls.Add(this.textBoxOppositeTicket);
|
this.tabPage2.Controls.Add(this.textBoxOppositeTicket);
|
||||||
@@ -1228,6 +1230,16 @@
|
|||||||
this.button21.UseVisualStyleBackColor = true;
|
this.button21.UseVisualStyleBackColor = true;
|
||||||
this.button21.Click += new System.EventHandler(this.button21_Click);
|
this.button21.Click += new System.EventHandler(this.button21_Click);
|
||||||
//
|
//
|
||||||
|
// button22
|
||||||
|
//
|
||||||
|
this.button22.Location = new System.Drawing.Point(216, 293);
|
||||||
|
this.button22.Name = "button22";
|
||||||
|
this.button22.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.button22.TabIndex = 19;
|
||||||
|
this.button22.Text = "OrderModify";
|
||||||
|
this.button22.UseVisualStyleBackColor = true;
|
||||||
|
this.button22.Click += new System.EventHandler(this.button22_Click);
|
||||||
|
//
|
||||||
// Form1
|
// Form1
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
@@ -1368,6 +1380,7 @@
|
|||||||
private System.Windows.Forms.TextBox textBoxOppositeTicket;
|
private System.Windows.Forms.TextBox textBoxOppositeTicket;
|
||||||
private System.Windows.Forms.Button button15;
|
private System.Windows.Forms.Button button15;
|
||||||
private System.Windows.Forms.Button button21;
|
private System.Windows.Forms.Button button21;
|
||||||
|
private System.Windows.Forms.Button button22;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,10 @@ namespace TestApiClientUI
|
|||||||
|
|
||||||
private void RunOnUiThread(Action action)
|
private void RunOnUiThread(Action action)
|
||||||
{
|
{
|
||||||
this.BeginInvoke(action);
|
if (!IsDisposed)
|
||||||
|
{
|
||||||
|
this.BeginInvoke(action);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void apiClient_ConnectionStateChanged(object sender, MtConnectionEventArgs e)
|
private void apiClient_ConnectionStateChanged(object sender, MtConnectionEventArgs e)
|
||||||
@@ -875,8 +878,8 @@ namespace TestApiClientUI
|
|||||||
{
|
{
|
||||||
var result =
|
var result =
|
||||||
string.Format(
|
string.Format(
|
||||||
"Order: Ticket = {0}, Symbol = {1}, Operation = {2}, OpenPrice = {3}, ClosePrice = {4}, Lots = {5}, Profit = {6}, Comment = {7}, Commission = {8}, MagicNumber = {9}, OpenTime = {10}, CloseTime = {11}, Swap = {12}",
|
"Order: Ticket = {0}, Symbol = {1}, Operation = {2}, OpenPrice = {3}, ClosePrice = {4}, Lots = {5}, Profit = {6}, Comment = {7}, Commission = {8}, MagicNumber = {9}, OpenTime = {10}, CloseTime = {11}, Swap = {12}, Expiration = {13}",
|
||||||
order.Ticket, order.Symbol, order.Operation, order.OpenPrice, order.ClosePrice, order.Lots, order.Profit, order.Comment, order.Commission, order.MagicNumber, order.OpenTime, order.CloseTime, order.Swap);
|
order.Ticket, order.Symbol, order.Operation, order.OpenPrice, order.ClosePrice, order.Lots, order.Profit, order.Comment, order.Commission, order.MagicNumber, order.OpenTime, order.CloseTime, order.Swap, order.Expiration);
|
||||||
AddToLog(result);
|
AddToLog(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -895,8 +898,8 @@ namespace TestApiClientUI
|
|||||||
{
|
{
|
||||||
var result =
|
var result =
|
||||||
string.Format(
|
string.Format(
|
||||||
"Order: Ticket = {0}, Symbol = {1}, Operation = {2}, OpenPrice = {3}, ClosePrice = {4}, Lots = {5}, Profit = {6}, Comment = {7}, Commission = {8}, MagicNumber = {9}, OpenTime = {10}, CloseTime = {11}, Swap = {12}",
|
"Order: Ticket = {0}, Symbol = {1}, Operation = {2}, OpenPrice = {3}, ClosePrice = {4}, Lots = {5}, Profit = {6}, Comment = {7}, Commission = {8}, MagicNumber = {9}, OpenTime = {10}, CloseTime = {11}, Swap = {12}, Expiration = {13}",
|
||||||
order.Ticket, order.Symbol, order.Operation, order.OpenPrice, order.ClosePrice, order.Lots, order.Profit, order.Comment, order.Commission, order.MagicNumber, order.OpenTime, order.CloseTime, order.Swap);
|
order.Ticket, order.Symbol, order.Operation, order.OpenPrice, order.ClosePrice, order.Lots, order.Profit, order.Comment, order.Commission, order.MagicNumber, order.OpenTime, order.CloseTime, order.Swap, order.Expiration);
|
||||||
AddToLog(result);
|
AddToLog(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -979,5 +982,25 @@ namespace TestApiClientUI
|
|||||||
|
|
||||||
AddToLog(string.Format("Delete order result: {0}, ticket = {1}", deleted, ticket));
|
AddToLog(string.Format("Delete order result: {0}, ticket = {1}", deleted, ticket));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void button22_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var ticket = int.Parse(textBoxIndexTicket.Text);
|
||||||
|
|
||||||
|
double price;
|
||||||
|
double.TryParse(textBoxOrderPrice.Text, out price);
|
||||||
|
|
||||||
|
double stoploss;
|
||||||
|
double.TryParse(textBoxOrderStoploss.Text, out stoploss);
|
||||||
|
|
||||||
|
double takeprofit;
|
||||||
|
double.TryParse(textBoxOrderProffit.Text, out takeprofit);
|
||||||
|
|
||||||
|
var expiration = DateTime.MinValue;
|
||||||
|
|
||||||
|
var modified = await Execute(() => _apiClient.OrderModify(ticket, price, stoploss, takeprofit, expiration));
|
||||||
|
|
||||||
|
AddToLog(string.Format("Modify order result: {0}, ticket = {1}", modified, ticket));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
+33
-1
@@ -3422,9 +3422,12 @@ string OnRequest(string json)
|
|||||||
case 5: //OrderCloseBy
|
case 5: //OrderCloseBy
|
||||||
response = ExecuteRequestOrderCloseBy(jo);
|
response = ExecuteRequestOrderCloseBy(jo);
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6: //OrderDelete
|
||||||
response = ExecuteRequestOrderDelete(jo);
|
response = ExecuteRequestOrderDelete(jo);
|
||||||
break;
|
break;
|
||||||
|
case 7: //OrderModify
|
||||||
|
response = ExecuteRequestOrderModify(jo);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Print("OnRequest [WARNING]: Unknown request type ", requestType);
|
Print("OnRequest [WARNING]: Unknown request type ", requestType);
|
||||||
response = CreateErrorResponse(-1, "Unknown request type");
|
response = CreateErrorResponse(-1, "Unknown request type");
|
||||||
@@ -3462,6 +3465,7 @@ JSONObject* GetOrderJson(int index, int select, int pool)
|
|||||||
datetime openTime = OrderOpenTime();
|
datetime openTime = OrderOpenTime();
|
||||||
datetime closeTime = OrderCloseTime();
|
datetime closeTime = OrderCloseTime();
|
||||||
double swap = OrderSwap();
|
double swap = OrderSwap();
|
||||||
|
datetime expiration = OrderExpiration();
|
||||||
|
|
||||||
JSONObject *joOrder = new JSONObject();
|
JSONObject *joOrder = new JSONObject();
|
||||||
joOrder.put("Ticket", new JSONNumber(ticket));
|
joOrder.put("Ticket", new JSONNumber(ticket));
|
||||||
@@ -3479,6 +3483,7 @@ JSONObject* GetOrderJson(int index, int select, int pool)
|
|||||||
joOrder.put("MtOpenTime", new JSONNumber(openTime));
|
joOrder.put("MtOpenTime", new JSONNumber(openTime));
|
||||||
joOrder.put("MtCloseTime", new JSONNumber(closeTime));
|
joOrder.put("MtCloseTime", new JSONNumber(closeTime));
|
||||||
joOrder.put("Swap", new JSONNumber(swap));
|
joOrder.put("Swap", new JSONNumber(swap));
|
||||||
|
joOrder.put("MtExpiration", new JSONNumber(expiration));
|
||||||
|
|
||||||
return joOrder;
|
return joOrder;
|
||||||
}
|
}
|
||||||
@@ -3666,3 +3671,30 @@ string ExecuteRequestOrderDelete(JSONObject *jo)
|
|||||||
return CreateErrorResponse(GetLastError(), "OrderDelete failed");
|
return CreateErrorResponse(GetLastError(), "OrderDelete failed");
|
||||||
return CreateSuccessResponse("", NULL);
|
return CreateSuccessResponse("", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string ExecuteRequestOrderModify(JSONObject *jo)
|
||||||
|
{
|
||||||
|
if (jo.getValue("Ticket") == NULL)
|
||||||
|
return CreateErrorResponse(-1, "Undefinded mandatory parameter Ticket");
|
||||||
|
if (jo.getValue("Price") == NULL)
|
||||||
|
return CreateErrorResponse(-1, "Undefinded mandatory parameter Price");
|
||||||
|
if (jo.getValue("Stoploss") == NULL)
|
||||||
|
return CreateErrorResponse(-1, "Undefinded mandatory parameter Stoploss");
|
||||||
|
if (jo.getValue("Takeprofit") == NULL)
|
||||||
|
return CreateErrorResponse(-1, "Undefinded mandatory parameter Takeprofit");
|
||||||
|
if (jo.getValue("Expiration") == NULL)
|
||||||
|
return CreateErrorResponse(-1, "Undefinded mandatory parameter Expiration");
|
||||||
|
|
||||||
|
int ticket = jo.getInt("Ticket");
|
||||||
|
double price = jo.getDouble("Price");
|
||||||
|
double stoploss = jo.getDouble("Stoploss");
|
||||||
|
double takeprofit = jo.getDouble("Takeprofit");
|
||||||
|
int expiration = jo.getInt("Expiration");
|
||||||
|
|
||||||
|
JSONValue *jvArrowColor = jo.getValue("ArrowColor");
|
||||||
|
int arrowcolor = (jvArrowColor != NULL) ? jvArrowColor.getInt() : CLR_NONE;
|
||||||
|
|
||||||
|
if (!OrderModify(ticket, price, stoploss, takeprofit, expiration, arrowcolor))
|
||||||
|
return CreateErrorResponse(GetLastError(), "OrderModify failed");
|
||||||
|
return CreateSuccessResponse("", NULL);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user