8#include <pybind11/chrono.h>
9#include <pybind11/numpy.h>
10#include <pybind11/pybind11.h>
21namespace py = pybind11;
27using str =
const std::string;
36using DealsData = std::optional<std::vector<TradeDeal>>;
42using BookData = std::optional<std::vector<BookInfo>>;
45using OrdersData = std::optional<std::vector<TradeOrder>>;
57using DateTime = std::chrono::system_clock::time_point;
71using Login = std::function<bool(uint64_t,
str&,
str&, uint32_t)>;
77using GetVersion = std::function<std::optional<VersionInfo>()>;
80using GetLastError = std::function<std::optional<LastErrorResult>()>;
335 str& path, uint64_t account,
str& pw,
str& srv, uint32_t timeout,
bool portable
338 ? this_handlers.
init_full(path, account, pw, srv, timeout, portable)
348 [[nodiscard]]
virtual auto login(uint64_t account,
str& pw,
str& srv, uint32_t timeout) ->
bool {
349 return this_handlers.
login ? this_handlers.
login(account, pw, srv, timeout) :
false;
360 [[nodiscard]]
virtual auto version() -> std::optional<VersionInfo> {
367 [[nodiscard]]
virtual auto last_error() -> std::optional<LastErrorResult> {
369 : std::make_tuple(-1, std::string(
"fail"));
380 [[nodiscard]]
virtual auto account_info() -> std::optional<AccountInfo> {
409 [[nodiscard]]
virtual auto symbol_info(
str& symbol) -> std::optional<SymbolInfo> {
460 auto from_ts =
static_cast<int64_t
>(std::chrono::system_clock::to_time_t(from));
472 : py::array_t<RateInfo>();
484 : py::array_t<RateInfo>();
494 auto from_ts =
static_cast<int64_t
>(std::chrono::system_clock::to_time_t(from));
495 auto to_ts =
static_cast<int64_t
>(std::chrono::system_clock::to_time_t(to));
507 : py::array_t<RateInfo>();
518 auto from_ts =
static_cast<int64_t
>(std::chrono::system_clock::to_time_t(from));
532 : py::array_t<TickInfo>();
543 auto from_ts =
static_cast<int64_t
>(std::chrono::system_clock::to_time_t(from));
544 auto to_ts =
static_cast<int64_t
>(std::chrono::system_clock::to_time_t(to));
557 : py::array_t<TickInfo>();
641 [[nodiscard]]
virtual auto order_check(
const py::dict& dict) -> std::optional<OrderCheckResult> {
655 [[nodiscard]]
virtual auto order_send(
const py::dict& dict) -> std::optional<OrderSentResult> {
673 -> std::optional<double> {
686 -> std::optional<double> {
710 auto from_ts =
static_cast<int64_t
>(std::chrono::system_clock::to_time_t(from));
711 auto to_ts =
static_cast<int64_t
>(std::chrono::system_clock::to_time_t(to));
729 auto from_ts =
static_cast<int64_t
>(std::chrono::system_clock::to_time_t(from));
730 auto to_ts =
static_cast<int64_t
>(std::chrono::system_clock::to_time_t(to));
764 auto from_ts =
static_cast<int64_t
>(std::chrono::system_clock::to_time_t(from));
765 auto to_ts =
static_cast<int64_t
>(std::chrono::system_clock::to_time_t(to));
797 auto from_ts =
static_cast<int64_t
>(std::chrono::system_clock::to_time_t(from));
798 auto to_ts =
static_cast<int64_t
>(std::chrono::system_clock::to_time_t(to));
807 auto from_ts =
static_cast<int64_t
>(std::chrono::system_clock::to_time_t(from));
808 auto to_ts =
static_cast<int64_t
>(std::chrono::system_clock::to_time_t(to));
842 auto from_ts =
static_cast<int64_t
>(std::chrono::system_clock::to_time_t(from));
843 auto to_ts =
static_cast<int64_t
>(std::chrono::system_clock::to_time_t(to));
848 Handlers this_handlers;
std::function< OrdersData(int64_t, int64_t)> GetHistoryOrdersByRange
Callback to retrieve historical orders within a specific time range.
Definition metatrader.hpp:194
std::function< std::optional< int32_t >(int64_t, int64_t)> GetHistoryOrdersTotal
Callback to retrieve the total count of historical orders within a time range.
Definition metatrader.hpp:206
std::function< std::optional< int32_t >(int64_t, int64_t)> GetHistoryDealsTotal
Callback to retrieve the total count of historical deals within a time range.
Definition metatrader.hpp:221
std::function< DealsData(int64_t, int64_t)> GetHistoryDealsByRange
Callback to retrieve historical deals (executions) within a time range.
Definition metatrader.hpp:209
std::function< DealsData(int64_t, int64_t, str &)> GetHistoryDealsByGroup
Callback to retrieve historical deals (executions) within a time range buy asset.
Definition metatrader.hpp:212
std::function< OrdersData(int64_t, int64_t, str &)> GetHistoryOrdersByGroup
Callback to retrieve historical orders within a specific time range and filter.
Definition metatrader.hpp:197
std::function< DealsData(uint64_t)> GetHistoryDealsByPosId
Callback to retrieve historical deals associated with a specific Position ID.
Definition metatrader.hpp:218
std::function< OrdersData(uint64_t)> GetHistoryOrdersByPosId
Callback to retrieve all historical orders associated with a specific Position ID.
Definition metatrader.hpp:203
std::function< std::optional< TradeOrder >(uint64_t)> GetHistoryOrderByTicket
Callback to retrieve a specific historical order by its ticket ID.
Definition metatrader.hpp:200
std::function< DealsData(uint64_t)> GetHistoryDealsByTicket
Callback to retrieve historical deals associated with a specific Order Ticket.
Definition metatrader.hpp:215
std::function< std::optional< int32_t >()> GetTotalOrders
Callback to retrieve the total count of active orders.
Definition metatrader.hpp:149
std::function< std::optional< TradeOrder >(uint64_t)> GetOrderByTicket
Callback to retrieve a specific order by its unique ticket ID.
Definition metatrader.hpp:146
std::function< OrdersData(str &)> GetOrdersBySymbol
Callback to retrieve trade orders filtered by symbol.
Definition metatrader.hpp:140
std::function< OrdersData(str &)> GetOrdersByGroup
Callback to retrieve trade orders filtered by a specific group.
Definition metatrader.hpp:143
std::function< OrdersData()> GetOrdersAll
Callback to retrieve all current trade orders.
Definition metatrader.hpp:137
std::function< std::optional< int32_t >()> GetTotalPositions
Callback to retrieve the total count of active positions.
Definition metatrader.hpp:169
std::function< PositionsData()> GetPositionsAll
Callback to retrieve all active trade positions.
Definition metatrader.hpp:157
std::function< PositionsData(str &)> GetPositionsBySymbol
Callback to retrieve active positions filtered by symbol.
Definition metatrader.hpp:160
std::function< std::optional< TradePosition >(uint64_t)> GetPositionByTicket
Callback to retrieve a specific position by its unique ticket ID.
Definition metatrader.hpp:166
std::function< PositionsData(str &)> GetPositionsByGroup
Callback to retrieve active positions filtered by group.
Definition metatrader.hpp:163
Namespace containing MetaTrader 5 (MT5) client definitions and wrapper classes.
Definition metatrader.hpp:24
std::function< bool(str &, uint64_t, str &, str &, uint32_t, bool)> InitializeFull
Callback to initialize the MT5 terminal with full configuration options.
Definition metatrader.hpp:68
std::tuple< int32_t, std::string > LastErrorResult
Tuple representing the last error: <error code, error description>.
Definition metatrader.hpp:33
std::chrono::system_clock::time_point DateTime
System clock time point for date/time operations.
Definition metatrader.hpp:57
std::function< bool()> InitializeAuto
Callback to initialize the MT5 terminal automatically.
Definition metatrader.hpp:62
std::function< RateInfoType(str &, int32_t, int32_t, int32_t)> GetRatesByPos
Callback to get rates starting from a specific index position.
Definition metatrader.hpp:121
std::function< std::optional< OrderCheckResult >(const TradeRequest &)> CheckOrder
Callback to check an order request before sending.
Definition metatrader.hpp:182
std::function< std::optional< AccountInfo >()> GetAccountInfo
Callback to retrieve account information.
Definition metatrader.hpp:86
std::function< bool(uint64_t, str &, str &, uint32_t)> Login
Callback to login to an account.
Definition metatrader.hpp:71
std::function< BookData(str &)> GetBookInfo
Callback to get the current Market Book state for a symbol.
Definition metatrader.hpp:113
std::function< std::optional< VersionInfo >()> GetVersion
Callback to retrieve the terminal version.
Definition metatrader.hpp:77
std::function< std::optional< SymbolInfo >(str &)> GetSymbolInfo
Callback to retrieve information for a specific symbol.
Definition metatrader.hpp:89
std::function< SymbolsData()> GetSymbolsAll
Callback to retrieve all available symbols.
Definition metatrader.hpp:98
std::function< std::optional< TerminalInfo >()> GetTerminalInfo
Callback to retrieve static terminal information.
Definition metatrader.hpp:83
std::function< bool(str &)> InitializeWithPath
Callback to initialize the MT5 terminal with a specific path.
Definition metatrader.hpp:65
std::function< bool(str &)> UnsubscribeBook
Callback to unsubscribe from the Market Book for a symbol.
Definition metatrader.hpp:110
std::optional< py::array_t< TickInfo > > TickInfoType
Optional Numpy array of TickInfo structures.
Definition metatrader.hpp:54
std::function< std::optional< double >(int32_t, str &, double, double, double)> CalculateProfit
Callback to calculate profit.
Definition metatrader.hpp:179
std::optional< py::array_t< RateInfo > > RateInfoType
Optional Numpy array of RateInfo structures (OHLCV data).
Definition metatrader.hpp:51
std::function< std::optional< TickInfo >(str &)> GetTickInfo
Callback to retrieve the last tick for a specific symbol.
Definition metatrader.hpp:92
std::function< bool(str &, bool)> SelectSymbol
Callback to select or deselect a symbol in Market Watch.
Definition metatrader.hpp:101
std::optional< std::vector< TradePosition > > PositionsData
Optional vector of TradePosition objects.
Definition metatrader.hpp:48
std::function< SymbolsData(str &)> GetSymbolsByGroup
Callback to retrieve symbols belonging to a specific group.
Definition metatrader.hpp:104
std::function< void()> Shutdown
Callback to shut down the initialized terminal.
Definition metatrader.hpp:74
std::function< std::optional< LastErrorResult >()> GetLastError
Callback to retrieve the last error code and description.
Definition metatrader.hpp:80
std::function< RateInfoType(str &, int32_t, int64_t, int32_t)> GetRatesByDate
Callback to get rates starting from a specific date.
Definition metatrader.hpp:118
std::optional< std::vector< SymbolInfo > > SymbolsData
Optional vector of SymbolInfo objects.
Definition metatrader.hpp:39
std::function< TickInfoType(str &, int64_t, int32_t, int32_t)> GetTicksByDate
Callback to get ticks starting from a specific date.
Definition metatrader.hpp:127
std::function< RateInfoType(str &, int32_t, int64_t, int64_t)> GetRatesByRange
Callback to get rates within a time range.
Definition metatrader.hpp:124
std::optional< std::vector< TradeOrder > > OrdersData
Optional vector of TradeOrder objects.
Definition metatrader.hpp:45
std::function< TickInfoType(str &, int64_t, int64_t, int32_t)> GetTicksByRange
Callback to get ticks within a time range.
Definition metatrader.hpp:130
std::function< std::optional< double >(int32_t, str &, double, double)> CalculateMargin
Callback to calculate margin.
Definition metatrader.hpp:176
std::optional< std::vector< BookInfo > > BookData
Optional vector of BookInfo (Market Depth) objects.
Definition metatrader.hpp:42
std::function< std::optional< OrderSentResult >(const TradeRequest &)> SendOrder
Callback to send an order to the market.
Definition metatrader.hpp:185
const std::string str
Alias for const std::string to simplify function signatures.
Definition metatrader.hpp:27
std::optional< std::vector< TradeDeal > > DealsData
Optional vector of TradeDeal objects.
Definition metatrader.hpp:36
std::function< std::optional< int32_t >()> GetTotalSymbols
Callback to get the total count of available symbols.
Definition metatrader.hpp:95
std::tuple< int32_t, int32_t, std::string > VersionInfo
Tuple representing version info: <major version, minor version, build date string>.
Definition metatrader.hpp:30
std::function< bool(str &)> SubscribeBook
Callback to subscribe to the Market Book (Depth of Market) for a symbol.
Definition metatrader.hpp:107
Declares the public API for the Metatrader5 objects in bbstrader library. This is the primary file th...
Structure to send trade requests to the server.
Definition objects.hpp:515