zwischenstand
All checks were successful
MT5 Helm GitOps Deploy / build-and-deploy (push) Has been skipped
All checks were successful
MT5 Helm GitOps Deploy / build-and-deploy (push) Has been skipped
This commit is contained in:
parent
eb213fd79a
commit
917b66ac0a
3 changed files with 14 additions and 4 deletions
|
|
@ -6,6 +6,8 @@ WORKDIR /app
|
||||||
|
|
||||||
COPY requirements.txt .
|
COPY requirements.txt .
|
||||||
RUN pip install -r 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
|
RUN pip install --no-deps mt5linux==0.1.9
|
||||||
|
|
||||||
COPY *.py ./
|
COPY *.py ./
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,9 @@ logging.basicConfig(
|
||||||
)
|
)
|
||||||
log = logging.getLogger("mt5-mcp")
|
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)
|
# MT5 Bridge (abstraction over mock / live)
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
@ -251,6 +254,7 @@ class LiveBridge(MT5Bridge):
|
||||||
if self._rpyc_conn is None or self._rpyc_conn.closed:
|
if self._rpyc_conn is None or self._rpyc_conn.closed:
|
||||||
try:
|
try:
|
||||||
self._rpyc_conn = rpyc.classic.connect(self.rpyc_host, self.rpyc_port)
|
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("import MetaTrader5 as mt5")
|
||||||
self._rpyc_conn.execute("from datetime import datetime, timedelta")
|
self._rpyc_conn.execute("from datetime import datetime, timedelta")
|
||||||
self._rpyc_conn.execute("mt5.initialize()")
|
self._rpyc_conn.execute("mt5.initialize()")
|
||||||
|
|
@ -265,6 +269,9 @@ class LiveBridge(MT5Bridge):
|
||||||
try:
|
try:
|
||||||
from mt5linux import MetaTrader5 as MT5
|
from mt5linux import MetaTrader5 as MT5
|
||||||
self.mt5 = MT5(host=self.rpyc_host, port=self.rpyc_port)
|
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
|
# Broker-Login aus Umgebungsvariablen (bots.env) – leer = Terminal-Login verwenden
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
if os.getenv("MT5_LOGIN"):
|
if os.getenv("MT5_LOGIN"):
|
||||||
|
|
@ -283,6 +290,7 @@ class LiveBridge(MT5Bridge):
|
||||||
self.connected = True
|
self.connected = True
|
||||||
return True
|
return True
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
|
# Kann auch von der Windows-Seite kommen (z.B. MetaTrader5 vs. numpy 2)
|
||||||
log.error(f"ImportError: {e}")
|
log.error(f"ImportError: {e}")
|
||||||
return False
|
return False
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
@ -487,7 +495,7 @@ class LiveBridge(MT5Bridge):
|
||||||
vol = grouped.count()
|
vol = grouped.count()
|
||||||
|
|
||||||
idx = ohlc_open.index.intersection(ohlc_close.index)
|
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:]
|
idx = idx[-bars:]
|
||||||
|
|
||||||
if len(idx) == 0:
|
if len(idx) == 0:
|
||||||
|
|
@ -966,7 +974,7 @@ async def mcp_tools():
|
||||||
{
|
{
|
||||||
"name": "get_orders",
|
"name": "get_orders",
|
||||||
"description": "Get pending orders",
|
"description": "Get pending orders",
|
||||||
"inputSchema": {"type": "object", "properties": {}},
|
"inputSchema": {"type": "object", "properties"{}},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
fastapi
|
fastapi
|
||||||
uvicorn
|
uvicorn
|
||||||
pydantic
|
pydantic
|
||||||
# mt5linux wird im Dockerfile separat installiert
|
# mt5linux wird im Dockerfile separat (0.1.9, --no-deps) installiert
|
||||||
rpyc
|
rpyc>=6,<7 # muss zur rpyc-Version im MT5-Container passen
|
||||||
pandas
|
pandas
|
||||||
numpy
|
numpy
|
||||||
# Live-Trader
|
# Live-Trader
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue