Skip to content

Commit

Permalink
Merge pull request #39 from fortesenselabs/nt-backtest-environment
Browse files Browse the repository at this point in the history
fix: update README and improve signal processing
  • Loading branch information
seekersoftec authored Oct 9, 2024
2 parents 4359c85 + ca0666d commit df1f51b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
5 changes: 5 additions & 0 deletions packages/itbot_signal_forwarder/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ PHONE_NUMBER=""
MT5_ACCOUNT_NUMBER=12345
MT5_PASSWORD=password
MT5_SERVER=MetaTrader-Demo

# WhatsApp details (optional)
# WHATSAPP_ACCOUNT_SID = YOUR_WHATSAPP_ACCOUNT_SID
# WHATSAPP_AUTH_TOKEN = YOUR_WHATSAPP_AUTH_TOKEN
# WHATSAPP_TARGET = 'whatsapp:+14155552671' # Phone number or group chat ID
24 changes: 9 additions & 15 deletions packages/itbot_signal_forwarder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,33 @@ This Python script forwards trading signals from the [intelligent-trading-bot](h
- Subscribes to the `intelligent-trading-bot` Telegram channel using telethon.
- Parses incoming messages for trading signals.
- Forwards parsed signals to a WhatsApp group or individual contact. [Not done]
- Sends the signals to MetaTrader 5 for potential execution (configuration required). [Currently in Progress]
- Sends the signals to MetaTrader 5 for potential execution (configuration required).

**Requirements:**

- Python 3.8+
- `aiogram` library for Telegram integration (see installation instructions: [invalid URL removed])
- `twilio` library for WhatsApp integration (see installation instructions: [https://www.twilio.com/docs/whatsapp/quickstart](https://www.twilio.com/docs/whatsapp/quickstart))
- `telethon` library for Telegram integration (see installation instructions)
- MetaTrader 5 API (see installation instructions: [https://www.mql5.com/en/docs/integration](https://www.mql5.com/en/docs/integration))

**Installation:**

1. Clone this repository or download the script.
2. Install required libraries:
```bash
pip install aiogram twilio
pip install -r requirements.txt
```
3. Configure `config.py` (see below for details).
3. Configure `.env` (see below for details).

**Configuration:**

1. Create a `config.py` file in the same directory as the script.
2. Add the following configurations to `config.py`:
1. Create a `.env` file in the same directory as the script.
2. Add the following configurations to `.env`:

```python
# Telegram API credentials
BOT_TOKEN = 'YOUR_BOT_TOKEN' # Replace with your bot token

# WhatsApp details (optional)
WHATSAPP_ACCOUNT_SID = YOUR_WHATSAPP_ACCOUNT_SID
WHATSAPP_AUTH_TOKEN = YOUR_WHATSAPP_AUTH_TOKEN
WHATSAPP_TARGET = 'whatsapp:+14155552671' # Phone number or group chat ID
API_ID = ""
API_HASH = ""
PHONE_NUMBER = ""

# MetaTrader 5 details (optional)
MT5_ACCOUNT = YOUR_MT5_ACCOUNT_NUMBER
Expand All @@ -46,8 +42,6 @@ This Python script forwards trading signals from the [intelligent-trading-bot](h
```

- Replace placeholders with your actual credentials.
- Obtain a Telegram bot token from BotFather.
- Obtain a Twilio account and WhatsApp sandbox testing credentials (optional).
- MetaTrader 5 details can be found in your trading platform settings (optional).

**Usage:**
Expand Down
10 changes: 7 additions & 3 deletions packages/itbot_signal_forwarder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def parse_trading_data(self, data: str) -> List[Dict[str, str]]:
Returns:
List[Dict[str, str]]: Parsed trading data with fields such as price, score, trend, and zone.
"""
if "₿" not in data:
return []

# Pattern to extract price, score, trend direction, and zone from each entry
pattern = re.compile(
r"₿ (?P<price>[\d,]+) Score: (?P<score>[-+]\d+\.\d{2})\s*(?P<trend>↑)?\s*(?P<zone>[\w\s]+)?"
Expand Down Expand Up @@ -197,9 +200,10 @@ async def new_message_listener(event):
if "ZONE" in text:
# Parse the message text for trading signals
signals = self.parse_trading_data(text)
self.logger.debug(f"Processed signals: {signals}")
for signal in signals:
await self.forward_signal_to_mt5(signal)
if len(signals) > 0:
self.logger.debug(f"Processed signals: {signals}")
for signal in signals:
await self.forward_signal_to_mt5(signal)

# Start the client and listen for new messages
with self.client:
Expand Down

0 comments on commit df1f51b

Please sign in to comment.