Refactored MtApiService (ver. 1.0.24): Added ExpertHandle to MtQuote and MtEvent. Added event QuoteUpdate to MtApiClient.

This commit is contained in:
DW
2016-11-18 15:47:55 +02:00
parent 39599436ab
commit c722511c03
22 changed files with 260 additions and 265 deletions
+1 -1
View File
@@ -78,7 +78,7 @@
<Compile Include="MtConnectionProfile.cs" /> <Compile Include="MtConnectionProfile.cs" />
<Compile Include="MtExecutorManager.cs" /> <Compile Include="MtExecutorManager.cs" />
<Compile Include="MtExpert.cs" /> <Compile Include="MtExpert.cs" />
<Compile Include="MtInstrument.cs" /> <Compile Include="MtQuote.cs" />
<Compile Include="MtResponse.cs" /> <Compile Include="MtResponse.cs" />
<Compile Include="MtServer.cs" /> <Compile Include="MtServer.cs" />
<Compile Include="MtCommand.cs" /> <Compile Include="MtCommand.cs" />
+7 -6
View File
@@ -12,6 +12,7 @@ namespace MTApiService
private const string ServiceName = "MtApiService"; private const string ServiceName = "MtApiService";
public delegate void MtQuoteHandler(MtQuote quote); public delegate void MtQuoteHandler(MtQuote quote);
public delegate void MtEventHandler(MtEvent e);
#region Fields #region Fields
private static readonly ILog Log = LogManager.GetLogger(typeof(MtClient)); private static readonly ILog Log = LogManager.GetLogger(typeof(MtClient));
@@ -213,7 +214,7 @@ namespace MTApiService
} }
/// <exception cref="CommunicationException">Thrown when connection failed</exception> /// <exception cref="CommunicationException">Thrown when connection failed</exception>
public IEnumerable<MtQuote> GetQuotes() public List<MtQuote> GetQuotes()
{ {
Log.Debug("GetQuotes: begin."); Log.Debug("GetQuotes: begin.");
@@ -259,7 +260,7 @@ namespace MTApiService
if (quote == null) return; if (quote == null) return;
QuoteUpdated?.Invoke(quote); QuoteUpdated?.Invoke( quote);
Log.Debug("OnQuoteUpdate: end."); 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."); Log.Debug("OnMtEvent: end.");
} }
@@ -342,7 +343,7 @@ namespace MTApiService
public event MtQuoteHandler QuoteUpdated; public event MtQuoteHandler QuoteUpdated;
public event EventHandler ServerDisconnected; public event EventHandler ServerDisconnected;
public event EventHandler ServerFailed; public event EventHandler ServerFailed;
public event EventHandler<MtEventArgs> MtEventReceived; public event MtEventHandler MtEventReceived;
#endregion #endregion
} }
} }
+5 -8
View File
@@ -7,20 +7,17 @@ namespace MTApiService
public class MtEvent public class MtEvent
{ {
[DataMember] [DataMember]
public int EventType { get; private set; } public int EventType { get; internal set; }
[DataMember] [DataMember]
public string Payload { get; private set; } public string Payload { get; internal set; }
public MtEvent(int eventType, string payload) [DataMember]
{ public int ExpertHandle { get; internal set; }
EventType = eventType;
Payload = payload;
}
public override string ToString() public override string ToString()
{ {
return "MtEvent = " + EventType + ", Payload = " + Payload; return $"EventType = {EventType}; Payload = {Payload}; ExpertHandle = {ExpertHandle}";
} }
} }
+3 -2
View File
@@ -6,6 +6,7 @@ namespace MTApiService
public class MtExpert public class MtExpert
{ {
public delegate void MtQuoteHandler(MtExpert expert, MtQuote quote); public delegate void MtQuoteHandler(MtExpert expert, MtQuote quote);
public delegate void MtEventHandler(MtExpert expert, MtEvent e);
#region Private Fields #region Private Fields
private static readonly ILog Log = LogManager.GetLogger(typeof(MtExpert)); private static readonly ILog Log = LogManager.GetLogger(typeof(MtExpert));
@@ -187,7 +188,7 @@ namespace MTApiService
private void FireOnMtEvent(MtEvent mtEvent) private void FireOnMtEvent(MtEvent mtEvent)
{ {
OnMtEvent?.Invoke(this, new MtEventArgs(mtEvent)); OnMtEvent?.Invoke(this, mtEvent);
} }
#endregion #endregion
@@ -195,7 +196,7 @@ namespace MTApiService
public event EventHandler Deinited; public event EventHandler Deinited;
public event MtQuoteHandler QuoteChanged; public event MtQuoteHandler QuoteChanged;
public event EventHandler CommandExecuted; public event EventHandler CommandExecuted;
public event EventHandler<MtEventArgs> OnMtEvent; public event MtEventHandler OnMtEvent;
#endregion #endregion
} }
} }
-29
View File
@@ -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;
}
}
}
+25
View File
@@ -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}";
}
}
}
+3 -3
View File
@@ -398,11 +398,11 @@ namespace MTApiService
Log.Debug("expert_QuoteChanged: end."); 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."); Log.Debug("Expert_OnMtEvent: end.");
} }
+3 -3
View File
@@ -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) lock (_experts)
{ {
@@ -111,7 +111,7 @@ namespace MTApiService
if (expert != null) if (expert != null)
{ {
expert.Quote = new MtQuote(symbol, bid, ask); expert.Quote = new MtQuote { Instrument = symbol, Bid = bid, Ask = ask, ExpertHandle = expertHandle };
} }
else else
{ {
@@ -133,7 +133,7 @@ namespace MTApiService
if (expert != null) if (expert != null)
{ {
expert.SendEvent(new MtEvent(eventType, payload)); expert.SendEvent(new MtEvent { EventType = eventType, Payload = payload, ExpertHandle = expertHandle });
} }
else else
{ {
+7 -7
View File
@@ -66,7 +66,7 @@ namespace MTApiService
if (callback == null) if (callback == null)
{ {
Log.Warn("Connect: end. Callback is not definded."); Log.Warn("Connect: end. Callback is not defined.");
return false; return false;
} }
@@ -158,7 +158,7 @@ namespace MTApiService
public void QuoteUpdate(MtQuote quote) public void QuoteUpdate(MtQuote quote)
{ {
Log.Debug("QuoteUpdate: begin."); Log.DebugFormat("QuoteUpdate: begin. quote = {0}", quote);
ExecuteCallbackAction(a => a.OnQuoteUpdate(quote)); ExecuteCallbackAction(a => a.OnQuoteUpdate(quote));
@@ -167,7 +167,7 @@ namespace MTApiService
public void OnQuoteAdded(MtQuote quote) public void OnQuoteAdded(MtQuote quote)
{ {
Log.Debug("OnQuoteAdded: begin."); Log.DebugFormat("OnQuoteAdded: begin. quote = {0}", quote);
ExecuteCallbackAction(a => a.OnQuoteAdded(quote)); ExecuteCallbackAction(a => a.OnQuoteAdded(quote));
@@ -176,18 +176,18 @@ namespace MTApiService
public void OnQuoteRemoved(MtQuote quote) public void OnQuoteRemoved(MtQuote quote)
{ {
Log.Debug("OnQuoteRemoved: begin."); Log.DebugFormat("OnQuoteRemoved: begin. quote = {0}", quote);
ExecuteCallbackAction(a => a.OnQuoteRemoved(quote)); ExecuteCallbackAction(a => a.OnQuoteRemoved(quote));
Log.Debug("OnQuoteRemoved: end."); 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."); Log.Debug("OnMtEvent: end.");
} }
+2 -2
View File
@@ -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.23.0")] [assembly: AssemblyVersion("1.0.24.0")]
[assembly: AssemblyFileVersion("1.0.23.0")] [assembly: AssemblyFileVersion("1.0.24.0")]
-5
View File
@@ -33,10 +33,5 @@ namespace MtApi
} }
#endregion #endregion
public static MtQuote Convert(this MTApiService.MtQuote quote)
{
return (quote != null) ? new MtQuote(quote.Instrument, quote.Bid, quote.Ask) : null;
}
} }
} }
+11 -7
View File
@@ -81,14 +81,15 @@ namespace MtApi
///<summary> ///<summary>
///Load quotes connected into MetaTrader API. ///Load quotes connected into MetaTrader API.
///</summary> ///</summary>
public IEnumerable<MtQuote> GetQuotes() public List<MtQuote> GetQuotes()
{ {
IEnumerable<MTApiService.MtQuote> quotes; IEnumerable<MTApiService.MtQuote> quotes;
lock (_client) lock (_client)
{ {
quotes = _client.GetQuotes(); quotes = _client.GetQuotes();
} }
return quotes?.Select(q => q.Convert());
return quotes?.Select(q => new MtQuote(q)).ToList();
} }
#endregion #endregion
@@ -1847,10 +1848,12 @@ namespace MtApi
{ {
if (_isBacktestingMode) if (_isBacktestingMode)
{ {
QuoteUpdate?.Invoke(this, new MtQuoteEventArgs(new MtQuote(quote)));
QuoteUpdated?.Invoke(this, quote.Instrument, quote.Bid, quote.Ask); QuoteUpdated?.Invoke(this, quote.Instrument, quote.Bid, quote.Ask);
} }
else else
{ {
QuoteUpdate?.FireEventAsync(this, new MtQuoteEventArgs(new MtQuote(quote)));
QuoteUpdated.FireEventAsync(this, quote.Instrument, quote.Bid, quote.Ask); QuoteUpdated.FireEventAsync(this, quote.Instrument, quote.Bid, quote.Ask);
} }
} }
@@ -1868,23 +1871,23 @@ namespace MtApi
private void _client_QuoteRemoved(MTApiService.MtQuote quote) 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) 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) switch(eventType)
{ {
case MtEventTypes.LastTimeBar: case MtEventTypes.LastTimeBar:
{ {
FireOnLastTimeBar(JsonConvert.DeserializeObject<MtTimeBar>(e.Event.Payload)); FireOnLastTimeBar(JsonConvert.DeserializeObject<MtTimeBar>(e.Payload));
} }
break; break;
default: default:
@@ -1907,6 +1910,7 @@ namespace MtApi
#region Events #region Events
public event MtApiQuoteHandler QuoteUpdated; public event MtApiQuoteHandler QuoteUpdated;
public event EventHandler<MtQuoteEventArgs> QuoteUpdate;
public event EventHandler<MtQuoteEventArgs> QuoteAdded; public event EventHandler<MtQuoteEventArgs> QuoteAdded;
public event EventHandler<MtQuoteEventArgs> QuoteRemoved; public event EventHandler<MtQuoteEventArgs> QuoteRemoved;
public event EventHandler<MtConnectionEventArgs> ConnectionStateChanged; public event EventHandler<MtConnectionEventArgs> ConnectionStateChanged;
+9
View File
@@ -5,6 +5,7 @@
public string Instrument { get; private set; } public string Instrument { get; private set; }
public double Bid { get; private set; } public double Bid { get; private set; }
public double Ask { get; private set; } public double Ask { get; private set; }
public int ExpertHandle { get; private set; }
public MtQuote(string instrument, double bid, double ask) public MtQuote(string instrument, double bid, double ask)
{ {
@@ -12,5 +13,13 @@
Bid = bid; Bid = bid;
Ask = ask; Ask = ask;
} }
internal MtQuote(MTApiService.MtQuote quote)
{
Instrument = quote.Instrument;
Bid = quote.Bid;
Ask = quote.Ask;
ExpertHandle = quote.ExpertHandle;
}
} }
} }
-3
View File
@@ -1,7 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MtApi namespace MtApi
{ {
-4
View File
@@ -1,8 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MtApi namespace MtApi
{ {
+100 -99
View File
@@ -43,7 +43,7 @@
this.colSymbol = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.colSymbol = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.colBid = ((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.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.listBoxEventLog = new System.Windows.Forms.ListBox();
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabControl1 = new System.Windows.Forms.TabControl();
@@ -110,6 +110,15 @@
this.listBoxAccountInfo = new System.Windows.Forms.ListBox(); this.listBoxAccountInfo = new System.Windows.Forms.ListBox();
this.button4 = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button();
this.tabPage4 = new System.Windows.Forms.TabPage(); 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.comboBox6 = new System.Windows.Forms.ComboBox();
this.label29 = new System.Windows.Forms.Label(); this.label29 = new System.Windows.Forms.Label();
this.comboBox5 = new System.Windows.Forms.ComboBox(); this.comboBox5 = new System.Windows.Forms.ComboBox();
@@ -157,15 +166,6 @@
this.button28 = new System.Windows.Forms.Button(); this.button28 = new System.Windows.Forms.Button();
this.label28 = new System.Windows.Forms.Label(); this.label28 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox(); 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.groupBox1.SuspendLayout();
this.statusStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout();
this.groupBox2.SuspendLayout(); this.groupBox2.SuspendLayout();
@@ -288,7 +288,7 @@
this.colSymbol, this.colSymbol,
this.colBid, this.colBid,
this.colAsk, this.colAsk,
this.colFeedCount}); this.colExpertHandle});
this.listViewQuotes.Location = new System.Drawing.Point(6, 19); this.listViewQuotes.Location = new System.Drawing.Point(6, 19);
this.listViewQuotes.Name = "listViewQuotes"; this.listViewQuotes.Name = "listViewQuotes";
this.listViewQuotes.Size = new System.Drawing.Size(357, 104); this.listViewQuotes.Size = new System.Drawing.Size(357, 104);
@@ -309,9 +309,10 @@
// //
this.colAsk.Text = "Ask"; this.colAsk.Text = "Ask";
// //
// colFeedCount // colExpertHandle
// //
this.colFeedCount.Text = "Feeds"; this.colExpertHandle.Text = "ExpertHandle";
this.colExpertHandle.Width = 80;
// //
// listBoxEventLog // listBoxEventLog
// //
@@ -1071,6 +1072,91 @@
this.tabPage4.Text = "MarketInfo"; this.tabPage4.Text = "MarketInfo";
this.tabPage4.UseVisualStyleBackColor = true; 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 // comboBox6
// //
this.comboBox6.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBox6.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
@@ -1569,91 +1655,6 @@
this.textBox1.TabIndex = 0; this.textBox1.TabIndex = 0;
this.textBox1.Text = "EURUSD"; 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 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -1780,7 +1781,7 @@
private System.Windows.Forms.Button button8; private System.Windows.Forms.Button button8;
private System.Windows.Forms.Button button11; private System.Windows.Forms.Button button11;
private System.Windows.Forms.Button button12; 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.TabPage tabPage6;
private System.Windows.Forms.Button button13; private System.Windows.Forms.Button button13;
private System.Windows.Forms.Button button14; private System.Windows.Forms.Button button14;
+29 -41
View File
@@ -35,6 +35,7 @@ namespace TestApiClientUI
comboBox10.DataSource = Enum.GetNames(typeof(EnumTerminalInfoDouble)); comboBox10.DataSource = Enum.GetNames(typeof(EnumTerminalInfoDouble));
_apiClient.QuoteUpdated += apiClient_QuoteUpdated; _apiClient.QuoteUpdated += apiClient_QuoteUpdated;
_apiClient.QuoteUpdate += _apiClient_QuoteUpdate;
_apiClient.QuoteAdded += apiClient_QuoteAdded; _apiClient.QuoteAdded += apiClient_QuoteAdded;
_apiClient.QuoteRemoved += apiClient_QuoteRemoved; _apiClient.QuoteRemoved += apiClient_QuoteRemoved;
_apiClient.ConnectionStateChanged += apiClient_ConnectionStateChanged; _apiClient.ConnectionStateChanged += apiClient_ConnectionStateChanged;
@@ -112,12 +113,18 @@ namespace TestApiClientUI
private void apiClient_QuoteRemoved(object sender, MtQuoteEventArgs e) 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) 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) 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) private void apiClient_QuoteUpdated(object sender, string symbol, double bid, double ask)
{ {
Console.WriteLine(@"Quote: Symbol = {0}, Bid = {1}, Ask = {2}", symbol, bid, 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 UI of quite is busy we are skipping this update
if (_isUiQuoteUpdateReady) if (_isUiQuoteUpdateReady)
{ {
RunOnUiThread(() => ChangeQuote(symbol, bid, ask)); RunOnUiThread(() => ChangeQuote(e.Quote));
} }
} }
private void AddNewQuote(MtQuote quote) private void AddNewQuote(MtQuote quote)
{ {
if (quote == null) var key = quote.ExpertHandle.ToString();
return;
if (string.IsNullOrEmpty(quote.Instrument) == false if (listViewQuotes.Items.ContainsKey(key) == false)
&& listViewQuotes.Items.ContainsKey(quote.Instrument) == 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.Bid.ToString(CultureInfo.CurrentCulture));
item.SubItems.Add(quote.Ask.ToString(CultureInfo.CurrentCulture)); item.SubItems.Add(quote.Ask.ToString(CultureInfo.CurrentCulture));
item.SubItems.Add("1"); item.SubItems.Add(key);
listViewQuotes.Items.Add(item); 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) private void RemoveQuote(MtQuote quote)
{ {
if (quote == null) var key = quote.ExpertHandle.ToString();
return;
if (string.IsNullOrEmpty(quote.Instrument) == false if (listViewQuotes.Items.ContainsKey(key))
&& listViewQuotes.Items.ContainsKey(quote.Instrument))
{ {
var item = listViewQuotes.Items[quote.Instrument]; listViewQuotes.Items.RemoveByKey(key);
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();
}
} }
} }
private void ChangeQuote(string symbol, double bid, double ask) private void ChangeQuote(MtQuote quote)
{ {
_isUiQuoteUpdateReady = false; _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[key];
{ item.SubItems[1].Text = quote.Bid.ToString(CultureInfo.CurrentCulture);
var item = listViewQuotes.Items[symbol]; item.SubItems[2].Text = quote.Ask.ToString(CultureInfo.CurrentCulture);
item.SubItems[1].Text = bid.ToString(CultureInfo.CurrentCulture);
item.SubItems[2].Text = ask.ToString(CultureInfo.CurrentCulture);
}
} }
_isUiQuoteUpdateReady = true; _isUiQuoteUpdateReady = true;
+3 -3
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup> </startup>
</configuration> </configuration>
@@ -1,7 +1,7 @@
'------------------------------------------------------------------------------ '------------------------------------------------------------------------------
' <auto-generated> ' <auto-generated>
' This code was generated by a tool. ' 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 ' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated. ' the code is regenerated.
@@ -1,7 +1,7 @@
'------------------------------------------------------------------------------ '------------------------------------------------------------------------------
' <auto-generated> ' <auto-generated>
' This code was generated by a tool. ' 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 ' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated. ' the code is regenerated.
@@ -11,6 +11,7 @@
Option Strict On Option Strict On
Option Explicit On Option Explicit On
Imports System
Namespace My.Resources Namespace My.Resources
@@ -21,20 +22,20 @@ Namespace My.Resources
'''<summary> '''<summary>
''' A strongly-typed resource class, for looking up localized strings, etc. ''' A strongly-typed resource class, for looking up localized strings, etc.
'''</summary> '''</summary>
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0"), _ <Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0"), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _ Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _ Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _ Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
Friend Module Resources Friend Module Resources
Private resourceMan As Global.System.Resources.ResourceManager Private resourceMan As Global.System.Resources.ResourceManager
Private resourceCulture As Global.System.Globalization.CultureInfo Private resourceCulture As Global.System.Globalization.CultureInfo
'''<summary> '''<summary>
''' Returns the cached ResourceManager instance used by this class. ''' Returns the cached ResourceManager instance used by this class.
'''</summary> '''</summary>
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _ <Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
Get Get
If Object.ReferenceEquals(resourceMan, Nothing) Then If Object.ReferenceEquals(resourceMan, Nothing) Then
@@ -44,17 +45,17 @@ Namespace My.Resources
Return resourceMan Return resourceMan
End Get End Get
End Property End Property
'''<summary> '''<summary>
''' Overrides the current thread's CurrentUICulture property for all ''' Overrides the current thread's CurrentUICulture property for all
''' resource lookups using this strongly typed resource class. ''' resource lookups using this strongly typed resource class.
'''</summary> '''</summary>
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _ <Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Friend Property Culture() As Global.System.Globalization.CultureInfo Friend Property Culture() As Global.System.Globalization.CultureInfo
Get Get
Return resourceCulture Return resourceCulture
End Get End Get
Set(ByVal value As Global.System.Globalization.CultureInfo) Set
resourceCulture = value resourceCulture = value
End Set End Set
End Property End Property
@@ -1,7 +1,7 @@
'------------------------------------------------------------------------------ '------------------------------------------------------------------------------
' <auto-generated> ' <auto-generated>
' This code was generated by a tool. ' 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 ' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated. ' the code is regenerated.
@@ -13,42 +13,42 @@ Option Explicit On
Namespace My Namespace My
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _ <Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0"), _ Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0"), _
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _ Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Partial Friend NotInheritable Class MySettings Partial Friend NotInheritable Class MySettings
Inherits Global.System.Configuration.ApplicationSettingsBase 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" #Region "My.Settings Auto-Save Functionality"
#If _MyType = "WindowsForms" Then #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
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _ <Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs)
If My.Application.SaveMySettingsOnExit Then If My.Application.SaveMySettingsOnExit Then
My.Settings.Save() My.Settings.Save()
End If End If
End Sub End Sub
#End If #End If
#End Region #End Region
Public Shared ReadOnly Property [Default]() As MySettings Public Shared ReadOnly Property [Default]() As MySettings
Get Get
#If _MyType = "WindowsForms" Then #If _MyType = "WindowsForms" Then
If Not addedHandler Then If Not addedHandler Then
SyncLock addedHandlerLockObject SyncLock addedHandlerLockObject
If Not addedHandler Then If Not addedHandler Then
AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
addedHandler = True addedHandler = True
End If End If
End SyncLock End SyncLock
End If End If
#End If #End If
Return defaultInstance Return defaultInstance
End Get End Get
@@ -13,8 +13,9 @@
<AssemblyName>TestMtApi</AssemblyName> <AssemblyName>TestMtApi</AssemblyName>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<MyType>WindowsForms</MyType> <MyType>WindowsForms</MyType>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile> <TargetFrameworkProfile>
</TargetFrameworkProfile>
<PublishUrl>publish\</PublishUrl> <PublishUrl>publish\</PublishUrl>
<Install>true</Install> <Install>true</Install>
<InstallFrom>Disk</InstallFrom> <InstallFrom>Disk</InstallFrom>
@@ -40,6 +41,7 @@
<OutputPath>bin\Debug\</OutputPath> <OutputPath>bin\Debug\</OutputPath>
<DocumentationFile>TestMtApi.xml</DocumentationFile> <DocumentationFile>TestMtApi.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn> <NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
@@ -50,6 +52,7 @@
<OutputPath>bin\Release\</OutputPath> <OutputPath>bin\Release\</OutputPath>
<DocumentationFile>TestMtApi.xml</DocumentationFile> <DocumentationFile>TestMtApi.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn> <NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<OptionExplicit>On</OptionExplicit> <OptionExplicit>On</OptionExplicit>
@@ -67,7 +70,6 @@
<ApplicationManifest>My Project\app.manifest</ApplicationManifest> <ApplicationManifest>My Project\app.manifest</ApplicationManifest>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="MtApi, Version=1.0.7.0, Culture=neutral, processorArchitecture=MSIL" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Deployment" /> <Reference Include="System.Deployment" />
@@ -126,6 +128,7 @@
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config" />
<None Include="My Project\app.manifest" /> <None Include="My Project\app.manifest" />
<None Include="My Project\Application.myapp"> <None Include="My Project\Application.myapp">
<Generator>MyApplicationCodeGenerator</Generator> <Generator>MyApplicationCodeGenerator</Generator>
@@ -159,6 +162,12 @@
<Install>true</Install> <Install>true</Install>
</BootstrapperPackage> </BootstrapperPackage>
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\MtApi\MtApi.csproj">
<Project>{7a76c388-a8fb-4949-8170-24d4742e934e}</Project>
<Name>MtApi</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.