mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-13 02:38:07 +00:00
MtApi5: Moving some functions to new core
This commit is contained in:
@@ -1,11 +0,0 @@
|
|||||||
namespace MtApi5.Events
|
|
||||||
{
|
|
||||||
internal enum Mt5EventTypes
|
|
||||||
{
|
|
||||||
OnTradeTransaction = 1,
|
|
||||||
OnBookEvent = 2,
|
|
||||||
OnTick = 3,
|
|
||||||
OnLastTimeBar = 4,
|
|
||||||
OnLockTicks = 5
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,7 @@
|
|||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
public class ExecutionException: Exception
|
public class ExecutionException(ErrorCode errorCode, string? message) : Exception(message)
|
||||||
{
|
{
|
||||||
public ExecutionException(ErrorCode errorCode, string? message)
|
public ErrorCode ErrorCode { get; private set; } = errorCode;
|
||||||
:base(message)
|
|
||||||
{
|
|
||||||
ErrorCode = errorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ErrorCode ErrorCode { get; private set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,261 +0,0 @@
|
|||||||
// ReSharper disable InconsistentNaming
|
|
||||||
namespace MtApi5
|
|
||||||
{
|
|
||||||
internal enum Mt5CommandType
|
|
||||||
{
|
|
||||||
//NoCommand = 0
|
|
||||||
|
|
||||||
//trade operations
|
|
||||||
//OrderSend = 1,
|
|
||||||
GetQuote = 1,
|
|
||||||
OrderCalcMargin = 2,
|
|
||||||
OrderCalcProfit = 3,
|
|
||||||
//OrderSendAsync = 5,
|
|
||||||
PositionsTotal = 6,
|
|
||||||
PositionGetSymbol = 7,
|
|
||||||
PositionSelect = 8,
|
|
||||||
PositionGetDouble = 9,
|
|
||||||
PositionGetInteger = 10,
|
|
||||||
PositionGetString = 11,
|
|
||||||
PositionGetTicket = 4,
|
|
||||||
OrdersTotal = 12,
|
|
||||||
OrderGetTicket = 13,
|
|
||||||
OrderSelect = 14,
|
|
||||||
OrderGetDouble = 15,
|
|
||||||
OrderGetInteger = 16,
|
|
||||||
OrderGetString = 17,
|
|
||||||
HistorySelect = 18,
|
|
||||||
HistorySelectByPosition = 19,
|
|
||||||
HistoryOrderSelect = 20,
|
|
||||||
HistoryOrdersTotal = 21,
|
|
||||||
HistoryOrderGetTicket = 22,
|
|
||||||
HistoryOrderGetDouble = 23,
|
|
||||||
HistoryOrderGetInteger = 24,
|
|
||||||
HistoryOrderGetString = 25,
|
|
||||||
HistoryDealSelect = 26,
|
|
||||||
HistoryDealsTotal = 27,
|
|
||||||
HistoryDealGetTicket = 28,
|
|
||||||
HistoryDealGetDouble = 29,
|
|
||||||
HistoryDealGetInteger = 30,
|
|
||||||
HistoryDealGetString = 31,
|
|
||||||
|
|
||||||
//Account Information
|
|
||||||
AccountInfoDouble = 32,
|
|
||||||
AccountInfoInteger = 33,
|
|
||||||
AccountInfoString = 34,
|
|
||||||
|
|
||||||
//Access to Timeseries and Indicator Data
|
|
||||||
SeriesInfoInteger = 35,
|
|
||||||
Bars = 36,
|
|
||||||
Bars2 = 1036,
|
|
||||||
BarsCalculated = 37,
|
|
||||||
// IndicatorCreate = 38,
|
|
||||||
// IndicatorParameters = 38,
|
|
||||||
// IndicatorRelease = 39,
|
|
||||||
CopyBuffer = 40,
|
|
||||||
CopyBuffer1 = 1040,
|
|
||||||
CopyBuffer2 = 1140,
|
|
||||||
CopyRates = 41,
|
|
||||||
CopyRates1 = 1041,
|
|
||||||
CopyRates2 = 1141,
|
|
||||||
CopyTime = 42,
|
|
||||||
CopyTime1 = 1042,
|
|
||||||
CopyTime2 = 1142,
|
|
||||||
CopyOpen = 43,
|
|
||||||
CopyOpen1 = 1043,
|
|
||||||
CopyOpen2 = 1143,
|
|
||||||
CopyHigh = 44,
|
|
||||||
CopyHigh1 = 1044,
|
|
||||||
CopyHigh2 = 1144,
|
|
||||||
CopyLow = 45,
|
|
||||||
CopyLow1 = 1045,
|
|
||||||
CopyLow2 = 1145,
|
|
||||||
CopyClose = 46,
|
|
||||||
CopyClose1 = 1046,
|
|
||||||
CopyClose2 = 1146,
|
|
||||||
CopyTickVolume = 47,
|
|
||||||
CopyTickVolume1 = 1047,
|
|
||||||
CopyTickVolume2 = 1147,
|
|
||||||
CopyRealVolume = 48,
|
|
||||||
CopyRealVolume1 = 1048,
|
|
||||||
CopyRealVolume2 = 1148,
|
|
||||||
CopySpread = 49,
|
|
||||||
CopySpread1 = 1049,
|
|
||||||
CopySpread2 = 1149,
|
|
||||||
|
|
||||||
//Market Information
|
|
||||||
SymbolsTotal = 50,
|
|
||||||
SymbolName = 51,
|
|
||||||
SymbolSelect = 52,
|
|
||||||
SymbolIsSynchronized = 53,
|
|
||||||
SymbolInfoDouble = 54,
|
|
||||||
SymbolInfoInteger = 55,
|
|
||||||
SymbolInfoString = 56,
|
|
||||||
SymbolInfoTick = 57,
|
|
||||||
SymbolInfoSessionQuote = 58,
|
|
||||||
SymbolInfoSessionTrade = 59,
|
|
||||||
MarketBookAdd = 60,
|
|
||||||
MarketBookRelease = 61,
|
|
||||||
//MarketBookGet = 62,
|
|
||||||
OrderCloseAll = 63,
|
|
||||||
|
|
||||||
//CTrade
|
|
||||||
PositionClose = 64,
|
|
||||||
PositionOpen = 65,
|
|
||||||
PositionModify = 6066,
|
|
||||||
PositionClosePartial_bySymbol = 6067,
|
|
||||||
PositionClosePartial_byTicket = 6068,
|
|
||||||
//PositionOpenWithResult = 1065,
|
|
||||||
|
|
||||||
//Backtesting
|
|
||||||
BacktestingReady = 66,
|
|
||||||
IsTesting = 67,
|
|
||||||
|
|
||||||
//Requests
|
|
||||||
MtRequest = 155,
|
|
||||||
|
|
||||||
PositionSelectByTicket = 69,
|
|
||||||
|
|
||||||
ObjectCreate = 70,
|
|
||||||
ObjectName = 71,
|
|
||||||
ObjectDelete = 72,
|
|
||||||
ObjectsDeleteAll = 73,
|
|
||||||
ObjectFind = 74,
|
|
||||||
ObjectGetTimeByValue = 75,
|
|
||||||
ObjectGetValueByTime = 76,
|
|
||||||
ObjectMove = 77,
|
|
||||||
ObjectsTotal = 78,
|
|
||||||
ObjectGetDouble = 79,
|
|
||||||
ObjectGetInteger = 80,
|
|
||||||
ObjectGetString = 81,
|
|
||||||
ObjectSetDouble = 82,
|
|
||||||
ObjectSetInteger = 83,
|
|
||||||
ObjectSetString = 84,
|
|
||||||
//TextSetFont = 85,
|
|
||||||
//TextOut = 86,
|
|
||||||
//TextGetSize = 87,
|
|
||||||
|
|
||||||
iAC = 88,
|
|
||||||
iAD = 89,
|
|
||||||
iADX = 90,
|
|
||||||
iADXWilder = 91,
|
|
||||||
iAlligator = 92,
|
|
||||||
iAMA = 93,
|
|
||||||
iAO = 94,
|
|
||||||
iATR = 95,
|
|
||||||
iBearsPower = 96,
|
|
||||||
iBands = 97,
|
|
||||||
iBullsPower = 98,
|
|
||||||
iCCI = 99,
|
|
||||||
iChaikin = 100,
|
|
||||||
//iCustom = 101,
|
|
||||||
iDEMA = 102,
|
|
||||||
iDeMarker = 103,
|
|
||||||
iEnvelopes = 104,
|
|
||||||
iForce = 105,
|
|
||||||
iFractals = 106,
|
|
||||||
iFrAMA = 107,
|
|
||||||
iGator = 108,
|
|
||||||
iIchimoku = 109,
|
|
||||||
iBWMFI = 110,
|
|
||||||
iMomentum = 111,
|
|
||||||
iMFI = 112,
|
|
||||||
iMA = 113,
|
|
||||||
iOsMA = 114,
|
|
||||||
iMACD = 115,
|
|
||||||
iOBV = 116,
|
|
||||||
iSAR = 117,
|
|
||||||
iRSI = 118,
|
|
||||||
iRVI = 119,
|
|
||||||
iStdDev = 120,
|
|
||||||
iStochastic = 121,
|
|
||||||
iTEMA = 122,
|
|
||||||
iTriX = 123,
|
|
||||||
iWPR = 124,
|
|
||||||
iVIDyA = 125,
|
|
||||||
iVolumes = 126,
|
|
||||||
|
|
||||||
//Date and Time
|
|
||||||
TimeCurrent = 127,
|
|
||||||
TimeTradeServer = 128,
|
|
||||||
TimeLocal = 129,
|
|
||||||
TimeGMT = 130,
|
|
||||||
|
|
||||||
IndicatorRelease = 131,
|
|
||||||
|
|
||||||
//Chart Operations
|
|
||||||
ChartId = 206,
|
|
||||||
ChartRedraw = 207,
|
|
||||||
ChartApplyTemplate = 236,
|
|
||||||
ChartSaveTemplate = 237,
|
|
||||||
ChartWindowFind = 238,
|
|
||||||
//ChartTimePriceToXY = 239,
|
|
||||||
//ChartXYToTimePrice = 240,
|
|
||||||
ChartOpen = 241,
|
|
||||||
ChartFirst = 242,
|
|
||||||
ChartNext = 243,
|
|
||||||
ChartClose = 244,
|
|
||||||
ChartSymbol = 245,
|
|
||||||
ChartPeriod = 246,
|
|
||||||
ChartSetDouble = 247,
|
|
||||||
ChartSetInteger = 248,
|
|
||||||
ChartSetString = 249,
|
|
||||||
ChartGetDouble = 250,
|
|
||||||
ChartGetInteger = 251,
|
|
||||||
ChartGetString = 252,
|
|
||||||
ChartNavigate = 253,
|
|
||||||
ChartIndicatorDelete = 254,
|
|
||||||
ChartIndicatorName = 255,
|
|
||||||
ChartIndicatorsTotal = 256,
|
|
||||||
ChartWindowOnDropped = 257,
|
|
||||||
ChartPriceOnDropped = 258,
|
|
||||||
ChartTimeOnDropped = 259,
|
|
||||||
ChartXOnDropped = 260,
|
|
||||||
ChartYOnDropped = 261,
|
|
||||||
ChartSetSymbolPeriod = 262,
|
|
||||||
ChartScreenShot = 263,
|
|
||||||
ChartIndicatorAdd = 280,
|
|
||||||
ChartIndicatorGet = 281,
|
|
||||||
|
|
||||||
// Terminal Operations
|
|
||||||
TerminalCompany = 68,
|
|
||||||
TerminalName = 69,
|
|
||||||
TerminalPath = 70,
|
|
||||||
|
|
||||||
//Checkup
|
|
||||||
GetLastError = 132,
|
|
||||||
TerminalInfoString = 153,
|
|
||||||
TerminalInfoInteger = 204,
|
|
||||||
TerminalInfoDouble = 205,
|
|
||||||
|
|
||||||
//Common Functions
|
|
||||||
Alert = 136,
|
|
||||||
Comment = 137, //TODO
|
|
||||||
GetTickCount = 138, //TODO
|
|
||||||
GetMicrosecondCount = 139, //TODO
|
|
||||||
MessageBox = 140, //TODO
|
|
||||||
PeriodSeconds = 141, //TODO
|
|
||||||
PlaySound = 142, //TODO
|
|
||||||
Print = 68,
|
|
||||||
ResetLastError = 143,
|
|
||||||
SendNotification = 144, //TODO
|
|
||||||
SendMail = 145, //TODO
|
|
||||||
|
|
||||||
//Global Variables
|
|
||||||
GlobalVariableCheck = 146,
|
|
||||||
GlobalVariableTime = 147,
|
|
||||||
GlobalVariableDel = 148,
|
|
||||||
GlobalVariableGet = 149,
|
|
||||||
GlobalVariableName = 150,
|
|
||||||
GlobalVariableSet = 151,
|
|
||||||
GlobalVariablesFlush = 152,
|
|
||||||
GlobalVariableTemp = 154,
|
|
||||||
GlobalVariableSetOnCondition = 156,
|
|
||||||
GlobalVariablesDeleteAll = 157,
|
|
||||||
GlobalVariablesTotal = 158,
|
|
||||||
|
|
||||||
UnlockTicks = 159,
|
|
||||||
PositionCloseAll = 160,
|
|
||||||
TesterStop = 161
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+42
-38
@@ -1,10 +1,10 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using MtApi5.Requests;
|
using MtApi5.Requests;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using MtApi5.Events;
|
|
||||||
using MtClient;
|
using MtClient;
|
||||||
using System.Reflection.Metadata;
|
using MtApi5.MtProtocol;
|
||||||
using System.Collections.Generic;
|
using System.Linq;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
|
||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
@@ -265,11 +265,12 @@ namespace MtApi5
|
|||||||
///Returns the symbol corresponding to the open position and automatically selects the position for further working with it using functions PositionGetDouble, PositionGetInteger, PositionGetString.
|
///Returns the symbol corresponding to the open position and automatically selects the position for further working with it using functions PositionGetDouble, PositionGetInteger, PositionGetString.
|
||||||
///</summary>
|
///</summary>
|
||||||
///<param name="index">Number of the position in the list of open positions.</param>
|
///<param name="index">Number of the position in the list of open positions.</param>
|
||||||
public string PositionGetSymbol(int index)
|
public string? PositionGetSymbol(int index)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { index };
|
Dictionary<string, object> commandParameters = [];
|
||||||
|
commandParameters["Index"] = index;
|
||||||
|
|
||||||
return SendCommand<string>(Mt5CommandType.PositionGetSymbol, commandParameters);
|
return SendCommand<string>(ExecutorHandle, Mt5CommandType.PositionGetSymbol, commandParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
@@ -789,9 +790,8 @@ namespace MtApi5
|
|||||||
///<param name="propertyId">Identifier of the property.</param>
|
///<param name="propertyId">Identifier of the property.</param>
|
||||||
public double AccountInfoDouble(ENUM_ACCOUNT_INFO_DOUBLE propertyId)
|
public double AccountInfoDouble(ENUM_ACCOUNT_INFO_DOUBLE propertyId)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { (int)propertyId };
|
Dictionary<string, object> commandParameters = new() { { "PropertyId", propertyId } };
|
||||||
|
return SendCommand<double>(ExecutorHandle, Mt5CommandType.AccountInfoDouble, commandParameters);
|
||||||
return SendCommand<double>(Mt5CommandType.AccountInfoDouble, commandParameters);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
@@ -800,20 +800,18 @@ namespace MtApi5
|
|||||||
///<param name="propertyId">Identifier of the property.</param>
|
///<param name="propertyId">Identifier of the property.</param>
|
||||||
public long AccountInfoInteger(ENUM_ACCOUNT_INFO_INTEGER propertyId)
|
public long AccountInfoInteger(ENUM_ACCOUNT_INFO_INTEGER propertyId)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { (int)propertyId };
|
Dictionary<string, object> commandParameters = new() { { "PropertyId", propertyId } };
|
||||||
|
return SendCommand<long>(ExecutorHandle, Mt5CommandType.AccountInfoInteger, commandParameters);
|
||||||
return SendCommand<long>(Mt5CommandType.AccountInfoInteger, commandParameters);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
///Returns the value of the corresponding account property.
|
///Returns the value of the corresponding account property.
|
||||||
///</summary>
|
///</summary>
|
||||||
///<param name="propertyId">Identifier of the property.</param>
|
///<param name="propertyId">Identifier of the property.</param>
|
||||||
public string AccountInfoString(ENUM_ACCOUNT_INFO_STRING propertyId)
|
public string? AccountInfoString(ENUM_ACCOUNT_INFO_STRING propertyId)
|
||||||
{
|
{
|
||||||
var commandParameters = new ArrayList { (int)propertyId };
|
Dictionary<string, object> commandParameters = new() { { "PropertyId", propertyId } };
|
||||||
|
return SendCommand<string>(ExecutorHandle, Mt5CommandType.AccountInfoString, commandParameters);
|
||||||
return SendCommand<string>(Mt5CommandType.AccountInfoString, commandParameters);
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -3424,6 +3422,8 @@ namespace MtApi5
|
|||||||
{
|
{
|
||||||
_experts = experts;
|
_experts = experts;
|
||||||
_quotes = quotes;
|
_quotes = quotes;
|
||||||
|
if (_executorHandle == 0)
|
||||||
|
_executorHandle = (_experts.Count > 0) ? _experts.ElementAt(0) : 0;
|
||||||
}
|
}
|
||||||
_quotesWaiter.Set();
|
_quotesWaiter.Set();
|
||||||
|
|
||||||
@@ -3470,6 +3470,9 @@ namespace MtApi5
|
|||||||
_experts.Remove(handle);
|
_experts.Remove(handle);
|
||||||
if (_quotes.TryGetValue(handle, out quote))
|
if (_quotes.TryGetValue(handle, out quote))
|
||||||
_quotes.Remove(handle);
|
_quotes.Remove(handle);
|
||||||
|
if (_executorHandle == handle)
|
||||||
|
_executorHandle = (_experts.Count > 0) ? _experts.ElementAt(0) : 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (quote != null)
|
if (quote != null)
|
||||||
@@ -3480,19 +3483,19 @@ namespace MtApi5
|
|||||||
{
|
{
|
||||||
Log?.Debug($"GetQuote: expertHandle = {expertHandle}");
|
Log?.Debug($"GetQuote: expertHandle = {expertHandle}");
|
||||||
|
|
||||||
var e = SendCommand<OnTickEvent>(expertHandle, Mt5CommandType.GetQuote);
|
var e = SendCommand<MtQuote>(expertHandle, Mt5CommandType.GetQuote);
|
||||||
if (e == null || string.IsNullOrEmpty(e.Instrument) || e.Tick == null)
|
if (e == null || string.IsNullOrEmpty(e.Instrument) || e.Tick == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
Mt5Quote quote = new()
|
Mt5Quote quote = new()
|
||||||
{
|
{
|
||||||
Instrument = e.Instrument,
|
Instrument = e.Instrument,
|
||||||
Bid = e.Tick.bid,
|
Bid = e.Tick.Bid,
|
||||||
Ask = e.Tick.ask,
|
Ask = e.Tick.Ask,
|
||||||
ExpertHandle = expertHandle,
|
ExpertHandle = expertHandle,
|
||||||
Volume = e.Tick.volume,
|
Volume = e.Tick.Volume,
|
||||||
Time = e.Tick.time,
|
Time = Mt5TimeConverter.ConvertFromMtTime(e.Tick.Time),
|
||||||
Last = e.Tick.last
|
Last = e.Tick.Last
|
||||||
};
|
};
|
||||||
|
|
||||||
return quote;
|
return quote;
|
||||||
@@ -3510,62 +3513,62 @@ namespace MtApi5
|
|||||||
Disconnect(false);
|
Disconnect(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ReceivedOnTradeTransactionEvent(int expertHandler, string payload)
|
private void ReceivedOnTradeTransactionEvent(int expertHandle, string payload)
|
||||||
{
|
{
|
||||||
var e = JsonConvert.DeserializeObject<OnTradeTransactionEvent>(payload);
|
var e = JsonConvert.DeserializeObject<OnTradeTransactionEvent>(payload);
|
||||||
if (e == null)
|
if (e == null)
|
||||||
return;
|
return;
|
||||||
OnTradeTransaction?.Invoke(this, new Mt5TradeTransactionEventArgs
|
OnTradeTransaction?.Invoke(this, new Mt5TradeTransactionEventArgs
|
||||||
{
|
{
|
||||||
ExpertHandle = expertHandler,
|
ExpertHandle = expertHandle,
|
||||||
Trans = e.Trans,
|
Trans = e.Trans,
|
||||||
Request = e.Request,
|
Request = e.Request,
|
||||||
Result = e.Result
|
Result = e.Result
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ReceivedOnBookEvent(int expertHandler, string payload)
|
private void ReceivedOnBookEvent(int expertHandle, string payload)
|
||||||
{
|
{
|
||||||
var e = JsonConvert.DeserializeObject<OnBookEvent>(payload);
|
var e = JsonConvert.DeserializeObject<OnBookEvent>(payload);
|
||||||
if (e == null || string.IsNullOrEmpty(e.Symbol))
|
if (e == null || string.IsNullOrEmpty(e.Symbol))
|
||||||
return;
|
return;
|
||||||
OnBookEvent?.Invoke(this, new Mt5BookEventArgs
|
OnBookEvent?.Invoke(this, new Mt5BookEventArgs
|
||||||
{
|
{
|
||||||
ExpertHandle = expertHandler,
|
ExpertHandle = expertHandle,
|
||||||
Symbol = e.Symbol
|
Symbol = e.Symbol
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ReceivedOnTickEvent(int expertHandler, string payload)
|
private void ReceivedOnTickEvent(int expertHandle, string payload)
|
||||||
{
|
{
|
||||||
var e = JsonConvert.DeserializeObject<OnTickEvent>(payload);
|
var e = JsonConvert.DeserializeObject<MtQuote>(payload);
|
||||||
if (e == null || string.IsNullOrEmpty(e.Instrument) || e.Tick == null)
|
if (e == null || string.IsNullOrEmpty(e.Instrument) || e.Tick == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QuoteUpdated?.Invoke(this, e.Instrument, e.Tick.bid, e.Tick.ask);
|
QuoteUpdated?.Invoke(this, e.Instrument, e.Tick.Bid, e.Tick.Ask);
|
||||||
|
|
||||||
Mt5Quote quote = new()
|
Mt5Quote quote = new()
|
||||||
{
|
{
|
||||||
Instrument = e.Instrument,
|
Instrument = e.Instrument,
|
||||||
Bid = e.Tick.bid,
|
Bid = e.Tick.Bid,
|
||||||
Ask = e.Tick.ask,
|
Ask = e.Tick.Ask,
|
||||||
ExpertHandle = expertHandler,
|
ExpertHandle = expertHandle,
|
||||||
Volume = e.Tick.volume,
|
Volume = e.Tick.Volume,
|
||||||
Time = e.Tick.time,
|
Time = Mt5TimeConverter.ConvertFromMtTime(e.Tick.Time),
|
||||||
Last = e.Tick.last
|
Last = e.Tick.Last
|
||||||
};
|
};
|
||||||
QuoteUpdate?.Invoke(this, new Mt5QuoteEventArgs(quote));
|
QuoteUpdate?.Invoke(this, new Mt5QuoteEventArgs(quote));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ReceivedOnLastTimeBarEvent(int expertHandler, string payload)
|
private void ReceivedOnLastTimeBarEvent(int expertHandle, string payload)
|
||||||
{
|
{
|
||||||
var e = JsonConvert.DeserializeObject<OnLastTimeBarEvent>(payload);
|
var e = JsonConvert.DeserializeObject<OnLastTimeBarEvent>(payload);
|
||||||
if (e == null || string.IsNullOrEmpty(e.Instrument) || e.Rates == null)
|
if (e == null || string.IsNullOrEmpty(e.Instrument) || e.Rates == null)
|
||||||
return;
|
return;
|
||||||
OnLastTimeBar?.Invoke(this, new Mt5TimeBarArgs(expertHandler, e.Instrument, e.Rates));
|
OnLastTimeBar?.Invoke(this, new Mt5TimeBarArgs(expertHandle, e.Instrument, e.Rates));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ReceivedOnLockTicksEvent(int expertHandler, string payload)
|
private void ReceivedOnLockTicksEvent(int expertHandle, string payload)
|
||||||
{
|
{
|
||||||
var e = JsonConvert.DeserializeObject<OnLockTicksEvent>(payload);
|
var e = JsonConvert.DeserializeObject<OnLockTicksEvent>(payload);
|
||||||
if (e == null || string.IsNullOrEmpty(e.Instrument))
|
if (e == null || string.IsNullOrEmpty(e.Instrument))
|
||||||
@@ -3592,6 +3595,7 @@ namespace MtApi5
|
|||||||
|
|
||||||
_quotes.Clear();
|
_quotes.Clear();
|
||||||
_experts.Clear();
|
_experts.Clear();
|
||||||
|
_executorHandle = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
client?.Disconnect();
|
client?.Disconnect();
|
||||||
|
|||||||
Executable
+8
@@ -0,0 +1,8 @@
|
|||||||
|
namespace MtApi5.MtProtocol
|
||||||
|
{
|
||||||
|
internal class FuncResult<T>
|
||||||
|
{
|
||||||
|
public bool RetVal { get; set; }
|
||||||
|
public T? Result { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable
+12
@@ -0,0 +1,12 @@
|
|||||||
|
namespace MtApi5.MtProtocol
|
||||||
|
{
|
||||||
|
public class MtTick
|
||||||
|
{
|
||||||
|
public double Bid { get; set; } // Current Bid price
|
||||||
|
public double Ask { get; set; } // Current Ask price
|
||||||
|
public long Time { get; set; } // Time of the last prices update
|
||||||
|
public double Last { get; set; } // Price of the last deal (Last)
|
||||||
|
public ulong Volume { get; set; } // Volume for the current Last price
|
||||||
|
public double VolumeReal { get; set; } // Volume for the current Last price with greater accuracy
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable
+260
@@ -0,0 +1,260 @@
|
|||||||
|
// ReSharper disable InconsistentNaming
|
||||||
|
namespace MtApi5.MtProtocol
|
||||||
|
{
|
||||||
|
internal enum Mt5CommandType
|
||||||
|
{
|
||||||
|
//NoCommand = 0
|
||||||
|
|
||||||
|
GetQuote = 1,
|
||||||
|
//trade operations
|
||||||
|
OrderCalcMargin = 2,
|
||||||
|
OrderCalcProfit = 3,
|
||||||
|
//OrderSendAsync = 5,
|
||||||
|
PositionsTotal = 6,
|
||||||
|
PositionGetSymbol = 7,
|
||||||
|
PositionSelect = 8,
|
||||||
|
PositionGetDouble = 9,
|
||||||
|
PositionGetInteger = 10,
|
||||||
|
PositionGetString = 11,
|
||||||
|
PositionGetTicket = 4,
|
||||||
|
OrdersTotal = 12,
|
||||||
|
OrderGetTicket = 13,
|
||||||
|
OrderSelect = 14,
|
||||||
|
OrderGetDouble = 15,
|
||||||
|
OrderGetInteger = 16,
|
||||||
|
OrderGetString = 17,
|
||||||
|
HistorySelect = 18,
|
||||||
|
HistorySelectByPosition = 19,
|
||||||
|
HistoryOrderSelect = 20,
|
||||||
|
HistoryOrdersTotal = 21,
|
||||||
|
HistoryOrderGetTicket = 22,
|
||||||
|
HistoryOrderGetDouble = 23,
|
||||||
|
HistoryOrderGetInteger = 24,
|
||||||
|
HistoryOrderGetString = 25,
|
||||||
|
HistoryDealSelect = 26,
|
||||||
|
HistoryDealsTotal = 27,
|
||||||
|
HistoryDealGetTicket = 28,
|
||||||
|
HistoryDealGetDouble = 29,
|
||||||
|
HistoryDealGetInteger = 30,
|
||||||
|
HistoryDealGetString = 31,
|
||||||
|
|
||||||
|
//Account Information
|
||||||
|
AccountInfoDouble = 32,
|
||||||
|
AccountInfoInteger = 33,
|
||||||
|
AccountInfoString = 34,
|
||||||
|
|
||||||
|
//Access to Timeseries and Indicator Data
|
||||||
|
SeriesInfoInteger = 35,
|
||||||
|
Bars = 36,
|
||||||
|
Bars2 = 1036,
|
||||||
|
BarsCalculated = 37,
|
||||||
|
// IndicatorCreate = 38,
|
||||||
|
// IndicatorParameters = 38,
|
||||||
|
// IndicatorRelease = 39,
|
||||||
|
CopyBuffer = 40,
|
||||||
|
CopyBuffer1 = 1040,
|
||||||
|
CopyBuffer2 = 1140,
|
||||||
|
CopyRates = 41,
|
||||||
|
CopyRates1 = 1041,
|
||||||
|
CopyRates2 = 1141,
|
||||||
|
CopyTime = 42,
|
||||||
|
CopyTime1 = 1042,
|
||||||
|
CopyTime2 = 1142,
|
||||||
|
CopyOpen = 43,
|
||||||
|
CopyOpen1 = 1043,
|
||||||
|
CopyOpen2 = 1143,
|
||||||
|
CopyHigh = 44,
|
||||||
|
CopyHigh1 = 1044,
|
||||||
|
CopyHigh2 = 1144,
|
||||||
|
CopyLow = 45,
|
||||||
|
CopyLow1 = 1045,
|
||||||
|
CopyLow2 = 1145,
|
||||||
|
CopyClose = 46,
|
||||||
|
CopyClose1 = 1046,
|
||||||
|
CopyClose2 = 1146,
|
||||||
|
CopyTickVolume = 47,
|
||||||
|
CopyTickVolume1 = 1047,
|
||||||
|
CopyTickVolume2 = 1147,
|
||||||
|
CopyRealVolume = 48,
|
||||||
|
CopyRealVolume1 = 1048,
|
||||||
|
CopyRealVolume2 = 1148,
|
||||||
|
CopySpread = 49,
|
||||||
|
CopySpread1 = 1049,
|
||||||
|
CopySpread2 = 1149,
|
||||||
|
|
||||||
|
//Market Information
|
||||||
|
SymbolsTotal = 50,
|
||||||
|
SymbolName = 51,
|
||||||
|
SymbolSelect = 52,
|
||||||
|
SymbolIsSynchronized = 53,
|
||||||
|
SymbolInfoDouble = 54,
|
||||||
|
SymbolInfoInteger = 55,
|
||||||
|
SymbolInfoString = 56,
|
||||||
|
SymbolInfoTick = 57,
|
||||||
|
SymbolInfoSessionQuote = 58,
|
||||||
|
SymbolInfoSessionTrade = 59,
|
||||||
|
MarketBookAdd = 60,
|
||||||
|
MarketBookRelease = 61,
|
||||||
|
//MarketBookGet = 62,
|
||||||
|
OrderCloseAll = 63,
|
||||||
|
|
||||||
|
//CTrade
|
||||||
|
PositionClose = 64,
|
||||||
|
PositionOpen = 65,
|
||||||
|
PositionModify = 6066,
|
||||||
|
PositionClosePartial_bySymbol = 6067,
|
||||||
|
PositionClosePartial_byTicket = 6068,
|
||||||
|
//PositionOpenWithResult = 1065,
|
||||||
|
|
||||||
|
//Backtesting
|
||||||
|
BacktestingReady = 66,
|
||||||
|
IsTesting = 67,
|
||||||
|
|
||||||
|
//Requests
|
||||||
|
MtRequest = 155,
|
||||||
|
|
||||||
|
PositionSelectByTicket = 69,
|
||||||
|
|
||||||
|
ObjectCreate = 70,
|
||||||
|
ObjectName = 71,
|
||||||
|
ObjectDelete = 72,
|
||||||
|
ObjectsDeleteAll = 73,
|
||||||
|
ObjectFind = 74,
|
||||||
|
ObjectGetTimeByValue = 75,
|
||||||
|
ObjectGetValueByTime = 76,
|
||||||
|
ObjectMove = 77,
|
||||||
|
ObjectsTotal = 78,
|
||||||
|
ObjectGetDouble = 79,
|
||||||
|
ObjectGetInteger = 80,
|
||||||
|
ObjectGetString = 81,
|
||||||
|
ObjectSetDouble = 82,
|
||||||
|
ObjectSetInteger = 83,
|
||||||
|
ObjectSetString = 84,
|
||||||
|
//TextSetFont = 85,
|
||||||
|
//TextOut = 86,
|
||||||
|
//TextGetSize = 87,
|
||||||
|
|
||||||
|
iAC = 88,
|
||||||
|
iAD = 89,
|
||||||
|
iADX = 90,
|
||||||
|
iADXWilder = 91,
|
||||||
|
iAlligator = 92,
|
||||||
|
iAMA = 93,
|
||||||
|
iAO = 94,
|
||||||
|
iATR = 95,
|
||||||
|
iBearsPower = 96,
|
||||||
|
iBands = 97,
|
||||||
|
iBullsPower = 98,
|
||||||
|
iCCI = 99,
|
||||||
|
iChaikin = 100,
|
||||||
|
//iCustom = 101,
|
||||||
|
iDEMA = 102,
|
||||||
|
iDeMarker = 103,
|
||||||
|
iEnvelopes = 104,
|
||||||
|
iForce = 105,
|
||||||
|
iFractals = 106,
|
||||||
|
iFrAMA = 107,
|
||||||
|
iGator = 108,
|
||||||
|
iIchimoku = 109,
|
||||||
|
iBWMFI = 110,
|
||||||
|
iMomentum = 111,
|
||||||
|
iMFI = 112,
|
||||||
|
iMA = 113,
|
||||||
|
iOsMA = 114,
|
||||||
|
iMACD = 115,
|
||||||
|
iOBV = 116,
|
||||||
|
iSAR = 117,
|
||||||
|
iRSI = 118,
|
||||||
|
iRVI = 119,
|
||||||
|
iStdDev = 120,
|
||||||
|
iStochastic = 121,
|
||||||
|
iTEMA = 122,
|
||||||
|
iTriX = 123,
|
||||||
|
iWPR = 124,
|
||||||
|
iVIDyA = 125,
|
||||||
|
iVolumes = 126,
|
||||||
|
|
||||||
|
//Date and Time
|
||||||
|
TimeCurrent = 127,
|
||||||
|
TimeTradeServer = 128,
|
||||||
|
TimeLocal = 129,
|
||||||
|
TimeGMT = 130,
|
||||||
|
|
||||||
|
IndicatorRelease = 131,
|
||||||
|
|
||||||
|
//Chart Operations
|
||||||
|
ChartId = 206,
|
||||||
|
ChartRedraw = 207,
|
||||||
|
ChartApplyTemplate = 236,
|
||||||
|
ChartSaveTemplate = 237,
|
||||||
|
ChartWindowFind = 238,
|
||||||
|
//ChartTimePriceToXY = 239,
|
||||||
|
//ChartXYToTimePrice = 240,
|
||||||
|
ChartOpen = 241,
|
||||||
|
ChartFirst = 242,
|
||||||
|
ChartNext = 243,
|
||||||
|
ChartClose = 244,
|
||||||
|
ChartSymbol = 245,
|
||||||
|
ChartPeriod = 246,
|
||||||
|
ChartSetDouble = 247,
|
||||||
|
ChartSetInteger = 248,
|
||||||
|
ChartSetString = 249,
|
||||||
|
ChartGetDouble = 250,
|
||||||
|
ChartGetInteger = 251,
|
||||||
|
ChartGetString = 252,
|
||||||
|
ChartNavigate = 253,
|
||||||
|
ChartIndicatorDelete = 254,
|
||||||
|
ChartIndicatorName = 255,
|
||||||
|
ChartIndicatorsTotal = 256,
|
||||||
|
ChartWindowOnDropped = 257,
|
||||||
|
ChartPriceOnDropped = 258,
|
||||||
|
ChartTimeOnDropped = 259,
|
||||||
|
ChartXOnDropped = 260,
|
||||||
|
ChartYOnDropped = 261,
|
||||||
|
ChartSetSymbolPeriod = 262,
|
||||||
|
ChartScreenShot = 263,
|
||||||
|
ChartIndicatorAdd = 280,
|
||||||
|
ChartIndicatorGet = 281,
|
||||||
|
|
||||||
|
// Terminal Operations
|
||||||
|
TerminalCompany = 68,
|
||||||
|
TerminalName = 69,
|
||||||
|
TerminalPath = 70,
|
||||||
|
|
||||||
|
//Checkup
|
||||||
|
GetLastError = 132,
|
||||||
|
TerminalInfoString = 153,
|
||||||
|
TerminalInfoInteger = 204,
|
||||||
|
TerminalInfoDouble = 205,
|
||||||
|
|
||||||
|
//Common Functions
|
||||||
|
Alert = 136,
|
||||||
|
Comment = 137, //TODO
|
||||||
|
GetTickCount = 138, //TODO
|
||||||
|
GetMicrosecondCount = 139, //TODO
|
||||||
|
MessageBox = 140, //TODO
|
||||||
|
PeriodSeconds = 141, //TODO
|
||||||
|
PlaySound = 142, //TODO
|
||||||
|
Print = 68,
|
||||||
|
ResetLastError = 143,
|
||||||
|
SendNotification = 144, //TODO
|
||||||
|
SendMail = 145, //TODO
|
||||||
|
|
||||||
|
//Global Variables
|
||||||
|
GlobalVariableCheck = 146,
|
||||||
|
GlobalVariableTime = 147,
|
||||||
|
GlobalVariableDel = 148,
|
||||||
|
GlobalVariableGet = 149,
|
||||||
|
GlobalVariableName = 150,
|
||||||
|
GlobalVariableSet = 151,
|
||||||
|
GlobalVariablesFlush = 152,
|
||||||
|
GlobalVariableTemp = 154,
|
||||||
|
GlobalVariableSetOnCondition = 156,
|
||||||
|
GlobalVariablesDeleteAll = 157,
|
||||||
|
GlobalVariablesTotal = 158,
|
||||||
|
|
||||||
|
UnlockTicks = 159,
|
||||||
|
PositionCloseAll = 160,
|
||||||
|
TesterStop = 161
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable
+11
@@ -0,0 +1,11 @@
|
|||||||
|
namespace MtApi5.MtProtocol
|
||||||
|
{
|
||||||
|
internal enum Mt5EventTypes
|
||||||
|
{
|
||||||
|
OnTradeTransaction = 1,
|
||||||
|
OnBookEvent = 2,
|
||||||
|
OnTick = 3,
|
||||||
|
OnLastTimeBar = 4,
|
||||||
|
OnLockTicks = 5
|
||||||
|
}
|
||||||
|
}
|
||||||
Regular → Executable
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
namespace MtApi5.Events
|
namespace MtApi5.MtProtocol
|
||||||
{
|
{
|
||||||
internal class OnTickEvent
|
internal class MtQuote
|
||||||
{
|
{
|
||||||
public MqlTick? Tick { get; set; }
|
public MtTick? Tick { get; set; }
|
||||||
public string? Instrument { get; set; }
|
public string? Instrument { get; set; }
|
||||||
public int ExpertHandle { get; set; }
|
public int ExpertHandle { get; set; }
|
||||||
}
|
}
|
||||||
Regular → Executable
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
namespace MtApi5.Events
|
namespace MtApi5.MtProtocol
|
||||||
{
|
{
|
||||||
internal class OnBookEvent
|
internal class OnBookEvent
|
||||||
{
|
{
|
||||||
Regular → Executable
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
namespace MtApi5.Events
|
namespace MtApi5.MtProtocol
|
||||||
{
|
{
|
||||||
public class OnLastTimeBarEvent
|
internal class OnLastTimeBarEvent
|
||||||
{
|
{
|
||||||
public MqlRates? Rates { get; set; }
|
public MqlRates? Rates { get; set; }
|
||||||
public string? Instrument { get; set; }
|
public string? Instrument { get; set; }
|
||||||
Regular → Executable
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
namespace MtApi5.Events
|
namespace MtApi5.MtProtocol
|
||||||
{
|
{
|
||||||
internal class OnLockTicksEvent
|
internal class OnLockTicksEvent
|
||||||
{
|
{
|
||||||
Regular → Executable
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
namespace MtApi5.Events
|
namespace MtApi5.MtProtocol
|
||||||
{
|
{
|
||||||
internal class OnTradeTransactionEvent
|
internal class OnTradeTransactionEvent
|
||||||
{
|
{
|
||||||
Regular → Executable
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
namespace MtApi5.Requests
|
namespace MtApi5.MtProtocol
|
||||||
{
|
{
|
||||||
internal class Response<T>
|
internal class Response<T>
|
||||||
{
|
{
|
||||||
Reference in New Issue
Block a user