Changed design of monitors for better extensibility

This commit is contained in:
m.bochmann
2020-10-13 15:10:26 +02:00
parent 9a5acac2db
commit a12ddba765
9 changed files with 283 additions and 245 deletions
+6 -49
View File
@@ -1,56 +1,13 @@
using MtApi.Monitors.Triggers;
namespace MtApi.Monitors
{
public class TimeframeTradeMonitor : TradeMonitor
{
#region Fields
private volatile bool _isStarted;
#endregion
#region ctor
public TimeframeTradeMonitor(MtApiClient apiClient)
: base(apiClient)
public TimeframeTradeMonitor(MtApiClient apiClient)
: base(apiClient, new NewBarTrigger(apiClient))
{
apiClient.OnLastTimeBar += ApiClient_OnLastTimeBar;
SyncTrigger = true; //Sync-Trigger set to true, to have the same behavior as before
}
#endregion
#region Public Methods
//
// Summary:
// Gets a value indicating whether the TimeframeTradeMonitor should raise checking orders
//
// Returns:
// true if PositionMonitor should check orders
// otherwise, false.
public override bool IsStarted => _isStarted;
#endregion
#region Protected Methods
protected override void OnMtConnected() {}
protected override void OnMtDisconnected() {}
protected override void OnStart()
{
_isStarted = true;
}
protected override void OnStop()
{
_isStarted = false;
}
#endregion
#region Private Methods
private void ApiClient_OnLastTimeBar(object sender, TimeBarArgs e)
{
if (_isStarted)
{
Check();
}
}
#endregion
}
}
}