74e3754a80
* feat: add MT5 order metadata, coverage report, and env-backed CLI config * fix: align review-driven trading and history contracts * Bump pdmt5 to 1.1.0 * test: stabilize history gaps CLI assertion * fix: address review follow-ups for gaps and filling mode
156 lines
4.5 KiB
Python
156 lines
4.5 KiB
Python
"""mt5cli: Generic MT5 data and execution infrastructure for Python applications.
|
|
|
|
Downstream packages should import from this module (``from mt5cli import ...``)
|
|
rather than private submodule helpers. See ``docs/api/public-contract.md`` for
|
|
the stable SDK contract, CLI surface, internal modules, and out-of-scope
|
|
strategy responsibilities.
|
|
"""
|
|
|
|
from importlib.metadata import version
|
|
|
|
from .client import MT5Client, build_config, mt5_session
|
|
from .contract import STABLE_SDK_EXPORTS
|
|
from .exceptions import (
|
|
Mt5CliError,
|
|
Mt5ConnectionError,
|
|
Mt5OperationError,
|
|
Mt5SchemaError,
|
|
)
|
|
from .history import (
|
|
RateTarget,
|
|
build_rate_targets,
|
|
drop_forming_rate_bar,
|
|
load_rate_series_by_granularity,
|
|
load_rate_series_from_sqlite,
|
|
report_rate_gaps,
|
|
)
|
|
from .sdk import (
|
|
AccountSpec,
|
|
ThrottledHistoryUpdater,
|
|
collect_history,
|
|
collect_latest_closed_rates_by_granularity,
|
|
collect_latest_closed_rates_for_accounts,
|
|
collect_latest_rates_for_accounts_with_retries,
|
|
fetch_latest_closed_rates,
|
|
resolve_account_spec,
|
|
resolve_account_specs,
|
|
update_history,
|
|
update_history_with_config,
|
|
update_observability,
|
|
update_observability_with_config,
|
|
)
|
|
from .trading import (
|
|
ExecutionStatus,
|
|
MarginVolume,
|
|
OrderExecutionResult,
|
|
OrderFillingMode,
|
|
OrderLimits,
|
|
OrderSide,
|
|
OrderTimeMode,
|
|
PositionSide,
|
|
ProjectionMode,
|
|
calculate_account_projected_margin_ratio,
|
|
calculate_margin_and_volume,
|
|
calculate_new_position_margin_ratio,
|
|
calculate_positions_margin,
|
|
calculate_positions_margin_by_symbol,
|
|
calculate_positions_margin_safe,
|
|
calculate_projected_margin_ratio,
|
|
calculate_spread_ratio,
|
|
calculate_symbol_group_margin_ratio,
|
|
calculate_trailing_stop_updates,
|
|
calculate_volume_by_margin,
|
|
close_open_positions,
|
|
create_trading_client,
|
|
detect_position_side,
|
|
determine_order_limits,
|
|
ensure_symbol_selected,
|
|
estimate_order_margin,
|
|
extract_tick_price,
|
|
fetch_latest_closed_rates_for_trading_client,
|
|
fetch_latest_closed_rates_indexed,
|
|
fetch_recent_history_deals_for_trading_client,
|
|
get_account_snapshot,
|
|
get_positions_frame,
|
|
get_symbol_snapshot,
|
|
get_tick_snapshot,
|
|
mt5_trading_session,
|
|
normalize_order_volume,
|
|
place_market_order,
|
|
resolve_broker_filling_mode,
|
|
update_sltp_for_open_positions,
|
|
update_trailing_stop_loss_for_open_positions,
|
|
)
|
|
|
|
__version__ = version(__package__) if __package__ else None
|
|
|
|
__all__ = [
|
|
"STABLE_SDK_EXPORTS",
|
|
"AccountSpec",
|
|
"ExecutionStatus",
|
|
"MT5Client",
|
|
"MarginVolume",
|
|
"Mt5CliError",
|
|
"Mt5ConnectionError",
|
|
"Mt5OperationError",
|
|
"Mt5SchemaError",
|
|
"OrderExecutionResult",
|
|
"OrderFillingMode",
|
|
"OrderLimits",
|
|
"OrderSide",
|
|
"OrderTimeMode",
|
|
"PositionSide",
|
|
"ProjectionMode",
|
|
"RateTarget",
|
|
"ThrottledHistoryUpdater",
|
|
"build_config",
|
|
"build_rate_targets",
|
|
"calculate_account_projected_margin_ratio",
|
|
"calculate_margin_and_volume",
|
|
"calculate_new_position_margin_ratio",
|
|
"calculate_positions_margin",
|
|
"calculate_positions_margin_by_symbol",
|
|
"calculate_positions_margin_safe",
|
|
"calculate_projected_margin_ratio",
|
|
"calculate_spread_ratio",
|
|
"calculate_symbol_group_margin_ratio",
|
|
"calculate_trailing_stop_updates",
|
|
"calculate_volume_by_margin",
|
|
"close_open_positions",
|
|
"collect_history",
|
|
"collect_latest_closed_rates_by_granularity",
|
|
"collect_latest_closed_rates_for_accounts",
|
|
"collect_latest_rates_for_accounts_with_retries",
|
|
"create_trading_client",
|
|
"detect_position_side",
|
|
"determine_order_limits",
|
|
"drop_forming_rate_bar",
|
|
"ensure_symbol_selected",
|
|
"estimate_order_margin",
|
|
"extract_tick_price",
|
|
"fetch_latest_closed_rates",
|
|
"fetch_latest_closed_rates_for_trading_client",
|
|
"fetch_latest_closed_rates_indexed",
|
|
"fetch_recent_history_deals_for_trading_client",
|
|
"get_account_snapshot",
|
|
"get_positions_frame",
|
|
"get_symbol_snapshot",
|
|
"get_tick_snapshot",
|
|
"load_rate_series_by_granularity",
|
|
"load_rate_series_from_sqlite",
|
|
"mt5_session",
|
|
"mt5_trading_session",
|
|
"normalize_order_volume",
|
|
"place_market_order",
|
|
"report_rate_gaps",
|
|
"resolve_account_spec",
|
|
"resolve_account_specs",
|
|
"resolve_broker_filling_mode",
|
|
"update_history",
|
|
"update_history_with_config",
|
|
"update_observability",
|
|
"update_observability_with_config",
|
|
"update_sltp_for_open_positions",
|
|
"update_trailing_stop_loss_for_open_positions",
|
|
]
|