diff --git a/MtApi/ExtensionMethods.cs b/MtApi/ExtensionMethods.cs index b59af497..64f33ad1 100755 --- a/MtApi/ExtensionMethods.cs +++ b/MtApi/ExtensionMethods.cs @@ -8,44 +8,6 @@ namespace MtApi { static class ExtensionMethods { - #region Event Methods - - public static async void FireEvent(this MtApiQuoteHandler evenHandler, object sender, string symbol, double bid, double ask) - { - if (evenHandler != null) - { - await Task.Factory.StartNew(() => - { - evenHandler(sender, symbol, bid, ask); - }); - } - } - - public static async void FireEvent(this EventHandler eventHandler, object sender) - { - if (eventHandler != null) - { - await Task.Factory.StartNew(() => - { - eventHandler(sender, EventArgs.Empty); - }); - } - } - - public static async void FireEvent(this EventHandler eventHandler, object sender, T e) - where T : EventArgs - { - if (eventHandler != null) - { - await Task.Factory.StartNew(() => - { - eventHandler(sender, e); - }); - } - } - - #endregion - public static MtQuote Parse(this MTApiService.MtQuote quote) { return (quote != null) ? new MtQuote(quote.Instrument, quote.Bid, quote.Ask) : null; diff --git a/MtApi/MqlRates.cs b/MtApi/MqlRates.cs new file mode 100644 index 00000000..539e74cb --- /dev/null +++ b/MtApi/MqlRates.cs @@ -0,0 +1,22 @@ +using System; + +namespace MtApi +{ + public class MqlRates + { + public int MtTime { get; set; } + + public DateTime Time + { + get { return MtApiTimeConverter.ConvertFromMtTime(MtTime); } + } + + public double Open { get; set; } + public double High { get; set; } + public double Low { get; set; } + public double Close { get; set; } + public long TickVolume { get; set; } + public int Spread { get; set; } + public long RealVolume { get; set; } + } +} diff --git a/MtApi/MtApi.csproj b/MtApi/MtApi.csproj index 91ff9c59..0cc71a28 100755 --- a/MtApi/MtApi.csproj +++ b/MtApi/MtApi.csproj @@ -60,6 +60,7 @@ + @@ -76,6 +77,7 @@ + @@ -86,6 +88,7 @@ + diff --git a/MtApi/MtApiClient.cs b/MtApi/MtApiClient.cs index 087c8c0e..47be5034 100755 --- a/MtApi/MtApiClient.cs +++ b/MtApi/MtApiClient.cs @@ -16,6 +16,7 @@ namespace MtApi public sealed class MtApiClient { private const int DoubleArrayLimit = 64800; + private volatile bool IsBacktestingMode = false; #region MetaTrader Constants @@ -1365,6 +1366,47 @@ namespace MtApi return SendCommand(MtCommandType.RefreshRates, null); } + public List CopyRates(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count) + { + var response = SendRequest(new CopyRates1Request + { + SymbolName = symbol_name, + Timeframe = timeframe, + StartPos = start_pos, + Count = count + }); + return response != null ? response.Rates : null; + } + + public List CopyRates(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, int count) + { + var response = SendRequest(new CopyRates2Request + { + SymbolName = symbol_name, + Timeframe = timeframe, + StartTime = MtApiTimeConverter.ConvertToMtTime(start_time), + Count = count + }); + return response != null ? response.Rates : null; + } + + public List CopyRates(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, DateTime stop_time) + { + var response = SendRequest(new CopyRates3Request + { + SymbolName = symbol_name, + Timeframe = timeframe, + StartTime = MtApiTimeConverter.ConvertToMtTime(start_time), + StopTime = MtApiTimeConverter.ConvertToMtTime(stop_time) + }); + return response != null ? response.Rates : null; + } + + private void BaBacktestingReady() + { + SendCommand(MtCommandType.BacktestingReady, null); + } + #endregion #region Checkup @@ -1385,7 +1427,6 @@ namespace MtApi private void Connect(string host, int port) { UpdateConnectionState(MtConnectionState.Connecting, string.Format("Connecting to {0}:{1}", host, port)); - try { _client.Open(host, port); @@ -1396,14 +1437,13 @@ namespace MtApi UpdateConnectionState(MtConnectionState.Failed, string.Format("Failed connection to {0}:{1}. {2}", host, port, e.Message)); return; } - UpdateConnectionState(MtConnectionState.Connected, string.Format("Connected to {0}:{1}", host, port)); + OnConnected(); } private void Connect(int port) { UpdateConnectionState(MtConnectionState.Connecting, string.Format("Connecting to 'localhost':{0}", port)); - try { _client.Open(port); @@ -1414,8 +1454,17 @@ namespace MtApi UpdateConnectionState(MtConnectionState.Failed, string.Format("Failed connection to 'localhost':{0}. {1}", port, e.Message)); return; } - UpdateConnectionState(MtConnectionState.Connected, string.Format("Connected to 'localhost':{0}", port)); + OnConnected(); + } + + private void OnConnected() + { + IsBacktestingMode = IsTesting(); + if (IsBacktestingMode) + { + BaBacktestingReady(); + } } private void Disconnect() @@ -1440,7 +1489,8 @@ namespace MtApi if (changed) { - ConnectionStateChanged.FireEvent(this, new MtConnectionEventArgs(state, message)); + var handler = ConnectionStateChanged; + handler?.BeginInvoke(this, new MtConnectionEventArgs(state, message), (a) => handler.EndInvoke(a), null); } } @@ -1522,7 +1572,15 @@ namespace MtApi { if (quote != null) { - QuoteUpdated.FireEvent(this, quote.Instrument, quote.Bid, quote.Ask); + var handler = QuoteUpdated; + if (IsBacktestingMode) + { + handler?.Invoke(this, quote.Instrument, quote.Bid, quote.Ask); + } + else + { + handler?.BeginInvoke(this, quote.Instrument, quote.Bid, quote.Ask, (a) => handler.EndInvoke(a), null); + } } } @@ -1538,12 +1596,14 @@ namespace MtApi private void mClient_QuoteRemoved(MTApiService.MtQuote quote) { - QuoteRemoved.FireEvent(this, new MtQuoteEventArgs(quote.Parse())); + var handler = QuoteRemoved; + handler?.BeginInvoke(this, new MtQuoteEventArgs(quote.Parse()), (a) => handler.EndInvoke(a), null); } private void mClient_QuoteAdded(MTApiService.MtQuote quote) { - QuoteAdded.FireEvent(this, new MtQuoteEventArgs(quote.Parse())); + var handler = QuoteAdded; + handler?.BeginInvoke(this, new MtQuoteEventArgs(quote.Parse()), (a) => handler.EndInvoke(a), null); } #endregion diff --git a/MtApi/MtCommandType.cs b/MtApi/MtCommandType.cs index f537758d..757f5af0 100755 --- a/MtApi/MtCommandType.cs +++ b/MtApi/MtCommandType.cs @@ -192,6 +192,9 @@ namespace MtApi SymbolInfoString = 154, //Requests - MtRequest = 155 + MtRequest = 155, + + //Backtesting + BacktestingReady = 156 } } diff --git a/MtApi/MtTypes.cs b/MtApi/MtTypes.cs index 3e12f783..ff48f41b 100755 --- a/MtApi/MtTypes.cs +++ b/MtApi/MtTypes.cs @@ -1,14 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace MtApi +namespace MtApi { - class MtTypes - { - } - public enum ENUM_TERMINAL_INFO_STRING { TERMINAL_LANGUAGE = 13, @@ -27,4 +18,30 @@ namespace MtApi SYMBOL_DESCRIPTION = 20, SYMBOL_PATH = 21 } + + public enum ENUM_TIMEFRAMES + { + PERIOD_CURRENT = 0, + PERIOD_M1 = 1, + PERIOD_M2 = 2, + PERIOD_M3 = 3, + PERIOD_M4 = 4, + PERIOD_M5 = 5, + PERIOD_M6 = 6, + PERIOD_M10 = 10, + PERIOD_M12 = 12, + PERIOD_M15 = 15, + PERIOD_M20 = 20, + PERIOD_M30 = 30, + PERIOD_H1 = 60, + PERIOD_H2 = 120, + PERIOD_H3 = 180, + PERIOD_H4 = 240, + PERIOD_H6 = 360, + PERIOD_H8 = 480, + PERIOD_H12 = 720, + PERIOD_D1 = 1440, + PERIOD_W1 = 10080, + PERIOD_MN1 = 43200 + } } diff --git a/MtApi/Requests/CopyRatesRequest.cs b/MtApi/Requests/CopyRatesRequest.cs new file mode 100644 index 00000000..b2e4275a --- /dev/null +++ b/MtApi/Requests/CopyRatesRequest.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MtApi.Requests +{ + public abstract class CopyRatesRequestBase : RequestBase + { + public enum CopyRatesTypeEnum + { + CopyRates_1 = 1, + CopyRates_2 = 2, + CopyRates_3 = 3, + } + + public override RequestType RequestType + { + get { return RequestType.CopyRates; } + } + + public abstract CopyRatesTypeEnum CopyRatesType { get; } + + public string SymbolName { get; set; } + public ENUM_TIMEFRAMES Timeframe { get; set; } + } + + public class CopyRates1Request : CopyRatesRequestBase + { + public override CopyRatesTypeEnum CopyRatesType + { + get { return CopyRatesTypeEnum.CopyRates_1; } + } + + public int StartPos { get; set; } + public int Count { get; set; } + } + + public class CopyRates2Request : CopyRatesRequestBase + { + public override CopyRatesTypeEnum CopyRatesType + { + get { return CopyRatesTypeEnum.CopyRates_2; } + } + + public int StartTime { get; set; } + public int Count { get; set; } + } + + public class CopyRates3Request : CopyRatesRequestBase + { + public override CopyRatesTypeEnum CopyRatesType + { + get { return CopyRatesTypeEnum.CopyRates_3; } + } + + public int StartTime { get; set; } + public int StopTime { get; set; } + } +} diff --git a/MtApi/Requests/RequestType.cs b/MtApi/Requests/RequestType.cs index 457b1293..4097d2bb 100644 --- a/MtApi/Requests/RequestType.cs +++ b/MtApi/Requests/RequestType.cs @@ -10,6 +10,7 @@ OrderCloseBy = 5, OrderDelete = 6, OrderModify = 7, - iCustom = 8 + iCustom = 8, + CopyRates = 9 } } \ No newline at end of file diff --git a/MtApi/Responses/CopyRatesResponse.cs b/MtApi/Responses/CopyRatesResponse.cs new file mode 100644 index 00000000..e8e0c7e8 --- /dev/null +++ b/MtApi/Responses/CopyRatesResponse.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace MtApi.Responses +{ + public class CopyRatesResponse: ResponseBase + { + public List Rates { get; set; } + } +} diff --git a/TestClients/TestApiClientUI/Form1.Designer.cs b/TestClients/TestApiClientUI/Form1.Designer.cs index 28f5c1a1..2f424feb 100644 --- a/TestClients/TestApiClientUI/Form1.Designer.cs +++ b/TestClients/TestApiClientUI/Form1.Designer.cs @@ -114,6 +114,19 @@ this.button5 = new System.Windows.Forms.Button(); this.listBoxMarketInfo = new System.Windows.Forms.ListBox(); this.tabPage5 = new System.Windows.Forms.TabPage(); + this.dateTimePicker2 = new System.Windows.Forms.DateTimePicker(); + this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker(); + this.label6 = new System.Windows.Forms.Label(); + this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); + this.label27 = new System.Windows.Forms.Label(); + this.label7 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.comboBox3 = new System.Windows.Forms.ComboBox(); + this.label4 = new System.Windows.Forms.Label(); + this.button26 = new System.Windows.Forms.Button(); + this.button25 = new System.Windows.Forms.Button(); + this.button24 = new System.Windows.Forms.Button(); this.button12 = new System.Windows.Forms.Button(); this.button11 = new System.Windows.Forms.Button(); this.button10 = new System.Windows.Forms.Button(); @@ -131,6 +144,8 @@ this.tabPage7 = new System.Windows.Forms.TabPage(); this.button23 = new System.Windows.Forms.Button(); this.iCustomBtn = new System.Windows.Forms.Button(); + this.button27 = new System.Windows.Forms.Button(); + this.textBoxPrint = new System.Windows.Forms.TextBox(); this.groupBox1.SuspendLayout(); this.statusStrip1.SuspendLayout(); this.groupBox2.SuspendLayout(); @@ -142,6 +157,8 @@ this.tabPage3.SuspendLayout(); this.tabPage4.SuspendLayout(); this.tabPage5.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); this.tabPage6.SuspendLayout(); this.tabPage7.SuspendLayout(); this.SuspendLayout(); @@ -1082,6 +1099,19 @@ // // tabPage5 // + this.tabPage5.Controls.Add(this.dateTimePicker2); + this.tabPage5.Controls.Add(this.dateTimePicker1); + this.tabPage5.Controls.Add(this.label6); + this.tabPage5.Controls.Add(this.numericUpDown2); + this.tabPage5.Controls.Add(this.numericUpDown1); + this.tabPage5.Controls.Add(this.label27); + this.tabPage5.Controls.Add(this.label7); + this.tabPage5.Controls.Add(this.label5); + this.tabPage5.Controls.Add(this.comboBox3); + this.tabPage5.Controls.Add(this.label4); + this.tabPage5.Controls.Add(this.button26); + this.tabPage5.Controls.Add(this.button25); + this.tabPage5.Controls.Add(this.button24); this.tabPage5.Controls.Add(this.button12); this.tabPage5.Controls.Add(this.button11); this.tabPage5.Controls.Add(this.button10); @@ -1101,6 +1131,118 @@ this.tabPage5.Text = "Timeframes"; this.tabPage5.UseVisualStyleBackColor = true; // + // dateTimePicker2 + // + this.dateTimePicker2.Location = new System.Drawing.Point(324, 226); + this.dateTimePicker2.Name = "dateTimePicker2"; + this.dateTimePicker2.Size = new System.Drawing.Size(200, 20); + this.dateTimePicker2.TabIndex = 21; + // + // dateTimePicker1 + // + this.dateTimePicker1.Location = new System.Drawing.Point(324, 200); + this.dateTimePicker1.Name = "dateTimePicker1"; + this.dateTimePicker1.Size = new System.Drawing.Size(200, 20); + this.dateTimePicker1.TabIndex = 21; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(456, 178); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(35, 13); + this.label6.TabIndex = 20; + this.label6.Text = "Count"; + // + // numericUpDown2 + // + this.numericUpDown2.Location = new System.Drawing.Point(497, 176); + this.numericUpDown2.Name = "numericUpDown2"; + this.numericUpDown2.Size = new System.Drawing.Size(120, 20); + this.numericUpDown2.TabIndex = 19; + // + // numericUpDown1 + // + this.numericUpDown1.Location = new System.Drawing.Point(324, 175); + this.numericUpDown1.Name = "numericUpDown1"; + this.numericUpDown1.Size = new System.Drawing.Size(120, 20); + this.numericUpDown1.TabIndex = 19; + // + // label27 + // + this.label27.AutoSize = true; + this.label27.Location = new System.Drawing.Point(260, 232); + this.label27.Name = "label27"; + this.label27.Size = new System.Drawing.Size(52, 13); + this.label27.TabIndex = 17; + this.label27.Text = "StopTime"; + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(260, 202); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(52, 13); + this.label7.TabIndex = 17; + this.label7.Text = "StartTime"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(258, 178); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(47, 13); + this.label5.TabIndex = 17; + this.label5.Text = "StartPos"; + // + // comboBox3 + // + this.comboBox3.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBox3.FormattingEnabled = true; + this.comboBox3.Location = new System.Drawing.Point(324, 143); + this.comboBox3.Name = "comboBox3"; + this.comboBox3.Size = new System.Drawing.Size(121, 21); + this.comboBox3.TabIndex = 16; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(259, 146); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(59, 13); + this.label4.TabIndex = 15; + this.label4.Text = "TimeFrame"; + // + // button26 + // + this.button26.Location = new System.Drawing.Point(485, 252); + this.button26.Name = "button26"; + this.button26.Size = new System.Drawing.Size(93, 23); + this.button26.TabIndex = 14; + this.button26.Text = "CopyRates_3"; + this.button26.UseVisualStyleBackColor = true; + this.button26.Click += new System.EventHandler(this.button26_Click); + // + // button25 + // + this.button25.Location = new System.Drawing.Point(386, 252); + this.button25.Name = "button25"; + this.button25.Size = new System.Drawing.Size(93, 23); + this.button25.TabIndex = 14; + this.button25.Text = "CopyRates_2"; + this.button25.UseVisualStyleBackColor = true; + this.button25.Click += new System.EventHandler(this.button25_Click); + // + // button24 + // + this.button24.Location = new System.Drawing.Point(287, 252); + this.button24.Name = "button24"; + this.button24.Size = new System.Drawing.Size(93, 23); + this.button24.TabIndex = 14; + this.button24.Text = "CopyRates_1"; + this.button24.UseVisualStyleBackColor = true; + this.button24.Click += new System.EventHandler(this.button24_Click); + // // button12 // this.button12.Location = new System.Drawing.Point(141, 201); @@ -1171,7 +1313,7 @@ // label26 // this.label26.AutoSize = true; - this.label26.Location = new System.Drawing.Point(142, 22); + this.label26.Location = new System.Drawing.Point(271, 107); this.label26.Name = "label26"; this.label26.Size = new System.Drawing.Size(44, 13); this.label26.TabIndex = 6; @@ -1179,10 +1321,11 @@ // // textBoxSelectedSymbol // - this.textBoxSelectedSymbol.Location = new System.Drawing.Point(195, 16); + this.textBoxSelectedSymbol.Location = new System.Drawing.Point(324, 101); this.textBoxSelectedSymbol.Name = "textBoxSelectedSymbol"; this.textBoxSelectedSymbol.Size = new System.Drawing.Size(100, 20); this.textBoxSelectedSymbol.TabIndex = 5; + this.textBoxSelectedSymbol.Text = "EURUSD"; // // button6 // @@ -1204,6 +1347,8 @@ // // tabPage6 // + this.tabPage6.Controls.Add(this.textBoxPrint); + this.tabPage6.Controls.Add(this.button27); this.tabPage6.Controls.Add(this.button14); this.tabPage6.Controls.Add(this.button13); this.tabPage6.Location = new System.Drawing.Point(4, 22); @@ -1266,6 +1411,23 @@ this.iCustomBtn.UseVisualStyleBackColor = true; this.iCustomBtn.Click += new System.EventHandler(this.iCustomBtn_Click); // + // button27 + // + this.button27.Location = new System.Drawing.Point(601, 16); + this.button27.Name = "button27"; + this.button27.Size = new System.Drawing.Size(75, 23); + this.button27.TabIndex = 2; + this.button27.Text = "Print"; + this.button27.UseVisualStyleBackColor = true; + this.button27.Click += new System.EventHandler(this.button27_Click); + // + // textBoxPrint + // + this.textBoxPrint.Location = new System.Drawing.Point(209, 16); + this.textBoxPrint.Name = "textBoxPrint"; + this.textBoxPrint.Size = new System.Drawing.Size(386, 20); + this.textBoxPrint.TabIndex = 3; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -1299,7 +1461,10 @@ this.tabPage4.PerformLayout(); this.tabPage5.ResumeLayout(false); this.tabPage5.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); this.tabPage6.ResumeLayout(false); + this.tabPage6.PerformLayout(); this.tabPage7.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); @@ -1410,6 +1575,21 @@ private System.Windows.Forms.TabPage tabPage7; private System.Windows.Forms.Button iCustomBtn; private System.Windows.Forms.Button button23; + private System.Windows.Forms.Button button24; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.ComboBox comboBox3; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.NumericUpDown numericUpDown1; + private System.Windows.Forms.DateTimePicker dateTimePicker1; + private System.Windows.Forms.NumericUpDown numericUpDown2; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.DateTimePicker dateTimePicker2; + private System.Windows.Forms.Label label27; + private System.Windows.Forms.Button button26; + private System.Windows.Forms.Button button25; + private System.Windows.Forms.Button button27; + private System.Windows.Forms.TextBox textBoxPrint; } } diff --git a/TestClients/TestApiClientUI/Form1.cs b/TestClients/TestApiClientUI/Form1.cs index dc5817c7..f62aa984 100644 --- a/TestClients/TestApiClientUI/Form1.cs +++ b/TestClients/TestApiClientUI/Form1.cs @@ -17,6 +17,8 @@ namespace TestApiClientUI { InitializeComponent(); + comboBox3.DataSource = Enum.GetNames(typeof(ENUM_TIMEFRAMES)); + _apiClient.QuoteUpdated += apiClient_QuoteUpdated; _apiClient.QuoteAdded += apiClient_QuoteAdded; _apiClient.QuoteRemoved += apiClient_QuoteRemoved; @@ -85,26 +87,24 @@ namespace TestApiClientUI private void apiClient_QuoteRemoved(object sender, MtQuoteEventArgs e) { - RunOnUiThread(() => - { - RemoveQuote(e.Quote); - }); + RunOnUiThread(() => RemoveQuote(e.Quote) ); } private void apiClient_QuoteAdded(object sender, MtQuoteEventArgs e) { - RunOnUiThread(() => - { - AddNewQuote(e.Quote); - }); + RunOnUiThread(() => AddNewQuote(e.Quote)); } + private volatile bool IsUiQuoteUpdateReady = true; + private void apiClient_QuoteUpdated(object sender, string symbol, double bid, double ask) { - this.BeginInvoke((Action)(() => + Console.WriteLine("Quote: Symbol = {0}, Bid = {1}, Ask = {2}", symbol, bid, ask); + //if UI of quite is busy we are skipping this update + if (IsUiQuoteUpdateReady) { - ChangeQuote(symbol, bid, ask); - })); + RunOnUiThread(() => ChangeQuote(symbol, bid, ask)); + } } private void AddNewQuote(MtQuote quote) @@ -153,6 +153,7 @@ namespace TestApiClientUI private void ChangeQuote(string symbol, double bid, double ask) { + IsUiQuoteUpdateReady = false; if (string.IsNullOrEmpty(symbol) == false) { if (listViewQuotes.Items.ContainsKey(symbol) == true) @@ -162,6 +163,7 @@ namespace TestApiClientUI item.SubItems[2].Text = ask.ToString(); } } + IsUiQuoteUpdateReady = true; } private void OnConnected() @@ -1040,5 +1042,93 @@ namespace TestApiClientUI var retVal = await Execute(() => _apiClient.iCustom(symbol, (int)timeframe, name, parameters, mode, shift)); AddToLog(string.Format("ICustom result: {0}", retVal)); } + + private async void button24_Click(object sender, EventArgs e) + { + string symbol = textBoxSelectedSymbol.Text; + ENUM_TIMEFRAMES timeframes; + Enum.TryParse(comboBox3.SelectedValue.ToString(), out timeframes); + + int startPos = Convert.ToInt32(numericUpDown1.Value); + int count = Convert.ToInt32(numericUpDown2.Value); + + var rates = await Execute(() => _apiClient.CopyRates(symbol, timeframes, startPos, count)); + + if (rates != null) + { + foreach (var r in rates) + { + var result = string.Format("Rate: Time = {0}, Open = {1}, High = {2}, Low = {3}, Close = {4}, TickVolume = {5}, Spread = {6}, RealVolume = {7}", + r.Time, r.Open, r.High, r.Low, r.Close, r.TickVolume, r.Spread, r.RealVolume); + AddToLog(result); + } + } + else + { + AddToLog("CopyRates: 0 rates"); + } + } + + private async void button25_Click(object sender, EventArgs e) + { + string symbol = textBoxSelectedSymbol.Text; + ENUM_TIMEFRAMES timeframes; + Enum.TryParse(comboBox3.SelectedValue.ToString(), out timeframes); + + DateTime startTime = dateTimePicker1.Value; + int count = Convert.ToInt32(numericUpDown2.Value); + + var rates = await Execute(() => _apiClient.CopyRates(symbol, timeframes, startTime, count)); + + if (rates != null) + { + foreach (var r in rates) + { + var result = string.Format("Rate: Time = {0}, Open = {1}, High = {2}, Low = {3}, Close = {4}, TickVolume = {5}, Spread = {6}, RealVolume = {7}", + r.Time, r.Open, r.High, r.Low, r.Close, r.TickVolume, r.Spread, r.RealVolume); + AddToLog(result); + } + } + else + { + AddToLog("CopyRates: 0 rates"); + } + } + + private async void button26_Click(object sender, EventArgs e) + { + string symbol = textBoxSelectedSymbol.Text; + ENUM_TIMEFRAMES timeframes; + Enum.TryParse(comboBox3.SelectedValue.ToString(), out timeframes); + + DateTime startTime = dateTimePicker1.Value; + DateTime stopTime = dateTimePicker1.Value; + + var rates = await Execute(() => _apiClient.CopyRates(symbol, timeframes, startTime, stopTime)); + + if (rates != null) + { + foreach (var r in rates) + { + var result = string.Format("Rate: Time = {0}, Open = {1}, High = {2}, Low = {3}, Close = {4}, TickVolume = {5}, Spread = {6}, RealVolume = {7}", + r.Time, r.Open, r.High, r.Low, r.Close, r.TickVolume, r.Spread, r.RealVolume); + AddToLog(result); + } + } + else + { + AddToLog("CopyRates: 0 rates"); + } + } + + private void button27_Click(object sender, EventArgs e) + { + var msg = textBoxPrint.Text; + if (!string.IsNullOrEmpty(msg)) + { + _apiClient.Print(msg); + AddToLog(string.Format("Print executed")); + } + } } } diff --git a/TestClients/TestApiClientUI/TestApiClientUI.csproj b/TestClients/TestApiClientUI/TestApiClientUI.csproj index 5286c295..6ec38586 100644 --- a/TestClients/TestApiClientUI/TestApiClientUI.csproj +++ b/TestClients/TestApiClientUI/TestApiClientUI.csproj @@ -86,10 +86,6 @@ false - - False - C:\Program Files (x86)\MtApi\MtApi.dll - False C:\Program Files (x86)\MtApi\Newtonsoft.Json.dll @@ -160,6 +156,12 @@ true + + + {7a76c388-a8fb-4949-8170-24d4742e934e} + MtApi + +