mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-15 11:48:09 +00:00
@@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace MtApi
|
||||||
|
{
|
||||||
|
public class ChartEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
internal ChartEventArgs(int expertHandle, MtChartEvent chartEvent)
|
||||||
|
{
|
||||||
|
ExpertHandle = expertHandle;
|
||||||
|
ChartId = chartEvent.ChartId;
|
||||||
|
EventId = chartEvent.EventId;
|
||||||
|
Lparam = chartEvent.Lparam;
|
||||||
|
Dparam = chartEvent.Dparam;
|
||||||
|
Sparam = chartEvent.Sparam;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ExpertHandle { get; }
|
||||||
|
public long ChartId { get; }
|
||||||
|
public int EventId { get; }
|
||||||
|
public long Lparam { get; }
|
||||||
|
public double Dparam { get; }
|
||||||
|
public string Sparam { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
namespace MtApi
|
||||||
|
{
|
||||||
|
public enum EnumChartEvent
|
||||||
|
{
|
||||||
|
CHARTEVENT_KEYDOWN = 0,
|
||||||
|
CHARTEVENT_MOUSE_MOVE = 10,
|
||||||
|
CHARTEVENT_OBJECT_CREATE = 7,
|
||||||
|
CHARTEVENT_OBJECT_CHANGE = 8,
|
||||||
|
CHARTEVENT_OBJECT_DELETE = 6,
|
||||||
|
CHARTEVENT_CLICK = 4,
|
||||||
|
CHARTEVENT_OBJECT_CLICK = 1,
|
||||||
|
CHARTEVENT_OBJECT_DRAG = 2,
|
||||||
|
CHARTEVENT_OBJECT_ENDEDIT = 3,
|
||||||
|
CHARTEVENT_CHART_CHANGE = 9,
|
||||||
|
CHARTEVENT_CUSTOM = 1000,
|
||||||
|
CHARTEVENT_CUSTOM_LAST = 66534
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -58,6 +58,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="ChartEventArgs.cs" />
|
||||||
<Compile Include="ChartPeriod.cs" />
|
<Compile Include="ChartPeriod.cs" />
|
||||||
<Compile Include="EnumAlignMode.cs" />
|
<Compile Include="EnumAlignMode.cs" />
|
||||||
<Compile Include="EnumChartPropertyDouble.cs" />
|
<Compile Include="EnumChartPropertyDouble.cs" />
|
||||||
@@ -77,6 +78,7 @@
|
|||||||
<Compile Include="Monitors\AvailabilityOrdersEventArgs.cs" />
|
<Compile Include="Monitors\AvailabilityOrdersEventArgs.cs" />
|
||||||
<Compile Include="MqlRates.cs" />
|
<Compile Include="MqlRates.cs" />
|
||||||
<Compile Include="MqlTick.cs" />
|
<Compile Include="MqlTick.cs" />
|
||||||
|
<Compile Include="MtChartEvent.cs" />
|
||||||
<Compile Include="MtConnectionEventArgs.cs" />
|
<Compile Include="MtConnectionEventArgs.cs" />
|
||||||
<Compile Include="MtConnectionException.cs" />
|
<Compile Include="MtConnectionException.cs" />
|
||||||
<Compile Include="MtConnectionState.cs" />
|
<Compile Include="MtConnectionState.cs" />
|
||||||
|
|||||||
+12
-5
@@ -3068,18 +3068,24 @@ namespace MtApi
|
|||||||
switch(eventType)
|
switch(eventType)
|
||||||
{
|
{
|
||||||
case MtEventTypes.LastTimeBar:
|
case MtEventTypes.LastTimeBar:
|
||||||
{
|
FireOnLastTimeBar(e.ExpertHandle, JsonConvert.DeserializeObject<MtTimeBar>(e.Payload));
|
||||||
FireOnLastTimeBar(JsonConvert.DeserializeObject<MtTimeBar>(e.Payload));
|
break;
|
||||||
}
|
case MtEventTypes.ChartEvent:
|
||||||
|
FireOnChartEvent(e.ExpertHandle, JsonConvert.DeserializeObject<MtChartEvent>(e.Payload));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FireOnLastTimeBar(MtTimeBar timeBar)
|
private void FireOnLastTimeBar(int expertHandler, MtTimeBar timeBar)
|
||||||
{
|
{
|
||||||
OnLastTimeBar?.Invoke(this, new TimeBarArgs(timeBar));
|
OnLastTimeBar?.Invoke(this, new TimeBarArgs(expertHandler, timeBar));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FireOnChartEvent(int expertHandler, MtChartEvent chartEvent)
|
||||||
|
{
|
||||||
|
OnChartEvent?.Invoke(this, new ChartEventArgs(expertHandler, chartEvent));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BacktestingReady()
|
private void BacktestingReady()
|
||||||
@@ -3097,6 +3103,7 @@ namespace MtApi
|
|||||||
public event EventHandler<MtQuoteEventArgs> QuoteRemoved;
|
public event EventHandler<MtQuoteEventArgs> QuoteRemoved;
|
||||||
public event EventHandler<MtConnectionEventArgs> ConnectionStateChanged;
|
public event EventHandler<MtConnectionEventArgs> ConnectionStateChanged;
|
||||||
public event EventHandler<TimeBarArgs> OnLastTimeBar;
|
public event EventHandler<TimeBarArgs> OnLastTimeBar;
|
||||||
|
public event EventHandler<ChartEventArgs> OnChartEvent;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace MtApi
|
||||||
|
{
|
||||||
|
internal class MtChartEvent
|
||||||
|
{
|
||||||
|
public long ChartId { get; set; }
|
||||||
|
public int EventId { get; set; }
|
||||||
|
public long Lparam { get; set; }
|
||||||
|
public double Dparam { get; set; }
|
||||||
|
public string Sparam { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
{
|
{
|
||||||
public enum MtEventTypes
|
public enum MtEventTypes
|
||||||
{
|
{
|
||||||
LastTimeBar = 1
|
LastTimeBar = 1,
|
||||||
|
ChartEvent = 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-11
@@ -11,16 +11,7 @@ namespace MtApi
|
|||||||
public double Close { get; set; }
|
public double Close { get; set; }
|
||||||
public double High { get; set; }
|
public double High { get; set; }
|
||||||
public double Low { get; set; }
|
public double Low { get; set; }
|
||||||
|
public DateTime OpenTime => MtApiTimeConverter.ConvertFromMtTime(MtOpenTime);
|
||||||
public DateTime OpenTime
|
public DateTime CloseTime => MtApiTimeConverter.ConvertFromMtTime(MtCloseTime);
|
||||||
{
|
|
||||||
get { return MtApiTimeConverter.ConvertFromMtTime(MtOpenTime); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public DateTime CloseTime
|
|
||||||
{
|
|
||||||
get { return MtApiTimeConverter.ConvertFromMtTime(MtCloseTime); }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.37.0")]
|
[assembly: AssemblyVersion("1.0.38.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.37.0")]
|
[assembly: AssemblyFileVersion("1.0.38.0")]
|
||||||
@@ -4,11 +4,18 @@ namespace MtApi
|
|||||||
{
|
{
|
||||||
public class TimeBarArgs: EventArgs
|
public class TimeBarArgs: EventArgs
|
||||||
{
|
{
|
||||||
|
internal TimeBarArgs(int expertHandle, MtTimeBar timeBar)
|
||||||
|
: this(timeBar)
|
||||||
|
{
|
||||||
|
ExpertHandle = expertHandle;
|
||||||
|
}
|
||||||
|
|
||||||
public TimeBarArgs(MtTimeBar timeBar)
|
public TimeBarArgs(MtTimeBar timeBar)
|
||||||
{
|
{
|
||||||
TimeBar = timeBar;
|
TimeBar = timeBar;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MtTimeBar TimeBar { get; private set; }
|
public int ExpertHandle { get; }
|
||||||
|
public MtTimeBar TimeBar { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,5 +114,7 @@ namespace MtApi5
|
|||||||
|
|
||||||
//Requests
|
//Requests
|
||||||
MtRequest = 155,
|
MtRequest = 155,
|
||||||
|
|
||||||
|
PositionSelectByTicket = 69
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -223,6 +223,17 @@ namespace MtApi5
|
|||||||
return SendCommand<bool>(Mt5CommandType.PositionSelect, commandParameters);
|
return SendCommand<bool>(Mt5CommandType.PositionSelect, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
///Selects an open position to work with based on the ticket number specified in the position. If successful, returns true. Returns false if the function failed.
|
||||||
|
///</summary>
|
||||||
|
///<param name="ticket">Position ticket.</param>
|
||||||
|
public bool PositionSelectByTicket(ulong ticket)
|
||||||
|
{
|
||||||
|
var commandParameters = new ArrayList { ticket };
|
||||||
|
|
||||||
|
return SendCommand<bool>(Mt5CommandType.PositionSelectByTicket, commandParameters);
|
||||||
|
}
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
///The function returns the requested property of an open position, pre-selected using PositionGetSymbol or PositionSelect.
|
///The function returns the requested property of an open position, pre-selected using PositionGetSymbol or PositionSelect.
|
||||||
///</summary>
|
///</summary>
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ namespace TestApiClientUI
|
|||||||
_apiClient.QuoteRemoved += apiClient_QuoteRemoved;
|
_apiClient.QuoteRemoved += apiClient_QuoteRemoved;
|
||||||
_apiClient.ConnectionStateChanged += apiClient_ConnectionStateChanged;
|
_apiClient.ConnectionStateChanged += apiClient_ConnectionStateChanged;
|
||||||
_apiClient.OnLastTimeBar += _apiClient_OnLastTimeBar;
|
_apiClient.OnLastTimeBar += _apiClient_OnLastTimeBar;
|
||||||
|
_apiClient.OnChartEvent += _apiClient_OnChartEvent;
|
||||||
|
|
||||||
InitOrderCommandsGroup();
|
InitOrderCommandsGroup();
|
||||||
|
|
||||||
@@ -134,7 +135,15 @@ namespace TestApiClientUI
|
|||||||
private void _apiClient_OnLastTimeBar(object sender, TimeBarArgs e)
|
private void _apiClient_OnLastTimeBar(object sender, TimeBarArgs e)
|
||||||
{
|
{
|
||||||
var msg =
|
var msg =
|
||||||
$"TimeBar: Symbol = {e.TimeBar.Symbol}, OpenTime = {e.TimeBar.OpenTime}, CloseTime = {e.TimeBar.CloseTime}, Open = {e.TimeBar.Open}, Close = {e.TimeBar.Close}, High = {e.TimeBar.High}, Low = {e.TimeBar.Low}";
|
$"TimeBar: ExpertHandle = {e.ExpertHandle}, Symbol = {e.TimeBar.Symbol}, OpenTime = {e.TimeBar.OpenTime}, CloseTime = {e.TimeBar.CloseTime}, Open = {e.TimeBar.Open}, Close = {e.TimeBar.Close}, High = {e.TimeBar.High}, Low = {e.TimeBar.Low}";
|
||||||
|
Console.WriteLine(msg);
|
||||||
|
PrintLog(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void _apiClient_OnChartEvent(object sender, ChartEventArgs e)
|
||||||
|
{
|
||||||
|
var msg =
|
||||||
|
$"OnChartEvent: ExpertHandle = {e.ExpertHandle}, ChartId = {e.ChartId}, EventId = {e.EventId}, Lparam = {e.Lparam}, Dparam = {e.Dparam}, Sparam = {e.Sparam}";
|
||||||
Console.WriteLine(msg);
|
Console.WriteLine(msg);
|
||||||
PrintLog(msg);
|
PrintLog(msg);
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
+16
-5
@@ -1719,15 +1719,19 @@ int executeCommand()
|
|||||||
|
|
||||||
case 68: //Print
|
case 68: //Print
|
||||||
{
|
{
|
||||||
string printMsg;
|
string printMsg;
|
||||||
StringInit(printMsg, 1000, 0);
|
StringInit(printMsg, 1000, 0);
|
||||||
|
|
||||||
getStringValue(ExpertHandle, 0, printMsg);
|
getStringValue(ExpertHandle, 0, printMsg);
|
||||||
|
|
||||||
Print(printMsg);
|
Print(printMsg);
|
||||||
sendBooleanResponse(ExpertHandle, true);
|
sendBooleanResponse(ExpertHandle, true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 69: //PositionSelectByTicket
|
||||||
|
Execute_PositionSelectByTicket();
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Print("Unknown command type = ", commandType);
|
Print("Unknown command type = ", commandType);
|
||||||
@@ -1738,6 +1742,13 @@ int executeCommand()
|
|||||||
return (commandType);
|
return (commandType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Execute_PositionSelectByTicket()
|
||||||
|
{
|
||||||
|
ulong ticket;
|
||||||
|
getULongValue(ExpertHandle, 0, ticket);
|
||||||
|
sendBooleanResponse(ExpertHandle, PositionSelectByTicket(ticket));
|
||||||
|
}
|
||||||
|
|
||||||
void PrintParamError(string paramName)
|
void PrintParamError(string paramName)
|
||||||
{
|
{
|
||||||
Print("[ERROR] parameter: ", paramName);
|
Print("[ERROR] parameter: ", paramName);
|
||||||
|
|||||||
Reference in New Issue
Block a user