mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-07-28 02:57:56 +00:00
Added function CopyRates. Implemented Backtesting
This commit is contained in:
@@ -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<T>(this EventHandler<T> 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;
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="ChartPeriod.cs" />
|
||||
<Compile Include="ExtensionMethods.cs" />
|
||||
<Compile Include="MqlRates.cs" />
|
||||
<Compile Include="MtConnectionEventArgs.cs" />
|
||||
<Compile Include="MtConnectionException.cs" />
|
||||
<Compile Include="MtConnectionState.cs" />
|
||||
@@ -76,6 +77,7 @@
|
||||
<Compile Include="MtApiColorConverter.cs" />
|
||||
<Compile Include="OrderSelectMode.cs" />
|
||||
<Compile Include="OrderSelectSource.cs" />
|
||||
<Compile Include="Requests\CopyRatesRequest.cs" />
|
||||
<Compile Include="Requests\GetOrderRequest.cs" />
|
||||
<Compile Include="Requests\GetOrdersRequest.cs" />
|
||||
<Compile Include="Requests\ICustomRequest.cs" />
|
||||
@@ -86,6 +88,7 @@
|
||||
<Compile Include="Requests\OrderSendRequest.cs" />
|
||||
<Compile Include="Requests\RequestBase.cs" />
|
||||
<Compile Include="Requests\RequestType.cs" />
|
||||
<Compile Include="Responses\CopyRatesResponse.cs" />
|
||||
<Compile Include="Responses\GetOrderResponse.cs" />
|
||||
<Compile Include="Responses\GetOrdersResponse.cs" />
|
||||
<Compile Include="Responses\ICustomResponse.cs" />
|
||||
|
||||
+68
-8
@@ -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<bool>(MtCommandType.RefreshRates, null);
|
||||
}
|
||||
|
||||
public List<MqlRates> CopyRates(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count)
|
||||
{
|
||||
var response = SendRequest<CopyRatesResponse>(new CopyRates1Request
|
||||
{
|
||||
SymbolName = symbol_name,
|
||||
Timeframe = timeframe,
|
||||
StartPos = start_pos,
|
||||
Count = count
|
||||
});
|
||||
return response != null ? response.Rates : null;
|
||||
}
|
||||
|
||||
public List<MqlRates> CopyRates(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, int count)
|
||||
{
|
||||
var response = SendRequest<CopyRatesResponse>(new CopyRates2Request
|
||||
{
|
||||
SymbolName = symbol_name,
|
||||
Timeframe = timeframe,
|
||||
StartTime = MtApiTimeConverter.ConvertToMtTime(start_time),
|
||||
Count = count
|
||||
});
|
||||
return response != null ? response.Rates : null;
|
||||
}
|
||||
|
||||
public List<MqlRates> CopyRates(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, DateTime stop_time)
|
||||
{
|
||||
var response = SendRequest<CopyRatesResponse>(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<object>(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
|
||||
|
||||
|
||||
@@ -192,6 +192,9 @@ namespace MtApi
|
||||
SymbolInfoString = 154,
|
||||
|
||||
//Requests
|
||||
MtRequest = 155
|
||||
MtRequest = 155,
|
||||
|
||||
//Backtesting
|
||||
BacktestingReady = 156
|
||||
}
|
||||
}
|
||||
|
||||
+27
-10
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
OrderCloseBy = 5,
|
||||
OrderDelete = 6,
|
||||
OrderModify = 7,
|
||||
iCustom = 8
|
||||
iCustom = 8,
|
||||
CopyRates = 9
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MtApi.Responses
|
||||
{
|
||||
public class CopyRatesResponse: ResponseBase
|
||||
{
|
||||
public List<MqlRates> Rates { get; set; }
|
||||
}
|
||||
}
|
||||
+182
-2
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<ENUM_TIMEFRAMES>(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<ENUM_TIMEFRAMES>(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<ENUM_TIMEFRAMES>(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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,10 +86,6 @@
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MtApi, Version=1.0.27.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>C:\Program Files (x86)\MtApi\MtApi.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>C:\Program Files (x86)\MtApi\Newtonsoft.Json.dll</HintPath>
|
||||
@@ -160,6 +156,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.CSharp.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.
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user