From c722511c031878398c66f7c3dfa2e51a3c75f635 Mon Sep 17 00:00:00 2001 From: DW Date: Fri, 18 Nov 2016 15:47:55 +0200 Subject: [PATCH] Refactored MtApiService (ver. 1.0.24): Added ExpertHandle to MtQuote and MtEvent. Added event QuoteUpdate to MtApiClient. --- MTApiService/MTApiService.csproj | 2 +- MTApiService/MtClient.cs | 13 +- MTApiService/MtEvent.cs | 13 +- MTApiService/MtExpert.cs | 5 +- MTApiService/MtInstrument.cs | 29 --- MTApiService/MtQuote.cs | 25 +++ MTApiService/MtServer.cs | 6 +- MTApiService/MtServerInstance.cs | 6 +- MTApiService/MtService.cs | 14 +- MTApiService/Properties/AssemblyInfo.cs | 4 +- MtApi/ExtensionMethods.cs | 5 - MtApi/MtApiClient.cs | 18 +- MtApi/MtQuote.cs | 9 + MtApi/MtQuoteEventArgs.cs | 3 - MtApi/TimeBarArgs.cs | 4 - TestClients/TestApiClientUI/Form1.Designer.cs | 199 +++++++++--------- TestClients/TestApiClientUI/Form1.cs | 70 +++--- TestClients/TestMtApi/TestMtApi/App.config | 6 +- .../My Project/Application.Designer.vb | 2 +- .../My Project/Resources.Designer.vb | 25 +-- .../TestMtApi/My Project/Settings.Designer.vb | 52 ++--- .../TestMtApi/TestMtApi/TestMtApi.vbproj | 15 +- 22 files changed, 260 insertions(+), 265 deletions(-) delete mode 100755 MTApiService/MtInstrument.cs create mode 100644 MTApiService/MtQuote.cs diff --git a/MTApiService/MTApiService.csproj b/MTApiService/MTApiService.csproj index f27bbab7..9bd012c7 100755 --- a/MTApiService/MTApiService.csproj +++ b/MTApiService/MTApiService.csproj @@ -78,7 +78,7 @@ - + diff --git a/MTApiService/MtClient.cs b/MTApiService/MtClient.cs index 1d063518..81d7009c 100755 --- a/MTApiService/MtClient.cs +++ b/MTApiService/MtClient.cs @@ -12,6 +12,7 @@ namespace MTApiService private const string ServiceName = "MtApiService"; public delegate void MtQuoteHandler(MtQuote quote); + public delegate void MtEventHandler(MtEvent e); #region Fields private static readonly ILog Log = LogManager.GetLogger(typeof(MtClient)); @@ -213,7 +214,7 @@ namespace MTApiService } /// Thrown when connection failed - public IEnumerable GetQuotes() + public List GetQuotes() { Log.Debug("GetQuotes: begin."); @@ -259,7 +260,7 @@ namespace MTApiService if (quote == null) return; - QuoteUpdated?.Invoke(quote); + QuoteUpdated?.Invoke( quote); Log.Debug("OnQuoteUpdate: end."); } @@ -293,11 +294,11 @@ namespace MTApiService } - public void OnMtEvent(MtEvent mtEvent) + public void OnMtEvent(MtEvent e) { - Log.DebugFormat("OnMtEvent: begin. event = {0}", mtEvent); + Log.DebugFormat("OnMtEvent: begin. event = {0}", e); - MtEventReceived?.Invoke(this, new MtEventArgs(mtEvent)); + MtEventReceived?.Invoke(e); Log.Debug("OnMtEvent: end."); } @@ -342,7 +343,7 @@ namespace MTApiService public event MtQuoteHandler QuoteUpdated; public event EventHandler ServerDisconnected; public event EventHandler ServerFailed; - public event EventHandler MtEventReceived; + public event MtEventHandler MtEventReceived; #endregion } } diff --git a/MTApiService/MtEvent.cs b/MTApiService/MtEvent.cs index 80b38b38..594d5fa0 100644 --- a/MTApiService/MtEvent.cs +++ b/MTApiService/MtEvent.cs @@ -7,20 +7,17 @@ namespace MTApiService public class MtEvent { [DataMember] - public int EventType { get; private set; } + public int EventType { get; internal set; } [DataMember] - public string Payload { get; private set; } + public string Payload { get; internal set; } - public MtEvent(int eventType, string payload) - { - EventType = eventType; - Payload = payload; - } + [DataMember] + public int ExpertHandle { get; internal set; } public override string ToString() { - return "MtEvent = " + EventType + ", Payload = " + Payload; + return $"EventType = {EventType}; Payload = {Payload}; ExpertHandle = {ExpertHandle}"; } } diff --git a/MTApiService/MtExpert.cs b/MTApiService/MtExpert.cs index 05c1669f..a66dd517 100755 --- a/MTApiService/MtExpert.cs +++ b/MTApiService/MtExpert.cs @@ -6,6 +6,7 @@ namespace MTApiService public class MtExpert { public delegate void MtQuoteHandler(MtExpert expert, MtQuote quote); + public delegate void MtEventHandler(MtExpert expert, MtEvent e); #region Private Fields private static readonly ILog Log = LogManager.GetLogger(typeof(MtExpert)); @@ -187,7 +188,7 @@ namespace MTApiService private void FireOnMtEvent(MtEvent mtEvent) { - OnMtEvent?.Invoke(this, new MtEventArgs(mtEvent)); + OnMtEvent?.Invoke(this, mtEvent); } #endregion @@ -195,7 +196,7 @@ namespace MTApiService public event EventHandler Deinited; public event MtQuoteHandler QuoteChanged; public event EventHandler CommandExecuted; - public event EventHandler OnMtEvent; + public event MtEventHandler OnMtEvent; #endregion } } diff --git a/MTApiService/MtInstrument.cs b/MTApiService/MtInstrument.cs deleted file mode 100755 index 0867dda1..00000000 --- a/MTApiService/MtInstrument.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Runtime.Serialization; - -namespace MTApiService -{ - [DataContract] - public class MtQuote - { - [DataMember] - public string Instrument { get; private set; } - - [DataMember] - public double Bid { get; private set; } - - [DataMember] - public double Ask { get; private set; } - - public MtQuote(string instrument, double bid, double ask) - { - Instrument = instrument; - Bid = bid; - Ask = ask; - } - - public override string ToString() - { - return "Instrument = " + Instrument + ", Bid = " + Bid + ", Ask = " + Ask; - } - } -} diff --git a/MTApiService/MtQuote.cs b/MTApiService/MtQuote.cs new file mode 100644 index 00000000..4c707f54 --- /dev/null +++ b/MTApiService/MtQuote.cs @@ -0,0 +1,25 @@ +using System.Runtime.Serialization; + +namespace MTApiService +{ + [DataContract] + public class MtQuote + { + [DataMember] + public string Instrument { get; internal set; } + + [DataMember] + public double Bid { get; internal set; } + + [DataMember] + public double Ask { get; internal set; } + + [DataMember] + public int ExpertHandle { get; internal set; } + + public override string ToString() + { + return $"Instrument = {Instrument}; Bid = {Bid}; Ask = {Ask}; ExpertHandle = {ExpertHandle}"; + } + } +} diff --git a/MTApiService/MtServer.cs b/MTApiService/MtServer.cs index db003534..e133b741 100755 --- a/MTApiService/MtServer.cs +++ b/MTApiService/MtServer.cs @@ -398,11 +398,11 @@ namespace MTApiService Log.Debug("expert_QuoteChanged: end."); } - private void Expert_OnMtEvent(object sender, MtEventArgs e) + private void Expert_OnMtEvent(MtExpert expert, MtEvent e) { - Log.DebugFormat("Expert_OnMtEvent: begin. event = {0}", e.Event); + Log.DebugFormat("Expert_OnMtEvent: begin. expert = {0}, event = {1}", expert, e); - _service.OnMtEvent(e.Event); + _service.OnMtEvent(e); Log.Debug("Expert_OnMtEvent: end."); } diff --git a/MTApiService/MtServerInstance.cs b/MTApiService/MtServerInstance.cs index a448198a..a1e4e882 100755 --- a/MTApiService/MtServerInstance.cs +++ b/MTApiService/MtServerInstance.cs @@ -60,7 +60,7 @@ namespace MTApiService } } - var expert = new MtExpert(expertHandle, new MtQuote(symbol, bid, ask), mtHandler); + var expert = new MtExpert(expertHandle, new MtQuote { Instrument = symbol, Bid = bid, Ask = ask, ExpertHandle = expertHandle }, mtHandler); lock (_experts) { @@ -111,7 +111,7 @@ namespace MTApiService if (expert != null) { - expert.Quote = new MtQuote(symbol, bid, ask); + expert.Quote = new MtQuote { Instrument = symbol, Bid = bid, Ask = ask, ExpertHandle = expertHandle }; } else { @@ -133,7 +133,7 @@ namespace MTApiService if (expert != null) { - expert.SendEvent(new MtEvent(eventType, payload)); + expert.SendEvent(new MtEvent { EventType = eventType, Payload = payload, ExpertHandle = expertHandle }); } else { diff --git a/MTApiService/MtService.cs b/MTApiService/MtService.cs index ce25dfdf..5dfea69f 100755 --- a/MTApiService/MtService.cs +++ b/MTApiService/MtService.cs @@ -66,7 +66,7 @@ namespace MTApiService if (callback == null) { - Log.Warn("Connect: end. Callback is not definded."); + Log.Warn("Connect: end. Callback is not defined."); return false; } @@ -158,7 +158,7 @@ namespace MTApiService public void QuoteUpdate(MtQuote quote) { - Log.Debug("QuoteUpdate: begin."); + Log.DebugFormat("QuoteUpdate: begin. quote = {0}", quote); ExecuteCallbackAction(a => a.OnQuoteUpdate(quote)); @@ -167,7 +167,7 @@ namespace MTApiService public void OnQuoteAdded(MtQuote quote) { - Log.Debug("OnQuoteAdded: begin."); + Log.DebugFormat("OnQuoteAdded: begin. quote = {0}", quote); ExecuteCallbackAction(a => a.OnQuoteAdded(quote)); @@ -176,18 +176,18 @@ namespace MTApiService public void OnQuoteRemoved(MtQuote quote) { - Log.Debug("OnQuoteRemoved: begin."); + Log.DebugFormat("OnQuoteRemoved: begin. quote = {0}", quote); ExecuteCallbackAction(a => a.OnQuoteRemoved(quote)); Log.Debug("OnQuoteRemoved: end."); } - public void OnMtEvent(MtEvent mtEvent) + public void OnMtEvent(MtEvent e) { - Log.Debug("OnMtEvent: begin."); + Log.DebugFormat("OnMtEvent: begin.quote = {0}", e); - ExecuteCallbackAction(a => a.OnMtEvent(mtEvent)); + ExecuteCallbackAction(a => a.OnMtEvent(e)); Log.Debug("OnMtEvent: end."); } diff --git a/MTApiService/Properties/AssemblyInfo.cs b/MTApiService/Properties/AssemblyInfo.cs index 8730db4e..d89d1407 100755 --- a/MTApiService/Properties/AssemblyInfo.cs +++ b/MTApiService/Properties/AssemblyInfo.cs @@ -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.23.0")] -[assembly: AssemblyFileVersion("1.0.23.0")] +[assembly: AssemblyVersion("1.0.24.0")] +[assembly: AssemblyFileVersion("1.0.24.0")] diff --git a/MtApi/ExtensionMethods.cs b/MtApi/ExtensionMethods.cs index f96146b6..9871cb9e 100755 --- a/MtApi/ExtensionMethods.cs +++ b/MtApi/ExtensionMethods.cs @@ -33,10 +33,5 @@ namespace MtApi } #endregion - - public static MtQuote Convert(this MTApiService.MtQuote quote) - { - return (quote != null) ? new MtQuote(quote.Instrument, quote.Bid, quote.Ask) : null; - } } } diff --git a/MtApi/MtApiClient.cs b/MtApi/MtApiClient.cs index 06e39417..65c4a8b2 100755 --- a/MtApi/MtApiClient.cs +++ b/MtApi/MtApiClient.cs @@ -81,14 +81,15 @@ namespace MtApi /// ///Load quotes connected into MetaTrader API. /// - public IEnumerable GetQuotes() + public List GetQuotes() { IEnumerable quotes; lock (_client) { quotes = _client.GetQuotes(); } - return quotes?.Select(q => q.Convert()); + + return quotes?.Select(q => new MtQuote(q)).ToList(); } #endregion @@ -1847,10 +1848,12 @@ namespace MtApi { if (_isBacktestingMode) { + QuoteUpdate?.Invoke(this, new MtQuoteEventArgs(new MtQuote(quote))); QuoteUpdated?.Invoke(this, quote.Instrument, quote.Bid, quote.Ask); } else { + QuoteUpdate?.FireEventAsync(this, new MtQuoteEventArgs(new MtQuote(quote))); QuoteUpdated.FireEventAsync(this, quote.Instrument, quote.Bid, quote.Ask); } } @@ -1868,23 +1871,23 @@ namespace MtApi private void _client_QuoteRemoved(MTApiService.MtQuote quote) { - QuoteRemoved.FireEventAsync(this, new MtQuoteEventArgs(quote.Convert())); + QuoteRemoved.FireEventAsync(this, new MtQuoteEventArgs(new MtQuote(quote))); } private void _client_QuoteAdded(MTApiService.MtQuote quote) { - QuoteAdded.FireEventAsync(this, new MtQuoteEventArgs(quote.Convert())); + QuoteAdded.FireEventAsync(this, new MtQuoteEventArgs(new MtQuote(quote))); } - private void _client_MtEventReceived(object sender, MtEventArgs e) + private void _client_MtEventReceived(MtEvent e) { - var eventType = (MtEventTypes) e.Event.EventType; + var eventType = (MtEventTypes) e.EventType; switch(eventType) { case MtEventTypes.LastTimeBar: { - FireOnLastTimeBar(JsonConvert.DeserializeObject(e.Event.Payload)); + FireOnLastTimeBar(JsonConvert.DeserializeObject(e.Payload)); } break; default: @@ -1907,6 +1910,7 @@ namespace MtApi #region Events public event MtApiQuoteHandler QuoteUpdated; + public event EventHandler QuoteUpdate; public event EventHandler QuoteAdded; public event EventHandler QuoteRemoved; public event EventHandler ConnectionStateChanged; diff --git a/MtApi/MtQuote.cs b/MtApi/MtQuote.cs index 34fb0954..0d61c489 100755 --- a/MtApi/MtQuote.cs +++ b/MtApi/MtQuote.cs @@ -5,6 +5,7 @@ public string Instrument { get; private set; } public double Bid { get; private set; } public double Ask { get; private set; } + public int ExpertHandle { get; private set; } public MtQuote(string instrument, double bid, double ask) { @@ -12,5 +13,13 @@ Bid = bid; Ask = ask; } + + internal MtQuote(MTApiService.MtQuote quote) + { + Instrument = quote.Instrument; + Bid = quote.Bid; + Ask = quote.Ask; + ExpertHandle = quote.ExpertHandle; + } } } diff --git a/MtApi/MtQuoteEventArgs.cs b/MtApi/MtQuoteEventArgs.cs index ac64c62a..1f78edaa 100755 --- a/MtApi/MtQuoteEventArgs.cs +++ b/MtApi/MtQuoteEventArgs.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace MtApi { diff --git a/MtApi/TimeBarArgs.cs b/MtApi/TimeBarArgs.cs index e8ae32ba..10694b75 100644 --- a/MtApi/TimeBarArgs.cs +++ b/MtApi/TimeBarArgs.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace MtApi { diff --git a/TestClients/TestApiClientUI/Form1.Designer.cs b/TestClients/TestApiClientUI/Form1.Designer.cs index f634d873..d54d5ea5 100644 --- a/TestClients/TestApiClientUI/Form1.Designer.cs +++ b/TestClients/TestApiClientUI/Form1.Designer.cs @@ -43,7 +43,7 @@ this.colSymbol = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.colBid = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.colAsk = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.colFeedCount = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.colExpertHandle = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.listBoxEventLog = new System.Windows.Forms.ListBox(); this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); this.tabControl1 = new System.Windows.Forms.TabControl(); @@ -110,6 +110,15 @@ this.listBoxAccountInfo = new System.Windows.Forms.ListBox(); this.button4 = new System.Windows.Forms.Button(); this.tabPage4 = new System.Windows.Forms.TabPage(); + this.button36 = new System.Windows.Forms.Button(); + this.comboBox10 = new System.Windows.Forms.ComboBox(); + this.comboBox9 = new System.Windows.Forms.ComboBox(); + this.button35 = new System.Windows.Forms.Button(); + this.button34 = new System.Windows.Forms.Button(); + this.comboBox8 = new System.Windows.Forms.ComboBox(); + this.label30 = new System.Windows.Forms.Label(); + this.button33 = new System.Windows.Forms.Button(); + this.comboBox7 = new System.Windows.Forms.ComboBox(); this.comboBox6 = new System.Windows.Forms.ComboBox(); this.label29 = new System.Windows.Forms.Label(); this.comboBox5 = new System.Windows.Forms.ComboBox(); @@ -157,15 +166,6 @@ this.button28 = new System.Windows.Forms.Button(); this.label28 = new System.Windows.Forms.Label(); this.textBox1 = new System.Windows.Forms.TextBox(); - this.comboBox7 = new System.Windows.Forms.ComboBox(); - this.button33 = new System.Windows.Forms.Button(); - this.label30 = new System.Windows.Forms.Label(); - this.comboBox8 = new System.Windows.Forms.ComboBox(); - this.button34 = new System.Windows.Forms.Button(); - this.button35 = new System.Windows.Forms.Button(); - this.comboBox9 = new System.Windows.Forms.ComboBox(); - this.comboBox10 = new System.Windows.Forms.ComboBox(); - this.button36 = new System.Windows.Forms.Button(); this.groupBox1.SuspendLayout(); this.statusStrip1.SuspendLayout(); this.groupBox2.SuspendLayout(); @@ -288,7 +288,7 @@ this.colSymbol, this.colBid, this.colAsk, - this.colFeedCount}); + this.colExpertHandle}); this.listViewQuotes.Location = new System.Drawing.Point(6, 19); this.listViewQuotes.Name = "listViewQuotes"; this.listViewQuotes.Size = new System.Drawing.Size(357, 104); @@ -309,9 +309,10 @@ // this.colAsk.Text = "Ask"; // - // colFeedCount + // colExpertHandle // - this.colFeedCount.Text = "Feeds"; + this.colExpertHandle.Text = "ExpertHandle"; + this.colExpertHandle.Width = 80; // // listBoxEventLog // @@ -1071,6 +1072,91 @@ this.tabPage4.Text = "MarketInfo"; this.tabPage4.UseVisualStyleBackColor = true; // + // button36 + // + this.button36.Location = new System.Drawing.Point(208, 157); + this.button36.Name = "button36"; + this.button36.Size = new System.Drawing.Size(111, 23); + this.button36.TabIndex = 36; + this.button36.Text = "TerminalInfoDouble"; + this.button36.UseVisualStyleBackColor = true; + this.button36.Click += new System.EventHandler(this.button36_Click); + // + // comboBox10 + // + this.comboBox10.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBox10.FormattingEnabled = true; + this.comboBox10.Location = new System.Drawing.Point(13, 157); + this.comboBox10.Name = "comboBox10"; + this.comboBox10.Size = new System.Drawing.Size(186, 21); + this.comboBox10.TabIndex = 35; + // + // comboBox9 + // + this.comboBox9.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBox9.FormattingEnabled = true; + this.comboBox9.Location = new System.Drawing.Point(13, 130); + this.comboBox9.Name = "comboBox9"; + this.comboBox9.Size = new System.Drawing.Size(186, 21); + this.comboBox9.TabIndex = 34; + // + // button35 + // + this.button35.Location = new System.Drawing.Point(208, 128); + this.button35.Name = "button35"; + this.button35.Size = new System.Drawing.Size(111, 23); + this.button35.TabIndex = 33; + this.button35.Text = "TerminalInfoInteger"; + this.button35.UseVisualStyleBackColor = true; + this.button35.Click += new System.EventHandler(this.button35_Click); + // + // button34 + // + this.button34.Location = new System.Drawing.Point(387, 47); + this.button34.Name = "button34"; + this.button34.Size = new System.Drawing.Size(112, 23); + this.button34.TabIndex = 32; + this.button34.Text = "SymbolInfoTick"; + this.button34.UseVisualStyleBackColor = true; + this.button34.Click += new System.EventHandler(this.button34_Click); + // + // comboBox8 + // + this.comboBox8.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBox8.FormattingEnabled = true; + this.comboBox8.Location = new System.Drawing.Point(13, 47); + this.comboBox8.Name = "comboBox8"; + this.comboBox8.Size = new System.Drawing.Size(186, 21); + this.comboBox8.TabIndex = 31; + // + // label30 + // + this.label30.AutoSize = true; + this.label30.Location = new System.Drawing.Point(10, 13); + this.label30.Name = "label30"; + this.label30.Size = new System.Drawing.Size(41, 13); + this.label30.TabIndex = 30; + this.label30.Text = "Symbol"; + // + // button33 + // + this.button33.Location = new System.Drawing.Point(208, 99); + this.button33.Name = "button33"; + this.button33.Size = new System.Drawing.Size(111, 23); + this.button33.TabIndex = 29; + this.button33.Text = "SymbolInfoDouble"; + this.button33.UseVisualStyleBackColor = true; + this.button33.Click += new System.EventHandler(this.button33_Click); + // + // comboBox7 + // + this.comboBox7.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBox7.FormattingEnabled = true; + this.comboBox7.Location = new System.Drawing.Point(13, 101); + this.comboBox7.Name = "comboBox7"; + this.comboBox7.Size = new System.Drawing.Size(186, 21); + this.comboBox7.TabIndex = 28; + // // comboBox6 // this.comboBox6.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; @@ -1569,91 +1655,6 @@ this.textBox1.TabIndex = 0; this.textBox1.Text = "EURUSD"; // - // comboBox7 - // - this.comboBox7.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBox7.FormattingEnabled = true; - this.comboBox7.Location = new System.Drawing.Point(13, 101); - this.comboBox7.Name = "comboBox7"; - this.comboBox7.Size = new System.Drawing.Size(186, 21); - this.comboBox7.TabIndex = 28; - // - // button33 - // - this.button33.Location = new System.Drawing.Point(208, 99); - this.button33.Name = "button33"; - this.button33.Size = new System.Drawing.Size(111, 23); - this.button33.TabIndex = 29; - this.button33.Text = "SymbolInfoDouble"; - this.button33.UseVisualStyleBackColor = true; - this.button33.Click += new System.EventHandler(this.button33_Click); - // - // label30 - // - this.label30.AutoSize = true; - this.label30.Location = new System.Drawing.Point(10, 13); - this.label30.Name = "label30"; - this.label30.Size = new System.Drawing.Size(41, 13); - this.label30.TabIndex = 30; - this.label30.Text = "Symbol"; - // - // comboBox8 - // - this.comboBox8.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBox8.FormattingEnabled = true; - this.comboBox8.Location = new System.Drawing.Point(13, 47); - this.comboBox8.Name = "comboBox8"; - this.comboBox8.Size = new System.Drawing.Size(186, 21); - this.comboBox8.TabIndex = 31; - // - // button34 - // - this.button34.Location = new System.Drawing.Point(387, 47); - this.button34.Name = "button34"; - this.button34.Size = new System.Drawing.Size(112, 23); - this.button34.TabIndex = 32; - this.button34.Text = "SymbolInfoTick"; - this.button34.UseVisualStyleBackColor = true; - this.button34.Click += new System.EventHandler(this.button34_Click); - // - // button35 - // - this.button35.Location = new System.Drawing.Point(208, 128); - this.button35.Name = "button35"; - this.button35.Size = new System.Drawing.Size(111, 23); - this.button35.TabIndex = 33; - this.button35.Text = "TerminalInfoInteger"; - this.button35.UseVisualStyleBackColor = true; - this.button35.Click += new System.EventHandler(this.button35_Click); - // - // comboBox9 - // - this.comboBox9.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBox9.FormattingEnabled = true; - this.comboBox9.Location = new System.Drawing.Point(13, 130); - this.comboBox9.Name = "comboBox9"; - this.comboBox9.Size = new System.Drawing.Size(186, 21); - this.comboBox9.TabIndex = 34; - // - // comboBox10 - // - this.comboBox10.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBox10.FormattingEnabled = true; - this.comboBox10.Location = new System.Drawing.Point(13, 157); - this.comboBox10.Name = "comboBox10"; - this.comboBox10.Size = new System.Drawing.Size(186, 21); - this.comboBox10.TabIndex = 35; - // - // button36 - // - this.button36.Location = new System.Drawing.Point(208, 157); - this.button36.Name = "button36"; - this.button36.Size = new System.Drawing.Size(111, 23); - this.button36.TabIndex = 36; - this.button36.Text = "TerminalInfoDouble"; - this.button36.UseVisualStyleBackColor = true; - this.button36.Click += new System.EventHandler(this.button36_Click); - // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -1780,7 +1781,7 @@ private System.Windows.Forms.Button button8; private System.Windows.Forms.Button button11; private System.Windows.Forms.Button button12; - private System.Windows.Forms.ColumnHeader colFeedCount; + private System.Windows.Forms.ColumnHeader colExpertHandle; private System.Windows.Forms.TabPage tabPage6; private System.Windows.Forms.Button button13; private System.Windows.Forms.Button button14; diff --git a/TestClients/TestApiClientUI/Form1.cs b/TestClients/TestApiClientUI/Form1.cs index ffae6639..2dea1035 100644 --- a/TestClients/TestApiClientUI/Form1.cs +++ b/TestClients/TestApiClientUI/Form1.cs @@ -35,6 +35,7 @@ namespace TestApiClientUI comboBox10.DataSource = Enum.GetNames(typeof(EnumTerminalInfoDouble)); _apiClient.QuoteUpdated += apiClient_QuoteUpdated; + _apiClient.QuoteUpdate += _apiClient_QuoteUpdate; _apiClient.QuoteAdded += apiClient_QuoteAdded; _apiClient.QuoteRemoved += apiClient_QuoteRemoved; _apiClient.ConnectionStateChanged += apiClient_ConnectionStateChanged; @@ -112,12 +113,18 @@ namespace TestApiClientUI private void apiClient_QuoteRemoved(object sender, MtQuoteEventArgs e) { - RunOnUiThread(() => RemoveQuote(e.Quote) ); + if (e.Quote != null) + { + RunOnUiThread(() => RemoveQuote(e.Quote)); + } } private void apiClient_QuoteAdded(object sender, MtQuoteEventArgs e) { - RunOnUiThread(() => AddNewQuote(e.Quote)); + if (e.Quote != null) + { + RunOnUiThread(() => AddNewQuote(e.Quote)); + } } private void _apiClient_OnLastTimeBar(object sender, TimeBarArgs e) @@ -131,72 +138,53 @@ namespace TestApiClientUI private void apiClient_QuoteUpdated(object sender, string symbol, double bid, double ask) { Console.WriteLine(@"Quote: Symbol = {0}, Bid = {1}, Ask = {2}", symbol, bid, ask); + } + + + private void _apiClient_QuoteUpdate(object sender, MtQuoteEventArgs e) + { //if UI of quite is busy we are skipping this update if (_isUiQuoteUpdateReady) { - RunOnUiThread(() => ChangeQuote(symbol, bid, ask)); + RunOnUiThread(() => ChangeQuote(e.Quote)); } } private void AddNewQuote(MtQuote quote) { - if (quote == null) - return; + var key = quote.ExpertHandle.ToString(); - if (string.IsNullOrEmpty(quote.Instrument) == false - && listViewQuotes.Items.ContainsKey(quote.Instrument) == false) + if (listViewQuotes.Items.ContainsKey(key) == false) { - var item = new ListViewItem(quote.Instrument) { Name = quote.Instrument }; + var item = new ListViewItem(quote.Instrument) { Name = key }; item.SubItems.Add(quote.Bid.ToString(CultureInfo.CurrentCulture)); item.SubItems.Add(quote.Ask.ToString(CultureInfo.CurrentCulture)); - item.SubItems.Add("1"); + item.SubItems.Add(key); listViewQuotes.Items.Add(item); } - else - { - var item = listViewQuotes.Items[quote.Instrument]; - int feedCount; - int.TryParse(item.SubItems[3].Text, out feedCount); - feedCount++; - item.SubItems[3].Text = feedCount.ToString(); - } } private void RemoveQuote(MtQuote quote) { - if (quote == null) - return; + var key = quote.ExpertHandle.ToString(); - if (string.IsNullOrEmpty(quote.Instrument) == false - && listViewQuotes.Items.ContainsKey(quote.Instrument)) + if (listViewQuotes.Items.ContainsKey(key)) { - var item = listViewQuotes.Items[quote.Instrument]; - int feedCount; - int.TryParse(item.SubItems[3].Text, out feedCount); - feedCount--; - if (feedCount <= 0) - { - listViewQuotes.Items.RemoveByKey(quote.Instrument); - } - else - { - item.SubItems[3].Text = feedCount.ToString(); - } + listViewQuotes.Items.RemoveByKey(key); } } - private void ChangeQuote(string symbol, double bid, double ask) + private void ChangeQuote(MtQuote quote) { _isUiQuoteUpdateReady = false; - if (string.IsNullOrEmpty(symbol) == false) + var key = quote.ExpertHandle.ToString(); + + if (listViewQuotes.Items.ContainsKey(key)) { - if (listViewQuotes.Items.ContainsKey(symbol)) - { - var item = listViewQuotes.Items[symbol]; - item.SubItems[1].Text = bid.ToString(CultureInfo.CurrentCulture); - item.SubItems[2].Text = ask.ToString(CultureInfo.CurrentCulture); - } + var item = listViewQuotes.Items[key]; + item.SubItems[1].Text = quote.Bid.ToString(CultureInfo.CurrentCulture); + item.SubItems[2].Text = quote.Ask.ToString(CultureInfo.CurrentCulture); } _isUiQuoteUpdateReady = true; diff --git a/TestClients/TestMtApi/TestMtApi/App.config b/TestClients/TestMtApi/TestMtApi/App.config index 75054283..82717522 100644 --- a/TestClients/TestMtApi/TestMtApi/App.config +++ b/TestClients/TestMtApi/TestMtApi/App.config @@ -1,6 +1,6 @@ - + - + - \ No newline at end of file + diff --git a/TestClients/TestMtApi/TestMtApi/My Project/Application.Designer.vb b/TestClients/TestMtApi/TestMtApi/My Project/Application.Designer.vb index d1e4182b..431f856b 100644 --- a/TestClients/TestMtApi/TestMtApi/My Project/Application.Designer.vb +++ b/TestClients/TestMtApi/TestMtApi/My Project/Application.Designer.vb @@ -1,7 +1,7 @@ '------------------------------------------------------------------------------ ' ' This code was generated by a tool. -' Runtime Version:4.0.30319.17929 +' Runtime Version:4.0.30319.42000 ' ' Changes to this file may cause incorrect behavior and will be lost if ' the code is regenerated. diff --git a/TestClients/TestMtApi/TestMtApi/My Project/Resources.Designer.vb b/TestClients/TestMtApi/TestMtApi/My Project/Resources.Designer.vb index e448f572..510bdcea 100644 --- a/TestClients/TestMtApi/TestMtApi/My Project/Resources.Designer.vb +++ b/TestClients/TestMtApi/TestMtApi/My Project/Resources.Designer.vb @@ -1,7 +1,7 @@ '------------------------------------------------------------------------------ ' ' This code was generated by a tool. -' Runtime Version:4.0.30319.17929 +' Runtime Version:4.0.30319.42000 ' ' Changes to this file may cause incorrect behavior and will be lost if ' the code is regenerated. @@ -11,6 +11,7 @@ Option Strict On Option Explicit On +Imports System Namespace My.Resources @@ -21,20 +22,20 @@ Namespace My.Resources ''' ''' A strongly-typed resource class, for looking up localized strings, etc. ''' - _ + _ Friend Module Resources - + Private resourceMan As Global.System.Resources.ResourceManager - + Private resourceCulture As Global.System.Globalization.CultureInfo - + ''' ''' Returns the cached ResourceManager instance used by this class. ''' - _ + _ Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager Get If Object.ReferenceEquals(resourceMan, Nothing) Then @@ -44,17 +45,17 @@ Namespace My.Resources Return resourceMan End Get End Property - + ''' ''' Overrides the current thread's CurrentUICulture property for all ''' resource lookups using this strongly typed resource class. ''' - _ + _ Friend Property Culture() As Global.System.Globalization.CultureInfo Get Return resourceCulture End Get - Set(ByVal value As Global.System.Globalization.CultureInfo) + Set resourceCulture = value End Set End Property diff --git a/TestClients/TestMtApi/TestMtApi/My Project/Settings.Designer.vb b/TestClients/TestMtApi/TestMtApi/My Project/Settings.Designer.vb index 3ad0d9d9..275f6c04 100644 --- a/TestClients/TestMtApi/TestMtApi/My Project/Settings.Designer.vb +++ b/TestClients/TestMtApi/TestMtApi/My Project/Settings.Designer.vb @@ -1,7 +1,7 @@ '------------------------------------------------------------------------------ ' ' This code was generated by a tool. -' Runtime Version:4.0.30319.17929 +' Runtime Version:4.0.30319.42000 ' ' Changes to this file may cause incorrect behavior and will be lost if ' the code is regenerated. @@ -13,42 +13,42 @@ Option Explicit On Namespace My - - _ + + _ Partial Friend NotInheritable Class MySettings Inherits Global.System.Configuration.ApplicationSettingsBase - - Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings), MySettings) - + + Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) + #Region "My.Settings Auto-Save Functionality" #If _MyType = "WindowsForms" Then - Private Shared addedHandler As Boolean + Private Shared addedHandler As Boolean - Private Shared addedHandlerLockObject As New Object + Private Shared addedHandlerLockObject As New Object - _ - Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) - If My.Application.SaveMySettingsOnExit Then - My.Settings.Save() - End If - End Sub + _ + Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) + If My.Application.SaveMySettingsOnExit Then + My.Settings.Save() + End If + End Sub #End If #End Region - + Public Shared ReadOnly Property [Default]() As MySettings Get - + #If _MyType = "WindowsForms" Then - If Not addedHandler Then - SyncLock addedHandlerLockObject - If Not addedHandler Then - AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings - addedHandler = True - End If - End SyncLock - End If + If Not addedHandler Then + SyncLock addedHandlerLockObject + If Not addedHandler Then + AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings + addedHandler = True + End If + End SyncLock + End If #End If Return defaultInstance End Get diff --git a/TestClients/TestMtApi/TestMtApi/TestMtApi.vbproj b/TestClients/TestMtApi/TestMtApi/TestMtApi.vbproj index adc93b90..b920cae6 100644 --- a/TestClients/TestMtApi/TestMtApi/TestMtApi.vbproj +++ b/TestClients/TestMtApi/TestMtApi/TestMtApi.vbproj @@ -13,8 +13,9 @@ TestMtApi 512 WindowsForms - v4.0 - Client + v4.5 + + publish\ true Disk @@ -40,6 +41,7 @@ bin\Debug\ TestMtApi.xml 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + false x86 @@ -50,6 +52,7 @@ bin\Release\ TestMtApi.xml 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + false On @@ -67,7 +70,6 @@ My Project\app.manifest - @@ -126,6 +128,7 @@ + MyApplicationCodeGenerator @@ -159,6 +162,12 @@ true + + + {7a76c388-a8fb-4949-8170-24d4742e934e} + MtApi + +