mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-13 02:38:07 +00:00
Merge branch 'dev'
This commit is contained in:
@@ -4,15 +4,17 @@ namespace MtApi5
|
||||
{
|
||||
public class Mt5TimeBarArgs: EventArgs
|
||||
{
|
||||
internal Mt5TimeBarArgs(int expertHandle, string symbol, MqlRates rates)
|
||||
internal Mt5TimeBarArgs(int expertHandle, string symbol, ENUM_TIMEFRAMES timeframe, MqlRates rates)
|
||||
{
|
||||
ExpertHandle = expertHandle;
|
||||
Rates = rates;
|
||||
Symbol = symbol;
|
||||
Timeframe = timeframe;
|
||||
}
|
||||
|
||||
public int ExpertHandle { get; }
|
||||
public string Symbol { get; }
|
||||
public ENUM_TIMEFRAMES Timeframe { get; }
|
||||
public MqlRates Rates { get; }
|
||||
}
|
||||
}
|
||||
|
||||
+15
-2
@@ -32,11 +32,24 @@ namespace MtApi5
|
||||
|
||||
private HashSet<int> _experts = [];
|
||||
private Dictionary<int, Mt5Quote> _quotes = [];
|
||||
private volatile int _command_timeout = 30000; // 30 seconds
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
private IMtLogger Log { get; }
|
||||
|
||||
// Time in milliseconds to wait for a response from MetaTrader for a command. Default is 30 seconds.
|
||||
public int CommandTimeout
|
||||
{
|
||||
get => _command_timeout;
|
||||
set
|
||||
{
|
||||
if (value <= 0)
|
||||
throw new ArgumentException("Command timeout must be greater than zero.");
|
||||
_command_timeout = value;
|
||||
}
|
||||
}
|
||||
|
||||
public MtApi5Client(IMtLogger? log = null)
|
||||
{
|
||||
_mtEventHandlers[Mt5EventTypes.OnBookEvent] = ReceivedOnBookEvent;
|
||||
@@ -3533,7 +3546,7 @@ namespace MtApi5
|
||||
var e = JsonConvert.DeserializeObject<OnLastTimeBarEvent>(payload);
|
||||
if (e == null || string.IsNullOrEmpty(e.Instrument) || e.Rates == null)
|
||||
return;
|
||||
OnLastTimeBar?.Invoke(this, new Mt5TimeBarArgs(expertHandle, e.Instrument, e.Rates));
|
||||
OnLastTimeBar?.Invoke(this, new Mt5TimeBarArgs(expertHandle, e.Instrument, e.Timeframe, e.Rates));
|
||||
}
|
||||
|
||||
private void ReceivedOnLockTicksEvent(int expertHandle, string payload)
|
||||
@@ -3588,7 +3601,7 @@ namespace MtApi5
|
||||
var payloadJson = payload == null ? string.Empty : JsonConvert.SerializeObject(payload);
|
||||
Log.Debug($"SendCommand: sending '{payloadJson}' ...");
|
||||
|
||||
var responseJson = client.SendCommand(expertHandle, (int)commandType, payloadJson);
|
||||
var responseJson = client.SendCommand(expertHandle, (int)commandType, payloadJson, CommandTimeout);
|
||||
|
||||
Log.Debug($"SendCommand: received response JSON [{responseJson}]");
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
{
|
||||
public MqlRates? Rates { get; set; }
|
||||
public string? Instrument { get; set; }
|
||||
public ENUM_TIMEFRAMES Timeframe { get; set; }
|
||||
public int ExpertHandle { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user