mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-15 11:48:09 +00:00
Started version 1.0.25. Added OrderModifyRequest. Changed function OrderModify to use request pattern.
This commit is contained in:
@@ -81,6 +81,7 @@
|
||||
<Compile Include="Requests\OrderCloseByRequest.cs" />
|
||||
<Compile Include="Requests\OrderCloseRequest.cs" />
|
||||
<Compile Include="Requests\OrderDeleteRequest.cs" />
|
||||
<Compile Include="Requests\OrderModifyRequest.cs" />
|
||||
<Compile Include="Requests\OrderSendRequest.cs" />
|
||||
<Compile Include="Requests\RequestBase.cs" />
|
||||
<Compile Include="Requests\RequestType.cs" />
|
||||
|
||||
+74
-46
@@ -28,11 +28,11 @@ namespace MtApi
|
||||
|
||||
public MtApiClient()
|
||||
{
|
||||
mClient.QuoteAdded +=new MtClient.MtQuoteHandler(mClient_QuoteAdded);
|
||||
mClient.QuoteRemoved += new MtClient.MtQuoteHandler(mClient_QuoteRemoved);
|
||||
mClient.QuoteUpdated += new MtClient.MtQuoteHandler(mClient_QuoteUpdated);
|
||||
mClient.ServerDisconnected += new EventHandler(mClient_ServerDisconnected);
|
||||
mClient.ServerFailed += new EventHandler(mClient_ServerFailed);
|
||||
_client.QuoteAdded +=new MtClient.MtQuoteHandler(mClient_QuoteAdded);
|
||||
_client.QuoteRemoved += new MtClient.MtQuoteHandler(mClient_QuoteRemoved);
|
||||
_client.QuoteUpdated += new MtClient.MtQuoteHandler(mClient_QuoteUpdated);
|
||||
_client.ServerDisconnected += new EventHandler(mClient_ServerDisconnected);
|
||||
_client.ServerFailed += new EventHandler(mClient_ServerFailed);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -79,16 +79,26 @@ namespace MtApi
|
||||
///</summary>
|
||||
public IEnumerable<MtQuote> GetQuotes()
|
||||
{
|
||||
var quotes = mClient.GetQuotes();
|
||||
var quotes = _client.GetQuotes();
|
||||
return quotes != null ? (from q in quotes select q.Parse()) : null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
///<summary>
|
||||
///Connection status of MetaTrader API.
|
||||
///</summary>
|
||||
public MtConnectionState ConnectionState { get; private set; }
|
||||
public MtConnectionState ConnectionState
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
return _connectionState;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -411,13 +421,29 @@ namespace MtApi
|
||||
|
||||
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) };
|
||||
return SendCommand<bool>(MtCommandType.OrderModify, commandParameters);
|
||||
var response = SendRequest<ResponseBase>(new OrderModifyRequest
|
||||
{
|
||||
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)
|
||||
{
|
||||
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()
|
||||
@@ -1342,60 +1368,64 @@ namespace MtApi
|
||||
#region Private Methods
|
||||
private void Connect(string host, int port)
|
||||
{
|
||||
ConnectionState = MtConnectionState.Connecting;
|
||||
ConnectionStateChanged.FireEvent(this
|
||||
, new MtConnectionEventArgs(MtConnectionState.Connecting, "Connecting to " + host + ":" + port));
|
||||
UpdateConnectionState(MtConnectionState.Connecting, string.Format("Connecting to {0}:{1}", host, port));
|
||||
|
||||
try
|
||||
{
|
||||
mClient.Open(host, port);
|
||||
mClient.Connect();
|
||||
_client.Open(host, port);
|
||||
_client.Connect();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ConnectionState = MtConnectionState.Failed;
|
||||
ConnectionStateChanged.FireEvent(this
|
||||
, new MtConnectionEventArgs(MtConnectionState.Failed, "Failed connection to " + host + ":" + port + ". " + e.Message));
|
||||
UpdateConnectionState(MtConnectionState.Failed, string.Format("Failed connection to {0}:{1}. {2}", host, port, e.Message));
|
||||
return;
|
||||
}
|
||||
|
||||
ConnectionState = MtConnectionState.Connected;
|
||||
ConnectionStateChanged.FireEvent(this
|
||||
, new MtConnectionEventArgs(MtConnectionState.Connected, "Connected to " + host + ":" + port));
|
||||
UpdateConnectionState(MtConnectionState.Connected, string.Format("Connected to {0}:{1}", host, port));
|
||||
}
|
||||
|
||||
private void Connect(int port)
|
||||
{
|
||||
ConnectionState = MtConnectionState.Connecting;
|
||||
ConnectionStateChanged.FireEvent(this
|
||||
, new MtConnectionEventArgs(MtConnectionState.Connecting, "Connecting to 'localhost':" + port));
|
||||
UpdateConnectionState(MtConnectionState.Connecting, string.Format("Connecting to 'localhost':{0}", port));
|
||||
|
||||
try
|
||||
{
|
||||
mClient.Open(port);
|
||||
mClient.Connect();
|
||||
_client.Open(port);
|
||||
_client.Connect();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ConnectionState = MtConnectionState.Failed;
|
||||
ConnectionStateChanged.FireEvent(this
|
||||
, new MtConnectionEventArgs(MtConnectionState.Failed, "Failed connection to 'localhost':" + port + ". " + e.Message));
|
||||
|
||||
UpdateConnectionState(MtConnectionState.Failed, string.Format("Failed connection to 'localhost':{0}. {1}", port, e.Message));
|
||||
return;
|
||||
}
|
||||
|
||||
ConnectionState = MtConnectionState.Connected;
|
||||
ConnectionStateChanged.FireEvent(this
|
||||
, new MtConnectionEventArgs(MtConnectionState.Connected, "Connected to 'localhost':" + port));
|
||||
UpdateConnectionState(MtConnectionState.Connected, string.Format("Connected to 'localhost':{0}", port));
|
||||
}
|
||||
|
||||
private void Disconnect()
|
||||
{
|
||||
mClient.Disconnect();
|
||||
mClient.Close();
|
||||
_client.Disconnect();
|
||||
_client.Close();
|
||||
|
||||
ConnectionState = MtConnectionState.Disconnected;
|
||||
ConnectionStateChanged.FireEvent(this, new MtConnectionEventArgs(MtConnectionState.Disconnected, "Disconnected"));
|
||||
UpdateConnectionState(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)
|
||||
@@ -1403,7 +1433,7 @@ namespace MtApi
|
||||
MtResponse response;
|
||||
try
|
||||
{
|
||||
response = mClient.SendCommand((int)commandType, commandParameters);
|
||||
response = _client.SendCommand((int)commandType, commandParameters);
|
||||
}
|
||||
catch (CommunicationException ex)
|
||||
{
|
||||
@@ -1451,7 +1481,7 @@ namespace MtApi
|
||||
MtResponseString res;
|
||||
try
|
||||
{
|
||||
res = (MtResponseString)mClient.SendCommand((int)MtCommandType.MtRequest, commandParameters);
|
||||
res = (MtResponseString)_client.SendCommand((int)MtCommandType.MtRequest, commandParameters);
|
||||
}
|
||||
catch (CommunicationException ex)
|
||||
{
|
||||
@@ -1482,16 +1512,12 @@ namespace MtApi
|
||||
|
||||
private void mClient_ServerDisconnected(object sender, EventArgs e)
|
||||
{
|
||||
ConnectionState = MtConnectionState.Disconnected;
|
||||
ConnectionStateChanged.FireEvent(this
|
||||
, new MtConnectionEventArgs(MtConnectionState.Disconnected, "MtApi is disconnected"));
|
||||
UpdateConnectionState(MtConnectionState.Disconnected, "MtApi is disconnected");
|
||||
}
|
||||
|
||||
private void mClient_ServerFailed(object sender, EventArgs e)
|
||||
{
|
||||
ConnectionState = MtConnectionState.Failed;
|
||||
ConnectionStateChanged.FireEvent(this
|
||||
, new MtConnectionEventArgs(MtConnectionState.Failed, "Failed connection with MtApi"));
|
||||
UpdateConnectionState(MtConnectionState.Failed, "Failed connection with MtApi");
|
||||
}
|
||||
|
||||
private void mClient_QuoteRemoved(MTApiService.MtQuote quote)
|
||||
@@ -1513,7 +1539,9 @@ namespace MtApi
|
||||
#endregion
|
||||
|
||||
#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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace MtApi
|
||||
public double Commission { get; set; }
|
||||
public int MagicNumber { get; set; }
|
||||
public double Swap { get; set; }
|
||||
public int MtExpiration { get; set; }
|
||||
|
||||
public DateTime OpenTime
|
||||
{
|
||||
@@ -27,5 +28,10 @@ namespace MtApi
|
||||
{
|
||||
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
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.24.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.24.0")]
|
||||
[assembly: AssemblyVersion("1.0.25.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,
|
||||
OrderClose = 4,
|
||||
OrderCloseBy = 5,
|
||||
OrderDelete = 6
|
||||
OrderDelete = 6,
|
||||
OrderModify = 7
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user