Skip to content

C++

Uses cpr for HTTP and nlohmann/json.

All examples assume the EA is running on the same computer with default ports. Order examples are for demo accounts.

#include <cpr/cpr.h>
#include <nlohmann/json.hpp>
#include <iostream>
int main() {
auto q = nlohmann::json::parse(
cpr::Get(cpr::Url{"http://127.0.0.1:81/v1/quote"},
cpr::Parameters{{"symbol", "EURUSD"}}).text);
std::cout << q["BID"] << " / " << q["ASK"] << "\n";
auto o = nlohmann::json::parse(
cpr::Post(cpr::Url{"http://127.0.0.1:81/v1/order"},
cpr::Parameters{{"symbol", "EURUSD"}, {"volume", "0.01"},
{"type", "ORDER_TYPE_BUY"}}).text);
std::cout << "RETCODE " << o["RETCODE"] << "\n";
}