mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-07 07:57:50 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| db4bb44fb3 | |||
| 68d5fa98af | |||
| dc28823ca9 |
@@ -11,12 +11,12 @@ ref class MT5Handler: IMetaTraderHandler
|
|||||||
public:
|
public:
|
||||||
MT5Handler()
|
MT5Handler()
|
||||||
{
|
{
|
||||||
msgId = WM_TIMER;
|
msgId = WM_USER + 4096;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void SendTickToMetaTrader(int handle)
|
virtual void SendTickToMetaTrader(int handle)
|
||||||
{
|
{
|
||||||
PostMessage((HWND)handle, msgId, 0, 0);
|
PostMessage((HWND)handle, msgId, 0x00000011, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -11,11 +11,13 @@ ref class MT4Handler: IMetaTraderHandler
|
|||||||
public:
|
public:
|
||||||
MT4Handler()
|
MT4Handler()
|
||||||
{
|
{
|
||||||
|
//msgId = RegisterWindowMessage("MetaTrader4_Internal_Message");
|
||||||
msgId = WM_TIMER;
|
msgId = WM_TIMER;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void SendTickToMetaTrader(int handle)
|
virtual void SendTickToMetaTrader(int handle)
|
||||||
{
|
{
|
||||||
|
//PostMessage((HWND)handle, msgId, 2, 1);
|
||||||
PostMessage((HWND)handle, msgId, 0, 0);
|
PostMessage((HWND)handle, msgId, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -256,3 +256,18 @@ int _stdcall getStringValue(int expertHandle, int paramIndex, wchar_t* res)
|
|||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int _stdcall getBooleanValue(int expertHandle, int paramIndex, int* res)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bool val = (bool)MtServerInstance::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
||||||
|
*res = val == true ? 1 : 0;
|
||||||
|
}
|
||||||
|
catch (Exception^ e)
|
||||||
|
{
|
||||||
|
Debug::WriteLine("[ERROR] MT5Connector:getBooleanValue(): " + e->Message);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
@@ -15,3 +15,4 @@ EXPORTS initExpert
|
|||||||
getIntValue
|
getIntValue
|
||||||
getDoubleValue
|
getDoubleValue
|
||||||
getStringValue
|
getStringValue
|
||||||
|
getBooleanValue
|
||||||
@@ -72,7 +72,6 @@
|
|||||||
<Compile Include="MtOrder.cs" />
|
<Compile Include="MtOrder.cs" />
|
||||||
<Compile Include="MtQuote.cs" />
|
<Compile Include="MtQuote.cs" />
|
||||||
<Compile Include="MtQuoteEventArgs.cs" />
|
<Compile Include="MtQuoteEventArgs.cs" />
|
||||||
<Compile Include="MtSession.cs" />
|
|
||||||
<Compile Include="MtTimeBar.cs" />
|
<Compile Include="MtTimeBar.cs" />
|
||||||
<Compile Include="MtTypes.cs" />
|
<Compile Include="MtTypes.cs" />
|
||||||
<Compile Include="Monitors\TradeMonitor.cs" />
|
<Compile Include="Monitors\TradeMonitor.cs" />
|
||||||
@@ -91,7 +90,6 @@
|
|||||||
<Compile Include="Requests\OrderDeleteRequest.cs" />
|
<Compile Include="Requests\OrderDeleteRequest.cs" />
|
||||||
<Compile Include="Requests\OrderModifyRequest.cs" />
|
<Compile Include="Requests\OrderModifyRequest.cs" />
|
||||||
<Compile Include="Requests\OrderSendRequest.cs" />
|
<Compile Include="Requests\OrderSendRequest.cs" />
|
||||||
<Compile Include="Requests\SessionRequest.cs" />
|
|
||||||
<Compile Include="Requests\RequestBase.cs" />
|
<Compile Include="Requests\RequestBase.cs" />
|
||||||
<Compile Include="Requests\RequestType.cs" />
|
<Compile Include="Requests\RequestType.cs" />
|
||||||
<Compile Include="Responses\CopyRatesResponse.cs" />
|
<Compile Include="Responses\CopyRatesResponse.cs" />
|
||||||
@@ -99,7 +97,6 @@
|
|||||||
<Compile Include="Responses\GetOrdersResponse.cs" />
|
<Compile Include="Responses\GetOrdersResponse.cs" />
|
||||||
<Compile Include="Responses\ICustomResponse.cs" />
|
<Compile Include="Responses\ICustomResponse.cs" />
|
||||||
<Compile Include="Responses\OrderSendResponse.cs" />
|
<Compile Include="Responses\OrderSendResponse.cs" />
|
||||||
<Compile Include="Responses\SessionResponce.cs" />
|
|
||||||
<Compile Include="Responses\ResponseBase.cs" />
|
<Compile Include="Responses\ResponseBase.cs" />
|
||||||
<Compile Include="SeriesIdentifier.cs" />
|
<Compile Include="SeriesIdentifier.cs" />
|
||||||
<Compile Include="TimeBarArgs.cs" />
|
<Compile Include="TimeBarArgs.cs" />
|
||||||
|
|||||||
+20
-6
@@ -652,6 +652,26 @@ namespace MtApi
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Symbols
|
||||||
|
public int SymbolsTotal(bool selected)
|
||||||
|
{
|
||||||
|
var commandParameters = new ArrayList { selected };
|
||||||
|
return SendCommand<int>(MtCommandType.SymbolsTotal, commandParameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string SymbolName(int pos, bool selected)
|
||||||
|
{
|
||||||
|
var commandParameters = new ArrayList { pos, selected };
|
||||||
|
return SendCommand<string>(MtCommandType.SymbolName, commandParameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool SymbolSelect(string name, bool select)
|
||||||
|
{
|
||||||
|
var commandParameters = new ArrayList { name, select };
|
||||||
|
return SendCommand<bool>(MtCommandType.SymbolSelect, commandParameters);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Common Function
|
#region Common Function
|
||||||
|
|
||||||
public void Alert(string msg)
|
public void Alert(string msg)
|
||||||
@@ -1422,12 +1442,6 @@ namespace MtApi
|
|||||||
var commandParameters = new ArrayList { name, (int)prop_id };
|
var commandParameters = new ArrayList { name, (int)prop_id };
|
||||||
return SendCommand<string>(MtCommandType.SymbolInfoString, commandParameters); ;
|
return SendCommand<string>(MtCommandType.SymbolInfoString, commandParameters); ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MtSession SymbolInfoSession(string symbol, DayOfWeek dayOfWeek, uint index, SessionType type)
|
|
||||||
{
|
|
||||||
var responce = SendRequest<SessionResponce>(new SessionRequest { Symbol = symbol, DayOfWeek = dayOfWeek, SessionIndex = (int)index, SessionType = type });
|
|
||||||
return responce != null ? responce.Session : null;
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Methods
|
#region Private Methods
|
||||||
|
|||||||
@@ -195,6 +195,11 @@ namespace MtApi
|
|||||||
MtRequest = 155,
|
MtRequest = 155,
|
||||||
|
|
||||||
//Backtesting
|
//Backtesting
|
||||||
BacktestingReady = 156
|
BacktestingReady = 156,
|
||||||
|
|
||||||
|
//Symbols
|
||||||
|
SymbolsTotal = 200,
|
||||||
|
SymbolName = 201,
|
||||||
|
SymbolSelect = 202
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace MtApi
|
|
||||||
{
|
|
||||||
public class MtSession
|
|
||||||
{
|
|
||||||
public string Symbol { get; set; }
|
|
||||||
public DayOfWeek DayOfWeek { get; set; }
|
|
||||||
public uint Index { get; set; }
|
|
||||||
public int MtFromTime { get; set; }
|
|
||||||
public DateTime From
|
|
||||||
{
|
|
||||||
get { return MtApiTimeConverter.ConvertFromMtTime(MtFromTime); }
|
|
||||||
}
|
|
||||||
public int MtToTime { get; set; }
|
|
||||||
public DateTime To
|
|
||||||
{
|
|
||||||
get { return MtApiTimeConverter.ConvertFromMtTime(MtToTime); }
|
|
||||||
}
|
|
||||||
public bool HasData { get; set; }
|
|
||||||
public SessionType Type { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum SessionType { Quote, Trade }
|
|
||||||
}
|
|
||||||
@@ -11,7 +11,6 @@
|
|||||||
OrderDelete = 6,
|
OrderDelete = 6,
|
||||||
OrderModify = 7,
|
OrderModify = 7,
|
||||||
iCustom = 8,
|
iCustom = 8,
|
||||||
CopyRates = 9,
|
CopyRates = 9
|
||||||
Session = 10,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace MtApi.Requests
|
|
||||||
{
|
|
||||||
public class SessionRequest : RequestBase
|
|
||||||
{
|
|
||||||
public string Symbol { get; set; }
|
|
||||||
public DayOfWeek DayOfWeek { get; set; }
|
|
||||||
public int SessionIndex { get; set; }
|
|
||||||
public SessionType SessionType { get; set; }
|
|
||||||
|
|
||||||
public override RequestType RequestType
|
|
||||||
{
|
|
||||||
get { return RequestType.Session; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace MtApi.Responses
|
|
||||||
{
|
|
||||||
public class SessionResponce : ResponseBase
|
|
||||||
{
|
|
||||||
public MtSession Session { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.10.0")]
|
[assembly: AssemblyVersion("1.0.9.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.10.0")]
|
[assembly: AssemblyFileVersion("1.0.9.0")]
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<?define PlatformSystemFolder = "SystemFolder" ?>
|
<?define PlatformSystemFolder = "SystemFolder" ?>
|
||||||
<?endif ?>
|
<?endif ?>
|
||||||
|
|
||||||
<?define ProductVersion="1.0.10" ?>
|
<?define ProductVersion="1.0.9" ?>
|
||||||
<?define Manufacturer="DW"?>
|
<?define Manufacturer="DW"?>
|
||||||
<?define ProductPath="..\build\products\$(var.Configuration)\"?>
|
<?define ProductPath="..\build\products\$(var.Configuration)\"?>
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
+38
-20
@@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
#include <Trade\SymbolInfo.mqh>
|
#include <Trade\SymbolInfo.mqh>
|
||||||
#include <trade/trade.mqh>
|
#include <trade/trade.mqh>
|
||||||
#property version "1.1"
|
|
||||||
#property description "MtApi (MT5) connection expert"
|
|
||||||
|
|
||||||
#import "MT5Connector.dll"
|
#import "MT5Connector.dll"
|
||||||
bool initExpert(int expertHandle, int port, string symbol, double bid, double ask, string& err);
|
bool initExpert(int expertHandle, int port, string symbol, double bid, double ask, string& err);
|
||||||
@@ -34,6 +32,8 @@
|
|||||||
bool getDoubleValue(int expertHandle, int paramIndex, double& res);
|
bool getDoubleValue(int expertHandle, int paramIndex, double& res);
|
||||||
bool getStringValue(int expertHandle, int paramIndex, string& res);
|
bool getStringValue(int expertHandle, int paramIndex, string& res);
|
||||||
bool getBooleanValue(int expertHandle, int paramIndex, bool& res);
|
bool getBooleanValue(int expertHandle, int paramIndex, bool& res);
|
||||||
|
|
||||||
|
// void verify(bool isDemo, string accountName, long accountNumber);
|
||||||
#import
|
#import
|
||||||
|
|
||||||
input int Port = 8228;
|
input int Port = 8228;
|
||||||
@@ -46,6 +46,9 @@ bool isCrashed = false;
|
|||||||
string symbolValue;
|
string symbolValue;
|
||||||
string commentValue;
|
string commentValue;
|
||||||
|
|
||||||
|
double myBid;
|
||||||
|
double myAsk;
|
||||||
|
|
||||||
string PARAM_SEPARATOR = ";";
|
string PARAM_SEPARATOR = ";";
|
||||||
|
|
||||||
int OnInit()
|
int OnInit()
|
||||||
@@ -66,9 +69,9 @@ void OnTick()
|
|||||||
|
|
||||||
int preinit()
|
int preinit()
|
||||||
{
|
{
|
||||||
StringInit(message, 1000, 0);
|
message = "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" + "";
|
||||||
StringInit(symbolValue, 1000, 0);
|
symbolValue = "222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222" + "";
|
||||||
StringInit(commentValue, 1000, 0);
|
commentValue = "333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333" + "";
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -85,6 +88,8 @@ int init()
|
|||||||
{
|
{
|
||||||
preinit();
|
preinit();
|
||||||
|
|
||||||
|
// verify(IsDemo(), AccountInfoString(ACCOUNT_NAME), AccountInfoInteger(ACCOUNT_LOGIN));
|
||||||
|
|
||||||
if (TerminalInfoInteger(TERMINAL_DLLS_ALLOWED) == false)
|
if (TerminalInfoInteger(TERMINAL_DLLS_ALLOWED) == false)
|
||||||
{
|
{
|
||||||
MessageBox("Dlls not allowed.", "MtApi", 0);
|
MessageBox("Dlls not allowed.", "MtApi", 0);
|
||||||
@@ -106,13 +111,16 @@ int init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
long chartID= ChartID();
|
long chartID= ChartID();
|
||||||
ExpertHandle = (int) ChartGetInteger(chartID, CHART_WINDOW_HANDLE);
|
ExpertHandle = ChartGetInteger(chartID, CHART_WINDOW_HANDLE);
|
||||||
|
|
||||||
MqlTick last_tick;
|
MqlTick last_tick;
|
||||||
SymbolInfoTick(Symbol(),last_tick);
|
SymbolInfoTick(Symbol(),last_tick);
|
||||||
double Bid = last_tick.bid;
|
double Bid = last_tick.bid;
|
||||||
double Ask = last_tick.ask;
|
double Ask = last_tick.ask;
|
||||||
|
|
||||||
|
myBid = Bid;
|
||||||
|
myAsk = Ask;
|
||||||
|
|
||||||
if (!initExpert(ExpertHandle, Port, Symbol(), Bid, Ask, message))
|
if (!initExpert(ExpertHandle, Port, Symbol(), Bid, Ask, message))
|
||||||
{
|
{
|
||||||
MessageBox(message, "MtApi", 0);
|
MessageBox(message, "MtApi", 0);
|
||||||
@@ -145,33 +153,43 @@ int deinit()
|
|||||||
}
|
}
|
||||||
|
|
||||||
int start()
|
int start()
|
||||||
|
{
|
||||||
|
if (isCrashed == 0)
|
||||||
{
|
{
|
||||||
MqlTick last_tick;
|
MqlTick last_tick;
|
||||||
SymbolInfoTick(Symbol(),last_tick);
|
SymbolInfoTick(Symbol(),last_tick);
|
||||||
double Bid = last_tick.bid;
|
double Bid = last_tick.bid;
|
||||||
double Ask = last_tick.ask;
|
double Ask = last_tick.ask;
|
||||||
|
|
||||||
|
if (executeCommand() != 0)
|
||||||
|
{
|
||||||
|
CSymbolInfo mysymbol;
|
||||||
|
mysymbol.Name (_Symbol);
|
||||||
|
mysymbol.RefreshRates();
|
||||||
|
|
||||||
|
Bid = mysymbol.Bid();
|
||||||
|
Ask = mysymbol.Ask();
|
||||||
|
|
||||||
|
if (myBid == Bid && myAsk == Ask)
|
||||||
|
{
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!updateQuote(ExpertHandle, Symbol(), Bid, Ask, message))
|
if (!updateQuote(ExpertHandle, Symbol(), Bid, Ask, message))
|
||||||
{
|
{
|
||||||
Print("updateQuote: [ERROR] ", message);
|
MessageBox(message, "MtApi", 0);
|
||||||
|
isCrashed = true;
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
myBid = Bid;
|
||||||
|
myAsk = Ask;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnTimer()
|
|
||||||
{
|
|
||||||
while(true)
|
|
||||||
{
|
|
||||||
int executedCommand = executeCommand();
|
|
||||||
if (executedCommand == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int executeCommand()
|
int executeCommand()
|
||||||
{
|
{
|
||||||
int commandType = 0;
|
int commandType = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user