This guide explains how to customize SignalTrader's behavior through configuration files.
SignalTrader uses JSON configuration files to allow easy customization of:
- Message command keywords
- Price extraction regex patterns
- Other user-configurable settings
The application searches for configuration files in multiple locations in order of preference:
- Current working directory (highest priority)
config/directory in current working directoryconfigs/directory in current working directorysettings/directory in current working directoryconfig/directory in project root (recommended)configs/directory in project rootsettings/directory in project root- Project root directory
This allows flexibility in organizing configuration files. For example:
# Option 1: config/ directory (recommended)
config/
├── keywords.json # Command keywords configuration
├── regex_patterns.json # Price extraction patterns
└── development.json # Application settings (git-ignored)
# Option 2: configs/ directory
configs/
├── keywords.json
└── regex_patterns.json
# Option 3: settings/ directory
settings/
├── keywords.json
└── regex_patterns.json
# Option 4: Project root
keywords.json
regex_patterns.json
The FileLoaderService provides a centralized, reusable solution for file loading across the application:
- Single Responsibility: Handles only file discovery and loading operations
- Multi-path Search: Automatically searches multiple directories
- Error Handling: Graceful handling of missing files and parse errors
- Comprehensive Logging: Detailed logs showing which files were loaded and from where
- Type Safety: Support for JSON and text files with proper typing
from Configure.file_loader import get_file_loader
# Get the service instance
file_loader = get_file_loader()
# Load JSON configuration
config = file_loader.load_json_file("keywords.json")
# Load text file
content = file_loader.load_text_file("readme.txt")
# Check if file exists
exists = file_loader.file_exists("settings.json")Edit config/keywords.json to customize command keywords:
{
"message_commands": {
"edit_keywords": [
"edit",
"edite",
"update",
"modify"
],
"delete_keywords": [
"حذف",
"delete",
"close",
"not a signal",
"vip"
],
"risk_free_keywords": [
"فری",
"risk free",
"risk-free"
],
"tp_keywords": [
"tp",
"هدف"
]
},
"description": {
"edit_keywords": "Keywords used to detect edit commands in reply messages",
"delete_keywords": "Keywords used to detect delete/close commands in reply messages",
"risk_free_keywords": "Keywords used to detect risk-free commands in reply messages",
"tp_keywords": "Keywords used to detect take profit commands in reply messages"
}
}To add your own keywords:
- Open
config/keywords.json - Add your keywords to the appropriate array
- Save the file
- Restart the application
Example - Adding "modify" to edit commands:
"edit_keywords": [
"edit",
"edite",
"update",
"modify",
"change" // Your custom keyword
]Edit config/regex_patterns.json to customize price extraction patterns:
{
"price_extraction_patterns": {
"first_price_patterns": [
"(\\d+(?:\\.\\d+)?)",
"(\\d+\\.\\d+)",
"@ (\\d+\\.\\d+)"
],
"tp_patterns": [
"tp\\s*\\d*[@:.-]?\\s*(\\d+\\.\\d+|\\d+)",
"tp\\s*(?:\\d*\\s*:\\s*)?(\\d+\\.\\d+)",
// ... more patterns
],
"sl_patterns": [
"sl\\s*:\\s*(\\d+\\.\\d+)",
"sl\\s*:\\s*(\\d+\\.?\\d*)",
// ... more patterns
]
}
}To add custom regex patterns:
- Open
config/regex_patterns.json - Add your pattern to the appropriate array
- Test the pattern with sample messages
- Save the file
- Restart the application
Example - Adding a custom TP pattern:
"tp_patterns": [
"tp\\s*\\d*[@:.-]?\\s*(\\d+\\.\\d+|\\d+)",
"target\\s*[:]?\\s*(\\d+\\.\\d+)" // Your custom pattern
]The application loads configuration files at startup. If a configuration file is missing or invalid:
- The application will log a warning
- Default behavior will be used (if available)
- The application will continue to run
To reload configuration files without restarting:
- Modify the configuration files
- Restart the application
- Backup Original Files: Always backup original configuration files before making changes
- Test Changes: Test configuration changes with sample messages
- Use Simple Keywords: Keep keywords simple and easy to remember
- Validate Regex: Test regex patterns thoroughly before deployment
- Version Control: Keep configuration files in version control for tracking changes
If your configuration changes are not taking effect:
- Check file syntax using a JSON validator
- Ensure file is in the correct location (
config/directory) - Check application logs for error messages
- Verify file permissions
If command keywords are not being recognized:
- Check that
config/keywords.jsonexists and is valid - Verify keywords are in the correct arrays
- Ensure keywords are lowercase (case-insensitive matching)
- Restart the application
If price extraction patterns are not working:
- Test your regex pattern using online regex testers
- Check that patterns are properly escaped
- Verify the pattern exists in the correct category
- Check application logs for pattern-related errors
- JSON Format: All configuration files must be valid JSON
- UTF-8 Encoding: Files must be saved with UTF-8 encoding
- No Comments: JSON does not support comments
- Proper Escaping: Special characters must be properly escaped
- Configuration files can contain sensitive patterns
- Do not commit sensitive configuration to public repositories
- Use environment variables for sensitive settings
- Regularly review and update keyword lists