bbstrader.api package

Module contents

Overview

The API Module provides a high-level client for interacting with the MetaTrader 5 platform. It serves as the primary interface for connecting to, retrieving data from, and sending commands to a MetaTrader 5 terminal from a Python application. The module is designed to simplify interactions and provide convenient data handling.

Features

  • High-Level MT5 Client: A simplified client (Mt5client) for easy access to MetaTrader 5 functionalities.

  • Dynamic Object Representation: Automatically patches MetaTrader 5 data objects for better string representation, making debugging easier.

  • DataFrame Conversion: Includes a utility function (trade_object_to_df) to quickly convert lists of MT5 trade objects (like deals, orders, positions) into pandas DataFrames for analysis.

  • Handler-Based Architecture: Uses a handler class (Mt5Handlers) to manage the underlying MetaTrader 5 API calls, promoting modularity.

Components

  • Mt5client: The main client instance used to interact with the MetaTrader 5 terminal.

  • Mt5Handlers: A class that encapsulates the direct calls to the MetaTrader 5 API.

  • Helper Functions: - trade_object_to_df: Converts lists of trade-related objects to pandas DataFrames. - Dynamic patching of __str__ and __repr__ for improved object inspection.

Notes

This module requires a running MetaTrader 5 terminal and the MetaTrader5 Python package to be installed. The connection is managed by the Mt5client.

bbstrader.api.dynamic_str(self)[source]
bbstrader.api.trade_object_to_df(obj_list)[source]

Fast conversion of a list of C++ bound objects to a pandas DataFrame.

Submodules

bbstrader.api.handlers module

bbstrader.api.handlers.check_order(request: TradeRequest) OrderCheckResult[source]
bbstrader.api.handlers.get_mt5_handlers()[source]

Exhaustively maps all MetaTrader 5 Python functions to the C++ Handlers struct, converting return values to the appropriate types.

bbstrader.api.handlers.get_time(ts)[source]
bbstrader.api.handlers.send_order(request: TradeRequest) OrderSentResult[source]