mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-15 19:58:10 +00:00
Added Request/Response mechanism into mtapi. Added structure MtOrder. Added functions GetOrder, GetOrders.
This commit is contained in:
@@ -6,6 +6,10 @@ using MTApiService;
|
||||
using System.Drawing;
|
||||
using System.Collections;
|
||||
using System.Net;
|
||||
using System.ServiceModel;
|
||||
using MtApi.Requests;
|
||||
using MtApi.Responses;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MtApi
|
||||
{
|
||||
@@ -345,6 +349,18 @@ namespace MtApi
|
||||
{
|
||||
return sendCommand<bool>(MtCommandType.OrderCloseAll, null);
|
||||
}
|
||||
|
||||
public MtOrder GetOrder(int index, OrderSelectMode select, OrderSelectSource pool)
|
||||
{
|
||||
var response = SendRequest<GetOrderResponse>(new GetOrderRequest { Index = index, Select = (int) select, Pool = (int) pool});
|
||||
return response != null ? response.Order : null;
|
||||
}
|
||||
|
||||
public IEnumerable<MtOrder> GetOrders(OrderSelectSource pool)
|
||||
{
|
||||
var response = SendRequest<GetOrdersResponse>(new GetOrdersRequest { Pool = (int)pool });
|
||||
return response != null ? response.Orders : null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Check Status
|
||||
@@ -1310,6 +1326,38 @@ namespace MtApi
|
||||
return result;
|
||||
}
|
||||
|
||||
private T SendRequest<T>(RequestBase request) where T : ResponseBase, new()
|
||||
{
|
||||
if (request == null)
|
||||
return default(T);
|
||||
|
||||
var serializer = RequestContainer.CreateNew(request).Serialize();
|
||||
var commandParameters = new ArrayList { serializer };
|
||||
|
||||
MtResponseString res;
|
||||
try
|
||||
{
|
||||
res = (MtResponseString)mClient.SendCommand((int)MtCommandType.MtRequest, commandParameters);
|
||||
}
|
||||
catch (CommunicationException ex)
|
||||
{
|
||||
throw new MtConnectionException(ex.Message, ex);
|
||||
}
|
||||
|
||||
if (res == null)
|
||||
{
|
||||
throw new MtExecutionException(-1, "Response from MetaTrader is null");
|
||||
}
|
||||
|
||||
var response = JsonConvert.DeserializeObject<T>(res.Value);
|
||||
if (response.ErrorCode != 0)
|
||||
{
|
||||
throw new MtExecutionException(response.ErrorCode, response.ErrorMessage);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private void mClient_QuoteUpdated(MTApiService.MtQuote quote)
|
||||
{
|
||||
if (quote != null)
|
||||
|
||||
Reference in New Issue
Block a user