mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-07-27 18:47:55 +00:00
Refactored MtApiService (ver. 1.0.24): Added ExpertHandle to MtQuote and MtEvent. Added event QuoteUpdate to MtApiClient.
This commit is contained in:
@@ -78,7 +78,7 @@
|
||||
<Compile Include="MtConnectionProfile.cs" />
|
||||
<Compile Include="MtExecutorManager.cs" />
|
||||
<Compile Include="MtExpert.cs" />
|
||||
<Compile Include="MtInstrument.cs" />
|
||||
<Compile Include="MtQuote.cs" />
|
||||
<Compile Include="MtResponse.cs" />
|
||||
<Compile Include="MtServer.cs" />
|
||||
<Compile Include="MtCommand.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
|
||||
}
|
||||
|
||||
/// <exception cref="CommunicationException">Thrown when connection failed</exception>
|
||||
public IEnumerable<MtQuote> GetQuotes()
|
||||
public List<MtQuote> 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<MtEventArgs> MtEventReceived;
|
||||
public event MtEventHandler MtEventReceived;
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<MtEventArgs> OnMtEvent;
|
||||
public event MtEventHandler OnMtEvent;
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.");
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
|
||||
@@ -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")]
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-7
@@ -81,14 +81,15 @@ namespace MtApi
|
||||
///<summary>
|
||||
///Load quotes connected into MetaTrader API.
|
||||
///</summary>
|
||||
public IEnumerable<MtQuote> GetQuotes()
|
||||
public List<MtQuote> GetQuotes()
|
||||
{
|
||||
IEnumerable<MTApiService.MtQuote> 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<MtTimeBar>(e.Event.Payload));
|
||||
FireOnLastTimeBar(JsonConvert.DeserializeObject<MtTimeBar>(e.Payload));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -1907,6 +1910,7 @@ namespace MtApi
|
||||
#region Events
|
||||
|
||||
public event MtApiQuoteHandler QuoteUpdated;
|
||||
public event EventHandler<MtQuoteEventArgs> QuoteUpdate;
|
||||
public event EventHandler<MtQuoteEventArgs> QuoteAdded;
|
||||
public event EventHandler<MtQuoteEventArgs> QuoteRemoved;
|
||||
public event EventHandler<MtConnectionEventArgs> ConnectionStateChanged;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace MtApi
|
||||
{
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MtApi
|
||||
{
|
||||
|
||||
+100
-99
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
|
||||
</startup>
|
||||
</configuration>
|
||||
</configuration>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' 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
-12
@@ -1,7 +1,7 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' 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
|
||||
'''<summary>
|
||||
''' A strongly-typed resource class, for looking up localized strings, etc.
|
||||
'''</summary>
|
||||
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0"), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
|
||||
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0"), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
|
||||
Friend Module Resources
|
||||
|
||||
|
||||
Private resourceMan As Global.System.Resources.ResourceManager
|
||||
|
||||
|
||||
Private resourceCulture As Global.System.Globalization.CultureInfo
|
||||
|
||||
|
||||
'''<summary>
|
||||
''' Returns the cached ResourceManager instance used by this class.
|
||||
'''</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
|
||||
Get
|
||||
If Object.ReferenceEquals(resourceMan, Nothing) Then
|
||||
@@ -44,17 +45,17 @@ Namespace My.Resources
|
||||
Return resourceMan
|
||||
End Get
|
||||
End Property
|
||||
|
||||
|
||||
'''<summary>
|
||||
''' Overrides the current thread's CurrentUICulture property for all
|
||||
''' resource lookups using this strongly typed resource class.
|
||||
'''</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
|
||||
Get
|
||||
Return resourceCulture
|
||||
End Get
|
||||
Set(ByVal value As Global.System.Globalization.CultureInfo)
|
||||
Set
|
||||
resourceCulture = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
+26
-26
@@ -1,7 +1,7 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' 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
|
||||
|
||||
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0"), _
|
||||
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
|
||||
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0"), _
|
||||
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
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
|
||||
|
||||
<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)
|
||||
If My.Application.SaveMySettingsOnExit Then
|
||||
My.Settings.Save()
|
||||
End If
|
||||
End Sub
|
||||
<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)
|
||||
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
|
||||
|
||||
@@ -13,8 +13,9 @@
|
||||
<AssemblyName>TestMtApi</AssemblyName>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<MyType>WindowsForms</MyType>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
@@ -40,6 +41,7 @@
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DocumentationFile>TestMtApi.xml</DocumentationFile>
|
||||
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
@@ -50,6 +52,7 @@
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DocumentationFile>TestMtApi.xml</DocumentationFile>
|
||||
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionExplicit>On</OptionExplicit>
|
||||
@@ -67,7 +70,6 @@
|
||||
<ApplicationManifest>My Project\app.manifest</ApplicationManifest>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MtApi, Version=1.0.7.0, Culture=neutral, processorArchitecture=MSIL" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Deployment" />
|
||||
@@ -126,6 +128,7 @@
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="My Project\app.manifest" />
|
||||
<None Include="My Project\Application.myapp">
|
||||
<Generator>MyApplicationCodeGenerator</Generator>
|
||||
@@ -159,6 +162,12 @@
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</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" />
|
||||
<!-- 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.
|
||||
|
||||
Reference in New Issue
Block a user