mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-20 06:13:09 +00:00
Updated documentation of newly added classes
This commit is contained in:
@@ -10,8 +10,13 @@ namespace MtApi.Monitors
|
|||||||
Opened = opened;
|
Opened = opened;
|
||||||
Closed = closed;
|
Closed = closed;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Contains all newly opened orders since the last time the monitor checked the open orders.
|
||||||
|
/// </summary>
|
||||||
public List<MtOrder> Opened { get; private set; }
|
public List<MtOrder> Opened { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Contains all newly closed orders since the last time the monitor checked the open orders.
|
||||||
|
/// </summary>
|
||||||
public List<MtOrder> Closed { get; private set; }
|
public List<MtOrder> Closed { get; private set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,11 @@ namespace MtApi.Monitors
|
|||||||
{
|
{
|
||||||
public class TimeframeTradeMonitor : TradeMonitor
|
public class TimeframeTradeMonitor : TradeMonitor
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor for initializing a new instance with a trigger instance of <see cref="NewBarTrigger"/>.
|
||||||
|
/// <para>SyncTrigger is set to true by default</para>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiClient">The <see cref="MtApiClient"/> which will be used to communicate with MetaTrader.</param>
|
||||||
public TimeframeTradeMonitor(MtApiClient apiClient)
|
public TimeframeTradeMonitor(MtApiClient apiClient)
|
||||||
: base(apiClient, new NewBarTrigger(apiClient))
|
: base(apiClient, new NewBarTrigger(apiClient))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,22 +5,43 @@ namespace MtApi.Monitors
|
|||||||
{
|
{
|
||||||
public class TimerTradeMonitor : TradeMonitor
|
public class TimerTradeMonitor : TradeMonitor
|
||||||
{
|
{
|
||||||
|
#region Fields
|
||||||
private readonly TimeElapsedTrigger _timeElapsedTrigger;
|
private readonly TimeElapsedTrigger _timeElapsedTrigger;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
/// <summary>
|
||||||
|
/// Interval for raising the trigger
|
||||||
|
/// </summary>
|
||||||
public double Interval
|
public double Interval
|
||||||
{
|
{
|
||||||
get => _timeElapsedTrigger.Interval.TotalMilliseconds;
|
get => _timeElapsedTrigger.Interval.TotalMilliseconds;
|
||||||
set => _timeElapsedTrigger.Interval = TimeSpan.FromMilliseconds(value);
|
set => _timeElapsedTrigger.Interval = TimeSpan.FromMilliseconds(value);
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ctors
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor for initializing a new instance with a default <see cref="Interval"/> of 10 seconds.
|
||||||
|
/// <para>SyncTrigger is set to true by default</para>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiClient">The <see cref="MtApiClient"/> which will be used to communicate with MetaTrader.</param>
|
||||||
public TimerTradeMonitor(MtApiClient apiClient)
|
public TimerTradeMonitor(MtApiClient apiClient)
|
||||||
: this(apiClient, new TimeElapsedTrigger(TimeSpan.FromSeconds(10)))
|
: this(apiClient, new TimeElapsedTrigger(TimeSpan.FromSeconds(10)))
|
||||||
{
|
{
|
||||||
SyncTrigger = true; //Sync-Trigger set to true, to have the same behavior as before
|
SyncTrigger = true; //Sync-Trigger set to true, to have the same behavior as before
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor for initializing a new instance with a custom instance of <see cref="TimeElapsedTrigger"/>.
|
||||||
|
/// <para>SyncTrigger is set to false by default</para>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiClient">The <see cref="MtApiClient"/> which will be used to communicate with MetaTrader.</param>
|
||||||
|
/// <param name="timeElapsedTrigger">The custom instance of <see cref="TimeElapsedTrigger"/> which will be used to trigger this instance of <see cref="TradeMonitor"/>.</param>
|
||||||
public TimerTradeMonitor(MtApiClient apiClient, TimeElapsedTrigger timeElapsedTrigger)
|
public TimerTradeMonitor(MtApiClient apiClient, TimeElapsedTrigger timeElapsedTrigger)
|
||||||
: base(apiClient, timeElapsedTrigger)
|
: base(apiClient, timeElapsedTrigger)
|
||||||
{
|
{
|
||||||
_timeElapsedTrigger = timeElapsedTrigger;
|
_timeElapsedTrigger = timeElapsedTrigger;
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,11 @@ namespace MtApi.Monitors
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ctor
|
#region ctor
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor for initializing an instance of <see cref="TradeMonitor"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiClient">The <see cref="MtApiClient"/> which will be used to communicate with MetaTrader.</param>
|
||||||
|
/// <param name="monitorTrigger">The custom instance of <see cref="IMonitorTrigger"/> which will be used to trigger this instance of <see cref="TradeMonitor"/>.</param>
|
||||||
public TradeMonitor(MtApiClient apiClient, IMonitorTrigger monitorTrigger) : base(apiClient, monitorTrigger) { }
|
public TradeMonitor(MtApiClient apiClient, IMonitorTrigger monitorTrigger) : base(apiClient, monitorTrigger) { }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -12,22 +12,46 @@ namespace MtApi.Monitors.Triggers
|
|||||||
private readonly MtApiClient _apiClient;
|
private readonly MtApiClient _apiClient;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if the trigger is started, otherwise false
|
||||||
|
/// </summary>
|
||||||
public bool IsStarted => _isStarted;
|
public bool IsStarted => _isStarted;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Events
|
||||||
|
/// <summary>
|
||||||
|
/// Event will be called if the trigger raised.
|
||||||
|
/// </summary>
|
||||||
public event EventHandler Raised;
|
public event EventHandler Raised;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ctor
|
||||||
public NewBarTrigger(MtApiClient apiClient)
|
public NewBarTrigger(MtApiClient apiClient)
|
||||||
{
|
{
|
||||||
_apiClient = apiClient;
|
_apiClient = apiClient;
|
||||||
_apiClient.OnLastTimeBar += _apiClient_OnLastTimeBar;
|
_apiClient.OnLastTimeBar += _apiClient_OnLastTimeBar;
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public methods
|
||||||
|
/// <summary>
|
||||||
|
/// Starts the trigger
|
||||||
|
/// </summary>
|
||||||
|
public void Start() => SetIsStarted(true);
|
||||||
|
/// <summary>
|
||||||
|
/// Stops the trigger
|
||||||
|
/// </summary>
|
||||||
|
public void Stop() => SetIsStarted(false);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Private methods
|
||||||
private void _apiClient_OnLastTimeBar(object sender, TimeBarArgs e)
|
private void _apiClient_OnLastTimeBar(object sender, TimeBarArgs e)
|
||||||
{
|
{
|
||||||
if (_isStarted)
|
if (_isStarted)
|
||||||
Raised?.Invoke(this, EventArgs.Empty);
|
Raised?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start() => SetIsStarted(true);
|
|
||||||
public void Stop() => SetIsStarted(false);
|
|
||||||
private void SetIsStarted(bool value)
|
private void SetIsStarted(bool value)
|
||||||
{
|
{
|
||||||
if (value != _isStarted)
|
if (value != _isStarted)
|
||||||
@@ -39,5 +63,6 @@ namespace MtApi.Monitors.Triggers
|
|||||||
_apiClient.OnLastTimeBar -= _apiClient_OnLastTimeBar;
|
_apiClient.OnLastTimeBar -= _apiClient_OnLastTimeBar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ namespace MtApi.Monitors.Triggers
|
|||||||
{
|
{
|
||||||
public class TimeElapsedTrigger : IMonitorTrigger
|
public class TimeElapsedTrigger : IMonitorTrigger
|
||||||
{
|
{
|
||||||
|
#region Fields
|
||||||
readonly Timer _timer;
|
readonly Timer _timer;
|
||||||
|
#endregion
|
||||||
|
|
||||||
public event EventHandler Raised;
|
#region Properties
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interval for raising the trigger
|
/// Interval for raising the trigger
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -16,25 +18,57 @@ namespace MtApi.Monitors.Triggers
|
|||||||
get => TimeSpan.FromMilliseconds(_timer.Interval);
|
get => TimeSpan.FromMilliseconds(_timer.Interval);
|
||||||
set => _timer.Interval = value.TotalMilliseconds;
|
set => _timer.Interval = value.TotalMilliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if the trigger is started, otherwise false
|
||||||
|
/// </summary>
|
||||||
public bool IsStarted => _timer.Enabled;
|
public bool IsStarted => _timer.Enabled;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If true, the trigger will raise continuosly after elapsed <see cref="Interval"/>, otherwise the trigger will raise only once after elapsed <see cref="Interval"/>.
|
||||||
|
/// </summary>
|
||||||
public bool AutoReset { get => _timer.AutoReset; set => _timer.AutoReset = value; }
|
public bool AutoReset { get => _timer.AutoReset; set => _timer.AutoReset = value; }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Events
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if the trigger is started, otherwise false
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler Raised;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ctor
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor for initializing TimeElapsedTrigger
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="time">Defines the interval for raising the event.</param>
|
||||||
|
/// <param name="autoReset">If true, the trigger will raise continuosly after elapsed <see cref="Interval"/>, otherwise the trigger will raise only once after elapsed <see cref="Interval"/>.</param>
|
||||||
public TimeElapsedTrigger(TimeSpan time, bool autoReset = true)
|
public TimeElapsedTrigger(TimeSpan time, bool autoReset = true)
|
||||||
{
|
{
|
||||||
_timer = new Timer(time.TotalMilliseconds);
|
_timer = new Timer(time.TotalMilliseconds);
|
||||||
_timer.Elapsed += _timer_Elapsed;
|
_timer.Elapsed += _timer_Elapsed;
|
||||||
AutoReset = autoReset;
|
AutoReset = autoReset;
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public methods
|
||||||
|
/// <summary>
|
||||||
|
/// Starts the trigger
|
||||||
|
/// </summary>
|
||||||
|
public void Start() => _timer.Start();
|
||||||
|
/// <summary>
|
||||||
|
/// Stops the trigger
|
||||||
|
/// </summary>
|
||||||
|
public void Stop() => _timer.Stop();
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region private methods
|
||||||
private void _timer_Elapsed(object sender, ElapsedEventArgs e)
|
private void _timer_Elapsed(object sender, ElapsedEventArgs e)
|
||||||
{
|
{
|
||||||
_timer.Elapsed -= _timer_Elapsed;
|
_timer.Elapsed -= _timer_Elapsed;
|
||||||
Raised?.Invoke(this, EventArgs.Empty);
|
Raised?.Invoke(this, EventArgs.Empty);
|
||||||
_timer.Elapsed += _timer_Elapsed;
|
_timer.Elapsed += _timer_Elapsed;
|
||||||
}
|
}
|
||||||
public void Stop() => _timer.Stop();
|
#endregion
|
||||||
|
|
||||||
public void Start() => _timer.Start();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user