zwischenstand
All checks were successful
MT5 Helm GitOps Deploy / build-and-deploy (push) Has been skipped

This commit is contained in:
bast 2026-11-06 00:56:14 +01:00
parent eb213fd79a
commit 917b66ac0a
3 changed files with 14 additions and 4 deletions

View file

@ -6,6 +6,8 @@ WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
# mt5linux 1.1.x nutzt Python-3.12-Syntax und hat eine andere Server-CLI.
# 0.1.9 passt zum gmag11-Server; seine uralten Pins (numpy 1.21 …) daher --no-deps.
RUN pip install --no-deps mt5linux==0.1.9
COPY *.py ./

View file

@ -45,6 +45,9 @@ logging.basicConfig(
)
log = logging.getLogger("mt5-mcp")
# Sekunden, die auf eine Antwort aus dem Wine-Python gewartet wird
RPYC_TIMEOUT = int(os.getenv("RPYC_TIMEOUT", "120"))
# ---------------------------------------------------------------------------
# MT5 Bridge (abstraction over mock / live)
# ---------------------------------------------------------------------------
@ -251,6 +254,7 @@ class LiveBridge(MT5Bridge):
if self._rpyc_conn is None or self._rpyc_conn.closed:
try:
self._rpyc_conn = rpyc.classic.connect(self.rpyc_host, self.rpyc_port)
self._rpyc_conn._config['sync_request_timeout'] = RPYC_TIMEOUT
self._rpyc_conn.execute("import MetaTrader5 as mt5")
self._rpyc_conn.execute("from datetime import datetime, timedelta")
self._rpyc_conn.execute("mt5.initialize()")
@ -265,6 +269,9 @@ class LiveBridge(MT5Bridge):
try:
from mt5linux import MetaTrader5 as MT5
self.mt5 = MT5(host=self.rpyc_host, port=self.rpyc_port)
# initialize() mit Login startet/verbindet das Terminal unter Wine und
# dauert oft >30s (RPyC-Default) -> sonst "result expired"
self.mt5._MetaTrader5__conn._config['sync_request_timeout'] = RPYC_TIMEOUT
# Broker-Login aus Umgebungsvariablen (bots.env) – leer = Terminal-Login verwenden
kwargs = {}
if os.getenv("MT5_LOGIN"):
@ -283,6 +290,7 @@ class LiveBridge(MT5Bridge):
self.connected = True
return True
except ImportError as e:
# Kann auch von der Windows-Seite kommen (z.B. MetaTrader5 vs. numpy 2)
log.error(f"ImportError: {e}")
return False
except Exception as e:
@ -487,7 +495,7 @@ class LiveBridge(MT5Bridge):
vol = grouped.count()
idx = ohlc_open.index.intersection(ohlc_close.index)
idx = idx.intersection(ohlc_high.index).intersection(ohlc_low.index)
idx = idx.intersection(ohlhigh.index).intersection(ohlc_low.index)
idx = idx[-bars:]
if len(idx) == 0:
@ -966,7 +974,7 @@ async def mcp_tools():
{
"name": "get_orders",
"description": "Get pending orders",
"inputSchema": {"type": "object", "properties": {}},
"inputSchema": {"type": "object", "properties"{}},
},
]
}

View file

@ -2,8 +2,8 @@
fastapi
uvicorn
pydantic
# mt5linux wird im Dockerfile separat installiert
rpyc
# mt5linux wird im Dockerfile separat (0.1.9, --no-deps) installiert
rpyc>=6,<7 # muss zur rpyc-Version im MT5-Container passen
pandas
numpy
# Live-Trader