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()}")
|
||||
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]:
|
||||
await self.ensure()
|
||||
symbol = self._resolve(symbol)
|
||||
|
|
@ -428,6 +440,8 @@ class LiveBridge(MT5Bridge):
|
|||
"volume_min": info.volume_min,
|
||||
"volume_max": info.volume_max,
|
||||
"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,
|
||||
}
|
||||
|
||||
|
|
@ -628,16 +642,17 @@ class LiveBridge(MT5Bridge):
|
|||
request = {
|
||||
"action": 1, # TRADE_ACTION_DEAL
|
||||
"symbol": symbol,
|
||||
"volume": volume,
|
||||
# MetaTrader5 verlangt Floats – ein int 0 ergibt (-2, 'Invalid "sl" argument')
|
||||
"volume": float(volume),
|
||||
"type": order_type,
|
||||
"price": price,
|
||||
"sl": sl,
|
||||
"tp": tp,
|
||||
"price": float(price),
|
||||
"sl": float(sl or 0.0),
|
||||
"tp": float(tp or 0.0),
|
||||
"deviation": 20,
|
||||
"magic": 202604,
|
||||
"comment": comment or "xgboost_sweep",
|
||||
"type_time": 0, # ORDER_TIME_GTC
|
||||
"type_filling": 1, # ORDER_FILLING_IOC
|
||||
"type_filling": self._filling(symbol),
|
||||
}
|
||||
|
||||
result = self.mt5.order_send(request)
|
||||
|
|
@ -671,9 +686,8 @@ class LiveBridge(MT5Bridge):
|
|||
"action": 6, # TRADE_ACTION_SLTP
|
||||
"position": ticket,
|
||||
"symbol": pos.symbol,
|
||||
"sl": sl if sl is not None else pos.sl,
|
||||
"tp": tp if tp is not None else pos.tp,
|
||||
"type_filling": 1, # ORDER_FILLING_IOC (Vantage)
|
||||
"sl": float(sl if sl is not None else pos.sl),
|
||||
"tp": float(tp if tp is not None else pos.tp),
|
||||
}
|
||||
|
||||
result = self.mt5.order_send(request)
|
||||
|
|
@ -703,15 +717,15 @@ class LiveBridge(MT5Bridge):
|
|||
request = {
|
||||
"action": 1, # TRADE_ACTION_DEAL
|
||||
"symbol": pos.symbol,
|
||||
"volume": pos.volume,
|
||||
"volume": float(pos.volume),
|
||||
"type": close_type,
|
||||
"position": ticket,
|
||||
"price": close_price,
|
||||
"position": int(ticket),
|
||||
"price": float(close_price),
|
||||
"deviation": 20,
|
||||
"magic": 202604,
|
||||
"comment": "xgboost_close",
|
||||
"type_time": 0,
|
||||
"type_filling": 1,
|
||||
"type_filling": self._filling(pos.symbol),
|
||||
}
|
||||
|
||||
result = self.mt5.order_send(request)
|
||||
|
|
@ -1077,4 +1091,4 @@ def main():
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
Loading…
Reference in a new issue