Skip to content

Commit

Permalink
Merge pull request #44 from fortesenselabs/feature/environments
Browse files Browse the repository at this point in the history
README Update & Code Improvements: MT5 Environment
  • Loading branch information
seekersoftec authored Oct 13, 2024
2 parents 46a7d4f + 13c0ac3 commit 6e514fc
Show file tree
Hide file tree
Showing 49 changed files with 2,393 additions and 1,235 deletions.
22 changes: 14 additions & 8 deletions packages/itbot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

This Python script forwards trading signals from the [intelligent-trading-bot](https://github.com/asavinov/intelligent-trading-bot) Telegram channel to both WhatsApp and MetaTrader 5.

**Features:**
## Features

- 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).

**Requirements:**
## Requirements

- Python 3.8+
- `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:**
## Installation

1. Clone this repository or download the script.
2. Install required libraries:
Expand All @@ -24,7 +24,7 @@ This Python script forwards trading signals from the [intelligent-trading-bot](h
```
3. Configure `.env` (see below for details).

**Configuration:**
## Configuration

1. Create a `.env` file in the same directory as the script.
2. Add the following configurations to `.env`:
Expand All @@ -44,16 +44,22 @@ This Python script forwards trading signals from the [intelligent-trading-bot](h
- Replace placeholders with your actual credentials.
- MetaTrader 5 details can be found in your trading platform settings (optional).

**Usage:**
## Usage

1. Run the script: `python main.py`
```bash
$ python main.py
```

**Disclaimer:**
## TODOs

This script is for educational purposes only. It is recommended to back-test any strategies before using them with real capital. You are solely responsible for any financial losses incurred while using this script.
- Train RL Agents for the top 5 assets from the Quantreo ML Project (data platform -> MT5)

## Credits

- https://github.com/asavinov/intelligent-trading-bot/
- https://github.com/fpierrem/telegram-aggregator/
- https://github.com/nsniteshsahni/telegram-channel-listener/

**Disclaimer:**

This script is for educational purposes only. It is recommended to back-test any strategies before using them with real capital. You are solely responsible for any financial losses incurred while using this script.
8 changes: 4 additions & 4 deletions packages/itbot/itbot/mt5_trader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
from datetime import datetime
from typing import Dict, Optional
from packages.itbot.itbot import Signal
from packages.itbot.itbot.MetaTrader5 import MetaTrader5 as mt5
from packages.itbot.itbot.terminal import (
from packages.itbot.itbot.portfolio import RiskManager
from trade_flow.common.logging import Logger
from packages.mt5any import (
DockerizedMT5TerminalConfig,
DockerizedMT5Terminal,
)
from packages.itbot.itbot.portfolio import RiskManager
from trade_flow.common.logging import Logger
from packages.mt5any import MetaTrader5 as mt5


SymbolInfo = object
Expand Down
8 changes: 1 addition & 7 deletions packages/itbot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import random
import re
from typing import List, Optional
import aiodbm
from telethon import events
from packages.itbot.agents import Agent, BasicMLAgent
from packages.itbot.itbot import Signal, TradeType
from packages.itbot.itbot.mt5_trader import MT5Trader
from packages.itbot.itbot.MetaTrader5 import MetaTrader5 as mt5
from packages.itbot.itbot.interfaces import TelegramInterface
from packages.mt5any import MetaTrader5 as mt5
from trade_flow.common.logging import Logger
from dotenv import load_dotenv

Expand Down Expand Up @@ -64,11 +63,6 @@ def __init__(
# Change signals_queue to hold only Signal objects
self.signals_queue: asyncio.Queue[Signal] = asyncio.Queue()

# # Initialize aiodbm for storing signals persistently
# self.signals_db = aiodbm.open(
# "signals.dbm", "c"
# ) # 'c' mode opens for read/write, creates if not exists

def _validate_signal(self, signal: Signal) -> bool:
"""
Validate the signal to ensure it meets the required criteria.
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions packages/mt5any/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
Provides an API integration for Metatrader 5 with a Dockerized Terminal
"""

from .MetaTrader5 import *
from .terminal import ContainerStatus, DockerizedMT5TerminalConfig, DockerizedMT5Terminal
File renamed without changes.
2 changes: 2 additions & 0 deletions trade_flow/environments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
from trade_flow.environments import generic
from trade_flow.environments import default
from trade_flow.environments import utils
from trade_flow.environments import gym_anytrading
from trade_flow.environments import metatrader
27 changes: 18 additions & 9 deletions trade_flow/environments/gym_anytrading/examples/SB3_a2c_ppo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/fortesenselabs/Tech/labs/Financial_Eng/Financial_Markets/lab/trade_flow/trade_flow/feed/__init__.py:19: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.\n",
" df = pd.read_csv(path, parse_dates=True, index_col=index_name)\n"
]
}
],
"source": [
"from tqdm import tqdm\n",
"import random\n",
Expand All @@ -24,7 +33,6 @@
"import matplotlib.pyplot as plt\n",
"\n",
"import gymnasium as gym\n",
"# import gym_anytrading\n",
"from trade_flow.environments import gym_anytrading\n",
"\n",
"from stable_baselines3 import A2C, PPO\n",
Expand Down Expand Up @@ -208,7 +216,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"Episode: 40, Avg. Reward: 284.550: 100%|██████████| 50/50 [00:02<00:00, 18.59it/s]\n",
"Episode: 40, Avg. Reward: 284.550: 100%|██████████| 50/50 [00:02<00:00, 18.20it/s]\n",
"/home/fortesenselabs/anaconda3/envs/algo_trading/lib/python3.11/site-packages/torch/cuda/__init__.py:128: UserWarning: CUDA initialization: The NVIDIA driver on your system is too old (found version 11040). Please update your GPU driver by downloading and installing a new version from the URL: http://www.nvidia.com/Download/index.aspx Alternatively, go to: https://pytorch.org to install a PyTorch version that has been compiled with your version of the CUDA driver. (Triggered internally at ../c10/cuda/CUDAFunctions.cpp:108.)\n",
" return torch._C._cuda_getDeviceCount() > 0\n"
]
Expand All @@ -229,8 +237,8 @@
"name": "stderr",
"output_type": "stream",
"text": [
"model.learn(): 100%|██████████| 25000/25000 [01:10<00:00, 353.41it/s]\n",
"Episode: 40, Avg. Reward: 572.746: 100%|██████████| 50/50 [01:48<00:00, 2.16s/it]\n"
"model.learn(): 100%|██████████| 25000/25000 [01:14<00:00, 334.51it/s]\n",
"Episode: 40, Avg. Reward: 572.746: 100%|██████████| 50/50 [02:10<00:00, 2.61s/it]\n"
]
},
{
Expand All @@ -249,8 +257,8 @@
"name": "stderr",
"output_type": "stream",
"text": [
"model.learn(): 26600it [01:10, 377.94it/s] \n",
"Episode: 40, Avg. Reward: 629.892: 100%|██████████| 50/50 [01:32<00:00, 1.86s/it]"
"model.learn(): 26600it [01:29, 298.58it/s] \n",
"Episode: 40, Avg. Reward: 629.892: 100%|██████████| 50/50 [02:14<00:00, 2.70s/it]"
]
},
{
Expand Down Expand Up @@ -377,7 +385,8 @@
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"display_name": "algo_trading",
"language": "python",
"name": "python3"
},
"language_info": {
Expand All @@ -390,7 +399,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
"version": "3.11.10"
}
},
"nbformat": 4,
Expand Down
8 changes: 0 additions & 8 deletions trade_flow/environments/gym_mtsim/CITATION.cff

This file was deleted.

121 changes: 0 additions & 121 deletions trade_flow/environments/gym_mtsim/__init__.py

This file was deleted.

9 changes: 0 additions & 9 deletions trade_flow/environments/gym_mtsim/data/__init__.py

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion trade_flow/environments/gym_mtsim/envs/__init__.py

This file was deleted.

Loading

0 comments on commit 6e514fc

Please sign in to comment.