bbstrader.api¶
Handler injections that bridge the compiled C++ MetaTraderClient to a live MetaTrader 5
terminal via the Python MetaTrader5 package.
Note
The compiled bbstrader.api.client extension (MetaTraderClient, TradeRequest,
AccountInfo, etc.) is documented in the C++ API reference, since it
has no Python source for this generator to introspect.
api ¶
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.
trade_object_to_df ¶
Fast conversion of a list of C++ bound objects to a pandas DataFrame.
Source code in src/bbstrader/api/__init__.py
handlers ¶
get_mt5_handlers ¶
Exhaustively maps all MetaTrader 5 Python functions to the C++ Handlers struct, converting return values to the appropriate types.
Source code in src/bbstrader/api/handlers.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |