mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-18 21:28:10 +00:00
Implemented function PositionOpen. Made small refactoring
This commit is contained in:
+33
-19
@@ -30,11 +30,11 @@ namespace MtApi5
|
|||||||
{
|
{
|
||||||
ConnectionState = Mt5ConnectionState.Disconnected;
|
ConnectionState = Mt5ConnectionState.Disconnected;
|
||||||
|
|
||||||
mClient.QuoteAdded += new MtClient.MtQuoteHandler(mClient_QuoteAdded);
|
_client.QuoteAdded += mClient_QuoteAdded;
|
||||||
mClient.QuoteRemoved += new MtClient.MtQuoteHandler(mClient_QuoteRemoved);
|
_client.QuoteRemoved += mClient_QuoteRemoved;
|
||||||
mClient.QuoteUpdated += new MtClient.MtQuoteHandler(mClient_QuoteUpdated);
|
_client.QuoteUpdated += mClient_QuoteUpdated;
|
||||||
mClient.ServerDisconnected += new EventHandler(mClient_ServerDisconnected);
|
_client.ServerDisconnected += mClient_ServerDisconnected;
|
||||||
mClient.ServerFailed += new EventHandler(mClient_ServerFailed);
|
_client.ServerFailed += mClient_ServerFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
@@ -79,7 +79,7 @@ namespace MtApi5
|
|||||||
///</summary>
|
///</summary>
|
||||||
public IEnumerable<Mt5Quote> GetQuotes()
|
public IEnumerable<Mt5Quote> 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -470,7 +470,6 @@ namespace MtApi5
|
|||||||
///<summary>
|
///<summary>
|
||||||
///Close all open positions.
|
///Close all open positions.
|
||||||
///</summary>
|
///</summary>
|
||||||
///<param name="ticket">OrderCloseAll</param>
|
|
||||||
public bool OrderCloseAll()
|
public bool OrderCloseAll()
|
||||||
{
|
{
|
||||||
return sendCommand<bool>(Mt5CommandType.OrderCloseAll, null);
|
return sendCommand<bool>(Mt5CommandType.OrderCloseAll, null);
|
||||||
@@ -486,6 +485,24 @@ namespace MtApi5
|
|||||||
|
|
||||||
return sendCommand<bool>(Mt5CommandType.PositionClose, commandParameters);
|
return sendCommand<bool>(Mt5CommandType.PositionClose, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens a position with the specified parameters.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="symbol">symbol</param>
|
||||||
|
/// <param name="orderType">order type to open position </param>
|
||||||
|
/// <param name="volume">position volume</param>
|
||||||
|
/// <param name="price">execution price</param>
|
||||||
|
/// <param name="sl">Stop Loss price</param>
|
||||||
|
/// <param name="tp">Take Profit price</param>
|
||||||
|
/// <param name="comment">comment</param>
|
||||||
|
/// <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 = "")
|
||||||
|
{
|
||||||
|
var commandParameters = new ArrayList { symbol, (int) orderType, volume, price, sl, tp, comment };
|
||||||
|
|
||||||
|
return sendCommand<bool>(Mt5CommandType.PositionOpen, commandParameters);
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Account Information functions
|
#region Account Information functions
|
||||||
@@ -1384,8 +1401,8 @@ namespace MtApi5
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mClient.Open(host, port);
|
_client.Open(host, port);
|
||||||
mClient.Connect();
|
_client.Connect();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -1408,8 +1425,8 @@ namespace MtApi5
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mClient.Open(port);
|
_client.Open(port);
|
||||||
mClient.Connect();
|
_client.Connect();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -1427,8 +1444,8 @@ namespace MtApi5
|
|||||||
|
|
||||||
private void Disconnect()
|
private void Disconnect()
|
||||||
{
|
{
|
||||||
mClient.Disconnect();
|
_client.Disconnect();
|
||||||
mClient.Close();
|
_client.Close();
|
||||||
|
|
||||||
ConnectionState = Mt5ConnectionState.Disconnected;
|
ConnectionState = Mt5ConnectionState.Disconnected;
|
||||||
ConnectionStateChanged.FireEvent(this, new Mt5ConnectionEventArgs(Mt5ConnectionState.Disconnected, "Disconnected"));
|
ConnectionStateChanged.FireEvent(this, new Mt5ConnectionEventArgs(Mt5ConnectionState.Disconnected, "Disconnected"));
|
||||||
@@ -1436,7 +1453,7 @@ namespace MtApi5
|
|||||||
|
|
||||||
private T sendCommand<T>(Mt5CommandType commandType, ArrayList commandParameters)
|
private T sendCommand<T>(Mt5CommandType commandType, ArrayList commandParameters)
|
||||||
{
|
{
|
||||||
var response = mClient.SendCommand((int)commandType, commandParameters);
|
var response = _client.SendCommand((int)commandType, commandParameters);
|
||||||
|
|
||||||
if (response is MtResponseDouble)
|
if (response is MtResponseDouble)
|
||||||
return (T)Convert.ChangeType(((MtResponseDouble)response).Value, typeof(T));
|
return (T)Convert.ChangeType(((MtResponseDouble)response).Value, typeof(T));
|
||||||
@@ -1484,10 +1501,7 @@ namespace MtApi5
|
|||||||
{
|
{
|
||||||
if (quote != null)
|
if (quote != null)
|
||||||
{
|
{
|
||||||
if (QuoteUpdated != null)
|
QuoteUpdated?.Invoke(this, quote.Instrument, quote.Bid, quote.Ask);
|
||||||
{
|
|
||||||
QuoteUpdated(this, quote.Instrument, quote.Bid, quote.Ask);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1518,7 +1532,7 @@ namespace MtApi5
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Fields
|
#region Private Fields
|
||||||
private readonly MtClient mClient = new MtClient();
|
private readonly MtClient _client = new MtClient();
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,6 +101,9 @@ namespace MtApi5
|
|||||||
MarketBookRelease = 61,
|
MarketBookRelease = 61,
|
||||||
MarketBookGet = 62,
|
MarketBookGet = 62,
|
||||||
OrderCloseAll = 63,
|
OrderCloseAll = 63,
|
||||||
PositionClose = 64
|
|
||||||
|
//CTrade
|
||||||
|
PositionClose = 64,
|
||||||
|
PositionOpen = 65
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Regular → Executable
+7
-1
@@ -355,7 +355,7 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
||||||
<TabItem Header=" Market Info">
|
<TabItem Header="Market Info">
|
||||||
<WrapPanel VerticalAlignment="Top" Margin="5">
|
<WrapPanel VerticalAlignment="Top" Margin="5">
|
||||||
<Button Command="{Binding SymbolsTotalCommand}" Content="SymbolsTotal" Margin="2"/>
|
<Button Command="{Binding SymbolsTotalCommand}" Content="SymbolsTotal" Margin="2"/>
|
||||||
<Button Command="{Binding SymbolNameCommand}" Content="SymbolName" Margin="2"/>
|
<Button Command="{Binding SymbolNameCommand}" Content="SymbolName" Margin="2"/>
|
||||||
@@ -372,6 +372,12 @@
|
|||||||
<Button Command="{Binding MarketBookGetCommand}" Content="MarketBookGet" Margin="2"/>
|
<Button Command="{Binding MarketBookGetCommand}" Content="MarketBookGet" Margin="2"/>
|
||||||
</WrapPanel>
|
</WrapPanel>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
||||||
|
<TabItem Header="CTrade">
|
||||||
|
<WrapPanel VerticalAlignment="Top" Margin="5">
|
||||||
|
<Button Command="{Binding PositionOpenCommand}" Content="PositionOpen" Margin="2"/>
|
||||||
|
</WrapPanel>
|
||||||
|
</TabItem>
|
||||||
</TabControl>
|
</TabControl>
|
||||||
|
|
||||||
<Expander Grid.Row="2" Header="History" IsExpanded="True">
|
<Expander Grid.Row="2" Header="History" IsExpanded="True">
|
||||||
|
|||||||
Regular → Executable
+117
-124
@@ -1,12 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using MtApi5;
|
using MtApi5;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
namespace MtApi5TestClient
|
namespace MtApi5TestClient
|
||||||
{
|
{
|
||||||
@@ -46,90 +44,80 @@ namespace MtApi5TestClient
|
|||||||
public DelegateCommand MarketBookAddCommand { get; private set; }
|
public DelegateCommand MarketBookAddCommand { get; private set; }
|
||||||
public DelegateCommand MarketBookReleaseCommand { get; private set; }
|
public DelegateCommand MarketBookReleaseCommand { get; private set; }
|
||||||
public DelegateCommand MarketBookGetCommand { get; private set; }
|
public DelegateCommand MarketBookGetCommand { get; private set; }
|
||||||
|
|
||||||
|
public DelegateCommand PositionOpenCommand { get; private set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
private Mt5ConnectionState _ConnectionState;
|
private Mt5ConnectionState _connectionState;
|
||||||
public Mt5ConnectionState ConnectionState
|
public Mt5ConnectionState ConnectionState
|
||||||
{
|
{
|
||||||
get { return _ConnectionState; }
|
get { return _connectionState; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_ConnectionState = value;
|
_connectionState = value;
|
||||||
OnPropertyChanged("ConnectionState");
|
OnPropertyChanged("ConnectionState");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string _ConnectionMessage;
|
private string _connectionMessage;
|
||||||
public string ConnectionMessage
|
public string ConnectionMessage
|
||||||
{
|
{
|
||||||
get { return _ConnectionMessage; }
|
get { return _connectionMessage; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_ConnectionMessage = value;
|
_connectionMessage = value;
|
||||||
OnPropertyChanged("ConnectionMessage");
|
OnPropertyChanged("ConnectionMessage");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string _Host;
|
private string _host;
|
||||||
public string Host
|
public string Host
|
||||||
{
|
{
|
||||||
get { return _Host; }
|
get { return _host; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_Host = value;
|
_host = value;
|
||||||
OnPropertyChanged("Host");
|
OnPropertyChanged("Host");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int _Port;
|
private int _port;
|
||||||
public int Port
|
public int Port
|
||||||
{
|
{
|
||||||
get { return _Port; }
|
get { return _port; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_Port = value;
|
_port = value;
|
||||||
OnPropertyChanged("Port");
|
OnPropertyChanged("Port");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ObservableCollection<QuoteViewModel> _Quotes = new ObservableCollection<QuoteViewModel>();
|
public ObservableCollection<QuoteViewModel> Quotes { get; } = new ObservableCollection<QuoteViewModel>();
|
||||||
public ObservableCollection<QuoteViewModel> Quotes
|
|
||||||
{
|
|
||||||
get { return _Quotes; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private QuoteViewModel _SelectedQuote;
|
private QuoteViewModel _selectedQuote;
|
||||||
public QuoteViewModel SelectedQuote
|
public QuoteViewModel SelectedQuote
|
||||||
{
|
{
|
||||||
get { return _SelectedQuote; }
|
get { return _selectedQuote; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_SelectedQuote = value;
|
_selectedQuote = value;
|
||||||
OnPropertyChanged("SelectedQuote");
|
OnPropertyChanged("SelectedQuote");
|
||||||
OnSelectedQuoteChanged();
|
OnSelectedQuoteChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ObservableCollection<string> _History = new ObservableCollection<string>();
|
public ObservableCollection<string> History { get; } = new ObservableCollection<string>();
|
||||||
public ObservableCollection<string> History
|
|
||||||
{
|
|
||||||
get { return _History; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private ObservableCollection<MqlTradeRequestViewModel> _TradeRequests = new ObservableCollection<MqlTradeRequestViewModel>();
|
public ObservableCollection<MqlTradeRequestViewModel> TradeRequests { get; } = new ObservableCollection<MqlTradeRequestViewModel>();
|
||||||
public ObservableCollection<MqlTradeRequestViewModel> TradeRequests
|
|
||||||
{
|
|
||||||
get { return _TradeRequests; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private MqlTradeRequestViewModel _TradeRequest;
|
private MqlTradeRequestViewModel _tradeRequest;
|
||||||
public MqlTradeRequestViewModel TradeRequest
|
public MqlTradeRequestViewModel TradeRequest
|
||||||
{
|
{
|
||||||
get { return _TradeRequest; }
|
get { return _tradeRequest; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_TradeRequest = value;
|
_tradeRequest = value;
|
||||||
OnPropertyChanged("TradeRequest");
|
OnPropertyChanged("TradeRequest");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,27 +128,24 @@ namespace MtApi5TestClient
|
|||||||
|
|
||||||
public TimeSeriesValueViewModel TimeSeriesValues { get; set; }
|
public TimeSeriesValueViewModel TimeSeriesValues { get; set; }
|
||||||
|
|
||||||
private ObservableCollection<string> _TimeSeriesResults = new ObservableCollection<string>();
|
public ObservableCollection<string> TimeSeriesResults { get; } = new ObservableCollection<string>();
|
||||||
public ObservableCollection<string> TimeSeriesResults
|
|
||||||
{
|
|
||||||
get { return _TimeSeriesResults; }
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public Methods
|
#region Public Methods
|
||||||
public ViewModel()
|
public ViewModel()
|
||||||
{
|
{
|
||||||
// Init MtApi client
|
// Init MtApi client
|
||||||
mMtApiClient = new MtApi5Client();
|
_mtApiClient = new MtApi5Client();
|
||||||
|
|
||||||
mMtApiClient.ConnectionStateChanged += new EventHandler<Mt5ConnectionEventArgs>(mMtApiClient_ConnectionStateChanged);
|
_mtApiClient.ConnectionStateChanged += mMtApiClient_ConnectionStateChanged;
|
||||||
mMtApiClient.QuoteAdded += new EventHandler<Mt5QuoteEventArgs>(mMtApiClient_QuoteAdded);
|
_mtApiClient.QuoteAdded += mMtApiClient_QuoteAdded;
|
||||||
mMtApiClient.QuoteRemoved += new EventHandler<Mt5QuoteEventArgs>(mMtApiClient_QuoteRemoved);
|
_mtApiClient.QuoteRemoved += mMtApiClient_QuoteRemoved;
|
||||||
mMtApiClient.QuoteUpdated += new MtApi5Client.QuoteHandler(mMtApiClient_QuoteUpdated);
|
_mtApiClient.QuoteUpdated += mMtApiClient_QuoteUpdated;
|
||||||
|
|
||||||
_quotesMap = new Dictionary<string, QuoteViewModel>();
|
_quotesMap = new Dictionary<string, QuoteViewModel>();
|
||||||
|
|
||||||
ConnectionState = mMtApiClient.ConnectionState;
|
ConnectionState = _mtApiClient.ConnectionState;
|
||||||
ConnectionMessage = "Disconnected";
|
ConnectionMessage = "Disconnected";
|
||||||
Port = 8228; //default local port
|
Port = 8228; //default local port
|
||||||
|
|
||||||
@@ -174,13 +159,12 @@ namespace MtApi5TestClient
|
|||||||
|
|
||||||
TradeRequest = new MqlTradeRequestViewModel(request);
|
TradeRequest = new MqlTradeRequestViewModel(request);
|
||||||
|
|
||||||
TimeSeriesValues = new TimeSeriesValueViewModel();
|
TimeSeriesValues = new TimeSeriesValueViewModel { Count = 100 };
|
||||||
TimeSeriesValues.Count = 100;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Close()
|
public void Close()
|
||||||
{
|
{
|
||||||
mMtApiClient.BeginDisconnect();
|
_mtApiClient.BeginDisconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -223,6 +207,8 @@ namespace MtApi5TestClient
|
|||||||
MarketBookAddCommand = new DelegateCommand(ExecuteMarketBookAdd);
|
MarketBookAddCommand = new DelegateCommand(ExecuteMarketBookAdd);
|
||||||
MarketBookReleaseCommand = new DelegateCommand(ExecuteMarketBookRelease);
|
MarketBookReleaseCommand = new DelegateCommand(ExecuteMarketBookRelease);
|
||||||
MarketBookGetCommand = new DelegateCommand(ExecuteMarketBookGet);
|
MarketBookGetCommand = new DelegateCommand(ExecuteMarketBookGet);
|
||||||
|
|
||||||
|
PositionOpenCommand = new DelegateCommand(ExecutePositionOpen);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CanExecuteConnect(object o)
|
private bool CanExecuteConnect(object o)
|
||||||
@@ -234,11 +220,11 @@ namespace MtApi5TestClient
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(Host))
|
if (string.IsNullOrEmpty(Host))
|
||||||
{
|
{
|
||||||
mMtApiClient.BeginConnect(Port);
|
_mtApiClient.BeginConnect(Port);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mMtApiClient.BeginConnect(Host, Port);
|
_mtApiClient.BeginConnect(Host, Port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,7 +235,7 @@ namespace MtApi5TestClient
|
|||||||
|
|
||||||
private void ExecuteDisconnect(object o)
|
private void ExecuteDisconnect(object o)
|
||||||
{
|
{
|
||||||
mMtApiClient.BeginDisconnect();
|
_mtApiClient.BeginDisconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ExecuteOrderSend(object o)
|
private void ExecuteOrderSend(object o)
|
||||||
@@ -257,11 +243,11 @@ namespace MtApi5TestClient
|
|||||||
var request = TradeRequest.GetMqlTradeRequest();
|
var request = TradeRequest.GetMqlTradeRequest();
|
||||||
|
|
||||||
MqlTradeResult result;
|
MqlTradeResult result;
|
||||||
bool retVal = mMtApiClient.OrderSend(request, out result);
|
var retVal = _mtApiClient.OrderSend(request, out result);
|
||||||
|
|
||||||
string historyItem;
|
string historyItem;
|
||||||
|
|
||||||
if (retVal == true)
|
if (retVal)
|
||||||
{
|
{
|
||||||
historyItem = "OrderSend successed. " + MqlTradeResultToString(result);
|
historyItem = "OrderSend successed. " + MqlTradeResultToString(result);
|
||||||
}
|
}
|
||||||
@@ -275,25 +261,25 @@ namespace MtApi5TestClient
|
|||||||
|
|
||||||
private void ExecuteAccountInfoDouble(object o)
|
private void ExecuteAccountInfoDouble(object o)
|
||||||
{
|
{
|
||||||
var result = mMtApiClient.AccountInfoDouble(AccountInfoDoublePropertyId);
|
var result = _mtApiClient.AccountInfoDouble(AccountInfoDoublePropertyId);
|
||||||
|
|
||||||
var historyItem = string.Format("AccountInfoDouble: property_id = {0}; result = {1}", AccountInfoDoublePropertyId, result);
|
var historyItem = $"AccountInfoDouble: property_id = {AccountInfoDoublePropertyId}; result = {result}";
|
||||||
History.Add(historyItem);
|
History.Add(historyItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ExecuteAccountInfoInteger(object o)
|
private void ExecuteAccountInfoInteger(object o)
|
||||||
{
|
{
|
||||||
var result = mMtApiClient.AccountInfoInteger(AccountInfoIntegerPropertyId);
|
var result = _mtApiClient.AccountInfoInteger(AccountInfoIntegerPropertyId);
|
||||||
|
|
||||||
var historyItem = string.Format("AccountInfoInteger: property_id = {0}; result = {1}", AccountInfoDoublePropertyId, result);
|
var historyItem = $"AccountInfoInteger: property_id = {AccountInfoDoublePropertyId}; result = {result}";
|
||||||
History.Add(historyItem);
|
History.Add(historyItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ExecuteAccountInfoString(object o)
|
private void ExecuteAccountInfoString(object o)
|
||||||
{
|
{
|
||||||
var result = mMtApiClient.AccountInfoString(AccountInfoStringPropertyId);
|
var result = _mtApiClient.AccountInfoString(AccountInfoStringPropertyId);
|
||||||
|
|
||||||
var historyItem = string.Format("AccountInfoString: property_id = {0}; result = {1}", AccountInfoDoublePropertyId, result);
|
var historyItem = $"AccountInfoString: property_id = {AccountInfoDoublePropertyId}; result = {result}";
|
||||||
History.Add(historyItem);
|
History.Add(historyItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,12 +290,12 @@ namespace MtApi5TestClient
|
|||||||
TimeSeriesResults.Clear();
|
TimeSeriesResults.Clear();
|
||||||
|
|
||||||
DateTime[] timesArray;
|
DateTime[] timesArray;
|
||||||
var count = mMtApiClient.CopyTime(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, TimeSeriesValues.StartPos, TimeSeriesValues.Count, out timesArray);
|
var count = _mtApiClient.CopyTime(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, TimeSeriesValues.StartPos, TimeSeriesValues.Count, out timesArray);
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
foreach (var time in timesArray)
|
foreach (var time in timesArray)
|
||||||
{
|
{
|
||||||
TimeSeriesResults.Add(time.ToString());
|
TimeSeriesResults.Add(time.ToString(CultureInfo.CurrentCulture));
|
||||||
}
|
}
|
||||||
|
|
||||||
History.Add("CopyTime success");
|
History.Add("CopyTime success");
|
||||||
@@ -324,12 +310,12 @@ namespace MtApi5TestClient
|
|||||||
TimeSeriesResults.Clear();
|
TimeSeriesResults.Clear();
|
||||||
|
|
||||||
double[] opensArray;
|
double[] opensArray;
|
||||||
var count = mMtApiClient.CopyOpen(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, TimeSeriesValues.StartPos, TimeSeriesValues.Count, out opensArray);
|
var count = _mtApiClient.CopyOpen(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, TimeSeriesValues.StartPos, TimeSeriesValues.Count, out opensArray);
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
foreach (var open in opensArray)
|
foreach (var open in opensArray)
|
||||||
{
|
{
|
||||||
TimeSeriesResults.Add(open.ToString());
|
TimeSeriesResults.Add(open.ToString(CultureInfo.CurrentCulture));
|
||||||
}
|
}
|
||||||
|
|
||||||
History.Add("CopyOpen success");
|
History.Add("CopyOpen success");
|
||||||
@@ -344,12 +330,12 @@ namespace MtApi5TestClient
|
|||||||
TimeSeriesResults.Clear();
|
TimeSeriesResults.Clear();
|
||||||
|
|
||||||
double[] array;
|
double[] array;
|
||||||
var count = mMtApiClient.CopyHigh(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, TimeSeriesValues.StartPos, TimeSeriesValues.Count, out array);
|
var count = _mtApiClient.CopyHigh(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, TimeSeriesValues.StartPos, TimeSeriesValues.Count, out array);
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
foreach (var value in array)
|
foreach (var value in array)
|
||||||
{
|
{
|
||||||
TimeSeriesResults.Add(value.ToString());
|
TimeSeriesResults.Add(value.ToString(CultureInfo.CurrentCulture));
|
||||||
}
|
}
|
||||||
|
|
||||||
History.Add("CopyHigh success");
|
History.Add("CopyHigh success");
|
||||||
@@ -364,12 +350,12 @@ namespace MtApi5TestClient
|
|||||||
TimeSeriesResults.Clear();
|
TimeSeriesResults.Clear();
|
||||||
|
|
||||||
double[] array;
|
double[] array;
|
||||||
var count = mMtApiClient.CopyLow(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, TimeSeriesValues.StartPos, TimeSeriesValues.Count, out array);
|
var count = _mtApiClient.CopyLow(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, TimeSeriesValues.StartPos, TimeSeriesValues.Count, out array);
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
foreach (var value in array)
|
foreach (var value in array)
|
||||||
{
|
{
|
||||||
TimeSeriesResults.Add(value.ToString());
|
TimeSeriesResults.Add(value.ToString(CultureInfo.CurrentCulture));
|
||||||
}
|
}
|
||||||
|
|
||||||
History.Add("CopyLow success");
|
History.Add("CopyLow success");
|
||||||
@@ -384,12 +370,12 @@ namespace MtApi5TestClient
|
|||||||
TimeSeriesResults.Clear();
|
TimeSeriesResults.Clear();
|
||||||
|
|
||||||
double[] array;
|
double[] array;
|
||||||
var count = mMtApiClient.CopyClose(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, TimeSeriesValues.StartPos, TimeSeriesValues.Count, out array);
|
var count = _mtApiClient.CopyClose(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, TimeSeriesValues.StartPos, TimeSeriesValues.Count, out array);
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
foreach (var value in array)
|
foreach (var value in array)
|
||||||
{
|
{
|
||||||
TimeSeriesResults.Add(value.ToString());
|
TimeSeriesResults.Add(value.ToString(CultureInfo.CurrentCulture));
|
||||||
}
|
}
|
||||||
|
|
||||||
History.Add("CopyClose success");
|
History.Add("CopyClose success");
|
||||||
@@ -404,13 +390,13 @@ namespace MtApi5TestClient
|
|||||||
TimeSeriesResults.Clear();
|
TimeSeriesResults.Clear();
|
||||||
|
|
||||||
MqlRates[] ratesArray;
|
MqlRates[] ratesArray;
|
||||||
var count = mMtApiClient.CopyRates(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, TimeSeriesValues.StartPos, TimeSeriesValues.Count, out ratesArray);
|
var count = _mtApiClient.CopyRates(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, TimeSeriesValues.StartPos, TimeSeriesValues.Count, out ratesArray);
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
foreach (var rates in ratesArray)
|
foreach (var rates in ratesArray)
|
||||||
{
|
{
|
||||||
TimeSeriesResults.Add(string.Format("time={0}; open={1}; high={2}; low={3}; close={4}; tick_volume={5}; spread={6}; real_volume={7}",
|
TimeSeriesResults.Add(
|
||||||
rates.time, rates.open, rates.high, rates.low, rates.close, rates.tick_volume, rates.spread, rates.tick_volume));
|
$"time={rates.time}; open={rates.open}; high={rates.high}; low={rates.low}; close={rates.close}; tick_volume={rates.tick_volume}; spread={rates.spread}; real_volume={rates.tick_volume}");
|
||||||
}
|
}
|
||||||
|
|
||||||
History.Add("CopyRates success");
|
History.Add("CopyRates success");
|
||||||
@@ -425,7 +411,7 @@ namespace MtApi5TestClient
|
|||||||
TimeSeriesResults.Clear();
|
TimeSeriesResults.Clear();
|
||||||
|
|
||||||
long[] array;
|
long[] array;
|
||||||
var count = mMtApiClient.CopyTickVolume(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, TimeSeriesValues.StartPos, TimeSeriesValues.Count, out array);
|
var count = _mtApiClient.CopyTickVolume(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, TimeSeriesValues.StartPos, TimeSeriesValues.Count, out array);
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
foreach (var value in array)
|
foreach (var value in array)
|
||||||
@@ -445,7 +431,7 @@ namespace MtApi5TestClient
|
|||||||
TimeSeriesResults.Clear();
|
TimeSeriesResults.Clear();
|
||||||
|
|
||||||
long[] array;
|
long[] array;
|
||||||
var count = mMtApiClient.CopyRealVolume(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, TimeSeriesValues.StartPos, TimeSeriesValues.Count, out array);
|
var count = _mtApiClient.CopyRealVolume(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, TimeSeriesValues.StartPos, TimeSeriesValues.Count, out array);
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
foreach (var value in array)
|
foreach (var value in array)
|
||||||
@@ -465,7 +451,7 @@ namespace MtApi5TestClient
|
|||||||
TimeSeriesResults.Clear();
|
TimeSeriesResults.Clear();
|
||||||
|
|
||||||
int[] array;
|
int[] array;
|
||||||
var count = mMtApiClient.CopySpread(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, TimeSeriesValues.StartPos, TimeSeriesValues.Count, out array);
|
var count = _mtApiClient.CopySpread(TimeSeriesValues.SymbolValue, TimeSeriesValues.TimeFrame, TimeSeriesValues.StartPos, TimeSeriesValues.Count, out array);
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
foreach (var value in array)
|
foreach (var value in array)
|
||||||
@@ -480,60 +466,60 @@ namespace MtApi5TestClient
|
|||||||
|
|
||||||
private void ExecuteSymbolsTotal(object o)
|
private void ExecuteSymbolsTotal(object o)
|
||||||
{
|
{
|
||||||
var selectedCount = mMtApiClient.SymbolsTotal(true);
|
var selectedCount = _mtApiClient.SymbolsTotal(true);
|
||||||
History.Add("SymbolsTotal(true) success, result = " + selectedCount.ToString());
|
History.Add($"SymbolsTotal(true) success, result = {selectedCount}");
|
||||||
|
|
||||||
var commonCount = mMtApiClient.SymbolsTotal(false);
|
var commonCount = _mtApiClient.SymbolsTotal(false);
|
||||||
History.Add("SymbolsTotal(false) success, result = " + selectedCount.ToString());
|
History.Add($"SymbolsTotal(false) success, result = {commonCount}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ExecuteSymbolName(object o)
|
private void ExecuteSymbolName(object o)
|
||||||
{
|
{
|
||||||
var selectedSymbol = mMtApiClient.SymbolName(5, true);
|
var selectedSymbol = _mtApiClient.SymbolName(5, true);
|
||||||
History.Add("SymbolName(5, true) success, result = " + selectedSymbol);
|
History.Add("SymbolName(5, true) success, result = " + selectedSymbol);
|
||||||
|
|
||||||
var commonSymbol = mMtApiClient.SymbolName(5, false);
|
var commonSymbol = _mtApiClient.SymbolName(5, false);
|
||||||
History.Add("SymbolName(5, false) success, result = " + commonSymbol);
|
History.Add("SymbolName(5, false) success, result = " + commonSymbol);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ExecuteSymbolSelect(object o)
|
private void ExecuteSymbolSelect(object o)
|
||||||
{
|
{
|
||||||
var retVal = mMtApiClient.SymbolSelect("AUDJPY", true);
|
var retVal = _mtApiClient.SymbolSelect("AUDJPY", true);
|
||||||
History.Add("SymbolSelect(AUDJPY, true) success, result = " + retVal);
|
History.Add("SymbolSelect(AUDJPY, true) success, result = " + retVal);
|
||||||
|
|
||||||
//var retVal1 = mMtApiClient.SymbolSelect("AUDJPY", false);
|
//var retVal1 = _mtApiClient.SymbolSelect("AUDJPY", false);
|
||||||
//History.Add("SymbolSelect(AUDJPY, false) success, result = " + retVal1);
|
//History.Add("SymbolSelect(AUDJPY, false) success, result = " + retVal1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ExecuteSymbolIsSynchronized(object o)
|
private void ExecuteSymbolIsSynchronized(object o)
|
||||||
{
|
{
|
||||||
var retVal = mMtApiClient.SymbolIsSynchronized("EURUSD");
|
var retVal = _mtApiClient.SymbolIsSynchronized("EURUSD");
|
||||||
History.Add("SymbolIsSynchronized(EURUSD) success, result = " + retVal);
|
History.Add("SymbolIsSynchronized(EURUSD) success, result = " + retVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ExecuteSymbolInfoDouble(object o)
|
private void ExecuteSymbolInfoDouble(object o)
|
||||||
{
|
{
|
||||||
var retVal = mMtApiClient.SymbolInfoDouble("EURUSD", ENUM_SYMBOL_INFO_DOUBLE.SYMBOL_BID);
|
var retVal = _mtApiClient.SymbolInfoDouble("EURUSD", ENUM_SYMBOL_INFO_DOUBLE.SYMBOL_BID);
|
||||||
History.Add("SymbolInfoDouble(EURUSD, ENUM_SYMBOL_INFO_DOUBLE.SYMBOL_BID) success, result = " + retVal);
|
History.Add("SymbolInfoDouble(EURUSD, ENUM_SYMBOL_INFO_DOUBLE.SYMBOL_BID) success, result = " + retVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ExecuteSymbolInfoInteger(object o)
|
private void ExecuteSymbolInfoInteger(object o)
|
||||||
{
|
{
|
||||||
var retVal = mMtApiClient.SymbolInfoInteger("EURUSD", ENUM_SYMBOL_INFO_INTEGER.SYMBOL_SPREAD);
|
var retVal = _mtApiClient.SymbolInfoInteger("EURUSD", ENUM_SYMBOL_INFO_INTEGER.SYMBOL_SPREAD);
|
||||||
History.Add("SymbolInfoInteger(EURUSD, ENUM_SYMBOL_INFO_INTEGER.SYMBOL_SPREAD) success, result = " + retVal);
|
History.Add("SymbolInfoInteger(EURUSD, ENUM_SYMBOL_INFO_INTEGER.SYMBOL_SPREAD) success, result = " + retVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ExecuteSymbolInfoString(object o)
|
private void ExecuteSymbolInfoString(object o)
|
||||||
{
|
{
|
||||||
var retVal = mMtApiClient.SymbolInfoString("EURUSD", ENUM_SYMBOL_INFO_STRING.SYMBOL_DESCRIPTION);
|
var retVal = _mtApiClient.SymbolInfoString("EURUSD", ENUM_SYMBOL_INFO_STRING.SYMBOL_DESCRIPTION);
|
||||||
History.Add("SymbolInfoString(EURUSD, ENUM_SYMBOL_INFO_STRING.SYMBOL_DESCRIPTION) success, result = " + retVal);
|
History.Add("SymbolInfoString(EURUSD, ENUM_SYMBOL_INFO_STRING.SYMBOL_DESCRIPTION) success, result = " + retVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ExecuteSymbolInfoTick(object o)
|
private void ExecuteSymbolInfoTick(object o)
|
||||||
{
|
{
|
||||||
MqlTick tick;
|
MqlTick tick;
|
||||||
var retVal = mMtApiClient.SymbolInfoTick("EURUSD", out tick);
|
var retVal = _mtApiClient.SymbolInfoTick("EURUSD", out tick);
|
||||||
History.Add("SymbolInfoTick(EURUSD) success, result = " + retVal);
|
History.Add("SymbolInfoTick(EURUSD) success, result = " + retVal);
|
||||||
History.Add("SymbolInfoTick(EURUSD) tick.time = " + tick.time);
|
History.Add("SymbolInfoTick(EURUSD) tick.time = " + tick.time);
|
||||||
History.Add("SymbolInfoTick(EURUSD) tick.bid = " + tick.bid);
|
History.Add("SymbolInfoTick(EURUSD) tick.bid = " + tick.bid);
|
||||||
@@ -546,7 +532,7 @@ namespace MtApi5TestClient
|
|||||||
{
|
{
|
||||||
DateTime from;
|
DateTime from;
|
||||||
DateTime to;
|
DateTime to;
|
||||||
var retVal = mMtApiClient.SymbolInfoSessionQuote("EURUSD", ENUM_DAY_OF_WEEK.MONDAY, 0, out from, out to);
|
var retVal = _mtApiClient.SymbolInfoSessionQuote("EURUSD", ENUM_DAY_OF_WEEK.MONDAY, 0, out from, out to);
|
||||||
History.Add("SymbolInfoSessionQuote(EURUSD) success, result = " + retVal);
|
History.Add("SymbolInfoSessionQuote(EURUSD) success, result = " + retVal);
|
||||||
History.Add("SymbolInfoSessionQuote(EURUSD) from = " + from);
|
History.Add("SymbolInfoSessionQuote(EURUSD) from = " + from);
|
||||||
History.Add("SymbolInfoSessionQuote(EURUSD) to = " + to);
|
History.Add("SymbolInfoSessionQuote(EURUSD) to = " + to);
|
||||||
@@ -556,7 +542,7 @@ namespace MtApi5TestClient
|
|||||||
{
|
{
|
||||||
DateTime from;
|
DateTime from;
|
||||||
DateTime to;
|
DateTime to;
|
||||||
var retVal = mMtApiClient.SymbolInfoSessionTrade("EURUSD", ENUM_DAY_OF_WEEK.MONDAY, 0, out from, out to);
|
var retVal = _mtApiClient.SymbolInfoSessionTrade("EURUSD", ENUM_DAY_OF_WEEK.MONDAY, 0, out from, out to);
|
||||||
History.Add("SymbolInfoSessionTrade(EURUSD) success, result = " + retVal);
|
History.Add("SymbolInfoSessionTrade(EURUSD) success, result = " + retVal);
|
||||||
History.Add("SymbolInfoSessionTrade(EURUSD) from = " + from);
|
History.Add("SymbolInfoSessionTrade(EURUSD) from = " + from);
|
||||||
History.Add("SymbolInfoSessionTrade(EURUSD) to = " + to);
|
History.Add("SymbolInfoSessionTrade(EURUSD) to = " + to);
|
||||||
@@ -564,55 +550,63 @@ namespace MtApi5TestClient
|
|||||||
|
|
||||||
private void ExecuteMarketBookAdd(object o)
|
private void ExecuteMarketBookAdd(object o)
|
||||||
{
|
{
|
||||||
var retVal = mMtApiClient.MarketBookAdd("CHFJPY");
|
var retVal = _mtApiClient.MarketBookAdd("CHFJPY");
|
||||||
History.Add("MarketBookAdd(CHFJPY) success, result = " + retVal);
|
History.Add("MarketBookAdd(CHFJPY) success, result = " + retVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ExecuteMarketBookRelease(object o)
|
private void ExecuteMarketBookRelease(object o)
|
||||||
{
|
{
|
||||||
var retVal = mMtApiClient.MarketBookRelease("CHFJPY");
|
var retVal = _mtApiClient.MarketBookRelease("CHFJPY");
|
||||||
History.Add("MarketBookRelease(CHFJPY) success, result = " + retVal);
|
History.Add("MarketBookRelease(CHFJPY) success, result = " + retVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ExecuteMarketBookGet(object o)
|
private void ExecuteMarketBookGet(object o)
|
||||||
{
|
{
|
||||||
MqlBookInfo[] book;
|
MqlBookInfo[] book;
|
||||||
var retVal = mMtApiClient.MarketBookGet("EURUSD", out book);
|
var retVal = _mtApiClient.MarketBookGet("EURUSD", out book);
|
||||||
|
|
||||||
History.Add("MarketBookGet(EURUSD) success, result = " + retVal);
|
History.Add("MarketBookGet(EURUSD) success, result = " + retVal);
|
||||||
if (retVal == true && book != null)
|
|
||||||
|
if (retVal && book != null)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < book.Length; i++)
|
for (int i = 0; i < book.Length; i++)
|
||||||
{
|
{
|
||||||
History.Add(String.Format("MarketBookGet: book[{0}].price = {1}", i, book[i].price));
|
History.Add($"MarketBookGet: book[{i}].price = {book[i].price}");
|
||||||
History.Add(String.Format("MarketBookGet: book[{0}].price = {1}", i, book[i].volume));
|
History.Add($"MarketBookGet: book[{i}].price = {book[i].volume}");
|
||||||
History.Add(String.Format("MarketBookGet: book[{0}].price = {1}", i, book[i].type));
|
History.Add($"MarketBookGet: book[{i}].price = {book[i].type}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runOnUIThread(Action action)
|
private void ExecutePositionOpen(object obj)
|
||||||
{
|
{
|
||||||
if (Application.Current != null)
|
const string symbol = "EURUSD";
|
||||||
{
|
const ENUM_ORDER_TYPE orderType = ENUM_ORDER_TYPE.ORDER_TYPE_BUY;
|
||||||
Application.Current.Dispatcher.Invoke(action);
|
const double volume = 0.1;
|
||||||
}
|
const double price = 1.013;
|
||||||
|
const double sl = 1.00;
|
||||||
|
const double tp = 1.020;
|
||||||
|
const string comment = "Test PositionOpen";
|
||||||
|
|
||||||
|
var retVal = _mtApiClient.PositionOpen(symbol, orderType, volume, price, sl, tp, comment);
|
||||||
|
History.Add("PositionOpen: symbol EURUSD result = " + retVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runOnUIThread<T>(Action<T> action, params Object[] args)
|
private static void RunOnUiThread(Action action)
|
||||||
{
|
{
|
||||||
if (Application.Current != null)
|
Application.Current?.Dispatcher.Invoke(action);
|
||||||
{
|
|
||||||
Application.Current.Dispatcher.Invoke(action, args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private object mLocker = new object();
|
private static void RunOnUiThread<T>(Action<T> action, params object[] args)
|
||||||
|
{
|
||||||
|
Application.Current?.Dispatcher.Invoke(action, args);
|
||||||
|
}
|
||||||
|
|
||||||
private void mMtApiClient_QuoteUpdated(object sender, string symbol, double bid, double ask)
|
private void mMtApiClient_QuoteUpdated(object sender, string symbol, double bid, double ask)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(symbol) == false)
|
if (string.IsNullOrEmpty(symbol) == false)
|
||||||
{
|
{
|
||||||
if (_quotesMap.ContainsKey(symbol) == true)
|
if (_quotesMap.ContainsKey(symbol))
|
||||||
{
|
{
|
||||||
var qvm = _quotesMap[symbol];
|
var qvm = _quotesMap[symbol];
|
||||||
qvm.Bid = bid;
|
qvm.Bid = bid;
|
||||||
@@ -635,12 +629,12 @@ namespace MtApi5TestClient
|
|||||||
|
|
||||||
private void mMtApiClient_QuoteRemoved(object sender, Mt5QuoteEventArgs e)
|
private void mMtApiClient_QuoteRemoved(object sender, Mt5QuoteEventArgs e)
|
||||||
{
|
{
|
||||||
runOnUIThread<Mt5Quote>(RemoveQuote, e.Quote);
|
RunOnUiThread<Mt5Quote>(RemoveQuote, e.Quote);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mMtApiClient_QuoteAdded(object sender, Mt5QuoteEventArgs e)
|
private void mMtApiClient_QuoteAdded(object sender, Mt5QuoteEventArgs e)
|
||||||
{
|
{
|
||||||
runOnUIThread<Mt5Quote>(AddQuote, e.Quote);
|
RunOnUiThread<Mt5Quote>(AddQuote, e.Quote);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mMtApiClient_ConnectionStateChanged(object sender, Mt5ConnectionEventArgs e)
|
private void mMtApiClient_ConnectionStateChanged(object sender, Mt5ConnectionEventArgs e)
|
||||||
@@ -648,16 +642,16 @@ namespace MtApi5TestClient
|
|||||||
ConnectionState = e.Status;
|
ConnectionState = e.Status;
|
||||||
ConnectionMessage = e.ConnectionMessage;
|
ConnectionMessage = e.ConnectionMessage;
|
||||||
|
|
||||||
runOnUIThread(ConnectCommand.RaiseCanExecuteChanged);
|
RunOnUiThread(ConnectCommand.RaiseCanExecuteChanged);
|
||||||
runOnUIThread(DisconnectCommand.RaiseCanExecuteChanged);
|
RunOnUiThread(DisconnectCommand.RaiseCanExecuteChanged);
|
||||||
|
|
||||||
switch (e.Status)
|
switch (e.Status)
|
||||||
{
|
{
|
||||||
case Mt5ConnectionState.Connected:
|
case Mt5ConnectionState.Connected:
|
||||||
runOnUIThread(OnConnected);
|
RunOnUiThread(OnConnected);
|
||||||
break;
|
break;
|
||||||
case Mt5ConnectionState.Disconnected:
|
case Mt5ConnectionState.Disconnected:
|
||||||
runOnUIThread(OnDisconnected);
|
RunOnUiThread(OnDisconnected);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -667,7 +661,7 @@ namespace MtApi5TestClient
|
|||||||
if (quote == null)
|
if (quote == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QuoteViewModel qvm = null;
|
QuoteViewModel qvm;
|
||||||
|
|
||||||
if (_quotesMap.ContainsKey(quote.Instrument) == false)
|
if (_quotesMap.ContainsKey(quote.Instrument) == false)
|
||||||
{
|
{
|
||||||
@@ -690,7 +684,7 @@ namespace MtApi5TestClient
|
|||||||
if (quote == null)
|
if (quote == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_quotesMap.ContainsKey(quote.Instrument) == true)
|
if (_quotesMap.ContainsKey(quote.Instrument))
|
||||||
{
|
{
|
||||||
var qvm = _quotesMap[quote.Instrument];
|
var qvm = _quotesMap[quote.Instrument];
|
||||||
qvm.FeedCount--;
|
qvm.FeedCount--;
|
||||||
@@ -705,7 +699,7 @@ namespace MtApi5TestClient
|
|||||||
|
|
||||||
private void OnConnected()
|
private void OnConnected()
|
||||||
{
|
{
|
||||||
var quotes = mMtApiClient.GetQuotes();
|
var quotes = _mtApiClient.GetQuotes();
|
||||||
if (quotes != null)
|
if (quotes != null)
|
||||||
{
|
{
|
||||||
foreach (var quote in quotes)
|
foreach (var quote in quotes)
|
||||||
@@ -751,15 +745,14 @@ namespace MtApi5TestClient
|
|||||||
|
|
||||||
protected virtual void OnPropertyChanged(string propertyName)
|
protected virtual void OnPropertyChanged(string propertyName)
|
||||||
{
|
{
|
||||||
PropertyChangedEventHandler handler = PropertyChanged;
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||||
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Fields
|
#region Private Fields
|
||||||
private readonly MtApi5Client mMtApiClient;
|
private readonly MtApi5Client _mtApiClient;
|
||||||
|
|
||||||
private Dictionary<string, QuoteViewModel> _quotesMap;
|
private readonly Dictionary<string, QuoteViewModel> _quotesMap;
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -178,9 +178,15 @@ int executeCommand()
|
|||||||
|
|
||||||
if (!getCommandType(ExpertHandle, commandType))
|
if (!getCommandType(ExpertHandle, commandType))
|
||||||
{
|
{
|
||||||
|
Print("[ERROR] getCommandType");
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (commandType > 0)
|
||||||
|
{
|
||||||
|
Print("executeCommand: commnad type = ", commandType);
|
||||||
|
}
|
||||||
|
|
||||||
switch (commandType)
|
switch (commandType)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
@@ -209,6 +215,7 @@ int executeCommand()
|
|||||||
sendBooleanResponse(ExpertHandle, retVal);
|
sendBooleanResponse(ExpertHandle, retVal);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 64: //PositionClose
|
case 64: //PositionClose
|
||||||
{
|
{
|
||||||
int ticket;
|
int ticket;
|
||||||
@@ -1594,6 +1601,38 @@ int executeCommand()
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 65: //PositionOpen
|
||||||
|
{
|
||||||
|
string symbol;
|
||||||
|
StringInit(symbol, 50, 0);
|
||||||
|
ENUM_ORDER_TYPE order_type;
|
||||||
|
double volume;
|
||||||
|
double price;
|
||||||
|
double sl;
|
||||||
|
double tp;
|
||||||
|
string comment;
|
||||||
|
StringInit(comment, 1000, 0);
|
||||||
|
|
||||||
|
getStringValue(ExpertHandle, 0, symbol);
|
||||||
|
int order_type_int = 0;
|
||||||
|
getIntValue(ExpertHandle, 1, order_type_int);
|
||||||
|
order_type = (ENUM_ORDER_TYPE) order_type_int;
|
||||||
|
getDoubleValue(ExpertHandle, 2, volume);
|
||||||
|
getDoubleValue(ExpertHandle, 3, price);
|
||||||
|
getDoubleValue(ExpertHandle, 4, sl);
|
||||||
|
getDoubleValue(ExpertHandle, 5, tp);
|
||||||
|
getStringValue(ExpertHandle, 6, comment);
|
||||||
|
|
||||||
|
PrintFormat("command PositionOpen: symbol = %s, order_type = %d, volume = %f, price = %f, sl = %f, tp = %f, comment = %s",
|
||||||
|
symbol, order_type, volume, price, sl, tp, comment);
|
||||||
|
|
||||||
|
CTrade trade;
|
||||||
|
bool result = trade.PositionOpen(symbol, order_type, volume, price, sl, tp, comment);
|
||||||
|
sendBooleanResponse(ExpertHandle, result);
|
||||||
|
Print("command PositionOpen: result = ", result);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Print("Unknown command type = ", commandType);
|
Print("Unknown command type = ", commandType);
|
||||||
sendVoidResponse(ExpertHandle);
|
sendVoidResponse(ExpertHandle);
|
||||||
|
|||||||
Reference in New Issue
Block a user