├── .gitignore ├── MQL4 ├── Experts │ └── websockets.mq4 ├── Include │ └── lib_websockets.mqh └── Libraries │ ├── mt4-common.dll │ └── zlib1.dll ├── MQL5 ├── Experts │ └── websockets.mq5 ├── Include │ └── lib_websockets.mqh └── Libraries │ ├── mt4-common.dll │ └── zlib1.dll ├── README.md ├── mt4-websockets.sln └── mt4-websockets ├── main.cpp ├── mt4-websockets.def ├── mt4-websockets.vcxproj ├── params.h ├── safe_vector.cpp ├── safe_vector.hpp ├── stdafx.cpp ├── stdafx.h └── targetver.h /.gitignore: -------------------------------------------------------------------------------- 1 | Temp/ 2 | Bin/ 3 | .vs 4 | *.suo 5 | *.user 6 | *.userosscache 7 | ipch/ 8 | *.aps 9 | *.ncb 10 | *.opendb 11 | *.opensdf 12 | *.sdf 13 | *.cachefile 14 | *.VC.db 15 | -------------------------------------------------------------------------------- /MQL4/Experts/websockets.mq4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikha-dev/mt4-websockets/8bbffee4713a613140b2dd209685dcf2fd7e2057/MQL4/Experts/websockets.mq4 -------------------------------------------------------------------------------- /MQL4/Include/lib_websockets.mqh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikha-dev/mt4-websockets/8bbffee4713a613140b2dd209685dcf2fd7e2057/MQL4/Include/lib_websockets.mqh -------------------------------------------------------------------------------- /MQL4/Libraries/mt4-common.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikha-dev/mt4-websockets/8bbffee4713a613140b2dd209685dcf2fd7e2057/MQL4/Libraries/mt4-common.dll -------------------------------------------------------------------------------- /MQL4/Libraries/zlib1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikha-dev/mt4-websockets/8bbffee4713a613140b2dd209685dcf2fd7e2057/MQL4/Libraries/zlib1.dll -------------------------------------------------------------------------------- /MQL5/Experts/websockets.mq5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikha-dev/mt4-websockets/8bbffee4713a613140b2dd209685dcf2fd7e2057/MQL5/Experts/websockets.mq5 -------------------------------------------------------------------------------- /MQL5/Include/lib_websockets.mqh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikha-dev/mt4-websockets/8bbffee4713a613140b2dd209685dcf2fd7e2057/MQL5/Include/lib_websockets.mqh -------------------------------------------------------------------------------- /MQL5/Libraries/mt4-common.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikha-dev/mt4-websockets/8bbffee4713a613140b2dd209685dcf2fd7e2057/MQL5/Libraries/mt4-common.dll -------------------------------------------------------------------------------- /MQL5/Libraries/zlib1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikha-dev/mt4-websockets/8bbffee4713a613140b2dd209685dcf2fd7e2057/MQL5/Libraries/zlib1.dll -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Turns Metatrader4/Metatrader5 into websockets client. 2 | 3 | Note: make sure you have VSredist: https://www.microsoft.com/en-ie/download/details.aspx?id=48145 4 | 5 | Copy MQL4 folder to Data folder of mt4 (how to get where is Data folder is localted, open mt4, click File->Open Data Folder or just click Ctrl+Shft+D). 6 | In MT4 Navigator (to show Naavigator click Ctrl+N) select Expert Advisors->Advisors. Right click on websockets, select Modify. Editor will be opened, press F7 to compile. Done. 7 | -------------------------------------------------------------------------------- /mt4-websockets.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27130.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mt4-websockets", "mt4-websockets\mt4-websockets.vcxproj", "{7359E8DF-CF85-409D-833B-3B66F8DAC462}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | NDebug|x64 = NDebug|x64 13 | NDebug|x86 = NDebug|x86 14 | NRelease|x64 = NRelease|x64 15 | NRelease|x86 = NRelease|x86 16 | Release_auth_lic|x64 = Release_auth_lic|x64 17 | Release_auth_lic|x86 = Release_auth_lic|x86 18 | Release_auth_user_pass|x64 = Release_auth_user_pass|x64 19 | Release_auth_user_pass|x86 = Release_auth_user_pass|x86 20 | Release_Client|x64 = Release_Client|x64 21 | Release_Client|x86 = Release_Client|x86 22 | release_dll|x64 = release_dll|x64 23 | release_dll|x86 = release_dll|x86 24 | release_win|x64 = release_win|x64 25 | release_win|x86 = release_win|x86 26 | Release|x64 = Release|x64 27 | Release|x86 = Release|x86 28 | ReleaseMaster|x64 = ReleaseMaster|x64 29 | ReleaseMaster|x86 = ReleaseMaster|x86 30 | EndGlobalSection 31 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 32 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.Debug|x64.ActiveCfg = Debug|x64 33 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.Debug|x64.Build.0 = Debug|x64 34 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.Debug|x86.ActiveCfg = Debug|Win32 35 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.Debug|x86.Build.0 = Debug|Win32 36 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.NDebug|x64.ActiveCfg = Debug|x64 37 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.NDebug|x64.Build.0 = Debug|x64 38 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.NDebug|x86.ActiveCfg = Debug|Win32 39 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.NDebug|x86.Build.0 = Debug|Win32 40 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.NRelease|x64.ActiveCfg = Release|x64 41 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.NRelease|x64.Build.0 = Release|x64 42 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.NRelease|x86.ActiveCfg = Release|Win32 43 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.NRelease|x86.Build.0 = Release|Win32 44 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.Release_auth_lic|x64.ActiveCfg = Release|x64 45 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.Release_auth_lic|x64.Build.0 = Release|x64 46 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.Release_auth_lic|x86.ActiveCfg = Release|Win32 47 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.Release_auth_lic|x86.Build.0 = Release|Win32 48 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.Release_auth_user_pass|x64.ActiveCfg = Release|x64 49 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.Release_auth_user_pass|x64.Build.0 = Release|x64 50 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.Release_auth_user_pass|x86.ActiveCfg = Release|Win32 51 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.Release_auth_user_pass|x86.Build.0 = Release|Win32 52 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.Release_Client|x64.ActiveCfg = Release|x64 53 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.Release_Client|x64.Build.0 = Release|x64 54 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.Release_Client|x86.ActiveCfg = Release|Win32 55 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.Release_Client|x86.Build.0 = Release|Win32 56 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.release_dll|x64.ActiveCfg = Release|x64 57 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.release_dll|x64.Build.0 = Release|x64 58 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.release_dll|x86.ActiveCfg = Release|Win32 59 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.release_dll|x86.Build.0 = Release|Win32 60 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.release_win|x64.ActiveCfg = Release|x64 61 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.release_win|x64.Build.0 = Release|x64 62 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.release_win|x86.ActiveCfg = Release|Win32 63 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.release_win|x86.Build.0 = Release|Win32 64 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.Release|x64.ActiveCfg = Release|x64 65 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.Release|x64.Build.0 = Release|x64 66 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.Release|x86.ActiveCfg = Release|Win32 67 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.Release|x86.Build.0 = Release|Win32 68 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.ReleaseMaster|x64.ActiveCfg = Release|x64 69 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.ReleaseMaster|x64.Build.0 = Release|x64 70 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.ReleaseMaster|x86.ActiveCfg = Release|Win32 71 | {7359E8DF-CF85-409D-833B-3B66F8DAC462}.ReleaseMaster|x86.Build.0 = Release|Win32 72 | EndGlobalSection 73 | GlobalSection(SolutionProperties) = preSolution 74 | HideSolutionNode = FALSE 75 | EndGlobalSection 76 | GlobalSection(ExtensibilityGlobals) = postSolution 77 | SolutionGuid = {08964258-A61B-48D7-9E07-0818CDD29B8B} 78 | EndGlobalSection 79 | EndGlobal 80 | -------------------------------------------------------------------------------- /mt4-websockets/main.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "params.h" 3 | #include "safe_vector.hpp" 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #pragma comment(lib, "iphlpapi.lib") 11 | #pragma comment (lib, "crypt32") 12 | 13 | using namespace std; 14 | 15 | #define MT_EXPFUNC extern "C" __declspec(dllexport) 16 | #define dbg(msg) writeLog(".\\webscoket.log", msg); 17 | 18 | static ix::WebSocket webSocket; 19 | static SafeVector messages; 20 | static string last_error; 21 | 22 | int writeLog(const char *file, const char *content) { 23 | if (file && content) { 24 | FILE *fd; 25 | errno_t err = fopen_s(&fd, file, "a+b"); 26 | if (err != 0) 27 | return 1; 28 | else { 29 | SYSTEMTIME st; 30 | GetLocalTime(&st); 31 | fprintf(fd, "%04d.%02d.%02d %02d:%02d:%02d.%03d::%s\r\n", 32 | st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds, content); 33 | 34 | fclose(fd); 35 | } 36 | } 37 | return 0; 38 | } 39 | 40 | MT_EXPFUNC int __stdcall SetHeader(const char *key, const char * value) { 41 | ix::WebSocketHttpHeaders headers; 42 | headers[key] = value; 43 | webSocket.setExtraHeaders(headers); 44 | } 45 | 46 | MT_EXPFUNC int __stdcall Init(const char *url, int timeout, int heat_beat_period) { 47 | string server_url(url); 48 | 49 | try { 50 | ix::initNetSystem(); 51 | 52 | webSocket.setUrl(server_url); 53 | 54 | webSocket.setPingInterval(heat_beat_period); 55 | 56 | // Per message deflate connection is enabled by default. You can tweak its parameters or disable it 57 | webSocket.disablePerMessageDeflate(); 58 | 59 | // Setup a callback to be fired when a message or an event (open, close, error) is received 60 | webSocket.setOnMessageCallback([](const ix::WebSocketMessagePtr& msg) 61 | { 62 | if (msg->type == ix::WebSocketMessageType::Message) 63 | { 64 | messages.push_back(msg->str); 65 | } 66 | } 67 | ); 68 | 69 | ix::WebSocketInitResult r = webSocket.connect(timeout); 70 | 71 | if (r.success) { 72 | webSocket.start(); 73 | 74 | last_error.clear(); 75 | return 1; 76 | } 77 | 78 | last_error.append(r.errorStr); 79 | return 0; 80 | } 81 | catch (std::exception & e) { 82 | // std::cerr << "websockets something wrong happened! " << std::endl; 83 | // std::cerr << e.what() << std::endl; 84 | dbg(e.what()); 85 | last_error.append(e.what()); 86 | } 87 | catch (...) { 88 | } 89 | 90 | 91 | return 0; 92 | } 93 | 94 | MT_EXPFUNC void __stdcall Deinit() { 95 | try { 96 | webSocket.stop(); 97 | ix::uninitNetSystem(); 98 | } 99 | catch (std::exception & e) { 100 | // std::cerr << e.what() << std::endl; 101 | dbg(e.what()); 102 | } 103 | catch (...) { 104 | } 105 | 106 | } 107 | 108 | MT_EXPFUNC void __stdcall WSGetLastError(char *data) { 109 | 110 | if (last_error.length() > 0) { 111 | strcpy(data, last_error.c_str()); 112 | strcat(data, "\0"); 113 | } 114 | } 115 | 116 | MT_EXPFUNC int __stdcall httpSendPost(const char* url_, const char * input, int timeout, char *output) { 117 | ix::HttpResponsePtr out; 118 | std::string url(url_); 119 | 120 | ix::HttpClient httpClient; 121 | ix::HttpRequestArgsPtr args = httpClient.createRequest(); 122 | 123 | args->connectTimeout = timeout; 124 | args->transferTimeout = timeout; 125 | 126 | ix::SocketTLSOptions opts; 127 | //opts.caFile = "cacert.pem"; 128 | opts.caFile = "SYSTEM"; 129 | httpClient.setTLSOptions(opts); 130 | out = httpClient.post(url, std::string(input), args); 131 | 132 | auto statusCode = out->statusCode; 133 | 134 | if (statusCode == 200) { 135 | strcpy(output, out->body.c_str()); 136 | strcat(output, "\0"); 137 | } 138 | else { 139 | strcpy(output, out->errorMsg.c_str()); 140 | strcat(output, "\0"); 141 | } 142 | 143 | return statusCode; 144 | } 145 | 146 | MT_EXPFUNC int __stdcall GetCommand(char *data) { 147 | 148 | if (messages.size() > 0) { 149 | strcpy(data, messages.back().c_str()); 150 | strcat(data, "\0"); 151 | 152 | messages.pop_back(); 153 | 154 | return 1; 155 | } 156 | 157 | return 0; 158 | } 159 | 160 | MT_EXPFUNC int __stdcall SendCommand(const char *command) { 161 | webSocket.send(command); 162 | return 1; 163 | } 164 | 165 | inline bool is_base64(unsigned char c) { 166 | return (isalnum(c) || (c == '+') || (c == '/')); 167 | } 168 | 169 | std::string base64_decode(std::string const& encoded_string) { 170 | const std::string base64_chars = 171 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 172 | "abcdefghijklmnopqrstuvwxyz" 173 | "0123456789+/"; 174 | 175 | int in_len = encoded_string.size(); 176 | int i = 0; 177 | int j = 0; 178 | int in_ = 0; 179 | unsigned char char_array_4[4], char_array_3[3]; 180 | std::string ret; 181 | 182 | while (in_len-- && (encoded_string[in_] != '=') && is_base64(encoded_string[in_])) { 183 | char_array_4[i++] = encoded_string[in_]; in_++; 184 | if (i == 4) { 185 | for (i = 0; i < 4; i++) 186 | char_array_4[i] = base64_chars.find(char_array_4[i]); 187 | 188 | char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); 189 | char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); 190 | char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; 191 | 192 | for (i = 0; (i < 3); i++) 193 | ret += char_array_3[i]; 194 | i = 0; 195 | } 196 | } 197 | 198 | if (i) { 199 | for (j = i; j < 4; j++) 200 | char_array_4[j] = 0; 201 | 202 | for (j = 0; j < 4; j++) 203 | char_array_4[j] = base64_chars.find(char_array_4[j]); 204 | 205 | char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); 206 | char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); 207 | char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; 208 | 209 | for (j = 0; (j < i - 1); j++) ret += char_array_3[j]; 210 | } 211 | 212 | return ret; 213 | } 214 | 215 | MT_EXPFUNC int __stdcall base64Decode(const char* data, char *out) { 216 | strcpy(out, base64_decode(data).c_str()); 217 | strcat(out, "\0"); 218 | } 219 | 220 | char* getMAC_Address() 221 | { 222 | char buf[13]; 223 | IP_ADAPTER_INFO AdapterInfo[16]; // Allocate information for up to 16 NICs 224 | DWORD dwBufLen = sizeof(AdapterInfo); // Save the memory size of buffer 225 | 226 | DWORD dwStatus = GetAdaptersInfo( // Call GetAdapterInfo 227 | AdapterInfo, // [out] buffer to receive data 228 | &dwBufLen); // [in] size of receive data buffer 229 | // assert(dwStatus == ERROR_SUCCESS); // Verify return value is valid, no buffer overflow 230 | 231 | PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo; // Contains pointer to current adapter info 232 | sprintf_s(buf, "%02X%02X%02X%02X%02X%02X", 233 | pAdapterInfo->Address[0], 234 | pAdapterInfo->Address[1], 235 | pAdapterInfo->Address[2], 236 | pAdapterInfo->Address[3], 237 | pAdapterInfo->Address[4], 238 | pAdapterInfo->Address[5]); 239 | 240 | return buf; 241 | 242 | 243 | }; 244 | 245 | MT_EXPFUNC int __stdcall getMAC(char *out) { 246 | strcpy(out, getMAC_Address()); 247 | strcat(out, "\0"); 248 | 249 | return 0; 250 | } 251 | 252 | 253 | MT_EXPFUNC int __stdcall loadCache(const char* path) { 254 | Params.Init(path); 255 | return 0; 256 | } 257 | 258 | MT_EXPFUNC int __stdcall setCache(const char* key, const char *val) { 259 | Params.Set(key, val); 260 | return 0; 261 | } 262 | 263 | MT_EXPFUNC int __stdcall getCache(const char* key, char *val) { 264 | strcpy(val, Params.Get(key).c_str()); 265 | strcat(val, "\0"); 266 | 267 | return 0; 268 | } 269 | -------------------------------------------------------------------------------- /mt4-websockets/mt4-websockets.def: -------------------------------------------------------------------------------- 1 | LIBRARY "mt4-common.dll" 2 | EXPORTS 3 | Init 4 | Deinit 5 | httpSendPost 6 | SetHeader 7 | WSGetLastError 8 | GetCommand 9 | SendCommand 10 | base64Decode 11 | getMAC 12 | loadCache 13 | setCache 14 | getCache -------------------------------------------------------------------------------- /mt4-websockets/mt4-websockets.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 15.0 23 | {7359E8DF-CF85-409D-833B-3B66F8DAC462} 24 | Win32Proj 25 | microservicetutorial 26 | 10.0 27 | mt4-common 28 | 29 | 30 | 31 | Application 32 | true 33 | v143 34 | Unicode 35 | 36 | 37 | DynamicLibrary 38 | false 39 | v143 40 | true 41 | Unicode 42 | false 43 | 44 | 45 | Application 46 | true 47 | v143 48 | Unicode 49 | 50 | 51 | DynamicLibrary 52 | false 53 | v143 54 | true 55 | Unicode 56 | false 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | true 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | $(SolutionDir)Bin\$(Platform)\$(Configuration)\ 85 | $(SolutionDir)Temp\$(Platform)\$(Configuration)\ 86 | 87 | 88 | false 89 | $(SolutionDir)$(Platform)\$(Configuration)\ 90 | 91 | 92 | 93 | Use 94 | Level3 95 | Disabled 96 | true 97 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 98 | false 99 | 100 | 101 | 102 | 103 | Console 104 | true 105 | 106 | 107 | 108 | 109 | Use 110 | Level3 111 | Disabled 112 | true 113 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 114 | false 115 | 116 | 117 | Console 118 | true 119 | 120 | 121 | 122 | 123 | Use 124 | Level3 125 | MaxSpeed 126 | true 127 | true 128 | true 129 | _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 130 | true 131 | ..\..\vcpkg\installed\x86-windows\include;%(AdditionalIncludeDirectories) 132 | 133 | 134 | Console 135 | true 136 | true 137 | true 138 | ..\..\vcpkg\installed\x86-windows\lib\;$(SolutionDir)Bin/$(Platform)\$(Configuration); 139 | zlib.lib;mbedcrypto.lib;mbedx509.lib;mbedtls.lib;ixwebsocket.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 140 | mt4-websockets.def 141 | 142 | 143 | 144 | 145 | Use 146 | Level3 147 | MaxSpeed 148 | true 149 | true 150 | true 151 | _CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 152 | true 153 | ..\packages\x64-windows\include;..\..\boost_1_69_0;%(AdditionalIncludeDirectories); 154 | Sync 155 | 156 | 157 | Console 158 | true 159 | true 160 | true 161 | ..\packages\x64-windows\lib\;..\..\boost_1_69_0\lib64-msvc-14.1;$(SolutionDir)$(Platform)\$(Configuration); 162 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 163 | mt4-websockets.def 164 | 165 | 166 | taskkill /IM ServiceHub.DataWarehouseHost.exe /F 2>nul 1>nul 167 | Exit 0 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | Create 180 | Create 181 | Create 182 | Create 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | -------------------------------------------------------------------------------- /mt4-websockets/params.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using std::string; 9 | using std::set; 10 | 11 | typedef std::map mapType; 12 | 13 | class XParams { 14 | 15 | private: 16 | 17 | public: XParams() { 18 | 19 | } 20 | 21 | ~XParams(void) { 22 | data.clear(); 23 | } 24 | 25 | int Init( string pathCache ) { 26 | _pathCache = pathCache; 27 | 28 | FILE *file; 29 | 30 | try { 31 | _load( _pathCache.c_str() ); 32 | return 1; 33 | } catch (...) { 34 | remove( pathCache.c_str() ); 35 | return 0; 36 | } 37 | 38 | return 1; 39 | } 40 | 41 | bool Save() { 42 | if( _pathCache.empty() ) 43 | return false; 44 | 45 | FILE *file; 46 | 47 | if (( file = fopen( _pathCache.c_str(), "w" ) ) != NULL) { 48 | _dump( file ); 49 | fclose( file ); 50 | return true; 51 | } 52 | 53 | return false; 54 | } 55 | 56 | bool ClearCache() { 57 | data.clear(); 58 | return Save(); 59 | } 60 | 61 | void ClearCacheFile( const char * file ) { 62 | remove( file ); 63 | } 64 | 65 | void Free() { 66 | data.clear(); 67 | } 68 | 69 | void _load( const char *path ) { 70 | char *buf; 71 | std::string s, b; 72 | int nk = 0; 73 | char* key; 74 | char* val; 75 | int k, v; 76 | 77 | data.clear(); 78 | 79 | std::ifstream file(path); 80 | 81 | while (std::getline(file, s)) { 82 | b.append( s ); 83 | b.append( "&" ); 84 | } 85 | 86 | _tokenize( b, "=&" ); 87 | } 88 | 89 | void _dump( FILE * file ) { 90 | std::set::iterator si; 91 | 92 | for(mapType::iterator it = data.begin(); it != data.end(); ++it) { 93 | if(keys.count(it->first)) 94 | fprintf( file, "%s=%s\n", it->first.c_str(), it->second.c_str() ); 95 | } 96 | } 97 | 98 | double to_double( const std::string& s, double def ) 99 | { 100 | std::istringstream i(s); 101 | double x; 102 | if (!(i >> x)) 103 | return def; 104 | return x; 105 | } 106 | 107 | double Get(const std::string& key, double def ) { 108 | string s; 109 | double d; 110 | 111 | if( data.count( key ) != 0 ) 112 | s = data[key]; 113 | else 114 | return def; 115 | 116 | d = to_double( s, def ); 117 | 118 | return d; 119 | } 120 | 121 | string Get(const std::string& key ) { 122 | if( data.count( key ) != 0 ) 123 | return data[key]; 124 | else 125 | return ""; 126 | } 127 | 128 | const bool Set(const std::string& key, string val, bool is_save=false) { 129 | if(is_save) { 130 | keys.insert( key ); 131 | Save(); 132 | } 133 | data[key] = val; 134 | return true; 135 | } 136 | 137 | const bool Remove( const char* key ) { 138 | data.erase( key ); 139 | 140 | return true; 141 | } 142 | 143 | std::string Serialize() { 144 | return string(""); 145 | } 146 | 147 | void _tokenize(const std::string& args, const std::string& delims ) { 148 | char* tmp = _strdup(args.c_str()); 149 | char* seed = tmp; 150 | char* key = 0; 151 | char* val = 0; 152 | 153 | do { 154 | key = strtok(seed, delims.c_str()); 155 | seed = 0; 156 | val = strtok(seed, delims.c_str()); 157 | 158 | if (key && val) { 159 | data[key] = val; 160 | } 161 | } while (key && val); 162 | 163 | free(tmp); 164 | } 165 | 166 | string _decrypt( char * ePtr, const char* key ) { 167 | int len = strlen(ePtr); 168 | for ( int i = 0, j = 0 ; i < len; i++ ) { 169 | ePtr[i] = ePtr[i]^key[j++]; 170 | if( j == strlen(key)) 171 | j = 0; 172 | } 173 | 174 | return(string(ePtr)); 175 | } 176 | 177 | void _cvt(char *dest, const char *src) 178 | { 179 | const char *p = src; 180 | char code[3] = {0}; 181 | unsigned long ascii = 0; 182 | char *end = NULL; 183 | 184 | while(*p) 185 | { 186 | if(*p == '%') 187 | { 188 | memcpy(code, ++p, 2); 189 | ascii = strtoul(code, &end, 16); 190 | *dest++ = (char)ascii; 191 | p += 2; 192 | } 193 | else 194 | *dest++ = *p++; 195 | } 196 | } 197 | 198 | inline bool is_base64(unsigned char c) { 199 | return (isalnum(c) || (c == '+') || (c == '/')); 200 | } 201 | 202 | std::string base64_decode(std::string const& encoded_string) { 203 | const std::string base64_chars = 204 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 205 | "abcdefghijklmnopqrstuvwxyz" 206 | "0123456789+/"; 207 | 208 | int in_len = encoded_string.size(); 209 | int i = 0; 210 | int j = 0; 211 | int in_ = 0; 212 | unsigned char char_array_4[4], char_array_3[3]; 213 | std::string ret; 214 | 215 | while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) { 216 | char_array_4[i++] = encoded_string[in_]; in_++; 217 | if (i ==4) { 218 | for (i = 0; i <4; i++) 219 | char_array_4[i] = base64_chars.find(char_array_4[i]); 220 | 221 | char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); 222 | char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); 223 | char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; 224 | 225 | for (i = 0; (i < 3); i++) 226 | ret += char_array_3[i]; 227 | i = 0; 228 | } 229 | } 230 | 231 | if (i) { 232 | for (j = i; j <4; j++) 233 | char_array_4[j] = 0; 234 | 235 | for (j = 0; j <4; j++) 236 | char_array_4[j] = base64_chars.find(char_array_4[j]); 237 | 238 | char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); 239 | char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); 240 | char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; 241 | 242 | for (j = 0; (j < i - 1); j++) ret += char_array_3[j]; 243 | } 244 | 245 | return ret; 246 | } 247 | 248 | bool Deserialize( string &args, const char* key ) { 249 | string s; 250 | 251 | s = base64_decode( args ); 252 | _tokenize( s, "=&" ); 253 | 254 | return true; 255 | } 256 | 257 | private: 258 | 259 | set keys; 260 | mapType data; 261 | string _pathCache; 262 | }; 263 | 264 | static XParams Params; 265 | -------------------------------------------------------------------------------- /mt4-websockets/safe_vector.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include 3 | #include 4 | #include "safe_vector.hpp" 5 | 6 | void SafeVector::insert(string in, const int index) 7 | { 8 | lock_guard lock(mut); 9 | vec[index] = move(in); 10 | cond.notify_one(); 11 | } 12 | 13 | void SafeVector::push_back(string in) 14 | { 15 | lock_guard lock(mut); 16 | vec.push_back(move(in)); 17 | cond.notify_one(); 18 | } 19 | 20 | void SafeVector::pop_back() 21 | { 22 | lock_guard lock(mut); 23 | vec.pop_back(); 24 | cond.notify_one(); 25 | } 26 | 27 | string& SafeVector::back() 28 | { 29 | return vec.back(); 30 | } 31 | 32 | size_t SafeVector::size() { 33 | return vec.size(); 34 | } 35 | 36 | string& SafeVector::operator[](const int index) 37 | { 38 | return vec[index]; 39 | } 40 | 41 | vector::iterator SafeVector::begin() 42 | { 43 | return vec.begin(); 44 | } 45 | 46 | vector::iterator SafeVector::end() 47 | { 48 | return vec.end(); 49 | } 50 | 51 | vector SafeVector::toVector() 52 | { 53 | return vec; 54 | } -------------------------------------------------------------------------------- /mt4-websockets/safe_vector.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SAFEVECTOR_HPP 2 | #define SAFEVECTOR_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | class SafeVector { 11 | public: 12 | SafeVector() : vec(), mut(), cond() {} 13 | SafeVector(const SafeVector& orig) : vec(orig.vec), mut(), cond() {} 14 | ~SafeVector() {} 15 | 16 | void insert(string in, const int index); 17 | void push_back(string in); 18 | void pop_back(); 19 | size_t size(); 20 | string& operator[](const int index); 21 | string& back(); 22 | vector::iterator begin(); 23 | vector::iterator end(); 24 | vector toVector(); 25 | 26 | private: 27 | vector vec; 28 | mutex mut; 29 | condition_variable cond; 30 | }; 31 | 32 | #endif /* SAFEVECTOR_HPP */ -------------------------------------------------------------------------------- /mt4-websockets/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikha-dev/mt4-websockets/8bbffee4713a613140b2dd209685dcf2fd7e2057/mt4-websockets/stdafx.cpp -------------------------------------------------------------------------------- /mt4-websockets/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikha-dev/mt4-websockets/8bbffee4713a613140b2dd209685dcf2fd7e2057/mt4-websockets/stdafx.h -------------------------------------------------------------------------------- /mt4-websockets/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikha-dev/mt4-websockets/8bbffee4713a613140b2dd209685dcf2fd7e2057/mt4-websockets/targetver.h --------------------------------------------------------------------------------