mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-07-28 11:07:48 +00:00
Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d7b8ef894c | |||
| 7f33cebce1 | |||
| 84740787d5 | |||
| ad6bad5187 | |||
| 0086b02bc8 | |||
| f7e06c1570 | |||
| c86a3a3752 | |||
| be8a17c0fd | |||
| 5c6751de9b | |||
| 83776f8b7a | |||
| f1c1df1e00 | |||
| d6640300f5 | |||
| c9c188f697 | |||
| 3a4f561836 | |||
| bdb30edee3 | |||
| 29f501b055 | |||
| 521d7ea2c0 | |||
| 0e5bb40a6f | |||
| 14079dc3c1 | |||
| 3600a86971 | |||
| 83e62fbff7 | |||
| 5c96aeb2fd | |||
| a238e5eb36 | |||
| 11fd5b7527 | |||
| cbe75cfbf6 | |||
| 9581431a9f | |||
| acf0c12531 | |||
| 1eccda9b2c | |||
| fd4aac7c32 |
@@ -104,6 +104,14 @@ _DLLAPI int _stdcall updateQuote(int expertHandle, wchar_t* symbol, double bid,
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
_DLLAPI bool _stdcall sendEvent(int expertHandle, int eventType, wchar_t* payload, wchar_t* err)
|
||||
{
|
||||
return Execute<bool>([&expertHandle, &eventType, payload]() {
|
||||
MtAdapter::GetInstance()->SendEvent(expertHandle, eventType, gcnew String(payload));
|
||||
return true;
|
||||
}, err, false);
|
||||
}
|
||||
|
||||
_DLLAPI int _stdcall sendIntResponse(int expertHandle, int response, wchar_t* err)
|
||||
{
|
||||
return Execute<int>([&expertHandle, &response]() {
|
||||
|
||||
@@ -8,6 +8,50 @@ using log4net.Repository.Hierarchy;
|
||||
|
||||
namespace MTApiService
|
||||
{
|
||||
public class MtLog
|
||||
{
|
||||
#region ctor
|
||||
internal MtLog(Type type)
|
||||
{
|
||||
_log = LogManager.GetLogger(type);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Public
|
||||
|
||||
public void Debug(object message)
|
||||
{
|
||||
_log.Debug(message);
|
||||
}
|
||||
|
||||
public void Error(object message)
|
||||
{
|
||||
_log.Error(message);
|
||||
}
|
||||
|
||||
public void Fatal(object message)
|
||||
{
|
||||
_log.Fatal(message);
|
||||
}
|
||||
|
||||
public void Info(object message)
|
||||
{
|
||||
_log.Info(message);
|
||||
}
|
||||
|
||||
public void Warn(object message)
|
||||
{
|
||||
_log.Warn(message);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private
|
||||
|
||||
private readonly ILog _log;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class LogConfigurator
|
||||
{
|
||||
private const string LogFileNameExtension = "txt";
|
||||
@@ -48,5 +92,13 @@ namespace MTApiService
|
||||
#endif
|
||||
hierarchy.Configured = true;
|
||||
}
|
||||
|
||||
public static MtLog GetLogger(Type type)
|
||||
{
|
||||
if (type == null)
|
||||
throw new ArgumentNullException(nameof(type));
|
||||
|
||||
return new MtLog(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.28.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.28.0")]
|
||||
[assembly: AssemblyVersion("1.0.29.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.29.0")]
|
||||
@@ -994,6 +994,12 @@ namespace MtApi
|
||||
return MtApiTimeConverter.ConvertFromMtTime(commandResponse);
|
||||
}
|
||||
|
||||
public DateTime TimeGMT()
|
||||
{
|
||||
var commandResponse = SendCommand<int>(MtCommandType.TimeGMT, null);
|
||||
return MtApiTimeConverter.ConvertFromMtTime(commandResponse);
|
||||
}
|
||||
|
||||
public int TimeDay(DateTime date)
|
||||
{
|
||||
var commandParameters = new ArrayList { MtApiTimeConverter.ConvertToMtTime(date) };
|
||||
|
||||
@@ -111,6 +111,7 @@
|
||||
TimeSeconds = 86,
|
||||
TimeYear = 87,
|
||||
Year = 88,
|
||||
TimeGMT = 281,
|
||||
|
||||
//Global Variables
|
||||
GlobalVariableCheck = 89,
|
||||
|
||||
+3
-1
@@ -1,4 +1,6 @@
|
||||
namespace MtApi
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace MtApi
|
||||
{
|
||||
public enum ENUM_TERMINAL_INFO_STRING
|
||||
{
|
||||
|
||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.38.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.38.0")]
|
||||
[assembly: AssemblyVersion("1.0.40.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.40.0")]
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace MtApi5.Events
|
||||
{
|
||||
internal enum Mt5EventTypes
|
||||
{
|
||||
OnTradeTransaction = 1,
|
||||
OnBookEvent = 2
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace MtApi5.Events
|
||||
{
|
||||
internal class OnBookEvent
|
||||
{
|
||||
public string Symbol { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace MtApi5.Events
|
||||
{
|
||||
internal class OnTradeTransactionEvent
|
||||
{
|
||||
public MqlTradeTransaction Trans { get; set; }
|
||||
public MqlTradeRequest Request { get; set; }
|
||||
public MqlTradeResult Result { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
namespace MtApi5
|
||||
{
|
||||
public class MqlBookInfo
|
||||
@@ -14,8 +10,13 @@ namespace MtApi5
|
||||
this.volume = volume;
|
||||
}
|
||||
|
||||
public ENUM_BOOK_TYPE type { get; private set; } // Order type from ENUM_BOOK_TYPE enumeration
|
||||
public double price { get; private set; } // Price
|
||||
public long volume { get; private set; } // Volume
|
||||
public ENUM_BOOK_TYPE type { get; } // Order type from ENUM_BOOK_TYPE enumeration
|
||||
public double price { get; } // Price
|
||||
public long volume { get; } // Volume
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{type}|{price}|{volume}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace MtApi5
|
||||
{
|
||||
public class MqlParam
|
||||
{
|
||||
public ENUM_DATATYPE DataType { get; set; }
|
||||
public long? IntegerValue { get; set; }
|
||||
public double? DoubleValue { get; set; }
|
||||
public string StringValue { get; set; }
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
// ReSharper disable InconsistentNaming
|
||||
using System;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
// ReSharper disable InconsistentNaming
|
||||
using System;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
namespace MtApi5
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
public class MqlTradeCheckResult
|
||||
{
|
||||
public uint Retcode { get; private set; } // Reply code
|
||||
public double Balance { get; private set; } // Balance after the execution of the deal
|
||||
public double Equity { get; private set; } // Equity after the execution of the deal
|
||||
public double Profit { get; private set; } // Floating profit
|
||||
public double Margin { get; private set; } // Margin requirements
|
||||
public double Margin_free { get; private set; } // Free margin
|
||||
public double Margin_level { get; private set; } // Margin level
|
||||
public string Comment { get; private set; } // Comment to the reply code (description of the error)
|
||||
public uint Retcode { get; } // Reply code
|
||||
public double Balance { get; } // Balance after the execution of the deal
|
||||
public double Equity { get; } // Equity after the execution of the deal
|
||||
public double Profit { get; } // Floating profit
|
||||
public double Margin { get; } // Margin requirements
|
||||
public double Margin_free { get; } // Free margin
|
||||
public double Margin_level { get; } // Margin level
|
||||
public string Comment { get; } // Comment to the reply code (description of the error)
|
||||
|
||||
public MqlTradeCheckResult(uint retcode
|
||||
, double balance
|
||||
@@ -29,5 +31,10 @@
|
||||
Margin_level = margin_level;
|
||||
Comment = comment;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Retcode={Retcode}; Comment={Comment}; Balance={Balance}; Equity={Equity}; Profit={Profit}; Margin={Margin}; Margin_free={Margin_free}; Margin_level={Margin_level}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
// ReSharper disable InconsistentNaming
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
@@ -17,9 +19,23 @@ namespace MtApi5
|
||||
public ENUM_ORDER_TYPE Type { get; set; } // Order type
|
||||
public ENUM_ORDER_TYPE_FILLING Type_filling { get; set; } // Order execution type
|
||||
public ENUM_ORDER_TYPE_TIME Type_time { get; set; } // Order expiration type
|
||||
public DateTime Expiration { get; set; } // Order expiration time (for the orders of ORDER_TIME_SPECIFIED type)
|
||||
|
||||
[JsonIgnore]
|
||||
public DateTime Expiration // Order expiration time (for the orders of ORDER_TIME_SPECIFIED type)
|
||||
{
|
||||
get { return Mt5TimeConverter.ConvertFromMtTime(MtExpiration); }
|
||||
set { MtExpiration = Mt5TimeConverter.ConvertToMtTime(value); }
|
||||
}
|
||||
|
||||
public string Comment { get; set; } // Order comment
|
||||
public ulong Position { get; set; } // Position ticket
|
||||
public ulong PositionBy { get; set; } // The ticket of an opposite position
|
||||
|
||||
public int MtExpiration { get; private set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Action={Action}; Magic={Magic}; Order={Order}; Symbol={Symbol}; Volume={Volume}; Price={Price}; Stoplimit={Stoplimit}; Sl={Sl}; Tp={Tp}; Deviation={Deviation}; Type={Type}; Type_filling={Type_filling}; Type_time={Type_time}; Expiration={Expiration}; Comment={Comment}; Position={Position}; PositionBy={PositionBy}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+26
-11
@@ -1,4 +1,6 @@
|
||||
namespace MtApi5
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
public class MqlTradeResult
|
||||
{
|
||||
@@ -15,19 +17,32 @@
|
||||
Request_id = request_id;
|
||||
}
|
||||
|
||||
public uint Retcode { get; private set; } // Operation return code
|
||||
public ulong Deal { get; private set; } // Deal ticket, if it is performed
|
||||
public ulong Order { get; private set; } // Order ticket, if it is placed
|
||||
public double Volume { get; private set; } // Deal volume, confirmed by broker
|
||||
public double Price { get; private set; } // Deal price, confirmed by broker
|
||||
public double Bid { get; private set; } // Current Bid price
|
||||
public double Ask { get; private set; } // Current Ask price
|
||||
public string Comment { get; private set; } // Broker comment to operation (by default it is filled by the operation description)
|
||||
public uint Request_id { get; private set; } // Request ID set by the terminal during the dispatch
|
||||
internal MqlTradeResult(MqlTradeResult o)
|
||||
{
|
||||
Retcode = o.Retcode;
|
||||
Deal = o.Deal;
|
||||
Order = o.Order;
|
||||
Volume = o.Volume;
|
||||
Price = o.Price;
|
||||
Bid = o.Bid;
|
||||
Ask = o.Ask;
|
||||
Comment = o.Comment;
|
||||
Request_id = o.Request_id;
|
||||
}
|
||||
|
||||
public uint Retcode { get; } // Operation return code
|
||||
public ulong Deal { get; } // Deal ticket, if it is performed
|
||||
public ulong Order { get; } // Order ticket, if it is placed
|
||||
public double Volume { get; } // Deal volume, confirmed by broker
|
||||
public double Price { get; } // Deal price, confirmed by broker
|
||||
public double Bid { get; } // Current Bid price
|
||||
public double Ask { get; } // Current Ask price
|
||||
public string Comment { get; } // Broker comment to operation (by default it is filled by the operation description)
|
||||
public uint Request_id { get; } // Request ID set by the terminal during the dispatch
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Retcode={Retcode}; Deal={Deal}; Order={Order}; Volume={Volume}; Price={Price}; Bid={Bid}; Ask={Ask}; Comment={Comment}; Request_id={Request_id}";
|
||||
return $"Retcode={Retcode}; Comment={Comment}; Deal={Deal}; Order={Order}; Volume={Volume}; Price={Price}; Bid={Bid}; Ask={Ask}; Request_id={Request_id}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
public class MqlTradeTransaction
|
||||
{
|
||||
public ulong Deal { get; set; } // Deal ticket
|
||||
public ulong Order { get; set; } // Order ticket
|
||||
public string Symbol { get; set; } // Trade symbol name
|
||||
public ENUM_TRADE_TRANSACTION_TYPE Type { get; set; } // Trade transaction type
|
||||
public ENUM_ORDER_TYPE OrderType { get; set; } // Order type
|
||||
public ENUM_ORDER_STATE OrderState { get; set; } // Order state
|
||||
public ENUM_DEAL_TYPE DealType { get; set; } // Deal type
|
||||
public ENUM_ORDER_TYPE_TIME TimeType { get; set; } // Order type by action period
|
||||
|
||||
[JsonIgnore]
|
||||
public DateTime TimeExpiration // Order expiration time
|
||||
{
|
||||
get { return Mt5TimeConverter.ConvertFromMtTime(MtTimeExpiration); }
|
||||
set { MtTimeExpiration = Mt5TimeConverter.ConvertToMtTime(value); }
|
||||
}
|
||||
|
||||
public double Price { get; set; } // Price
|
||||
public double PriceTrigger { get; set; } // Stop limit order activation price
|
||||
public double PriceSl { get; set; } // Stop Loss level
|
||||
public double PriceTp { get; set; } // Take Profit level
|
||||
public double Volume { get; set; } // Volume in lots
|
||||
public ulong Position { get; set; } // Position ticket
|
||||
public ulong PositionBy { get; set; } // Ticket of an opposite position
|
||||
|
||||
public int MtTimeExpiration { get; private set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Deal={Deal}; Order={Order}; Symbol={Symbol}; Type={Type}; OrderType={OrderType}; OrderState={OrderState}; DealType={DealType}; TimeType={TimeType}; TimeExpiration={TimeExpiration}; Price={Price}; PriceTrigger{PriceTrigger}; PriceSl={PriceSl}; PriceTp={PriceTp}; Volume={Volume}; Position={Position}; PositionBy={PositionBy}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
public class Mt5BookEventArgs : EventArgs
|
||||
{
|
||||
public int ExpertHandle { get; set; }
|
||||
public string Symbol { get; set; } //Symbol of OnBookEvent event.
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
namespace MtApi5
|
||||
// ReSharper disable InconsistentNaming
|
||||
namespace MtApi5
|
||||
{
|
||||
internal enum Mt5CommandType
|
||||
{
|
||||
//NoCommand = 0
|
||||
|
||||
//trade operations
|
||||
OrderSend = 1,
|
||||
//OrderSend = 1,
|
||||
OrderCalcMargin = 2,
|
||||
OrderCalcProfit = 3,
|
||||
OrderCheck = 4,
|
||||
//OrderCheck = 4,
|
||||
//OrderSendAsync = 5,
|
||||
PositionsTotal = 6,
|
||||
PositionGetSymbol = 7,
|
||||
@@ -94,13 +95,13 @@
|
||||
SymbolInfoSessionTrade = 59,
|
||||
MarketBookAdd = 60,
|
||||
MarketBookRelease = 61,
|
||||
MarketBookGet = 62,
|
||||
//MarketBookGet = 62,
|
||||
OrderCloseAll = 63,
|
||||
|
||||
//CTrade
|
||||
PositionClose = 64,
|
||||
PositionOpen = 65,
|
||||
PositionOpenWithResult = 1065,
|
||||
//PositionOpenWithResult = 1065,
|
||||
|
||||
//Backtesting
|
||||
BacktestingReady = 66,
|
||||
@@ -170,6 +171,14 @@
|
||||
iTriX = 123,
|
||||
iWPR = 124,
|
||||
iVIDyA = 125,
|
||||
iVolumes = 126
|
||||
iVolumes = 126,
|
||||
|
||||
//Date and Time
|
||||
TimeCurrent = 127,
|
||||
TimeTradeServer = 128,
|
||||
TimeLocal = 129,
|
||||
TimeGMT = 130,
|
||||
|
||||
IndicatorRelease = 131
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ namespace MtApi5
|
||||
{
|
||||
public class Mt5ConnectionEventArgs: EventArgs
|
||||
{
|
||||
public Mt5ConnectionState Status { get; private set; }
|
||||
public string ConnectionMessage { get; private set; }
|
||||
public Mt5ConnectionState Status { get; }
|
||||
public string ConnectionMessage { get; }
|
||||
|
||||
public Mt5ConnectionEventArgs(Mt5ConnectionState status, string message)
|
||||
{
|
||||
|
||||
+77
-11
@@ -1,4 +1,6 @@
|
||||
namespace MtApi5
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
|
||||
// Chart Constants:
|
||||
@@ -580,16 +582,16 @@
|
||||
public enum ENUM_TRADE_TRANSACTION_TYPE
|
||||
{
|
||||
TRADE_TRANSACTION_ORDER_ADD = 0, //Adding a new open order
|
||||
TRADE_TRANSACTION_ORDER_UPDATE = 1, //Updating an open order
|
||||
TRADE_TRANSACTION_ORDER_DELETE = 2, //Removing an order from the list of the open ones
|
||||
TRADE_TRANSACTION_DEAL_ADD = 6, //Adding a deal to the history
|
||||
TRADE_TRANSACTION_DEAL_UPDATE = 7, //Updating a deal in the history
|
||||
TRADE_TRANSACTION_DEAL_DELETE = 8, //Deleting a deal from the history
|
||||
TRADE_TRANSACTION_HISTORY_ADD = 3, //Adding an order to the history as a result of execution or cancellation
|
||||
TRADE_TRANSACTION_HISTORY_UPDATE = 4, //Changing an order located in the orders history
|
||||
TRADE_TRANSACTION_HISTORY_DELETE = 5, //Deleting an order from the orders history
|
||||
TRADE_TRANSACTION_POSITION = 9, //Changing a position not related to a deal execution
|
||||
TRADE_TRANSACTION_REQUEST = 10 //Notification of the fact that a trade request has been processed by a server and processing result has been received
|
||||
TRADE_TRANSACTION_ORDER_UPDATE = 1, //Updating an open order. The updates include not only evident changes from the client terminal or a trade server sides but also changes of an order state when setting it (for example, transition from ORDER_STATE_STARTED to ORDER_STATE_PLACED or from ORDER_STATE_PLACED to ORDER_STATE_PARTIAL, etc.).
|
||||
TRADE_TRANSACTION_ORDER_DELETE = 2, //Removing an order from the list of the open ones. An order can be deleted from the open ones as a result of setting an appropriate request or execution (filling) and moving to the history.
|
||||
TRADE_TRANSACTION_DEAL_ADD = 6, //Adding a deal to the history. The action is performed as a result of an order execution or performing operations with an account balance.
|
||||
TRADE_TRANSACTION_DEAL_UPDATE = 7, //Updating a deal in the history. There may be cases when a previously executed deal is changed on a server. For example, a deal has been changed in an external trading system (exchange) where it was previously transferred by a broker.
|
||||
TRADE_TRANSACTION_DEAL_DELETE = 8, //Deleting a deal from the history. There may be cases when a previously executed deal is deleted from a server. For example, a deal has been deleted in an external trading system (exchange) where it was previously transferred by a broker.
|
||||
TRADE_TRANSACTION_HISTORY_ADD = 3, //Adding an order to the history as a result of execution or cancellation.
|
||||
TRADE_TRANSACTION_HISTORY_UPDATE = 4, //Changing an order located in the orders history. This type is provided for enhancing functionality on a trade server side.
|
||||
TRADE_TRANSACTION_HISTORY_DELETE = 5, //Deleting an order from the orders history. This type is provided for enhancing functionality on a trade server side.
|
||||
TRADE_TRANSACTION_POSITION = 9, //Changing a position not related to a deal execution. This type of transaction shows that a position has been changed on a trade server side. Position volume, open price, Stop Loss and Take Profit levels can be changed. Data on changes are submitted in MqlTradeTransaction structure via OnTradeTransaction handler. Position change (adding, changing or closing), as a result of a deal execution, does not lead to the occurrence of TRADE_TRANSACTION_POSITION transaction.
|
||||
TRADE_TRANSACTION_REQUEST = 10 //Notification of the fact that a trade request has been processed by a server and processing result has been received. Only type field (trade transaction type) must be analyzed for such transactions in MqlTradeTransaction structure. The second and third parameters of OnTradeTransaction (request and result) must be analyzed for additional data.
|
||||
}
|
||||
|
||||
#endregion //Trade Transaction Types
|
||||
@@ -782,4 +784,68 @@
|
||||
}
|
||||
|
||||
#endregion //Smoothing Methods
|
||||
|
||||
#region Indicator constants
|
||||
|
||||
public enum ENUM_INDICATOR
|
||||
{
|
||||
IND_AC = 5, // Accelerator Oscillator
|
||||
IND_AD = 6, // Accumulation/Distribution
|
||||
IND_ADX = 8, // Average Directional Index
|
||||
IND_ADXW = 9, // ADX by Welles Wilder
|
||||
IND_ALLIGATOR = 7, // Alligator
|
||||
IND_AMA = 40, // Adaptive Moving Average
|
||||
IND_AO = 11, // Awesome Oscillator
|
||||
IND_ATR = 10, // Average True Range
|
||||
IND_BANDS = 13, // Bollinger Bands®
|
||||
IND_BEARS = 12, // Bears Power
|
||||
IND_BULLS = 14, // Bulls Power
|
||||
IND_BWMFI = 22, // Market Facilitation Index
|
||||
IND_CCI = 15, // Commodity Channel Index
|
||||
IND_CHAIKIN = 41, // Chaikin Oscillator
|
||||
IND_CUSTOM = 43, // Custom indicator
|
||||
IND_DEMA = 36, // Double Exponential Moving Average
|
||||
IND_DEMARKER = 16, // DeMarker
|
||||
IND_ENVELOPES = 17, // Envelopes
|
||||
IND_FORCE = 18, // Force Index
|
||||
IND_FRACTALS = 19, // Fractals
|
||||
IND_FRAMA = 39, // Fractal Adaptive Moving Average
|
||||
IND_GATOR = 20, // Gator Oscillator
|
||||
IND_ICHIMOKU = 21, // Ichimoku Kinko Hyo
|
||||
IND_MA = 26, // Moving Average
|
||||
IND_MACD = 23, // MACD
|
||||
IND_MFI = 25, // Money Flow Index
|
||||
IND_MOMENTUM = 24, // Momentum
|
||||
IND_OBV = 28, // On Balance Volume
|
||||
IND_OSMA = 27, // OsMA
|
||||
IND_RSI = 30, // Relative Strength Index
|
||||
IND_RVI = 31, // Relative Vigor Index
|
||||
IND_SAR = 29, // Parabolic SAR
|
||||
IND_STDDEV = 32, // Standard Deviation
|
||||
IND_STOCHASTIC = 33, // Stochastic Oscillator
|
||||
IND_TEMA = 37, // Triple Exponential Moving Average
|
||||
IND_TRIX = 38, // Triple Exponential Moving Averages Oscillator
|
||||
IND_VIDYA = 42, // Variable Index Dynamic Average
|
||||
IND_VOLUMES = 34, // Volumes
|
||||
IND_WPR = 35 // Williams' Percent Ranges
|
||||
}
|
||||
|
||||
public enum ENUM_DATATYPE
|
||||
{
|
||||
TYPE_BOOL = 1,
|
||||
TYPE_CHAR = 2,
|
||||
TYPE_UCHAR = 3,
|
||||
TYPE_SHORT = 4,
|
||||
TYPE_USHORT = 5,
|
||||
TYPE_COLOR = 6,
|
||||
TYPE_INT = 7,
|
||||
TYPE_UINT = 8,
|
||||
TYPE_DATETIME = 9,
|
||||
TYPE_LONG = 10,
|
||||
TYPE_ULONG = 11,
|
||||
TYPE_FLOAT = 12,
|
||||
TYPE_DOUBLE = 13,
|
||||
TYPE_STRING = 14
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
+4
-9
@@ -1,15 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace MtApi5
|
||||
namespace MtApi5
|
||||
{
|
||||
public class Mt5Quote
|
||||
{
|
||||
public string Instrument { get; private set; }
|
||||
public double Bid { get; private set; }
|
||||
public double Ask { get; private set; }
|
||||
public string Instrument { get; }
|
||||
public double Bid { get; }
|
||||
public double Ask { get; }
|
||||
|
||||
public Mt5Quote(string instrument, double bid, double ask)
|
||||
{
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
public class Mt5QuoteEventArgs: EventArgs
|
||||
{
|
||||
public Mt5Quote Quote { get; private set; }
|
||||
public Mt5Quote Quote { get; }
|
||||
|
||||
public Mt5QuoteEventArgs(Mt5Quote quote)
|
||||
{
|
||||
|
||||
@@ -1,32 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
class Mt5TimeConverter
|
||||
internal class Mt5TimeConverter
|
||||
{
|
||||
public static DateTime ConvertFromMtTime(int time)
|
||||
{
|
||||
DateTime tmpTime = new DateTime(1970, 1, 1);
|
||||
var tmpTime = new DateTime(1970, 1, 1);
|
||||
return new DateTime(tmpTime.Ticks + (time * 0x989680L));
|
||||
}
|
||||
|
||||
public static DateTime ConvertFromMtTime(long time)
|
||||
{
|
||||
DateTime tmpTime = new DateTime(1970, 1, 1);
|
||||
var tmpTime = new DateTime(1970, 1, 1);
|
||||
return new DateTime(tmpTime.Ticks + (time * 0x989680L));
|
||||
}
|
||||
|
||||
public static int ConvertToMtTime(DateTime time)
|
||||
{
|
||||
int result = 0;
|
||||
if (time != DateTime.MinValue)
|
||||
{
|
||||
DateTime tmpTime = new DateTime(1970, 1, 1);
|
||||
result = (int)((time.Ticks - tmpTime.Ticks) / 0x989680L);
|
||||
}
|
||||
var result = 0;
|
||||
if (time == DateTime.MinValue) return result;
|
||||
var tmpTime = new DateTime(1970, 1, 1);
|
||||
result = (int)((time.Ticks - tmpTime.Ticks) / 0x989680L);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
public class Mt5TradeTransactionEventArgs : EventArgs
|
||||
{
|
||||
public int ExpertHandle { get; set; }
|
||||
public MqlTradeTransaction Trans { get; set; } // trade transaction structure
|
||||
public MqlTradeRequest Request { get; set; } // request structure
|
||||
public MqlTradeResult Result { get; set; } // result structure
|
||||
}
|
||||
}
|
||||
+16
-3
@@ -48,10 +48,15 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CopyTicksFlag.cs" />
|
||||
<Compile Include="Events\OnBookEvent.cs" />
|
||||
<Compile Include="Events\OnTradeTransactionEvent.cs" />
|
||||
<Compile Include="MqlBookInfo.cs" />
|
||||
<Compile Include="MqlParam.cs" />
|
||||
<Compile Include="MqlRates.cs" />
|
||||
<Compile Include="MqlTick.cs" />
|
||||
<Compile Include="MqlTradeCheckResult.cs" />
|
||||
<Compile Include="MqlTradeTransaction.cs" />
|
||||
<Compile Include="Mt5BookEventArgs.cs" />
|
||||
<Compile Include="Mt5TimeConverter.cs" />
|
||||
<Compile Include="Mt5Enums.cs" />
|
||||
<Compile Include="Mt5ConnectionEventArgs.cs" />
|
||||
@@ -59,20 +64,27 @@
|
||||
<Compile Include="MqlTradeRequest.cs" />
|
||||
<Compile Include="MqlTradeResult.cs" />
|
||||
<Compile Include="Mt5QuoteEventArgs.cs" />
|
||||
<Compile Include="Mt5TradeTransactionEventArgs.cs" />
|
||||
<Compile Include="MtApi5Client.cs" />
|
||||
<Compile Include="Mt5CommandType.cs" />
|
||||
<Compile Include="MtConverters.cs" />
|
||||
<Compile Include="ErrorCode.cs" />
|
||||
<Compile Include="ExecutionException.cs" />
|
||||
<Compile Include="Events\Mt5EventTypes.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Mt5Quote.cs" />
|
||||
<Compile Include="Requests\CopyTicksRequest.cs" />
|
||||
<Compile Include="Requests\ICustomRequest.cs" />
|
||||
<Compile Include="Requests\IndicatorCreateRequest.cs" />
|
||||
<Compile Include="Requests\MarketBookGetRequest.cs" />
|
||||
<Compile Include="Requests\OrderCheckRequest.cs" />
|
||||
<Compile Include="Requests\OrderCheckResult.cs" />
|
||||
<Compile Include="Requests\OrderSendRequest.cs" />
|
||||
<Compile Include="Requests\PositionOpenRequest.cs" />
|
||||
<Compile Include="Requests\RequestBase.cs" />
|
||||
<Compile Include="Requests\RequestType.cs" />
|
||||
<Compile Include="Responses\CopyTicksResponse.cs" />
|
||||
<Compile Include="Responses\ICustomResponse.cs" />
|
||||
<Compile Include="Responses\ResponseBase.cs" />
|
||||
<Compile Include="Requests\OrderSendResult.cs" />
|
||||
<Compile Include="Requests\Response.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MTApiService\MTApiService.csproj">
|
||||
@@ -83,6 +95,7 @@
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
+240
-50
@@ -1,13 +1,14 @@
|
||||
using System;
|
||||
// ReSharper disable InconsistentNaming
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MTApiService;
|
||||
using System.Collections;
|
||||
using System.ServiceModel;
|
||||
using MtApi5.Requests;
|
||||
using MtApi5.Responses;
|
||||
using Newtonsoft.Json;
|
||||
using System.Threading.Tasks;
|
||||
using MtApi5.Events;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
@@ -32,9 +33,11 @@ namespace MtApi5
|
||||
|
||||
|
||||
#region Private Fields
|
||||
private static readonly MtLog Log = LogConfigurator.GetLogger(typeof(MtApi5Client));
|
||||
|
||||
private MtClient _client;
|
||||
private readonly object _locker = new object();
|
||||
private volatile bool _isBacktestingMode = false;
|
||||
private volatile bool _isBacktestingMode;
|
||||
private Mt5ConnectionState _connectionState = Mt5ConnectionState.Disconnected;
|
||||
private int _executorHandle;
|
||||
#endregion
|
||||
@@ -78,8 +81,8 @@ namespace MtApi5
|
||||
public IEnumerable<Mt5Quote> GetQuotes()
|
||||
{
|
||||
var client = Client;
|
||||
var quotes = client != null ? client.GetQuotes() : null;
|
||||
return quotes?.Select(q => q.Parse());
|
||||
var quotes = client?.GetQuotes();
|
||||
return quotes?.Select(q => q.Convert());
|
||||
}
|
||||
|
||||
///<summary>
|
||||
@@ -104,17 +107,22 @@ namespace MtApi5
|
||||
/// </returns>
|
||||
public bool OrderSend(MqlTradeRequest request, out MqlTradeResult result)
|
||||
{
|
||||
Log.Debug($"OrderSend: request = {request}");
|
||||
|
||||
if (request == null)
|
||||
{
|
||||
Log.Warn("OrderSend: request is not defined!");
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
var commandParameters = request.ToArrayList();
|
||||
var response = SendRequest<OrderSendResult>(new OrderSendRequest
|
||||
{
|
||||
TradeRequest = request
|
||||
});
|
||||
|
||||
var strResult = SendCommand<string>(Mt5CommandType.OrderSend, commandParameters);
|
||||
|
||||
return strResult.ParseResult(ParamSeparator, out result);
|
||||
result = response?.TradeResult;
|
||||
return response != null && response.RetVal;
|
||||
}
|
||||
|
||||
///<summary>
|
||||
@@ -180,17 +188,22 @@ namespace MtApi5
|
||||
/// </returns>
|
||||
public bool OrderCheck(MqlTradeRequest request, out MqlTradeCheckResult result)
|
||||
{
|
||||
Log.Debug($"OrderCheck: request = {request}");
|
||||
|
||||
if (request == null)
|
||||
{
|
||||
Log.Warn("OrderCheck: request is not defined!");
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
var commandParameters = request.ToArrayList();
|
||||
var response = SendRequest<OrderCheckResult>(new OrderCheckRequest
|
||||
{
|
||||
TradeRequest = request
|
||||
});
|
||||
|
||||
var strResult = SendCommand<string>(Mt5CommandType.OrderSend, commandParameters);
|
||||
|
||||
return strResult.ParseResult(ParamSeparator, out result);
|
||||
result = response?.TradeCheckResult;
|
||||
return response != null && response.RetVal;
|
||||
}
|
||||
|
||||
///<summary>
|
||||
@@ -533,13 +546,25 @@ namespace MtApi5
|
||||
/// <param name="sl">Stop Loss price</param>
|
||||
/// <param name="tp">Take Profit price</param>
|
||||
/// <param name="comment">comment</param>
|
||||
/// <param name="result">output result</param>
|
||||
/// <returns>true - successful check of the basic structures, otherwise - false.</returns>
|
||||
public bool PositionOpen(string symbol, ENUM_ORDER_TYPE orderType, double volume, double price, double sl, double tp, string comment , out MqlTradeResult result)
|
||||
{
|
||||
var commandParameters = new ArrayList { symbol, (int)orderType, volume, price, sl, tp, comment };
|
||||
Log.Debug($"PositionOpen: symbol = {symbol}, orderType = {orderType}, volume = {volume}, price = {price}, sl = {sl}, tp = {tp}, comment = {comment}");
|
||||
|
||||
var strResult = SendCommand<string>(Mt5CommandType.PositionOpenWithResult, commandParameters);
|
||||
return strResult.ParseResult(ParamSeparator, out result);
|
||||
var response = SendRequest<OrderSendResult>(new PositionOpenRequest
|
||||
{
|
||||
Symbol = symbol,
|
||||
OrderType = orderType,
|
||||
Volume = volume,
|
||||
Price = price,
|
||||
Sl = sl,
|
||||
Tp = tp,
|
||||
Comment = comment
|
||||
});
|
||||
|
||||
result = response?.TradeResult;
|
||||
return response != null && response.RetVal;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -711,7 +736,7 @@ namespace MtApi5
|
||||
|
||||
return ratesArray?.Length ?? 0;
|
||||
}
|
||||
|
||||
|
||||
///<summary>
|
||||
///Gets history data of MqlRates structure of a specified symbol-period in specified quantity into the ratesArray array. The elements ordering of the copied data is from present to the past, i.e., starting position of 0 means the current bar.
|
||||
///</summary>
|
||||
@@ -1229,11 +1254,40 @@ namespace MtApi5
|
||||
///<see href="https://www.mql5.com/en/docs/series/copyticks"/>
|
||||
public List<MqlTick> CopyTicks(string symbolName, CopyTicksFlag flags = CopyTicksFlag.All, ulong from = 0, uint count = 0)
|
||||
{
|
||||
var response = SendRequest<CopyTicksResponse>(new CopyTicksRequest
|
||||
var response = SendRequest<List<MqlTick>>(new CopyTicksRequest
|
||||
{
|
||||
SymbolName = symbolName, Flags = (int)flags, From = from, Count = count
|
||||
SymbolName = symbolName,
|
||||
Flags = (int)flags,
|
||||
From = from,
|
||||
Count = count
|
||||
});
|
||||
return response.Ticks;
|
||||
return response;
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///The function returns the handle of a specified technical indicator created based on the array of parameters of MqlParam type.
|
||||
///</summary>
|
||||
///<param name="symbol">Name of a symbol, on data of which the indicator is calculated. NULL means the current symbol.</param>
|
||||
///<param name="period">The value of the timeframe can be one of values of the ENUM_TIMEFRAMES enumeration, 0 means the current timeframe.</param>
|
||||
///<param name="indicatorType">Indicator type, can be one of values of the ENUM_INDICATOR enumeration.</param>
|
||||
///<param name="parameters">An array of MqlParam type, whose elements contain the type and value of each input parameter of a technical indicator.</param>
|
||||
public int IndicatorCreate(string symbol, ENUM_TIMEFRAMES period, ENUM_INDICATOR indicatorType, List<MqlParam> parameters = null)
|
||||
{
|
||||
var response = SendRequest<int>(new IndicatorCreateRequest
|
||||
{
|
||||
Symbol = symbol,
|
||||
Period = period,
|
||||
IndicatorType = indicatorType,
|
||||
Parameters = parameters
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
||||
public bool IndicatorRelease(int indicatorHandle)
|
||||
{
|
||||
var commandParameters = new ArrayList { indicatorHandle };
|
||||
|
||||
return SendCommand<bool>(Mt5CommandType.IndicatorRelease, commandParameters);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -1407,22 +1461,13 @@ namespace MtApi5
|
||||
///<param name="book">Reference to an array of Depth of Market records.</param>
|
||||
public bool MarketBookGet(string symbol, out MqlBookInfo[] book)
|
||||
{
|
||||
var commandParameters = new ArrayList { symbol };
|
||||
|
||||
var retVal = SendCommand<MtMqlBookInfo[]>(Mt5CommandType.MarketBookGet, commandParameters);
|
||||
|
||||
book = null;
|
||||
if (retVal != null)
|
||||
var response = SendRequest<List<MqlBookInfo>>(new MarketBookGetRequest
|
||||
{
|
||||
book = new MqlBookInfo[retVal.Length];
|
||||
Symbol = symbol
|
||||
});
|
||||
|
||||
foreach (var t in retVal)
|
||||
{
|
||||
book[0] = new MqlBookInfo((ENUM_BOOK_TYPE)t.type, t.price, t.volume);
|
||||
}
|
||||
}
|
||||
|
||||
return book != null;
|
||||
book = response?.ToArray();
|
||||
return response != null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -1640,8 +1685,6 @@ namespace MtApi5
|
||||
|
||||
#region Technical Indicators
|
||||
|
||||
#endregion //Technical Indicators
|
||||
|
||||
///<summary>
|
||||
///The function creates Accelerator Oscillator in a global cache of the client terminal and returns its handle.
|
||||
///</summary>
|
||||
@@ -2169,7 +2212,8 @@ namespace MtApi5
|
||||
///<param name="parameters">input-parameters of a custom indicator. If there is no parameters specified, then default values will be used.</param>
|
||||
public int iCustom(string symbol, ENUM_TIMEFRAMES period, string name, double[] parameters)
|
||||
{
|
||||
var response = SendRequest<ICustomResponse>(new ICustomRequest
|
||||
Log.Debug("iCustom: called.");
|
||||
var response = SendRequest<int>(new ICustomRequest
|
||||
{
|
||||
Symbol = symbol,
|
||||
Timeframe = (int)period,
|
||||
@@ -2177,7 +2221,8 @@ namespace MtApi5
|
||||
Params = new ArrayList(parameters),
|
||||
ParamsType = ICustomRequest.ParametersType.Double
|
||||
});
|
||||
return response?.Value ?? 0;
|
||||
Log.Debug($"iCustom: response = {response}.");
|
||||
return response;
|
||||
}
|
||||
|
||||
///<summary>
|
||||
@@ -2189,7 +2234,8 @@ namespace MtApi5
|
||||
///<param name="parameters">input-parameters of a custom indicator. If there is no parameters specified, then default values will be used.</param>
|
||||
public int iCustom(string symbol, ENUM_TIMEFRAMES period, string name, int[] parameters)
|
||||
{
|
||||
var response = SendRequest<ICustomResponse>(new ICustomRequest
|
||||
Log.Debug("iCustom: called.");
|
||||
var response = SendRequest<int>(new ICustomRequest
|
||||
{
|
||||
Symbol = symbol,
|
||||
Timeframe = (int)period,
|
||||
@@ -2197,9 +2243,104 @@ namespace MtApi5
|
||||
Params = new ArrayList(parameters),
|
||||
ParamsType = ICustomRequest.ParametersType.Int
|
||||
});
|
||||
return response?.Value ?? 0;
|
||||
Log.Debug($"iCustom: response = {response}.");
|
||||
return response;
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///The function returns the handle of the Volumes indicator.
|
||||
///</summary>
|
||||
///<param name="symbol">The symbol name of the security, the data of which should be used to calculate the indicator.</param>
|
||||
///<param name="period">The value of the period can be one of the ENUM_TIMEFRAMES enumeration values, 0 means the current timeframe.</param>
|
||||
///<param name="name">The name of the custom indicator, with path relative to the root directory of indicators (MQL5/Indicators/). If an indicator is located in a subdirectory, for example, in MQL5/Indicators/Examples, its name must be specified like: "Examples\\indicator_name" (it is necessary to use a double slash instead of the single slash as a separator).</param>
|
||||
///<param name="parameters">input-parameters of a custom indicator. If there is no parameters specified, then default values will be used.</param>
|
||||
public int iCustom(string symbol, ENUM_TIMEFRAMES period, string name, string[] parameters)
|
||||
{
|
||||
Log.Debug("iCustom: called.");
|
||||
var response = SendRequest<int>(new ICustomRequest
|
||||
{
|
||||
Symbol = symbol,
|
||||
Timeframe = (int)period,
|
||||
Name = name,
|
||||
Params = new ArrayList(parameters),
|
||||
ParamsType = ICustomRequest.ParametersType.Int
|
||||
});
|
||||
Log.Debug($"iCustom: response = {response}.");
|
||||
return response;
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///The function returns the handle of the Volumes indicator.
|
||||
///</summary>
|
||||
///<param name="symbol">The symbol name of the security, the data of which should be used to calculate the indicator.</param>
|
||||
///<param name="period">The value of the period can be one of the ENUM_TIMEFRAMES enumeration values, 0 means the current timeframe.</param>
|
||||
///<param name="name">The name of the custom indicator, with path relative to the root directory of indicators (MQL5/Indicators/). If an indicator is located in a subdirectory, for example, in MQL5/Indicators/Examples, its name must be specified like: "Examples\\indicator_name" (it is necessary to use a double slash instead of the single slash as a separator).</param>
|
||||
///<param name="parameters">input-parameters of a custom indicator. If there is no parameters specified, then default values will be used.</param>
|
||||
public int iCustom(string symbol, ENUM_TIMEFRAMES period, string name, bool[] parameters)
|
||||
{
|
||||
Log.Debug("iCustom: called.");
|
||||
var response = SendRequest<int>(new ICustomRequest
|
||||
{
|
||||
Symbol = symbol,
|
||||
Timeframe = (int)period,
|
||||
Name = name,
|
||||
Params = new ArrayList(parameters),
|
||||
ParamsType = ICustomRequest.ParametersType.Int
|
||||
});
|
||||
Log.Debug($"iCustom: response = {response}.");
|
||||
return response;
|
||||
}
|
||||
|
||||
#endregion //Technical Indicators
|
||||
|
||||
#region Date and Time
|
||||
|
||||
///<summary>
|
||||
///Returns the last known server time, time of the last quote receipt for one of the symbols selected in the "Market Watch" window.
|
||||
///</summary>
|
||||
public DateTime TimeCurrent()
|
||||
{
|
||||
Log.Debug("TimeCurrent: called.");
|
||||
var response = SendCommand<long>(Mt5CommandType.TimeCurrent, null);
|
||||
Log.Debug($"TimeCurrent: response = {response}.");
|
||||
return Mt5TimeConverter.ConvertFromMtTime(response);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the calculated current time of the trade server. Unlike TimeCurrent(), the calculation of the time value is performed in the client terminal and depends on the time settings on your computer.
|
||||
///</summary>
|
||||
public DateTime TimeTradeServer()
|
||||
{
|
||||
Log.Debug("TimeTradeServer: called.");
|
||||
var response = SendCommand<long>(Mt5CommandType.TimeTradeServer, null);
|
||||
Log.Debug($"TimeTradeServer: response = {response}.");
|
||||
return Mt5TimeConverter.ConvertFromMtTime(response);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the local time of a computer, where the client terminal is running.
|
||||
///</summary>
|
||||
public DateTime TimeLocal()
|
||||
{
|
||||
Log.Debug("TimeLocal: called.");
|
||||
var response = SendCommand<long>(Mt5CommandType.TimeLocal, null);
|
||||
Log.Debug($"TimeLocal: response = {response}.");
|
||||
return Mt5TimeConverter.ConvertFromMtTime(response);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the GMT, which is calculated taking into account the DST switch by the local time on the computer where the client terminal is running.
|
||||
///</summary>
|
||||
public DateTime TimeGMT()
|
||||
{
|
||||
Log.Debug("TimeGMT: called.");
|
||||
var response = SendCommand<long>(Mt5CommandType.TimeGMT, null);
|
||||
Log.Debug($"TimeGMT: response = {response}.");
|
||||
return Mt5TimeConverter.ConvertFromMtTime(response);
|
||||
}
|
||||
|
||||
#endregion //Date and Time
|
||||
|
||||
#endregion // Public Methods
|
||||
|
||||
#region Properties
|
||||
@@ -2241,9 +2382,12 @@ namespace MtApi5
|
||||
|
||||
#region Events
|
||||
public event QuoteHandler QuoteUpdated;
|
||||
public event EventHandler<Mt5QuoteEventArgs> QuoteUpdate;
|
||||
public event EventHandler<Mt5QuoteEventArgs> QuoteAdded;
|
||||
public event EventHandler<Mt5QuoteEventArgs> QuoteRemoved;
|
||||
public event EventHandler<Mt5ConnectionEventArgs> ConnectionStateChanged;
|
||||
public event EventHandler<Mt5TradeTransactionEventArgs> OnTradeTransaction;
|
||||
public event EventHandler<Mt5BookEventArgs> OnBookEvent;
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
@@ -2297,6 +2441,7 @@ namespace MtApi5
|
||||
_client.QuoteUpdated += _client_QuoteUpdated;
|
||||
_client.ServerDisconnected += _client_ServerDisconnected;
|
||||
_client.ServerFailed += _client_ServerFailed;
|
||||
_client.MtEventReceived += _client_MtEventReceived;
|
||||
message = string.IsNullOrEmpty(client.Host) ? $"Connected to localhost:{client.Port}" : $"Connected to { client.Host}:{client.Port}";
|
||||
}
|
||||
|
||||
@@ -2311,6 +2456,45 @@ namespace MtApi5
|
||||
}
|
||||
}
|
||||
|
||||
private void _client_MtEventReceived(MtEvent e)
|
||||
{
|
||||
var eventType = (Mt5EventTypes)e.EventType;
|
||||
|
||||
switch (eventType)
|
||||
{
|
||||
case Mt5EventTypes.OnTradeTransaction:
|
||||
ReceivedOnTradeTransaction(e.ExpertHandle, e.Payload);
|
||||
break;
|
||||
case Mt5EventTypes.OnBookEvent:
|
||||
ReceivedOnBookEvent(e.ExpertHandle, e.Payload);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
private void ReceivedOnTradeTransaction(int expertHandler, string payload)
|
||||
{
|
||||
var e = JsonConvert.DeserializeObject<OnTradeTransactionEvent>(payload);
|
||||
OnTradeTransaction?.Invoke(this, new Mt5TradeTransactionEventArgs
|
||||
{
|
||||
ExpertHandle = expertHandler,
|
||||
Trans = e.Trans,
|
||||
Request = e.Request,
|
||||
Result = e.Result
|
||||
});
|
||||
}
|
||||
|
||||
private void ReceivedOnBookEvent(int expertHandler, string payload)
|
||||
{
|
||||
var e = JsonConvert.DeserializeObject<OnBookEvent>(payload);
|
||||
OnBookEvent?.Invoke(this, new Mt5BookEventArgs
|
||||
{
|
||||
ExpertHandle = expertHandler,
|
||||
Symbol = e.Symbol
|
||||
});
|
||||
}
|
||||
|
||||
private void Connect(string host, int port)
|
||||
{
|
||||
var client = new MtClient(host, port);
|
||||
@@ -2341,6 +2525,7 @@ namespace MtApi5
|
||||
_client.QuoteUpdated -= _client_QuoteUpdated;
|
||||
_client.ServerDisconnected -= _client_ServerDisconnected;
|
||||
_client.ServerFailed -= _client_ServerFailed;
|
||||
_client.MtEventReceived -= _client_MtEventReceived;
|
||||
|
||||
if (!failed)
|
||||
{
|
||||
@@ -2388,10 +2573,10 @@ namespace MtApi5
|
||||
}
|
||||
|
||||
var responseValue = response.GetValue();
|
||||
return responseValue != null ? (T)responseValue : default(T);
|
||||
return (T) responseValue;
|
||||
}
|
||||
|
||||
private T SendRequest<T>(RequestBase request) where T : ResponseBase, new()
|
||||
private T SendRequest<T>(RequestBase request)
|
||||
{
|
||||
if (request == null)
|
||||
return default(T);
|
||||
@@ -2410,22 +2595,21 @@ namespace MtApi5
|
||||
throw new ExecutionException(ErrorCode.ErrCustom, "Response from MetaTrader is null");
|
||||
}
|
||||
|
||||
var response = JsonConvert.DeserializeObject<T>(res);
|
||||
var response = JsonConvert.DeserializeObject<Response<T>>(res);
|
||||
if (response.ErrorCode != 0)
|
||||
{
|
||||
throw new ExecutionException((ErrorCode)response.ErrorCode, response.ErrorMessage);
|
||||
}
|
||||
|
||||
return response;
|
||||
return response.Value;
|
||||
}
|
||||
|
||||
|
||||
private void _client_QuoteUpdated(MtQuote quote)
|
||||
{
|
||||
if (quote != null)
|
||||
{
|
||||
QuoteUpdated?.Invoke(this, quote.Instrument, quote.Bid, quote.Ask);
|
||||
}
|
||||
if (quote == null) return;
|
||||
QuoteUpdate?.Invoke(this, new Mt5QuoteEventArgs(new Mt5Quote(quote.Instrument, quote.Bid, quote.Ask)));
|
||||
QuoteUpdated?.Invoke(this, quote.Instrument, quote.Bid, quote.Ask);
|
||||
}
|
||||
|
||||
private void _client_ServerDisconnected(object sender, EventArgs e)
|
||||
@@ -2440,12 +2624,18 @@ namespace MtApi5
|
||||
|
||||
private void _client_QuoteRemoved(MtQuote quote)
|
||||
{
|
||||
QuoteRemoved?.Invoke(this, new Mt5QuoteEventArgs(quote.Parse()));
|
||||
if (quote != null)
|
||||
{
|
||||
QuoteRemoved?.Invoke(this, new Mt5QuoteEventArgs(new Mt5Quote(quote.Instrument, quote.Bid, quote.Ask)));
|
||||
}
|
||||
}
|
||||
|
||||
private void _client_QuoteAdded(MtQuote quote)
|
||||
{
|
||||
QuoteAdded?.Invoke(this, new Mt5QuoteEventArgs(quote.Parse()));
|
||||
if (quote != null)
|
||||
{
|
||||
QuoteAdded?.Invoke(this, new Mt5QuoteEventArgs(new Mt5Quote(quote.Instrument, quote.Bid, quote.Ask)));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnConnected()
|
||||
|
||||
+20
-74
@@ -6,84 +6,18 @@ namespace MtApi5
|
||||
{
|
||||
internal static class MtConverters
|
||||
{
|
||||
private static readonly MtLog Log = LogConfigurator.GetLogger(typeof(MtConverters));
|
||||
|
||||
#region Values Converters
|
||||
public static Mt5Quote Parse(this MtQuote quote)
|
||||
public static Mt5Quote Convert(this MtQuote quote)
|
||||
{
|
||||
return (quote != null) ? new Mt5Quote(quote.Instrument, quote.Bid, quote.Ask) : null;
|
||||
}
|
||||
|
||||
public static bool ParseResult(this string inputString, char separator, out MqlTradeResult result)
|
||||
{
|
||||
var retVal = false;
|
||||
result = null;
|
||||
|
||||
if (string.IsNullOrEmpty(inputString) == false)
|
||||
{
|
||||
var values = inputString.Split(separator);
|
||||
if (values.Length == 10)
|
||||
{
|
||||
try
|
||||
{
|
||||
retVal = int.Parse(values[0]) != 0;
|
||||
|
||||
var retcode = uint.Parse(values[1]);
|
||||
var deal = ulong.Parse(values[2]);
|
||||
var order = ulong.Parse(values[3]);
|
||||
var volume = double.Parse(values[4]);
|
||||
var price = double.Parse(values[5]);
|
||||
var bid = double.Parse(values[6]);
|
||||
var ask = double.Parse(values[7]);
|
||||
var comment = values[8];
|
||||
var requestId = uint.Parse(values[9]);
|
||||
|
||||
result = new MqlTradeResult(retcode, deal, order, volume, price, bid, ask, comment, requestId);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public static bool ParseResult(this string inputString, char separator, out MqlTradeCheckResult result)
|
||||
{
|
||||
var retVal = false;
|
||||
result = null;
|
||||
|
||||
if (string.IsNullOrEmpty(inputString) == false)
|
||||
{
|
||||
var values = inputString.Split(separator);
|
||||
if (values.Length == 10)
|
||||
{
|
||||
try
|
||||
{
|
||||
retVal = int.Parse(values[0]) != 0;
|
||||
|
||||
var retcode = uint.Parse(values[1]);
|
||||
var balance = double.Parse(values[2]);
|
||||
var equity = double.Parse(values[3]);
|
||||
var profit = double.Parse(values[4]);
|
||||
var margin = double.Parse(values[5]);
|
||||
var marginFree = double.Parse(values[6]);
|
||||
var marginLevel = double.Parse(values[7]);
|
||||
var comment = values[8];
|
||||
|
||||
result = new MqlTradeCheckResult(retcode, balance, equity, profit, margin, marginFree, marginLevel, comment);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
retVal = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
return quote != null ? new Mt5Quote(quote.Instrument, quote.Bid, quote.Ask) : null;
|
||||
}
|
||||
|
||||
public static bool ParseResult(this string inputString, char separator, out double result)
|
||||
{
|
||||
Log.Debug($"ParseResult: inputString = {inputString}, separator = {separator}");
|
||||
|
||||
var retVal = false;
|
||||
result = 0;
|
||||
|
||||
@@ -98,18 +32,25 @@ namespace MtApi5
|
||||
|
||||
result = double.Parse(values[1]);
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
retVal = false;
|
||||
Log.Error($"ParseResult: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warn("ParseResult: input srting is null or empty!");
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public static bool ParseResult(this string inputString, char separator, out DateTime from, out DateTime to)
|
||||
{
|
||||
Log.Debug($"ParseResult: inputString = {inputString}, separator = {separator}");
|
||||
|
||||
var retVal = false;
|
||||
|
||||
from = new DateTime();
|
||||
@@ -130,12 +71,17 @@ namespace MtApi5
|
||||
var iTo= int.Parse(values[2]);
|
||||
to = Mt5TimeConverter.ConvertFromMtTime(iTo);
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
retVal = false;
|
||||
Log.Error($"ParseResult: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warn("ParseResult: input srting is null or empty!");
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.14")]
|
||||
[assembly: AssemblyFileVersion("1.0.14")]
|
||||
[assembly: AssemblyVersion("1.0.17")]
|
||||
[assembly: AssemblyFileVersion("1.0.17")]
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class IndicatorCreateRequest: RequestBase
|
||||
{
|
||||
public override RequestType RequestType => RequestType.IndicatorCreate;
|
||||
|
||||
public string Symbol { get; set; }
|
||||
public ENUM_TIMEFRAMES Period { get; set; }
|
||||
public ENUM_INDICATOR IndicatorType { get; set; }
|
||||
public List<MqlParam> Parameters { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class MarketBookGetRequest: RequestBase
|
||||
{
|
||||
public override RequestType RequestType => RequestType.MarketBookGet;
|
||||
|
||||
public string Symbol { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class OrderCheckRequest: RequestBase
|
||||
{
|
||||
public override RequestType RequestType => RequestType.OrderCheck;
|
||||
|
||||
public MqlTradeRequest TradeRequest { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
public class OrderCheckResult
|
||||
{
|
||||
public bool RetVal { get; set; }
|
||||
public MqlTradeCheckResult TradeCheckResult { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class OrderSendRequest: RequestBase
|
||||
{
|
||||
public override RequestType RequestType => RequestType.OrderSend;
|
||||
|
||||
public MqlTradeRequest TradeRequest { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class OrderSendResult
|
||||
{
|
||||
public bool RetVal { get; set; }
|
||||
public MqlTradeResult TradeResult { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class PositionOpenRequest: RequestBase
|
||||
{
|
||||
public override RequestType RequestType => RequestType.PositionOpen;
|
||||
|
||||
public string Symbol { get; set; }
|
||||
public ENUM_ORDER_TYPE OrderType { get; set; }
|
||||
public double Volume { get; set; }
|
||||
public double Price { get; set; }
|
||||
public double Sl { get; set; }
|
||||
public double Tp { get; set; }
|
||||
public string Comment { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,16 @@
|
||||
namespace MtApi5.Requests
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal enum RequestType
|
||||
{
|
||||
Unknown = 0,
|
||||
CopyTicks = 1,
|
||||
iCustom = 2
|
||||
iCustom = 2,
|
||||
OrderSend = 3,
|
||||
PositionOpen = 4,
|
||||
OrderCheck = 5,
|
||||
MarketBookGet = 6,
|
||||
IndicatorCreate = 7
|
||||
}
|
||||
}
|
||||
Executable → Regular
+4
-2
@@ -1,8 +1,10 @@
|
||||
namespace MtApi5.Responses
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class ResponseBase
|
||||
internal class Response<T>
|
||||
{
|
||||
public int ErrorCode { get; set; }
|
||||
public string ErrorMessage { get; set; }
|
||||
|
||||
public T Value { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MtApi5.Responses
|
||||
{
|
||||
internal class CopyTicksResponse: ResponseBase
|
||||
{
|
||||
public List<MqlTick> Ticks { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace MtApi5.Responses
|
||||
{
|
||||
internal class ICustomResponse: ResponseBase
|
||||
{
|
||||
public int Value { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
xmlns:mtapi5="clr-namespace:MtApi5;assembly=MtApi5"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
xmlns:mtApi5TestClient="clr-namespace:MtApi5TestClient"
|
||||
Title="MainWindow" Height="700" Width="650"
|
||||
Title="MainWindow" Height="700" Width="700"
|
||||
Closing="Window_Closing">
|
||||
<Window.Resources>
|
||||
<DataTemplate x:Key="ConnectionTextBlockTemplate" DataType="{x:Type mtapi5:Mt5ConnectionState}">
|
||||
@@ -84,6 +84,13 @@
|
||||
<x:Type TypeName="mtapi5:ENUM_TIMEFRAMES"/>
|
||||
</ObjectDataProvider.MethodParameters>
|
||||
</ObjectDataProvider>
|
||||
|
||||
<ObjectDataProvider x:Key="ENUM_INDICATOR_Key" MethodName="GetValues"
|
||||
ObjectType="{x:Type sys:Enum}">
|
||||
<ObjectDataProvider.MethodParameters>
|
||||
<x:Type TypeName="mtapi5:ENUM_INDICATOR"/>
|
||||
</ObjectDataProvider.MethodParameters>
|
||||
</ObjectDataProvider>
|
||||
</Window.Resources>
|
||||
|
||||
<Grid x:Name="_MainLayout">
|
||||
@@ -100,58 +107,33 @@
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Expander ExpandDirection="Right" IsExpanded="True"
|
||||
Grid.Row="0" Grid.Column="0" Margin="5">
|
||||
<Expander.Header>
|
||||
<TextBlock Text="Connection" RenderTransformOrigin="0.5,0.5" Margin="0,0,0,0" Width="Auto">
|
||||
<TextBlock.LayoutTransform>
|
||||
<TransformGroup>
|
||||
<ScaleTransform ScaleX="1" ScaleY="1"/>
|
||||
<SkewTransform AngleX="0" AngleY="0"/>
|
||||
<RotateTransform Angle="-90"/>
|
||||
<TranslateTransform X="0" Y="0"/>
|
||||
</TransformGroup>
|
||||
</TextBlock.LayoutTransform>
|
||||
<TextBlock.RenderTransform>
|
||||
<TransformGroup>
|
||||
<ScaleTransform ScaleX="1" ScaleY="1"/>
|
||||
<SkewTransform AngleX="0" AngleY="0"/>
|
||||
<RotateTransform Angle="0"/>
|
||||
<TranslateTransform X="0" Y="0"/>
|
||||
</TransformGroup>
|
||||
</TextBlock.RenderTransform>
|
||||
</TextBlock>
|
||||
</Expander.Header>
|
||||
<Expander.Content>
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="150"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="150"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Text="Host"/>
|
||||
<TextBox Grid.Row="0" Grid.Column="1"
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Text="Host"/>
|
||||
<TextBox Grid.Row="0" Grid.Column="1"
|
||||
Margin="5,0,0,0"
|
||||
Text="{Binding Host, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Text="Port"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="1"
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Text="Port"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="1"
|
||||
Margin="5,0,0,0"
|
||||
Text="{Binding Port, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
|
||||
<StackPanel Grid.Row="2" Grid.ColumnSpan="2" Margin="5" Orientation="Horizontal">
|
||||
<Button Content="Connect" Width="70" Command="{Binding ConnectCommand}" />
|
||||
<Button Margin="5,0,0,0" Width="70" Content="Disconnect" Command="{Binding DisconnectCommand}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Expander.Content>
|
||||
</Expander>
|
||||
<StackPanel Grid.Row="2" Grid.ColumnSpan="2" Margin="5" Orientation="Horizontal">
|
||||
<Button Content="Connect" Width="70" Command="{Binding ConnectCommand}" />
|
||||
<Button Margin="5,0,0,0" Width="70" Content="Disconnect" Command="{Binding DisconnectCommand}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<ListView Grid.Row="0" Grid.Column="1"
|
||||
ItemsSource="{Binding Quotes}"
|
||||
@@ -247,18 +229,26 @@
|
||||
SelectedItem="{Binding TradeRequest.Type_time}" Margin="5,0,0,0"/>
|
||||
|
||||
<TextBlock Grid.Column="2" Grid.Row="6" Text="Expiration" Margin="10,0,0,0"/>
|
||||
<TextBox Grid.Column="3" Grid.Row="6" Text="{Binding TradeRequest}" Margin="5,0,0,0"/>
|
||||
<TextBox Grid.Column="3" Grid.Row="6" Text="{Binding TradeRequest.Expiration}" Margin="5,0,0,0"/>
|
||||
|
||||
<TextBlock Grid.Column="0" Grid.Row="7" Text="Comment"/>
|
||||
<TextBox Grid.Column="1" Grid.Row="7" Grid.ColumnSpan="3" Text="{Binding TradeRequest}" Margin="5,0,0,0"/>
|
||||
<TextBox Grid.Column="1" Grid.Row="7" Grid.ColumnSpan="3" Text="{Binding TradeRequest.Comment}" Margin="5,0,0,0"/>
|
||||
</Grid>
|
||||
</Expander>
|
||||
|
||||
<StackPanel Grid.Row="1" Orientation="Vertical">
|
||||
<Button Content="OrderSend" Command="{Binding OrderSendCommand}" Width="100" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||
<Button Content="HistoryDealGetDouble" Command="{Binding HistoryDealGetDoubleCommand}" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||
<Button Content="HistoryDealGetInteger" Command="{Binding HistoryDealGetIntegerCommand}" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||
<Button Content="HistoryDealGetString" Command="{Binding HistoryDealGetStringCommand}" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Button Content="OrderSend" Command="{Binding OrderSendCommand}" Width="100" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||
<Button Content="OrderCheck" Command="{Binding OrderCheckCommand}" Width="100" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||
</StackPanel>
|
||||
|
||||
<WrapPanel>
|
||||
<Button Content="HistoryDealGetDouble" Command="{Binding HistoryDealGetDoubleCommand}" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||
<Button Content="HistoryDealGetInteger" Command="{Binding HistoryDealGetIntegerCommand}" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||
<Button Content="HistoryDealGetString" Command="{Binding HistoryDealGetStringCommand}" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||
<Button Content="HistoryOrderGetInteger" Command="{Binding HistoryOrderGetIntegerCommand}" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||
<Button Content="HistoryDealMethods" Command="{Binding HistoryDealMethodsCommand}" Height="25" HorizontalAlignment="Left" Margin="4"/>
|
||||
</WrapPanel>
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
@@ -322,32 +312,37 @@
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Grid Grid.Column="1">
|
||||
<Grid Grid.Column="1" Margin="2">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid Grid.Row="0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Row="0" Text="Symbol Name" Margin="1"/>
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Text="TimeFrame" Margin="1" HorizontalAlignment="Right"/>
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" Text="StartPos" Margin="1" HorizontalAlignment="Right"/>
|
||||
<TextBlock Grid.Row="3" Grid.Column="0" Text="Count" Margin="1" HorizontalAlignment="Right"/>
|
||||
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding TimeSeriesValues.SymbolValue}" Margin="1"/>
|
||||
<ComboBox Grid.Row="1" Grid.Column="1" Margin="1"
|
||||
ItemsSource="{Binding Source={StaticResource ENUM_TIMEFRAMES_Key}}"
|
||||
SelectedItem="{Binding TimeSeriesValues.TimeFrame}"/>
|
||||
<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding TimeSeriesValues.StartPos}" Margin="1"/>
|
||||
<TextBox Grid.Row="3" Grid.Column="1" Text="{Binding TimeSeriesValues.Count}" Margin="1"/>
|
||||
</Grid>
|
||||
|
||||
<TextBox Grid.Row="0" Text="symbolName"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="0" Text="timeframe"/>
|
||||
<TextBox Grid.Row="2" Grid.Column="0" Text="startPos"/>
|
||||
<TextBox Grid.Row="3" Grid.Column="0" Text="count"/>
|
||||
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding TimeSeriesValues.SymbolValue}"/>
|
||||
<ComboBox Grid.Row="1" Grid.Column="1"
|
||||
ItemsSource="{Binding Source={StaticResource ENUM_TIMEFRAMES_Key}}"
|
||||
SelectedItem="{Binding TimeSeriesValues.TimeFrame}"/>
|
||||
<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding TimeSeriesValues.StartPos}"/>
|
||||
<TextBox Grid.Row="3" Grid.Column="1" Text="{Binding TimeSeriesValues.Count}"/>
|
||||
|
||||
<WrapPanel Grid.Row="4" Grid.ColumnSpan="2" Grid.Column="0" Margin="10">
|
||||
<WrapPanel Grid.Row="1" Grid.Column="0" Margin="5">
|
||||
<Button Command="{Binding CopyRatesCommand}" Margin="1"
|
||||
Content="CopyRates" HorizontalAlignment="Left" />
|
||||
<Button Command="{Binding CopyTimesCommand}" Margin="1"
|
||||
@@ -368,11 +363,33 @@
|
||||
Content="CopySpread" HorizontalAlignment="Left" />
|
||||
<Button Command="{Binding CopyTicksCommand}" Margin="1"
|
||||
Content="CopyTicks" HorizontalAlignment="Left" />
|
||||
|
||||
</WrapPanel>
|
||||
|
||||
<Grid Grid.Row="2">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<ComboBox Grid.Row="0" Grid.Column="0"
|
||||
ItemsSource="{Binding Source={StaticResource ENUM_INDICATOR_Key}}"
|
||||
SelectedItem="{Binding TimeSeriesValues.IndicatorType}"/>
|
||||
<Button Grid.Row="0" Grid.Column="1" Command="{Binding IndicatorCreateCommand}" Margin="2"
|
||||
Content="IndicatorCreate" HorizontalAlignment="Left" />
|
||||
<Label Grid.Row="1" Grid.Column="0" Content="Indicator handle:" Margin="2"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="0" Margin="2" Width="30" PreviewTextInput="NumberValidationTextBox" Text="{Binding TimeSeriesValues.IndicatorHandle}"></TextBox>
|
||||
<Button Grid.Row="1" Grid.Column="1" Command="{Binding IndicatorReleaseCommand}" Margin="2"
|
||||
Content="IndicatorRelease" HorizontalAlignment="Left" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<ListBox ItemsSource="{Binding TimeSeriesResults}" />
|
||||
<ListBox Grid.Column="0" ItemsSource="{Binding TimeSeriesResults}" />
|
||||
|
||||
</Grid>
|
||||
</TabItem>
|
||||
@@ -400,10 +417,25 @@
|
||||
<Button Command="{Binding PositionOpenCommand}" Content="PositionOpen" Margin="2"/>
|
||||
</WrapPanel>
|
||||
</TabItem>
|
||||
|
||||
<TabItem Header="Indicators">
|
||||
<WrapPanel VerticalAlignment="Top" Margin="5">
|
||||
<Button Command="{Binding iCustomCommand}" Content="iCustom" Margin="2"/>
|
||||
</WrapPanel>
|
||||
</TabItem>
|
||||
|
||||
<TabItem Header="Time and Date">
|
||||
<WrapPanel VerticalAlignment="Top" Margin="5">
|
||||
<Button Command="{Binding TimeCurrentCommand}" Content="TimeCurrent" Margin="2"/>
|
||||
<Button Command="{Binding TimeTradeServerCommand}" Content="TimeTradeServer" Margin="2"/>
|
||||
<Button Command="{Binding TimeLocalCommand}" Content="TimeLocal" Margin="2"/>
|
||||
<Button Command="{Binding TimeGMTCommand}" Content="TimeGMT" Margin="2"/>
|
||||
</WrapPanel>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
|
||||
<Expander Grid.Row="2" Header="History" IsExpanded="True">
|
||||
<ListBox mtApi5TestClient:ListBoxBehavior.ScrollOnNewItem="true" Height="200" ItemsSource="{Binding History}"/>
|
||||
<Expander Grid.Row="2" Header="Console" IsExpanded="True">
|
||||
<ListBox mtApi5TestClient:ListBoxBehavior.ScrollOnNewItem="true" Height="180" ItemsSource="{Binding History}"/>
|
||||
</Expander>
|
||||
|
||||
<StatusBar Grid.Row="3">
|
||||
|
||||
@@ -1,37 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace MtApi5TestClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
public partial class MainWindow
|
||||
{
|
||||
ViewModel _vm { get; set; }
|
||||
private ViewModel Vm { get; }
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_vm = new ViewModel();
|
||||
_MainLayout.DataContext = _vm;
|
||||
Vm = new ViewModel();
|
||||
_MainLayout.DataContext = Vm;
|
||||
}
|
||||
|
||||
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
_vm.Close();
|
||||
Vm.Close();
|
||||
}
|
||||
|
||||
private void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
var regex = new Regex("[^0-9]+");
|
||||
e.Handled = regex.IsMatch(e.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using MtApi5;
|
||||
using MtApi5;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace MtApi5TestClient
|
||||
{
|
||||
public class TimeSeriesValueViewModel : INotifyPropertyChanged
|
||||
{
|
||||
private string _SymbolValue;
|
||||
private string _symbolValue;
|
||||
public string SymbolValue
|
||||
{
|
||||
get { return _SymbolValue; }
|
||||
get { return _symbolValue; }
|
||||
set
|
||||
{
|
||||
_SymbolValue = value;
|
||||
_symbolValue = value;
|
||||
OnPropertyChanged("SymbolValue");
|
||||
}
|
||||
}
|
||||
@@ -24,13 +20,36 @@ namespace MtApi5TestClient
|
||||
public int StartPos { get; set; }
|
||||
public int Count { get; set; }
|
||||
|
||||
|
||||
private int _indicatorHandle;
|
||||
public int IndicatorHandle
|
||||
{
|
||||
get { return _indicatorHandle; }
|
||||
set
|
||||
{
|
||||
_indicatorHandle = value;
|
||||
OnPropertyChanged("IndicatorHandle");
|
||||
}
|
||||
}
|
||||
|
||||
private ENUM_INDICATOR _indicatorType = ENUM_INDICATOR.IND_MACD;
|
||||
public ENUM_INDICATOR IndicatorType
|
||||
{
|
||||
get { return _indicatorType; }
|
||||
set
|
||||
{
|
||||
_indicatorType = value;
|
||||
OnPropertyChanged("IndicatorType");
|
||||
}
|
||||
}
|
||||
|
||||
#region INotifyPropertyChanged
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChangedEventHandler handler = PropertyChanged;
|
||||
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
|
||||
var handler = PropertyChanged;
|
||||
handler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
// ReSharper disable InconsistentNaming
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
@@ -16,9 +17,13 @@ namespace MtApi5TestClient
|
||||
public DelegateCommand DisconnectCommand { get; private set; }
|
||||
|
||||
public DelegateCommand OrderSendCommand { get; private set; }
|
||||
public DelegateCommand OrderCheckCommand { get; private set; }
|
||||
|
||||
public DelegateCommand HistoryOrderGetIntegerCommand { get; private set; }
|
||||
public DelegateCommand HistoryDealGetDoubleCommand { get; private set; }
|
||||
public DelegateCommand HistoryDealGetIntegerCommand { get; private set; }
|
||||
public DelegateCommand HistoryDealGetStringCommand { get; private set; }
|
||||
public DelegateCommand HistoryDealMethodsCommand { get; private set; }
|
||||
|
||||
public DelegateCommand AccountInfoDoubleCommand { get; private set; }
|
||||
public DelegateCommand AccountInfoIntegerCommand { get; private set; }
|
||||
@@ -30,6 +35,8 @@ namespace MtApi5TestClient
|
||||
public DelegateCommand CopyHighCommand { get; private set; }
|
||||
public DelegateCommand CopyLowCommand { get; private set; }
|
||||
public DelegateCommand CopyCloseCommand { get; private set; }
|
||||
public DelegateCommand IndicatorCreateCommand { get; private set; }
|
||||
public DelegateCommand IndicatorReleaseCommand { get; private set; }
|
||||
|
||||
public DelegateCommand CopyTickVolumeCommand { get; private set; }
|
||||
public DelegateCommand CopyRealVolumeCommand { get; private set; }
|
||||
@@ -53,6 +60,13 @@ namespace MtApi5TestClient
|
||||
public DelegateCommand PositionOpenCommand { get; private set; }
|
||||
|
||||
public DelegateCommand PrintCommand { get; private set; }
|
||||
|
||||
public DelegateCommand iCustomCommand { get; private set; }
|
||||
|
||||
public DelegateCommand TimeCurrentCommand { get; private set; }
|
||||
public DelegateCommand TimeTradeServerCommand { get; private set; }
|
||||
public DelegateCommand TimeLocalCommand { get; private set; }
|
||||
public DelegateCommand TimeGMTCommand { get; private set; }
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
@@ -160,6 +174,8 @@ namespace MtApi5TestClient
|
||||
_mtApiClient.QuoteAdded += mMtApiClient_QuoteAdded;
|
||||
_mtApiClient.QuoteRemoved += mMtApiClient_QuoteRemoved;
|
||||
_mtApiClient.QuoteUpdated += mMtApiClient_QuoteUpdated;
|
||||
_mtApiClient.OnTradeTransaction += mMtApiClient_OnTradeTransaction;
|
||||
_mtApiClient.OnBookEvent += _mtApiClient_OnBookEvent;
|
||||
|
||||
_quotesMap = new Dictionary<string, QuoteViewModel>();
|
||||
|
||||
@@ -196,9 +212,13 @@ namespace MtApi5TestClient
|
||||
DisconnectCommand = new DelegateCommand(ExecuteDisconnect, CanExecuteDisconnect);
|
||||
|
||||
OrderSendCommand = new DelegateCommand(ExecuteOrderSend);
|
||||
OrderCheckCommand = new DelegateCommand(ExecuteOrderCheck);
|
||||
|
||||
HistoryOrderGetIntegerCommand = new DelegateCommand(ExecuteHistoryOrderGetInteger);
|
||||
HistoryDealGetDoubleCommand = new DelegateCommand(ExecuteHistoryDealGetDouble);
|
||||
HistoryDealGetIntegerCommand = new DelegateCommand(ExecuteHistoryDealGetInteger);
|
||||
HistoryDealGetStringCommand = new DelegateCommand(ExecuteHistoryDealGetString);
|
||||
HistoryDealMethodsCommand = new DelegateCommand(ExecuteHistoryDealMethods);
|
||||
|
||||
AccountInfoDoubleCommand = new DelegateCommand(ExecuteAccountInfoDouble);
|
||||
AccountInfoIntegerCommand = new DelegateCommand(ExecuteAccountInfoInteger);
|
||||
@@ -210,6 +230,8 @@ namespace MtApi5TestClient
|
||||
CopyHighCommand = new DelegateCommand(ExecuteCopyHigh);
|
||||
CopyLowCommand = new DelegateCommand(ExecuteCopyLow);
|
||||
CopyCloseCommand = new DelegateCommand(ExecuteCopyClose);
|
||||
IndicatorCreateCommand = new DelegateCommand(ExecuteIndicatorCreate);
|
||||
IndicatorReleaseCommand = new DelegateCommand(ExecuteIndicatorRelease);
|
||||
|
||||
CopyTickVolumeCommand = new DelegateCommand(ExecuteCopyTickVolume);
|
||||
CopyRealVolumeCommand = new DelegateCommand(ExecuteCopyRealVolume);
|
||||
@@ -233,6 +255,13 @@ namespace MtApi5TestClient
|
||||
PositionOpenCommand = new DelegateCommand(ExecutePositionOpen);
|
||||
|
||||
PrintCommand = new DelegateCommand(ExecutePrint);
|
||||
|
||||
iCustomCommand = new DelegateCommand(ExecuteICustom);
|
||||
|
||||
TimeCurrentCommand = new DelegateCommand(ExecuteTimeCurrent);
|
||||
TimeTradeServerCommand = new DelegateCommand(ExecuteTimeTradeServer);
|
||||
TimeLocalCommand = new DelegateCommand(ExecuteTimeLocal);
|
||||
TimeGMTCommand = new DelegateCommand(ExecuteTimeGMT);
|
||||
}
|
||||
|
||||
private bool CanExecuteConnect(object o)
|
||||
@@ -265,18 +294,42 @@ namespace MtApi5TestClient
|
||||
private async void ExecuteOrderSend(object o)
|
||||
{
|
||||
var request = TradeRequest.GetMqlTradeRequest();
|
||||
|
||||
MqlTradeResult result = null;
|
||||
var retVal = await Execute(() =>
|
||||
{
|
||||
MqlTradeResult result;
|
||||
var ok = _mtApiClient.OrderSend(request, out result);
|
||||
return ok ? result : null;
|
||||
return ok;
|
||||
});
|
||||
|
||||
var message = retVal != null ? $"OrderSend successed. {MqlTradeResultToString(retVal)}" : "OrderSend failed.";
|
||||
var message = retVal ? $"OrderSend: success. {result}" : $"OrderSend: fail. {result}";
|
||||
AddLog(message);
|
||||
}
|
||||
|
||||
|
||||
private async void ExecuteOrderCheck(object obj)
|
||||
{
|
||||
var request = TradeRequest.GetMqlTradeRequest();
|
||||
MqlTradeCheckResult result = null;
|
||||
var retVal = await Execute(() =>
|
||||
{
|
||||
var ok = _mtApiClient.OrderCheck(request, out result);
|
||||
return ok;
|
||||
});
|
||||
|
||||
var message = retVal ? $"OrderCheck: success. {result}" : $"OrderCheck: fail. {result}";
|
||||
AddLog(message);
|
||||
}
|
||||
|
||||
private async void ExecuteHistoryOrderGetInteger(object o)
|
||||
{
|
||||
const ulong ticket = 12345;
|
||||
const ENUM_ORDER_PROPERTY_INTEGER propertyId = ENUM_ORDER_PROPERTY_INTEGER.ORDER_POSITION_ID;
|
||||
|
||||
var retVal = await Execute(() => _mtApiClient.HistoryOrderGetInteger(ticket, propertyId));
|
||||
|
||||
AddLog($"HistoryOrderGetInteger: {retVal}");
|
||||
}
|
||||
|
||||
private async void ExecuteHistoryDealGetDouble(object o)
|
||||
{
|
||||
const ulong ticket = 12345;
|
||||
@@ -307,6 +360,25 @@ namespace MtApi5TestClient
|
||||
AddLog($"HistoryDealGetString: {retVal}");
|
||||
}
|
||||
|
||||
private async void ExecuteHistoryDealMethods(object o)
|
||||
{
|
||||
try
|
||||
{
|
||||
var posId = await Execute(() => _mtApiClient.PositionGetInteger(ENUM_POSITION_PROPERTY_INTEGER.POSITION_IDENTIFIER));
|
||||
var history = await Execute(() => _mtApiClient.HistorySelectByPosition(posId));
|
||||
var historyDealsTotal = await Execute(() => _mtApiClient.HistoryDealsTotal());
|
||||
var histDealTicket = await Execute(() => _mtApiClient.HistoryDealGetTicket(0));
|
||||
var histDealPrice = await Execute(() => _mtApiClient.HistoryDealGetDouble(histDealTicket, ENUM_DEAL_PROPERTY_DOUBLE.DEAL_PRICE));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AddLog(ex.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
AddLog("ExecuteHistoryDealMethods: success.");
|
||||
}
|
||||
|
||||
private async void ExecuteAccountInfoDouble(object o)
|
||||
{
|
||||
var result = await Execute(() => _mtApiClient.AccountInfoDouble(AccountInfoDoublePropertyId));
|
||||
@@ -482,6 +554,48 @@ namespace MtApi5TestClient
|
||||
AddLog("CopyClose: success");
|
||||
}
|
||||
|
||||
private async void ExecuteIndicatorCreate(object o)
|
||||
{
|
||||
var parameters = new List<MqlParam>
|
||||
{
|
||||
new MqlParam
|
||||
{
|
||||
DataType = ENUM_DATATYPE.TYPE_INT,
|
||||
IntegerValue = 12
|
||||
},
|
||||
new MqlParam
|
||||
{
|
||||
DataType = ENUM_DATATYPE.TYPE_INT,
|
||||
IntegerValue = 26
|
||||
},
|
||||
new MqlParam
|
||||
{
|
||||
DataType = ENUM_DATATYPE.TYPE_INT,
|
||||
IntegerValue = 9
|
||||
},
|
||||
new MqlParam
|
||||
{
|
||||
DataType = ENUM_DATATYPE.TYPE_INT,
|
||||
IntegerValue = (int)ENUM_APPLIED_PRICE.PRICE_CLOSE
|
||||
}
|
||||
};
|
||||
|
||||
var retVal = await Execute(() =>
|
||||
_mtApiClient.IndicatorCreate(TimeSeriesValues.SymbolValue,
|
||||
TimeSeriesValues.TimeFrame, TimeSeriesValues.IndicatorType, parameters));
|
||||
|
||||
TimeSeriesValues.IndicatorHandle = retVal;
|
||||
AddLog($"IndicatorCreate [IND_MA]: result - {retVal}");
|
||||
}
|
||||
|
||||
private async void ExecuteIndicatorRelease(object o)
|
||||
{
|
||||
var indicatorHandle = TimeSeriesValues.IndicatorHandle;
|
||||
|
||||
var retVal = await Execute(() => _mtApiClient.IndicatorRelease(indicatorHandle));
|
||||
AddLog($"IndicatorRelease [{indicatorHandle}]: result - {retVal}");
|
||||
}
|
||||
|
||||
private async void ExecuteCopyRates(object o)
|
||||
{
|
||||
if (string.IsNullOrEmpty(TimeSeriesValues?.SymbolValue)) return;
|
||||
@@ -741,14 +855,14 @@ namespace MtApi5TestClient
|
||||
|
||||
private async void ExecuteMarketBookAdd(object o)
|
||||
{
|
||||
var retVal = await Execute(() => _mtApiClient.MarketBookAdd("CHFJPY"));
|
||||
AddLog($"MarketBookAdd(CHFJPY): result = {retVal}");
|
||||
var retVal = await Execute(() => _mtApiClient.MarketBookAdd("EURUSD"));
|
||||
AddLog($"MarketBookAdd(EURUSD): result = {retVal}");
|
||||
}
|
||||
|
||||
private async void ExecuteMarketBookRelease(object o)
|
||||
{
|
||||
var retVal = await Execute(() => _mtApiClient.MarketBookRelease("CHFJPY"));
|
||||
AddLog($"MarketBookRelease(CHFJPY): result = {retVal}");
|
||||
var retVal = await Execute(() => _mtApiClient.MarketBookRelease("EURUSD"));
|
||||
AddLog($"MarketBookRelease(EURUSD): result = {retVal}");
|
||||
}
|
||||
|
||||
private async void ExecuteMarketBookGet(object o)
|
||||
@@ -766,13 +880,11 @@ namespace MtApi5TestClient
|
||||
return;
|
||||
}
|
||||
|
||||
AddLog("MarketBookGet(EURUSD): success");
|
||||
AddLog($"MarketBookGet(EURUSD): success. Count = {result.Length}");
|
||||
|
||||
for (var i = 0; i < result.Length; i++)
|
||||
{
|
||||
AddLog($"MarketBookGet: book[{i}].price = {result[i].price}");
|
||||
AddLog($"MarketBookGet: book[{i}].price = {result[i].volume}");
|
||||
AddLog($"MarketBookGet: book[{i}].price = {result[i].type}");
|
||||
AddLog($"MarketBookGet: [{i}] - {result[i].price} | {result[i].volume} | {result[i].type}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -799,6 +911,41 @@ namespace MtApi5TestClient
|
||||
AddLog($"Print: message print in MetaTrader - {retVal}");
|
||||
}
|
||||
|
||||
private async void ExecuteICustom(object o)
|
||||
{
|
||||
const string symbol = "EURUSD";
|
||||
const ENUM_TIMEFRAMES timeframe = ENUM_TIMEFRAMES.PERIOD_H1;
|
||||
const string name = @"Examples\Custom Moving Average";
|
||||
int[] parameters = { 0, 21, (int)ENUM_APPLIED_PRICE.PRICE_CLOSE };
|
||||
|
||||
var retVal = await Execute(() => _mtApiClient.iCustom(symbol, timeframe, name, parameters));
|
||||
AddLog($"Custom Moving Average: result - {retVal}");
|
||||
}
|
||||
|
||||
private async void ExecuteTimeCurrent(object o)
|
||||
{
|
||||
var retVal = await Execute(() => _mtApiClient.TimeCurrent());
|
||||
AddLog($"TimeCurrent: {retVal}");
|
||||
}
|
||||
|
||||
private async void ExecuteTimeTradeServer(object o)
|
||||
{
|
||||
var retVal = await Execute(() => _mtApiClient.TimeTradeServer());
|
||||
AddLog($"TimeTradeServer: {retVal}");
|
||||
}
|
||||
|
||||
private async void ExecuteTimeLocal(object o)
|
||||
{
|
||||
var retVal = await Execute(() => _mtApiClient.TimeLocal());
|
||||
AddLog($"TimeLocal: {retVal}");
|
||||
}
|
||||
|
||||
private async void ExecuteTimeGMT(object o)
|
||||
{
|
||||
var retVal = await Execute(() => _mtApiClient.TimeGMT());
|
||||
AddLog($"TimeGMT: {retVal}");
|
||||
}
|
||||
|
||||
private static void RunOnUiThread(Action action)
|
||||
{
|
||||
Application.Current?.Dispatcher.Invoke(action);
|
||||
@@ -863,6 +1010,16 @@ namespace MtApi5TestClient
|
||||
}
|
||||
}
|
||||
|
||||
private void mMtApiClient_OnTradeTransaction(object sender, Mt5TradeTransactionEventArgs e)
|
||||
{
|
||||
AddLog($"OnTradeTransaction: ExpertHandle = {e.ExpertHandle}.{Environment.NewLine}Transaction = {e.Trans}.{Environment.NewLine}Request = {e.Request}.{Environment.NewLine}Result = {e.Result}.");
|
||||
}
|
||||
|
||||
private void _mtApiClient_OnBookEvent(object sender, Mt5BookEventArgs e)
|
||||
{
|
||||
AddLog($"OnBookEvent: ExpertHandle = {e.ExpertHandle}, Symbol = {e.Symbol}");
|
||||
}
|
||||
|
||||
private void AddQuote(Mt5Quote quote)
|
||||
{
|
||||
if (quote == null)
|
||||
@@ -921,20 +1078,6 @@ namespace MtApi5TestClient
|
||||
Quotes.Clear();
|
||||
}
|
||||
|
||||
private static string MqlTradeResultToString(MqlTradeResult result)
|
||||
{
|
||||
return result != null ?
|
||||
"Retcode = " + result.Retcode + ";"
|
||||
+ " Comment = " + result.Comment + ";"
|
||||
+ " Order = " + result.Order + ";"
|
||||
+ " Volume = " + result.Volume + ";"
|
||||
+ " Price = " + result.Price + ";"
|
||||
+ " Deal = " + result.Deal + ";"
|
||||
+ " Request_id = " + result.Request_id + ";"
|
||||
+ " Bid = " + result.Bid + ";"
|
||||
+ " Ask = " + result.Ask + ";" : string.Empty;
|
||||
}
|
||||
|
||||
private void OnSelectedQuoteChanged()
|
||||
{
|
||||
if (SelectedQuote == null) return;
|
||||
@@ -952,6 +1095,10 @@ namespace MtApi5TestClient
|
||||
{
|
||||
result = func();
|
||||
}
|
||||
catch (ExecutionException ex)
|
||||
{
|
||||
AddLog($"Exception: {ex.ErrorCode} - {ex.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AddLog($"Exception: {ex.Message}");
|
||||
|
||||
+116
-65
@@ -113,6 +113,13 @@
|
||||
this.label22 = new System.Windows.Forms.Label();
|
||||
this.textBoxErrorCode = new System.Windows.Forms.TextBox();
|
||||
this.tabPage3 = new System.Windows.Forms.TabPage();
|
||||
this.button70 = new System.Windows.Forms.Button();
|
||||
this.label33 = new System.Windows.Forms.Label();
|
||||
this.label32 = new System.Windows.Forms.Label();
|
||||
this.label31 = new System.Windows.Forms.Label();
|
||||
this.textBoxAccountHost = new System.Windows.Forms.TextBox();
|
||||
this.textBoxAccountPassword = new System.Windows.Forms.TextBox();
|
||||
this.textBoxAccountLogin = new System.Windows.Forms.TextBox();
|
||||
this.button67 = new System.Windows.Forms.Button();
|
||||
this.button66 = new System.Windows.Forms.Button();
|
||||
this.button65 = new System.Windows.Forms.Button();
|
||||
@@ -136,6 +143,8 @@
|
||||
this.label23 = new System.Windows.Forms.Label();
|
||||
this.textBoxAccountInfoSymbol = new System.Windows.Forms.TextBox();
|
||||
this.tabPage4 = new System.Windows.Forms.TabPage();
|
||||
this.comboBox12 = new System.Windows.Forms.ComboBox();
|
||||
this.button72 = new System.Windows.Forms.Button();
|
||||
this.button36 = new System.Windows.Forms.Button();
|
||||
this.comboBox10 = new System.Windows.Forms.ComboBox();
|
||||
this.comboBox9 = new System.Windows.Forms.ComboBox();
|
||||
@@ -182,6 +191,7 @@
|
||||
this.button14 = new System.Windows.Forms.Button();
|
||||
this.button13 = new System.Windows.Forms.Button();
|
||||
this.tabPage7 = new System.Windows.Forms.TabPage();
|
||||
this.button71 = new System.Windows.Forms.Button();
|
||||
this.button23 = new System.Windows.Forms.Button();
|
||||
this.iCustomBtn = new System.Windows.Forms.Button();
|
||||
this.tabPage8 = new System.Windows.Forms.TabPage();
|
||||
@@ -202,13 +212,7 @@
|
||||
this.button4 = new System.Windows.Forms.Button();
|
||||
this.tabPage11 = new System.Windows.Forms.TabPage();
|
||||
this.button69 = new System.Windows.Forms.Button();
|
||||
this.textBoxAccountLogin = new System.Windows.Forms.TextBox();
|
||||
this.textBoxAccountPassword = new System.Windows.Forms.TextBox();
|
||||
this.label31 = new System.Windows.Forms.Label();
|
||||
this.label32 = new System.Windows.Forms.Label();
|
||||
this.textBoxAccountHost = new System.Windows.Forms.TextBox();
|
||||
this.label33 = new System.Windows.Forms.Label();
|
||||
this.button70 = new System.Windows.Forms.Button();
|
||||
this.button73 = new System.Windows.Forms.Button();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
this.groupBox2.SuspendLayout();
|
||||
@@ -1154,6 +1158,64 @@
|
||||
this.tabPage3.Text = "Account Information";
|
||||
this.tabPage3.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// button70
|
||||
//
|
||||
this.button70.Location = new System.Drawing.Point(371, 292);
|
||||
this.button70.Name = "button70";
|
||||
this.button70.Size = new System.Drawing.Size(97, 23);
|
||||
this.button70.TabIndex = 18;
|
||||
this.button70.Text = "ChangeAccount";
|
||||
this.button70.UseVisualStyleBackColor = true;
|
||||
this.button70.Click += new System.EventHandler(this.button70_Click);
|
||||
//
|
||||
// label33
|
||||
//
|
||||
this.label33.AutoSize = true;
|
||||
this.label33.Location = new System.Drawing.Point(168, 269);
|
||||
this.label33.Name = "label33";
|
||||
this.label33.Size = new System.Drawing.Size(66, 13);
|
||||
this.label33.TabIndex = 17;
|
||||
this.label33.Text = "MT4 Server:";
|
||||
//
|
||||
// label32
|
||||
//
|
||||
this.label32.AutoSize = true;
|
||||
this.label32.Location = new System.Drawing.Point(168, 241);
|
||||
this.label32.Name = "label32";
|
||||
this.label32.Size = new System.Drawing.Size(56, 13);
|
||||
this.label32.TabIndex = 17;
|
||||
this.label32.Text = "Password:";
|
||||
//
|
||||
// label31
|
||||
//
|
||||
this.label31.AutoSize = true;
|
||||
this.label31.Location = new System.Drawing.Point(168, 214);
|
||||
this.label31.Name = "label31";
|
||||
this.label31.Size = new System.Drawing.Size(36, 13);
|
||||
this.label31.TabIndex = 17;
|
||||
this.label31.Text = "Login:";
|
||||
//
|
||||
// textBoxAccountHost
|
||||
//
|
||||
this.textBoxAccountHost.Location = new System.Drawing.Point(234, 266);
|
||||
this.textBoxAccountHost.Name = "textBoxAccountHost";
|
||||
this.textBoxAccountHost.Size = new System.Drawing.Size(238, 20);
|
||||
this.textBoxAccountHost.TabIndex = 17;
|
||||
//
|
||||
// textBoxAccountPassword
|
||||
//
|
||||
this.textBoxAccountPassword.Location = new System.Drawing.Point(234, 238);
|
||||
this.textBoxAccountPassword.Name = "textBoxAccountPassword";
|
||||
this.textBoxAccountPassword.Size = new System.Drawing.Size(238, 20);
|
||||
this.textBoxAccountPassword.TabIndex = 16;
|
||||
//
|
||||
// textBoxAccountLogin
|
||||
//
|
||||
this.textBoxAccountLogin.Location = new System.Drawing.Point(232, 212);
|
||||
this.textBoxAccountLogin.Name = "textBoxAccountLogin";
|
||||
this.textBoxAccountLogin.Size = new System.Drawing.Size(238, 20);
|
||||
this.textBoxAccountLogin.TabIndex = 15;
|
||||
//
|
||||
// button67
|
||||
//
|
||||
this.button67.Location = new System.Drawing.Point(157, 33);
|
||||
@@ -1368,6 +1430,8 @@
|
||||
//
|
||||
// tabPage4
|
||||
//
|
||||
this.tabPage4.Controls.Add(this.comboBox12);
|
||||
this.tabPage4.Controls.Add(this.button72);
|
||||
this.tabPage4.Controls.Add(this.button36);
|
||||
this.tabPage4.Controls.Add(this.comboBox10);
|
||||
this.tabPage4.Controls.Add(this.comboBox9);
|
||||
@@ -1391,6 +1455,25 @@
|
||||
this.tabPage4.Text = "MarketInfo";
|
||||
this.tabPage4.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// comboBox12
|
||||
//
|
||||
this.comboBox12.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBox12.FormattingEnabled = true;
|
||||
this.comboBox12.Location = new System.Drawing.Point(13, 188);
|
||||
this.comboBox12.Name = "comboBox12";
|
||||
this.comboBox12.Size = new System.Drawing.Size(186, 21);
|
||||
this.comboBox12.TabIndex = 38;
|
||||
//
|
||||
// button72
|
||||
//
|
||||
this.button72.Location = new System.Drawing.Point(208, 186);
|
||||
this.button72.Name = "button72";
|
||||
this.button72.Size = new System.Drawing.Size(111, 23);
|
||||
this.button72.TabIndex = 37;
|
||||
this.button72.Text = "TerminalInfoString";
|
||||
this.button72.UseVisualStyleBackColor = true;
|
||||
this.button72.Click += new System.EventHandler(this.button72_Click);
|
||||
//
|
||||
// button36
|
||||
//
|
||||
this.button36.Location = new System.Drawing.Point(208, 157);
|
||||
@@ -1785,6 +1868,7 @@
|
||||
//
|
||||
// tabPage6
|
||||
//
|
||||
this.tabPage6.Controls.Add(this.button73);
|
||||
this.tabPage6.Controls.Add(this.textBoxPrint);
|
||||
this.tabPage6.Controls.Add(this.button27);
|
||||
this.tabPage6.Controls.Add(this.button14);
|
||||
@@ -1799,14 +1883,14 @@
|
||||
//
|
||||
// textBoxPrint
|
||||
//
|
||||
this.textBoxPrint.Location = new System.Drawing.Point(13, 86);
|
||||
this.textBoxPrint.Location = new System.Drawing.Point(13, 108);
|
||||
this.textBoxPrint.Name = "textBoxPrint";
|
||||
this.textBoxPrint.Size = new System.Drawing.Size(386, 20);
|
||||
this.textBoxPrint.TabIndex = 3;
|
||||
//
|
||||
// button27
|
||||
//
|
||||
this.button27.Location = new System.Drawing.Point(405, 84);
|
||||
this.button27.Location = new System.Drawing.Point(405, 106);
|
||||
this.button27.Name = "button27";
|
||||
this.button27.Size = new System.Drawing.Size(75, 23);
|
||||
this.button27.TabIndex = 2;
|
||||
@@ -1836,6 +1920,7 @@
|
||||
//
|
||||
// tabPage7
|
||||
//
|
||||
this.tabPage7.Controls.Add(this.button71);
|
||||
this.tabPage7.Controls.Add(this.button23);
|
||||
this.tabPage7.Controls.Add(this.iCustomBtn);
|
||||
this.tabPage7.Location = new System.Drawing.Point(4, 40);
|
||||
@@ -1846,6 +1931,16 @@
|
||||
this.tabPage7.Text = "Technical Indicators";
|
||||
this.tabPage7.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// button71
|
||||
//
|
||||
this.button71.Location = new System.Drawing.Point(6, 64);
|
||||
this.button71.Name = "button71";
|
||||
this.button71.Size = new System.Drawing.Size(107, 23);
|
||||
this.button71.TabIndex = 17;
|
||||
this.button71.Text = "iBarShift";
|
||||
this.button71.UseVisualStyleBackColor = true;
|
||||
this.button71.Click += new System.EventHandler(this.button71_Click);
|
||||
//
|
||||
// button23
|
||||
//
|
||||
this.button23.Location = new System.Drawing.Point(6, 35);
|
||||
@@ -2076,63 +2171,15 @@
|
||||
this.button69.UseVisualStyleBackColor = true;
|
||||
this.button69.Click += new System.EventHandler(this.button69_Click);
|
||||
//
|
||||
// textBoxAccountLogin
|
||||
// button73
|
||||
//
|
||||
this.textBoxAccountLogin.Location = new System.Drawing.Point(232, 212);
|
||||
this.textBoxAccountLogin.Name = "textBoxAccountLogin";
|
||||
this.textBoxAccountLogin.Size = new System.Drawing.Size(238, 20);
|
||||
this.textBoxAccountLogin.TabIndex = 15;
|
||||
//
|
||||
// textBoxAccountPassword
|
||||
//
|
||||
this.textBoxAccountPassword.Location = new System.Drawing.Point(234, 238);
|
||||
this.textBoxAccountPassword.Name = "textBoxAccountPassword";
|
||||
this.textBoxAccountPassword.Size = new System.Drawing.Size(238, 20);
|
||||
this.textBoxAccountPassword.TabIndex = 16;
|
||||
//
|
||||
// label31
|
||||
//
|
||||
this.label31.AutoSize = true;
|
||||
this.label31.Location = new System.Drawing.Point(168, 214);
|
||||
this.label31.Name = "label31";
|
||||
this.label31.Size = new System.Drawing.Size(36, 13);
|
||||
this.label31.TabIndex = 17;
|
||||
this.label31.Text = "Login:";
|
||||
//
|
||||
// label32
|
||||
//
|
||||
this.label32.AutoSize = true;
|
||||
this.label32.Location = new System.Drawing.Point(168, 241);
|
||||
this.label32.Name = "label32";
|
||||
this.label32.Size = new System.Drawing.Size(56, 13);
|
||||
this.label32.TabIndex = 17;
|
||||
this.label32.Text = "Password:";
|
||||
//
|
||||
// textBoxAccountHost
|
||||
//
|
||||
this.textBoxAccountHost.Location = new System.Drawing.Point(234, 266);
|
||||
this.textBoxAccountHost.Name = "textBoxAccountHost";
|
||||
this.textBoxAccountHost.Size = new System.Drawing.Size(238, 20);
|
||||
this.textBoxAccountHost.TabIndex = 17;
|
||||
//
|
||||
// label33
|
||||
//
|
||||
this.label33.AutoSize = true;
|
||||
this.label33.Location = new System.Drawing.Point(168, 269);
|
||||
this.label33.Name = "label33";
|
||||
this.label33.Size = new System.Drawing.Size(66, 13);
|
||||
this.label33.TabIndex = 17;
|
||||
this.label33.Text = "MT4 Server:";
|
||||
//
|
||||
// button70
|
||||
//
|
||||
this.button70.Location = new System.Drawing.Point(371, 292);
|
||||
this.button70.Name = "button70";
|
||||
this.button70.Size = new System.Drawing.Size(97, 23);
|
||||
this.button70.TabIndex = 18;
|
||||
this.button70.Text = "ChangeAccount";
|
||||
this.button70.UseVisualStyleBackColor = true;
|
||||
this.button70.Click += new System.EventHandler(this.button70_Click);
|
||||
this.button73.Location = new System.Drawing.Point(13, 74);
|
||||
this.button73.Name = "button73";
|
||||
this.button73.Size = new System.Drawing.Size(75, 23);
|
||||
this.button73.TabIndex = 4;
|
||||
this.button73.Text = "TimeGMT";
|
||||
this.button73.UseVisualStyleBackColor = true;
|
||||
this.button73.Click += new System.EventHandler(this.button73_Click);
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
@@ -2366,6 +2413,10 @@
|
||||
private System.Windows.Forms.TextBox textBoxAccountPassword;
|
||||
private System.Windows.Forms.TextBox textBoxAccountLogin;
|
||||
private System.Windows.Forms.Button button70;
|
||||
private System.Windows.Forms.Button button71;
|
||||
private System.Windows.Forms.ComboBox comboBox12;
|
||||
private System.Windows.Forms.Button button72;
|
||||
private System.Windows.Forms.Button button73;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace TestApiClientUI
|
||||
comboBox9.DataSource = Enum.GetNames(typeof(EnumTerminalInfoInteger));
|
||||
comboBox10.DataSource = Enum.GetNames(typeof(EnumTerminalInfoDouble));
|
||||
comboBox11.DataSource = Enum.GetNames(typeof(EnumObject));
|
||||
comboBox12.DataSource = Enum.GetNames(typeof(ENUM_TERMINAL_INFO_STRING));
|
||||
comboBoxAccountInfoCmd.DataSource = Enum.GetNames(typeof(TradeOperation));
|
||||
|
||||
_apiClient.QuoteUpdated += apiClient_QuoteUpdated;
|
||||
@@ -615,18 +616,28 @@ namespace TestApiClientUI
|
||||
listBoxProceHistory.DataSource = items;
|
||||
}
|
||||
|
||||
//TimeCurrent
|
||||
private void button13_Click(object sender, EventArgs e)
|
||||
{
|
||||
var retVal = _apiClient.TimeCurrent();
|
||||
PrintLog($"TimeCurrent result: {retVal}");
|
||||
}
|
||||
|
||||
//TimeLocal
|
||||
private void button14_Click(object sender, EventArgs e)
|
||||
{
|
||||
var retVal = _apiClient.TimeLocal();
|
||||
PrintLog($"TimeLocal result: {retVal}");
|
||||
}
|
||||
|
||||
//TimeGMT
|
||||
private void button73_Click(object sender, EventArgs e)
|
||||
{
|
||||
var retVal = _apiClient.TimeGMT();
|
||||
PrintLog($"TimeGMT result: {retVal}");
|
||||
}
|
||||
|
||||
//RefreshRates
|
||||
private void buttonRefreshRates_Click(object sender, EventArgs e)
|
||||
{
|
||||
var retVal = _apiClient.RefreshRates();
|
||||
@@ -1129,6 +1140,16 @@ namespace TestApiClientUI
|
||||
PrintLog($"TerminalInfoDouble: result = {result}");
|
||||
}
|
||||
|
||||
//TerminalInfoString
|
||||
private async void button72_Click(object sender, EventArgs e)
|
||||
{
|
||||
ENUM_TERMINAL_INFO_STRING propId;
|
||||
Enum.TryParse(comboBox12.Text, out propId);
|
||||
|
||||
var result = await Execute(() => _apiClient.TerminalInfoString(propId));
|
||||
PrintLog($"TerminalInfoString: result = {result}");
|
||||
}
|
||||
|
||||
private void checkBox2_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
var checkbox = sender as CheckBox;
|
||||
@@ -1462,5 +1483,21 @@ namespace TestApiClientUI
|
||||
var result = await Execute(() => _apiClient.ChangeAccount(login, password, host));
|
||||
PrintLog($"ChangeAccount result: {result}");
|
||||
}
|
||||
|
||||
//iBarShift
|
||||
private async void button71_Click(object sender, EventArgs e)
|
||||
{
|
||||
const string symbol = "EURUSD";
|
||||
const ChartPeriod timeframe = ChartPeriod.PERIOD_D1;
|
||||
|
||||
var time1 = _apiClient.TimeCurrent();
|
||||
var time2 = _apiClient.iTime(symbol, timeframe, 5);
|
||||
|
||||
var result1 = await Execute(() => _apiClient.iBarShift(symbol, timeframe, time1, true));
|
||||
var result2 = await Execute(() => _apiClient.iBarShift(symbol, timeframe, time2, true));
|
||||
|
||||
PrintLog($"iBarShift result1 = {result1}, time = {time1}");
|
||||
PrintLog($"iBarShift result2 = {result2}, time = {time2}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
+587
-59
@@ -1,7 +1,7 @@
|
||||
#property copyright "Vyacheslav Demidyuk"
|
||||
#property link ""
|
||||
|
||||
#property version "1.3"
|
||||
#property version "1.4"
|
||||
#property description "MtApi (MT5) connection expert"
|
||||
|
||||
#include <json.mqh>
|
||||
@@ -29,6 +29,8 @@
|
||||
bool sendMqlBookInfoArrayResponse(int expertHandle, MqlBookInfo& values[], int size, string& err);
|
||||
bool sendErrorResponse(int expertHandle, int code, string message, string& err);
|
||||
|
||||
bool sendEvent(int expertHandle, int eventType, string payload, string& err);
|
||||
|
||||
bool getCommandType(int expertHandle, int& res, string& err);
|
||||
bool getIntValue(int expertHandle, int paramIndex, int& res, string& err);
|
||||
bool getUIntValue(int expertHandle, int paramIndex, uint& res, string& err);
|
||||
@@ -39,11 +41,12 @@
|
||||
bool getBooleanValue(int expertHandle, int paramIndex, bool& res, string& err);
|
||||
#import
|
||||
|
||||
//#define __DEBUG_LOG__
|
||||
|
||||
input int Port = 8228;
|
||||
|
||||
int ExpertHandle;
|
||||
|
||||
//string message;
|
||||
string _error;
|
||||
string _response_error;
|
||||
bool isCrashed = false;
|
||||
@@ -72,6 +75,33 @@ void OnDeinit(const int reason)
|
||||
void OnTick()
|
||||
{
|
||||
start();
|
||||
if (IsTesting()) OnTimer();
|
||||
}
|
||||
|
||||
void OnTradeTransaction(
|
||||
const MqlTradeTransaction& trans, // trade transaction structure
|
||||
const MqlTradeRequest& request, // request structure
|
||||
const MqlTradeResult& result // result structure
|
||||
)
|
||||
{
|
||||
#ifdef __DEBUG_LOG__
|
||||
PrintFormat("%s:", __FUNCTION__);
|
||||
#endif
|
||||
|
||||
MtOnTradeTransactionEvent* trans_event = new MtOnTradeTransactionEvent(trans, request, result);
|
||||
SendMtEvent(ON_TRADE_TRANSACTION_EVENT, trans_event);
|
||||
delete trans_event;
|
||||
}
|
||||
|
||||
void OnBookEvent(const string& symbol)
|
||||
{
|
||||
#ifdef __DEBUG_LOG__
|
||||
PrintFormat("%s: %s", __FUNCTION__, symbol);
|
||||
#endif
|
||||
|
||||
MtOnBookEvent * book_event = new MtOnBookEvent(symbol);
|
||||
SendMtEvent(ON_BOOK_EVENT, book_event);
|
||||
delete book_event;
|
||||
}
|
||||
|
||||
int preinit()
|
||||
@@ -92,7 +122,6 @@ bool IsDemo()
|
||||
bool IsTesting()
|
||||
{
|
||||
bool isTesting = MQLInfoInteger(MQL_TESTER);
|
||||
PrintFormat("IsTesting: %s", isTesting ? "true" : "false");
|
||||
return isTesting;
|
||||
}
|
||||
|
||||
@@ -141,7 +170,10 @@ int init()
|
||||
return (1);
|
||||
}
|
||||
|
||||
#ifdef __DEBUG_LOG__
|
||||
PrintFormat("Expert Handle = %d", ExpertHandle);
|
||||
PrintFormat("IsTesting: %s", IsTesting() ? "true" : "false");
|
||||
#endif
|
||||
|
||||
//--- Backtesting mode
|
||||
if (IsTesting())
|
||||
@@ -219,10 +251,12 @@ int executeCommand()
|
||||
return (0);
|
||||
}
|
||||
|
||||
#ifdef __DEBUG_LOG__
|
||||
if (commandType > 0)
|
||||
{
|
||||
Print("executeCommand: commnad type = ", commandType);
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (commandType)
|
||||
{
|
||||
@@ -475,15 +509,14 @@ int executeCommand()
|
||||
case 61: //MarketBookRelease
|
||||
Execute_MarketBookRelease();
|
||||
break;
|
||||
case 62: //MarketBookGet
|
||||
Execute_MarketBookGet();
|
||||
break;
|
||||
// case 62: //MarketBookGet
|
||||
// break;
|
||||
case 65: //PositionOpen
|
||||
Execute_PositionOpen(false);
|
||||
break;
|
||||
case 1065: //PositionOpenWithResult
|
||||
Execute_PositionOpen(true);
|
||||
break;
|
||||
// case 1065: //PositionOpenWithResult
|
||||
// Execute_PositionOpen(true);
|
||||
// break;
|
||||
case 66: //BacktestingReady
|
||||
Execute_BacktestingReady();
|
||||
break;
|
||||
@@ -657,6 +690,21 @@ int executeCommand()
|
||||
case 126: //iVolumes
|
||||
Execute_iVolumes();
|
||||
break;
|
||||
case 127: //TimeCurrent
|
||||
Execute_TimeCurrent();
|
||||
break;
|
||||
case 128: //TimeTradeServer
|
||||
Execute_TimeTradeServer();
|
||||
break;
|
||||
case 129: //TimeLocal
|
||||
Execute_TimeLocal();
|
||||
break;
|
||||
case 130: //TimeGMT
|
||||
Execute_TimeGMT();
|
||||
break;
|
||||
case 131: //IndicatorRelease
|
||||
Execute_IndicatorRelease();
|
||||
break;
|
||||
default:
|
||||
Print("Unknown command type = ", commandType);
|
||||
sendVoidResponse(ExpertHandle, _response_error);
|
||||
@@ -681,7 +729,9 @@ void Execute_Request()
|
||||
string response = "";
|
||||
if (request != "")
|
||||
{
|
||||
#ifdef __DEBUG_LOG__
|
||||
Print("Execute_Request: incoming request = ", request);
|
||||
#endif
|
||||
response = OnRequest(request);
|
||||
}
|
||||
|
||||
@@ -1151,7 +1201,7 @@ void Execute_HistoryOrderGetInteger()
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sendULongResponse(ExpertHandle, HistoryOrderGetInteger(ticket_number, (ENUM_ORDER_PROPERTY_INTEGER)property_id), _response_error))
|
||||
if (!sendLongResponse(ExpertHandle, HistoryOrderGetInteger(ticket_number, (ENUM_ORDER_PROPERTY_INTEGER)property_id), _response_error))
|
||||
{
|
||||
PrintResponseError("HistoryOrderGetInteger", _response_error);
|
||||
}
|
||||
@@ -3015,38 +3065,6 @@ void Execute_MarketBookRelease()
|
||||
}
|
||||
}
|
||||
|
||||
void Execute_MarketBookGet()
|
||||
{
|
||||
string symbol;
|
||||
StringInit(symbol, 100, 0);
|
||||
|
||||
if (!getStringValue(ExpertHandle, 0, symbol, _error))
|
||||
{
|
||||
PrintParamError("MarketBookGet", "symbol", _error);
|
||||
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
|
||||
return;
|
||||
}
|
||||
|
||||
MqlBookInfo book[];
|
||||
bool retVal = MarketBookGet(symbol, book);
|
||||
|
||||
if(retVal)
|
||||
{
|
||||
int size = ArraySize(book);
|
||||
if (!sendMqlBookInfoArrayResponse(ExpertHandle, book, size, _response_error))
|
||||
{
|
||||
PrintResponseError("MarketBookGet", _response_error);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!sendVoidResponse(ExpertHandle, _response_error))
|
||||
{
|
||||
PrintResponseError("MarketBookGet", _response_error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Execute_PositionOpen(bool isTradeResultRequired)
|
||||
{
|
||||
string symbol;
|
||||
@@ -3102,8 +3120,11 @@ void Execute_PositionOpen(bool isTradeResultRequired)
|
||||
return;
|
||||
}
|
||||
|
||||
PrintFormat("Execute_PositionOpen: symbol = %s, order_type = %d, volume = %f, price = %f, sl = %f, tp = %f, comment = %s",
|
||||
symbol, order_type, volume, price, sl, tp, comment);
|
||||
|
||||
#ifdef __DEBUG_LOG__
|
||||
PrintFormat("%s: symbol = %s, order_type = %d, volume = %f, price = %f, sl = %f, tp = %f, comment = %s",
|
||||
__FUNCTION__, symbol, order_type, volume, price, sl, tp, comment);
|
||||
#endif
|
||||
|
||||
CTrade trade;
|
||||
bool ok = trade.PositionOpen(symbol, (ENUM_ORDER_TYPE)order_type, volume, price, sl, tp, comment);
|
||||
@@ -5414,6 +5435,62 @@ void Execute_iVolumes()
|
||||
PrintResponseError("iVolumes", _response_error);
|
||||
}
|
||||
}
|
||||
|
||||
void Execute_TimeCurrent()
|
||||
{
|
||||
if (!sendLongResponse(ExpertHandle, TimeCurrent(), _response_error))
|
||||
{
|
||||
PrintResponseError("TimeCurrent", _response_error);
|
||||
}
|
||||
}
|
||||
|
||||
void Execute_TimeTradeServer()
|
||||
{
|
||||
if (!sendLongResponse(ExpertHandle, TimeTradeServer(), _response_error))
|
||||
{
|
||||
PrintResponseError("TimeTradeServer", _response_error);
|
||||
}
|
||||
}
|
||||
|
||||
void Execute_TimeLocal()
|
||||
{
|
||||
if (!sendLongResponse(ExpertHandle, TimeLocal(), _response_error))
|
||||
{
|
||||
PrintResponseError("TimeLocal", _response_error);
|
||||
}
|
||||
}
|
||||
|
||||
void Execute_TimeGMT()
|
||||
{
|
||||
if (!sendLongResponse(ExpertHandle, TimeGMT(), _response_error))
|
||||
{
|
||||
PrintResponseError("TimeGMT", _response_error);
|
||||
}
|
||||
}
|
||||
|
||||
#define GET_VALUE_OR_RETURN_WITH_SENDING_ERROR(get_func, argument_id, argument, cmd_name, param_name) if (!get_func(ExpertHandle, argument_id, argument, _error)) \
|
||||
{ \
|
||||
PrintParamError(cmd_name, param_name, _error); \
|
||||
sendErrorResponse(ExpertHandle, -1, _error, _response_error); \
|
||||
return; \
|
||||
} \
|
||||
|
||||
#define GET_INTEGER_VALUE(argument_id, argument, cmd_name, param_name) GET_VALUE_OR_RETURN_WITH_SENDING_ERROR(getIntValue, argument_id, argument, cmd_name, param_name)
|
||||
|
||||
void Execute_IndicatorRelease()
|
||||
{
|
||||
int indicator_handle;
|
||||
GET_INTEGER_VALUE(0, indicator_handle, "IndicatorRelease", "indicator_handle");
|
||||
|
||||
#ifdef __DEBUG_LOG__
|
||||
PrintFormat("%s: indicator_handle = %d", __FUNCTION__, indicator_handle);
|
||||
#endif
|
||||
|
||||
if (!sendBooleanResponse(ExpertHandle, IndicatorRelease(indicator_handle), _error))
|
||||
{
|
||||
PrintResponseError("IndicatorRelease", _response_error);
|
||||
}
|
||||
}
|
||||
|
||||
void PrintParamError(string paramName)
|
||||
{
|
||||
@@ -5543,6 +5620,8 @@ bool OrderCloseAll()
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------ Requests -------------------------------------------------------
|
||||
|
||||
string OnRequest(string json)
|
||||
{
|
||||
string response = "";
|
||||
@@ -5552,7 +5631,7 @@ string OnRequest(string json)
|
||||
|
||||
if(jv == NULL)
|
||||
{
|
||||
PrintFormat("OnRequest [ERROR]: %d - %s", (string)parser.getErrorCode(), parser.getErrorMessage());
|
||||
PrintFormat("%s [ERROR]: %d - %s", __FUNCTION__, (string)parser.getErrorCode(), parser.getErrorMessage());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -5569,8 +5648,23 @@ string OnRequest(string json)
|
||||
case 2: //iCustom
|
||||
response = ExecuteRequest_iCustom(jo);
|
||||
break;
|
||||
case 3: //OrderSend
|
||||
response = ExecuteRequest_OrderSend(jo);
|
||||
break;
|
||||
case 4: //PositionOpen
|
||||
response = ExecuteRequest_PositionOpen(jo);
|
||||
break;
|
||||
case 5: //OrderCheck
|
||||
response = ExecuteRequest_OrderCheck(jo);
|
||||
break;
|
||||
case 6: //MarketBookGet
|
||||
response = ExecuteRequest_MarketBookGet(jo);
|
||||
break;
|
||||
case 7: //IndicatorCreate
|
||||
response = ExecuteRequest_IndicatorCreate(jo);
|
||||
break;
|
||||
default:
|
||||
PrintFormat("OnRequest [WARNING]: Unknown request type %d", requestType);
|
||||
PrintFormat("%s [WARNING]: Unknown request type %d", __FUNCTION__, requestType);
|
||||
response = CreateErrorResponse(-1, "Unknown request type");
|
||||
break;
|
||||
}
|
||||
@@ -5616,17 +5710,6 @@ string CreateSuccessResponse(string responseName, JSONValue* responseBody)
|
||||
return result;
|
||||
}
|
||||
|
||||
JSONObject* Serialize(MqlTick& tick)
|
||||
{
|
||||
JSONObject *jo = new JSONObject();
|
||||
jo.put("MtTime", new JSONNumber(tick.time));
|
||||
jo.put("bid", new JSONNumber(tick.bid));
|
||||
jo.put("ask", new JSONNumber(tick.ask));
|
||||
jo.put("last", new JSONNumber(tick.last));
|
||||
jo.put("volume", new JSONNumber(tick.volume));
|
||||
return jo;
|
||||
}
|
||||
|
||||
string ExecuteRequest_CopyTicks(JSONObject *jo)
|
||||
{
|
||||
if (jo.getValue("SymbolName") == NULL)
|
||||
@@ -5651,10 +5734,10 @@ string ExecuteRequest_CopyTicks(JSONObject *jo)
|
||||
JSONArray* jaTicks = new JSONArray();
|
||||
for(int i = 0; i < received; i++)
|
||||
{
|
||||
jaTicks.put(i, Serialize(ticks[i]));
|
||||
jaTicks.put(i, MqlTickToJson(ticks[i]));
|
||||
}
|
||||
|
||||
return CreateSuccessResponse("Ticks", jaTicks);;
|
||||
return CreateSuccessResponse("Value", jaTicks);
|
||||
}
|
||||
|
||||
string ExecuteRequest_iCustom(JSONObject *jo)
|
||||
@@ -5760,4 +5843,449 @@ int iCustomT(string symbol, ENUM_TIMEFRAMES timeframe, string name, T &p[], int
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#define PRINT_MSG_AND_RETURN_VALUE(msg,value) PrintFormat("%s: %s",__FUNCTION__,msg);return value
|
||||
#define CHECK_JSON_VALUE(jo, name_value, return_fail_result) if (jo.getValue(name_value) == NULL) { PRINT_MSG_AND_RETURN_VALUE(StringFormat("failed to get %s from JSON!", name_value), return_fail_result); }
|
||||
|
||||
string ExecuteRequest_OrderSend(JSONObject *jo)
|
||||
{
|
||||
CHECK_JSON_VALUE(jo, "TradeRequest", CreateErrorResponse(-1, "Undefinded mandatory parameter TradeRequest"));
|
||||
JSONObject* trade_request_jo = jo.getObject("TradeRequest");
|
||||
|
||||
MqlTradeRequest trade_request = {0};
|
||||
bool converted = JsonToMqlTradeRequest(trade_request_jo, trade_request);
|
||||
if (converted == false)
|
||||
return CreateErrorResponse(-1, "Failed to parse parameter TradeRequest");
|
||||
|
||||
MqlTradeResult trade_result = {0};
|
||||
bool ok = OrderSend(trade_request, trade_result);
|
||||
|
||||
JSONObject* result_value_jo = new JSONObject();
|
||||
result_value_jo.put("RetVal", new JSONBool(ok));
|
||||
result_value_jo.put("TradeResult", MqlTradeResultToJson(trade_result));
|
||||
|
||||
#ifdef __DEBUG_LOG__
|
||||
PrintFormat("%s: return value = %s", __FUNCTION__, ok ? "true" : "false");
|
||||
#endif
|
||||
|
||||
return CreateSuccessResponse("Value", result_value_jo);
|
||||
}
|
||||
|
||||
string ExecuteRequest_PositionOpen(JSONObject *jo)
|
||||
{
|
||||
//Symbol
|
||||
CHECK_JSON_VALUE(jo, "Symbol", CreateErrorResponse(-1, "Undefinded mandatory parameter Symbol"));
|
||||
string symbol = jo.getString("Symbol");
|
||||
|
||||
//OrderType
|
||||
CHECK_JSON_VALUE(jo, "OrderType", CreateErrorResponse(-1, "Undefinded mandatory parameter OrderType"));
|
||||
ENUM_ORDER_TYPE order_type = (ENUM_ORDER_TYPE) jo.getInt("OrderType");
|
||||
|
||||
//Volume
|
||||
CHECK_JSON_VALUE(jo, "Volume", CreateErrorResponse(-1, "Undefinded mandatory parameter Volume"));
|
||||
double volume = jo.getDouble("Volume");
|
||||
|
||||
//Price
|
||||
CHECK_JSON_VALUE(jo, "Price", CreateErrorResponse(-1, "Undefinded mandatory parameter Price"));
|
||||
double price = jo.getDouble("Price");
|
||||
|
||||
//Sl
|
||||
CHECK_JSON_VALUE(jo, "Sl", CreateErrorResponse(-1, "Undefinded mandatory parameter Sl"));
|
||||
double sl = jo.getDouble("Sl");
|
||||
|
||||
//Tp
|
||||
CHECK_JSON_VALUE(jo, "Tp", CreateErrorResponse(-1, "Undefinded mandatory parameter Tp"));
|
||||
double tp = jo.getDouble("Tp");
|
||||
|
||||
//Comment
|
||||
string comment;
|
||||
if (jo.getValue("Comment") != NULL)
|
||||
{
|
||||
comment = jo.getString("Comment");
|
||||
}
|
||||
|
||||
#ifdef __DEBUG_LOG__
|
||||
PrintFormat("%s: symbol = %s, order_type = %d, volume = %f, price = %f, sl = %f, tp = %f, comment = %s",
|
||||
__FUNCTION__, symbol, order_type, volume, price, sl, tp, comment);
|
||||
#endif
|
||||
|
||||
CTrade trade;
|
||||
bool ok = trade.PositionOpen(symbol, order_type, volume, price, sl, tp, comment);
|
||||
|
||||
MqlTradeResult trade_result={0};
|
||||
trade.Result(trade_result);
|
||||
|
||||
JSONObject* result_value_jo = new JSONObject();
|
||||
result_value_jo.put("RetVal", new JSONBool(ok));
|
||||
result_value_jo.put("TradeResult", MqlTradeResultToJson(trade_result));
|
||||
|
||||
return CreateSuccessResponse("Value", result_value_jo);
|
||||
}
|
||||
|
||||
string ExecuteRequest_OrderCheck(JSONObject *jo)
|
||||
{
|
||||
CHECK_JSON_VALUE(jo, "TradeRequest", CreateErrorResponse(-1, "Undefinded mandatory parameter TradeRequest"));
|
||||
JSONObject* trade_request_jo = jo.getObject("TradeRequest");
|
||||
|
||||
MqlTradeRequest trade_request = {0};
|
||||
JsonToMqlTradeRequest(trade_request_jo, trade_request);
|
||||
|
||||
MqlTradeCheckResult trade_check_result = {0};
|
||||
bool ok = OrderCheck(trade_request, trade_check_result);
|
||||
|
||||
#ifdef __DEBUG_LOG__
|
||||
PrintFormat("%s: return value = %s", __FUNCTION__, ok ? "true" : "false");
|
||||
#endif
|
||||
|
||||
JSONObject* result_value_jo = new JSONObject();
|
||||
result_value_jo.put("RetVal", new JSONBool(ok));
|
||||
result_value_jo.put("TradeCheckResult", MqlTradeCheckResultToJson(trade_check_result));
|
||||
|
||||
return CreateSuccessResponse("Value", result_value_jo);
|
||||
}
|
||||
|
||||
JSONObject* MqlBookInfoToJson(MqlBookInfo& info)
|
||||
{
|
||||
JSONObject *jo = new JSONObject();
|
||||
jo.put("type", new JSONNumber((int)info.type));
|
||||
jo.put("price", new JSONNumber(info.price));
|
||||
jo.put("volume", new JSONNumber(info.volume));
|
||||
return jo;
|
||||
}
|
||||
|
||||
string ExecuteRequest_MarketBookGet(JSONObject *jo)
|
||||
{
|
||||
CHECK_JSON_VALUE(jo, "Symbol", CreateErrorResponse(-1, "Undefinded mandatory parameter Symbol"));
|
||||
string symbol = jo.getString("Symbol");
|
||||
|
||||
MqlBookInfo info_array[];
|
||||
bool ok = MarketBookGet(symbol, info_array);
|
||||
|
||||
#ifdef __DEBUG_LOG__
|
||||
PrintFormat("%s: return value = %s.", __FUNCTION__, ok ? "true" : "false");
|
||||
#endif
|
||||
|
||||
if (!ok)
|
||||
return CreateErrorResponse(GetLastError(), "MarketBookGet failed");
|
||||
|
||||
int size = ArraySize(info_array);
|
||||
JSONArray* book_ja = new JSONArray();
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
book_ja.put(i, MqlBookInfoToJson(info_array[i]));
|
||||
}
|
||||
|
||||
#ifdef __DEBUG_LOG__
|
||||
PrintFormat("%s: array size = %d.", __FUNCTION__, size);
|
||||
#endif
|
||||
|
||||
return CreateSuccessResponse("Value", book_ja);
|
||||
}
|
||||
|
||||
string ExecuteRequest_IndicatorCreate(JSONObject *jo)
|
||||
{
|
||||
//Symbol
|
||||
string symbol;
|
||||
if (jo.getValue("Symbol") != NULL)
|
||||
{
|
||||
symbol = jo.getString("Symbol");
|
||||
}
|
||||
|
||||
CHECK_JSON_VALUE(jo, "Period", CreateErrorResponse(-1, "Undefinded mandatory parameter Period"));
|
||||
ENUM_TIMEFRAMES period = (ENUM_TIMEFRAMES) jo.getInt("Period");
|
||||
|
||||
CHECK_JSON_VALUE(jo, "IndicatorType", CreateErrorResponse(-1, "Undefinded mandatory parameter IndicatorType"));
|
||||
ENUM_INDICATOR indicator_type = (ENUM_INDICATOR) jo.getInt("IndicatorType");
|
||||
|
||||
int indicator_handle = -1;
|
||||
if (jo.getValue("Parameters") != NULL)
|
||||
{
|
||||
JSONArray parameters_ja = jo.getArray("Parameters");
|
||||
int size = parameters_ja.size();
|
||||
if (size > 0)
|
||||
{
|
||||
MqlParam parameters[];
|
||||
ArrayResize(parameters, size);
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
JSONObject param_jo = parameters_ja.getObject(i);
|
||||
|
||||
parameters[i].type = (ENUM_DATATYPE)param_jo.getInt("DataType");
|
||||
if (param_jo.getValue("IntegerValue") != NULL)
|
||||
{
|
||||
parameters[i].integer_value = param_jo.getLong("IntegerValue");
|
||||
}
|
||||
if (param_jo.getValue("DoubleValue") != NULL)
|
||||
{
|
||||
parameters[i].double_value = param_jo.getDouble("DoubleValue");
|
||||
}
|
||||
if (param_jo.getValue("StringValue") != NULL)
|
||||
{
|
||||
parameters[i].string_value = param_jo.getString("StringValue");
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __DEBUG_LOG__
|
||||
PrintFormat("%s: symbol = %s, period = %d, indicator_type = %d, size = %d.", __FUNCTION__, symbol, period, indicator_type, size);
|
||||
#endif
|
||||
|
||||
indicator_handle = IndicatorCreate(symbol, period, indicator_type, size, parameters);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef __DEBUG_LOG__
|
||||
PrintFormat("%s: symbol = %s, period = %d, indicator_type = %d.", __FUNCTION__, symbol, period, indicator_type);
|
||||
#endif
|
||||
|
||||
indicator_handle = IndicatorCreate(symbol, period, indicator_type);
|
||||
}
|
||||
|
||||
#ifdef __DEBUG_LOG__
|
||||
PrintFormat("%s: result indicator handle = %d", __FUNCTION__, indicator_handle);
|
||||
#endif
|
||||
|
||||
return CreateSuccessResponse("Value", new JSONNumber(indicator_handle));
|
||||
}
|
||||
|
||||
//------------ Events -------------------------------------------------------
|
||||
|
||||
enum MtEventTypes
|
||||
{
|
||||
ON_TRADE_TRANSACTION_EVENT = 1,
|
||||
ON_BOOK_EVENT = 2
|
||||
};
|
||||
|
||||
class MtEvent
|
||||
{
|
||||
public:
|
||||
virtual JSONObject* CreateJson() = 0;
|
||||
};
|
||||
|
||||
class MtOnTradeTransactionEvent : public MtEvent
|
||||
{
|
||||
public:
|
||||
MtOnTradeTransactionEvent(const MqlTradeTransaction& trans, const MqlTradeRequest& request, const MqlTradeResult& result)
|
||||
{
|
||||
_trans = trans;
|
||||
_request = request;
|
||||
_result = result;
|
||||
}
|
||||
|
||||
virtual JSONObject* CreateJson()
|
||||
{
|
||||
JSONObject *jo = new JSONObject();
|
||||
jo.put("Trans", MqlTradeTransactionToJson(_trans));
|
||||
jo.put("Request", MqlTradeRequestToJson(_request));
|
||||
jo.put("Result", MqlTradeResultToJson(_result));
|
||||
return jo;
|
||||
}
|
||||
|
||||
private:
|
||||
MqlTradeTransaction _trans;
|
||||
MqlTradeRequest _request;
|
||||
MqlTradeResult _result;
|
||||
};
|
||||
|
||||
class MtOnBookEvent : public MtEvent
|
||||
{
|
||||
public:
|
||||
MtOnBookEvent(const string& symbol)
|
||||
{
|
||||
_symbol = symbol;
|
||||
}
|
||||
|
||||
virtual JSONObject* CreateJson()
|
||||
{
|
||||
JSONObject *jo = new JSONObject();
|
||||
jo.put("Symbol", new JSONString(_symbol));
|
||||
return jo;
|
||||
}
|
||||
|
||||
private:
|
||||
string _symbol;
|
||||
};
|
||||
|
||||
void SendMtEvent(MtEventTypes eventType, MtEvent* mtEvent)
|
||||
{
|
||||
#ifdef __DEBUG_LOG__
|
||||
PrintFormat("%s: eventType = %d", __FUNCTION__, eventType);
|
||||
#endif
|
||||
|
||||
JSONObject* json = mtEvent.CreateJson();
|
||||
if (sendEvent(ExpertHandle, (int)eventType, json.toString(), _error))
|
||||
{
|
||||
#ifdef __DEBUG_LOG__
|
||||
PrintFormat("%s: payload = %s", __FUNCTION__, json.toString());
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
PrintFormat("[ERROR] SendMtEvent: %s", _error);
|
||||
}
|
||||
|
||||
delete json;
|
||||
}
|
||||
|
||||
//-------------JSON converters -----------------------------------------
|
||||
bool JsonToMqlTradeRequest(JSONObject *jo, MqlTradeRequest& request)
|
||||
{
|
||||
//Action
|
||||
CHECK_JSON_VALUE(jo, "Action", false);
|
||||
request.action = (ENUM_TRADE_REQUEST_ACTIONS) jo.getInt("Action");
|
||||
|
||||
//Magic
|
||||
CHECK_JSON_VALUE(jo, "Magic", false);
|
||||
request.magic = jo.getLong("Magic");
|
||||
|
||||
//Order
|
||||
CHECK_JSON_VALUE(jo, "Order", false);
|
||||
request.order = jo.getLong("Magic");
|
||||
|
||||
//Symbol
|
||||
CHECK_JSON_VALUE(jo, "Symbol", false);
|
||||
StringInit(request.symbol, 100, 0);
|
||||
request.symbol = jo.getString("Symbol");
|
||||
|
||||
//Volume
|
||||
CHECK_JSON_VALUE(jo, "Volume", false);
|
||||
request.volume = jo.getDouble("Volume");
|
||||
|
||||
//Price
|
||||
CHECK_JSON_VALUE(jo, "Price", false);
|
||||
request.price = jo.getDouble("Price");
|
||||
|
||||
//Stoplimit
|
||||
CHECK_JSON_VALUE(jo, "Stoplimit", false);
|
||||
request.stoplimit = jo.getDouble("Stoplimit");
|
||||
|
||||
//Sl
|
||||
CHECK_JSON_VALUE(jo, "Sl", false);
|
||||
request.sl = jo.getDouble("Sl");
|
||||
|
||||
//Tp
|
||||
CHECK_JSON_VALUE(jo, "Tp", false);
|
||||
request.tp = jo.getDouble("Tp");
|
||||
|
||||
//Deviation
|
||||
CHECK_JSON_VALUE(jo, "Deviation", false);
|
||||
request.deviation = jo.getLong("Deviation");
|
||||
|
||||
//Type
|
||||
CHECK_JSON_VALUE(jo, "Type", false);
|
||||
request.type = (ENUM_ORDER_TYPE)jo.getInt("Type");
|
||||
|
||||
//Type_filling
|
||||
CHECK_JSON_VALUE(jo, "Type_filling", false);
|
||||
request.type_filling = (ENUM_ORDER_TYPE_FILLING)jo.getInt("Type_filling");
|
||||
|
||||
//Type_time
|
||||
CHECK_JSON_VALUE(jo, "Type_time", false);
|
||||
request.type_time = (ENUM_ORDER_TYPE_TIME)jo.getInt("Type_time");
|
||||
|
||||
//Expiration
|
||||
CHECK_JSON_VALUE(jo, "MtExpiration", false);
|
||||
request.expiration = (datetime)jo.getInt("MtExpiration");
|
||||
|
||||
//Comment
|
||||
if (jo.getValue("Comment") != NULL)
|
||||
{
|
||||
StringInit(request.comment, 1000, 0);
|
||||
request.comment = jo.getString("Comment");
|
||||
}
|
||||
|
||||
//Position
|
||||
CHECK_JSON_VALUE(jo, "Position", false);
|
||||
request.position = jo.getLong("Position");
|
||||
|
||||
//PositionBy
|
||||
CHECK_JSON_VALUE(jo, "PositionBy", false);
|
||||
request.position_by = jo.getLong("PositionBy");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
JSONObject* MqlTickToJson(MqlTick& tick)
|
||||
{
|
||||
JSONObject *jo = new JSONObject();
|
||||
jo.put("MtTime", new JSONNumber(tick.time));
|
||||
jo.put("bid", new JSONNumber(tick.bid));
|
||||
jo.put("ask", new JSONNumber(tick.ask));
|
||||
jo.put("last", new JSONNumber(tick.last));
|
||||
jo.put("volume", new JSONNumber(tick.volume));
|
||||
return jo;
|
||||
}
|
||||
|
||||
JSONObject* MqlTradeResultToJson(MqlTradeResult& result)
|
||||
{
|
||||
JSONObject* jo = new JSONObject();
|
||||
jo.put("Retcode", new JSONNumber(result.retcode));
|
||||
jo.put("Deal", new JSONNumber(result.deal));
|
||||
jo.put("Order", new JSONNumber(result.order));
|
||||
jo.put("Volume", new JSONNumber(result.volume));
|
||||
jo.put("Price", new JSONNumber(result.price));
|
||||
jo.put("Bid", new JSONNumber(result.bid));
|
||||
jo.put("Ask", new JSONNumber(result.ask));
|
||||
jo.put("Comment", new JSONString(result.comment));
|
||||
jo.put("Request_id", new JSONNumber(result.request_id));
|
||||
return jo;
|
||||
}
|
||||
|
||||
JSONObject* MqlTradeCheckResultToJson(MqlTradeCheckResult& result)
|
||||
{
|
||||
JSONObject* jo = new JSONObject();
|
||||
jo.put("Retcode", new JSONNumber(result.retcode));
|
||||
jo.put("Balance", new JSONNumber(result.balance));
|
||||
jo.put("Equity", new JSONNumber(result.equity));
|
||||
jo.put("Profit", new JSONNumber(result.profit));
|
||||
jo.put("Margin", new JSONNumber(result.margin));
|
||||
jo.put("Margin_free", new JSONNumber(result.margin_free));
|
||||
jo.put("Margin_level", new JSONNumber(result.margin_level));
|
||||
jo.put("Comment", new JSONString(result.comment));
|
||||
return jo;
|
||||
}
|
||||
|
||||
JSONObject* MqlTradeTransactionToJson(MqlTradeTransaction& trans)
|
||||
{
|
||||
JSONObject *jo = new JSONObject();
|
||||
jo.put("Deal", new JSONNumber(trans.deal));
|
||||
jo.put("Order", new JSONNumber(trans.order));
|
||||
jo.put("Symbol", new JSONString(trans.symbol));
|
||||
jo.put("Type", new JSONNumber((int)trans.type));
|
||||
jo.put("OrderType", new JSONNumber((int)trans.order_type));
|
||||
jo.put("OrderState", new JSONNumber((int)trans.order_state));
|
||||
jo.put("DealType", new JSONNumber((int)trans.deal_type));
|
||||
jo.put("TimeType", new JSONNumber((int)trans.time_type));
|
||||
jo.put("MtTimeExpiration", new JSONNumber((int)trans.time_expiration));
|
||||
jo.put("Price", new JSONNumber(trans.price));
|
||||
jo.put("PriceTrigger", new JSONNumber(trans.price_trigger));
|
||||
jo.put("PriceSl", new JSONNumber(trans.price_sl));
|
||||
jo.put("PriceTp", new JSONNumber(trans.price_tp));
|
||||
jo.put("Volume", new JSONNumber(trans.volume));
|
||||
jo.put("Position", new JSONNumber(trans.position));
|
||||
jo.put("PositionBy", new JSONNumber(trans.position_by));
|
||||
return jo;
|
||||
}
|
||||
|
||||
JSONObject* MqlTradeRequestToJson(MqlTradeRequest& request)
|
||||
{
|
||||
JSONObject *jo = new JSONObject();
|
||||
jo.put("Action", new JSONNumber((int)request.action));
|
||||
jo.put("Magic", new JSONNumber(request.magic));
|
||||
jo.put("Order", new JSONNumber(request.order));
|
||||
jo.put("Symbol", new JSONString(request.symbol));
|
||||
jo.put("Volume", new JSONNumber(request.volume));
|
||||
jo.put("Price", new JSONNumber(request.price));
|
||||
jo.put("Stoplimit", new JSONNumber(request.stoplimit));
|
||||
jo.put("Sl", new JSONNumber(request.sl));
|
||||
jo.put("Tp", new JSONNumber(request.tp));
|
||||
jo.put("Deviation", new JSONNumber(request.deviation));
|
||||
jo.put("Type", new JSONNumber((int)request.type));
|
||||
jo.put("Type_filling", new JSONNumber((int)request.type_filling));
|
||||
jo.put("Type_time", new JSONNumber((int)request.type_time));
|
||||
jo.put("MtExpiration", new JSONNumber((int)request.expiration));
|
||||
jo.put("Comment", new JSONString(request.comment));
|
||||
return jo;
|
||||
}
|
||||
+1
-1
@@ -257,7 +257,7 @@ public:
|
||||
{
|
||||
return (string)_long;
|
||||
} else {
|
||||
return (string)_dbl;
|
||||
return (_dbl!=0) ? (string)_dbl : "0";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user