bots/mcp_server.py aktualisiert
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
c53cb5aae3
commit
7bea7ad391
1 changed files with 27 additions and 13 deletions
|
|
@ -411,6 +411,18 @@ class LiveBridge(MT5Bridge):
|
||||||
log.warning(f"symbol_select({name}) failed: {self.mt5.last_error()}")
|
log.warning(f"symbol_select({name}) failed: {self.mt5.last_error()}")
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
def _filling(self, symbol: str) -> int:
|
||||||
|
"""Filling-Modus, den der Broker für dieses Symbol erlaubt.
|
||||||
|
symbol_info.filling_mode ist ein Bitfeld: 1 = FOK, 2 = IOC erlaubt.
|
||||||
|
Rückgabe als ORDER_FILLING_*: 0 = FOK, 1 = IOC, 2 = RETURN."""
|
||||||
|
override = os.getenv("ORDER_FILLING") # optional: FOK / IOC / RETURN
|
||||||
|
if override:
|
||||||
|
return {"FOK": 0, "IOC": 1, "RETURN": 2}[override.upper()]
|
||||||
|
info = self.mt5.symbol_info(symbol)
|
||||||
|
flags = int(getattr(info, "filling_mode", 0) or 0)
|
||||||
|
mode = 1 if flags & 2 else (0 if flags & 1 else 2)
|
||||||
|
return mode
|
||||||
|
|
||||||
async def symbol_info(self, symbol: str) -> Dict[str, Any]:
|
async def symbol_info(self, symbol: str) -> Dict[str, Any]:
|
||||||
await self.ensure()
|
await self.ensure()
|
||||||
symbol = self._resolve(symbol)
|
symbol = self._resolve(symbol)
|
||||||
|
|
@ -428,6 +440,8 @@ class LiveBridge(MT5Bridge):
|
||||||
"volume_min": info.volume_min,
|
"volume_min": info.volume_min,
|
||||||
"volume_max": info.volume_max,
|
"volume_max": info.volume_max,
|
||||||
"volume_step": info.volume_step,
|
"volume_step": info.volume_step,
|
||||||
|
"filling_mode": info.filling_mode,
|
||||||
|
"order_filling": {0: "FOK", 1: "IOC", 2: "RETURN"}[self._filling(info.name)],
|
||||||
"description": info.description,
|
"description": info.description,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -628,16 +642,17 @@ class LiveBridge(MT5Bridge):
|
||||||
request = {
|
request = {
|
||||||
"action": 1, # TRADE_ACTION_DEAL
|
"action": 1, # TRADE_ACTION_DEAL
|
||||||
"symbol": symbol,
|
"symbol": symbol,
|
||||||
"volume": volume,
|
# MetaTrader5 verlangt Floats – ein int 0 ergibt (-2, 'Invalid "sl" argument')
|
||||||
|
"volume": float(volume),
|
||||||
"type": order_type,
|
"type": order_type,
|
||||||
"price": price,
|
"price": float(price),
|
||||||
"sl": sl,
|
"sl": float(sl or 0.0),
|
||||||
"tp": tp,
|
"tp": float(tp or 0.0),
|
||||||
"deviation": 20,
|
"deviation": 20,
|
||||||
"magic": 202604,
|
"magic": 202604,
|
||||||
"comment": comment or "xgboost_sweep",
|
"comment": comment or "xgboost_sweep",
|
||||||
"type_time": 0, # ORDER_TIME_GTC
|
"type_time": 0, # ORDER_TIME_GTC
|
||||||
"type_filling": 1, # ORDER_FILLING_IOC
|
"type_filling": self._filling(symbol),
|
||||||
}
|
}
|
||||||
|
|
||||||
result = self.mt5.order_send(request)
|
result = self.mt5.order_send(request)
|
||||||
|
|
@ -671,9 +686,8 @@ class LiveBridge(MT5Bridge):
|
||||||
"action": 6, # TRADE_ACTION_SLTP
|
"action": 6, # TRADE_ACTION_SLTP
|
||||||
"position": ticket,
|
"position": ticket,
|
||||||
"symbol": pos.symbol,
|
"symbol": pos.symbol,
|
||||||
"sl": sl if sl is not None else pos.sl,
|
"sl": float(sl if sl is not None else pos.sl),
|
||||||
"tp": tp if tp is not None else pos.tp,
|
"tp": float(tp if tp is not None else pos.tp),
|
||||||
"type_filling": 1, # ORDER_FILLING_IOC (Vantage)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result = self.mt5.order_send(request)
|
result = self.mt5.order_send(request)
|
||||||
|
|
@ -703,15 +717,15 @@ class LiveBridge(MT5Bridge):
|
||||||
request = {
|
request = {
|
||||||
"action": 1, # TRADE_ACTION_DEAL
|
"action": 1, # TRADE_ACTION_DEAL
|
||||||
"symbol": pos.symbol,
|
"symbol": pos.symbol,
|
||||||
"volume": pos.volume,
|
"volume": float(pos.volume),
|
||||||
"type": close_type,
|
"type": close_type,
|
||||||
"position": ticket,
|
"position": int(ticket),
|
||||||
"price": close_price,
|
"price": float(close_price),
|
||||||
"deviation": 20,
|
"deviation": 20,
|
||||||
"magic": 202604,
|
"magic": 202604,
|
||||||
"comment": "xgboost_close",
|
"comment": "xgboost_close",
|
||||||
"type_time": 0,
|
"type_time": 0,
|
||||||
"type_filling": 1,
|
"type_filling": self._filling(pos.symbol),
|
||||||
}
|
}
|
||||||
|
|
||||||
result = self.mt5.order_send(request)
|
result = self.mt5.order_send(request)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue