import sys
from PyQt5.QtWidgets import (
QApplication, QMainWindow, QGroupBox, QFormLayout, QLabel, QLineEdit,
QSpinBox, QDoubleSpinBox, QCheckBox, QPushButton, QVBoxLayout, QWidget,
QMessageBox
)
from PyQt5.QtCore import Qt
class TradingRobotUI(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Forex Trading Robot Configuration")
self.setGeometry(100, 100, 600, 500) # Set window size and position
# Create central widget and main layout
central_widget = QWidget()
self.setCentralWidget(central_widget)
main_layout = QVBoxLayout()
central_widget.setLayout(main_layout)
# General Settings Group
gen_group = QGroupBox("General Settings")
gen_layout = QFormLayout()
self.currency_input = QLineEdit()
self.currency_input.setToolTip("Enter tradable currencies separated by commas (e.g., EURUSD,GBPUSD)")
gen_layout.addRow("List of tradable currencies:", self.currency_input)
self.reward_risk_spin = QSpinBox()
self.reward_risk_spin.setRange(1, 100) # Typical range for reward-to-risk ratio
self.reward_risk_spin.setToolTip("Integer value for reward-to-risk ratio")
gen_layout.addRow("Reward to risk:", self.reward_risk_spin)
self.capital_percent_spin = QDoubleSpinBox()
self.capital_percent_spin.setRange(0.0, 100.0)
self.capital_percent_spin.setSuffix("%")
self.capital_percent_spin.setToolTip("Percentage of capital to risk per position")
gen_layout.addRow("Percentage of capital per position:", self.capital_percent_spin)
gen_group.setLayout(gen_layout)
main_layout.addWidget(gen_group)
# Notifications Group
notif_group = QGroupBox("Notifications")
notif_layout = QFormLayout()
self.tg_token_input = QLineEdit()
self.tg_token_input.setEchoMode(QLineEdit.Password) # Mask with asterisks
self.tg_token_input.setToolTip("Telegram messenger token (masked for security)")
notif_layout.addRow("Telegram messenger token:", self.tg_token_input)
self.tg_chat_id_input = QLineEdit()
self.tg_chat_id_input.setEchoMode(QLineEdit.Password) # Mask with asterisks
self.tg_chat_id_input.setToolTip("Telegram messenger chat ID (masked for security)")
notif_layout.addRow("Telegram messenger chat ID:", self.tg_chat_id_input)
self.messenger_token_input = QLineEdit()
self.messenger_token_input.setEchoMode(QLineEdit.Password) # Mask with asterisks
self.messenger_token_input.setToolTip("Messenger token (masked for security) - e.g., for a secondary messenger")
notif_layout.addRow("Messenger token:", self.messenger_token_input) # Labeled as per your input
self.messenger_chat_id_input = QLineEdit()
self.messenger_chat_id_input.setEchoMode(QLineEdit.Password) # Mask with asterisks
self.messenger_chat_id_input.setToolTip("Messenger chat ID (masked for security) - e.g., for a secondary messenger")
notif_layout.addRow("Messenger chat ID:", self.messenger_chat_id_input) # Labeled as per your input
notif_group.setLayout(notif_layout)
main_layout.addWidget(notif_group)
# Wiggle Room Group
wiggle_group = QGroupBox("Wiggle Room Settings")
wiggle_layout = QFormLayout()
self.wiggle_allowed_check = QCheckBox("Is wiggle room allowed? (Yes/No)")
self.wiggle_allowed_check.setToolTip("Enable or disable wiggle room functionality")
wiggle_layout.addRow(self.wiggle_allowed_check)
self.stop_wiggle_spin = QDoubleSpinBox()
self.stop_wiggle_spin.setRange(0.0, 100.0) # Arbitrary range; adjust based on your needs
self.stop_wiggle_spin.setSuffix("%")
self.stop_wiggle_spin.setEnabled(False) # Disabled by default
self.stop_wiggle_spin.setToolTip("Decimal value for stop wiggle room (enabled only if wiggle room is allowed)")
wiggle_layout.addRow("Stop wiggle room:", self.stop_wiggle_spin)
self.entry_wiggle_spin = QDoubleSpinBox()
self.entry_wiggle_spin.setRange(0.0, 100.0) # Arbitrary range; adjust based on your needs
self.entry_wiggle_spin.setSuffix("%")
self.entry_wiggle_spin.setEnabled(False) # Disabled by default
self.entry_wiggle_spin.setToolTip("Decimal value for entry wiggle room (enabled only if wiggle room is allowed)")
wiggle_layout.addRow("Entry wiggle room:", self.entry_wiggle_spin)
wiggle_group.setLayout(wiggle_layout)
main_layout.addWidget(wiggle_group)
# Connect checkbox state to enable/disable wiggle room fields
self.wiggle_allowed_check.stateChanged.connect(self.toggle_wiggle_fields)
# MetaTrader Connection Group
mt_group = QGroupBox("MetaTrader Connection")
mt_layout = QFormLayout()
self.mt_username_spin = QSpinBox()
self.mt_username_spin.setRange(0, 1000000) # Large range for usernames; adjust if needed
self.mt_username_spin.setToolTip("Integer value for MetaTrader username")
mt_layout.addRow("MetaTrader username:", self.mt_username_spin)
self.mt_password_input = QLineEdit()
self.mt_password_input.setEchoMode(QLineEdit.Password) # Mask with asterisks
self.mt_password_input.setToolTip("MetaTrader password (masked for security)")
mt_layout.addRow("MetaTrader password:", self.mt_password_input)
self.mt_server_input = QLineEdit()
self.mt_server_input.setToolTip("MetaTrader server address (e.g., example.com)")
mt_layout.addRow("MetaTrader server address:", self.mt_server_input)
mt_group.setLayout(mt_layout)
main_layout.addWidget(mt_group)
# Start Button
self.start_button = QPushButton("Start Robot")
self.start_button.setToolTip("Start the trading robot with the configured settings")
main_layout.addWidget(self.start_button)
self.start_button.clicked.connect(self.start_robot)
def toggle_wiggle_fields(self, state):
"""Enable or disable wiggle room fields based on checkbox state."""
enabled = (state == Qt.Checked)
self.stop_wiggle_spin.setEnabled(enabled)
self.entry_wiggle_spin.setEnabled(enabled)
def start_robot(self):
"""Collect all inputs and start the robot. Currently prints settings for demo; integrate with your robot code here."""
# Collect inputs into a dictionary
settings = {
"currencies": [currency.strip() for currency in self.currency_input.text().split(',')], # Split by comma and strip whitespace
"reward_to_risk": self.reward_risk_spin.value(), # Integer
"capital_percentage": self.capital_percent_spin.value(), # Decimal
"telegram_token": self.tg_token_input.text(), # Masked string
"telegram_chat_id": self.tg_chat_id_input.text(), # Masked string
"messenger_token": self.messenger_token_input.text(), # Masked string (for secondary messenger)
"messenger_chat_id": self.messenger_chat_id_input.text(), # Masked string (for secondary messenger)
"wiggle_allowed": self.wiggle_allowed_check.isChecked(), # Boolean (Yes/No)
"stop_wiggle": self.stop_wiggle_spin.value() if self.wiggle_allowed_check.isChecked() else None, # Decimal, or None if not allowed
"entry_wiggle": self.entry_wiggle_spin.value() if self.wiggle_allowed_check.isChecked() else None, # Decimal, or None if not allowed
"mt_username": self.mt_username_spin.value(), # Integer
"mt_password": self.mt_password_input.text(), # Masked string
"mt_server": self.mt_server_input.text(), # String
}
# For demonstration, print the settings (in a real app, handle sensitive data securely)
print("Starting robot with the following settings:")
for key, value in settings.items():
print(f"{key}: {value}")
# Integrate with your robot code here, e.g.:
# from your_robot_module import TradingRobot
# robot = TradingRobot(**settings)
# robot.start()
# Show a confirmation message
msg = QMessageBox()
msg.setIcon(QMessageBox.Information)
msg.setText("Robot started with the provided settings.")
msg.setWindowTitle("Robot Started")
msg.exec_()
if __name__ == "__main__":
app = QApplication(sys.argv)
ui = TradingRobotUI()
ui.show()
sys.exit(app.exec_())