Reputation: 11
I am trying to write a trading bot using C++ in vscode which will be connected to metatrader 5 via binding (zeromq) on macOS. But after I installed brew install zeromq and also moved the zmq.h to :
" /Users/kiro/Library/Application Support/net.metaquotes.wine.metatrader5/drive_c/Program Files/MetaTrader 5/MQL5/Include/include "
and file libzmq.dylib to :
"/Users/kiro/Library/Application Support/net.metaquotes.wine.metatrader5/drive_c/Program Files/MetaTrader 5/MQL5/Libraries"
I am unable to bind the server, can someone help me?
For now I only use the example code to try to connect to the server via binding. When I compile this code, there is no error. But when I drag the script in Metatrader 5 to the chart I get those errors:
'''
#import "libzmq.dylib"
int zmq_ctx_new();
int zmq_socket(int context, int type);
int zmq_bind(int socket, string endpoint);
int zmq_recv(int socket, uchar &data[], int len, int flags);
int zmq_send(int socket, uchar &data[], int len, int flags);
int zmq_close(int socket);
int zmq_ctx_term(int context);
#import
void OnStart() {
int context = zmq_ctx_new();
int socket = zmq_socket(context, 4); // ZMQ_REP
zmq_bind(socket, "tcp://*:5555");
uchar data[];
ArrayResize(data, 256);
while (true) {
zmq_recv(socket, data, 256, 0);
Print("Received request: ", CharArrayToString(data));
string reply = "World";
uchar replyData[];
StringToCharArray(reply, replyData);
zmq_send(socket, replyData, StringLen(reply), 0);
}
zmq_close(socket);
zmq_ctx_term(context);
}
'''
When I compile it, there is no error. But when I drag the script on chart I get those errors:
2024.06.22 18:18:35.410 mql5 (EURUSD,M15) cannot load 'C:\Program Files\MetaTrader 5\MQL5\Libraries\libzmq.dylib' [193]
2024.06.22 18:18:35.413 mql5 (EURUSD,M15) cannot call 'zmq_ctx_new', 'libzmq.dylib' is not loaded
2024.06.22 18:18:35.413 mql5 (EURUSD,M15) unresolved import function call
on other hand code in c++ in vscode looks like this
''''
#include <zmqpp.hpp>
#include <iostream>
#include <string>
int main() {
try {
zmqpp::context context;
zmqpp::socket socket(context, zmqpp::socket_type::req);
std::cout << "Connecting to server..." << std::endl;
socket.connect("tcp://localhost:5555");
std::string request = "Hello, MT5";
zmqpp::message message;
message << request;
std::cout << "Sending message: " << request << std::endl;
socket.send(message);
zmqpp::message reply;
std::cout << "Waiting for reply..." << std::endl;
socket.receive(reply);
std::string reply_str;
reply >> reply_str;
std::cout << "Received: " << reply_str << std::endl;
} catch (const zmqpp::exception& e) {
std::cerr << "ZeroMQ Exception: " << e.what() << std::endl;
} catch (const std::exception& e) {
std::cerr << "Standard Exception: " << e.what() << std::endl;
} catch (...) {
std::cerr << "Unknown Exception" << std::endl;
}
return 0;
}
''''
and after building the code control + shift +b and ./main in the terminal I get this:
Connecting to server...
Sending message: Hello, MT5
Waiting for reply...
I
Upvotes: 0
Views: 68