bbstrader 0.2.95__py3-none-any.whl → 0.2.96__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of bbstrader might be problematic. Click here for more details.

@@ -11,7 +11,7 @@ from bbstrader.config import BBSTRADER_DIR
11
11
  from bbstrader.core.utils import TradeAction
12
12
  from bbstrader.metatrader.account import Account, check_mt5_connection
13
13
  from bbstrader.metatrader.trade import Trade
14
- from bbstrader.trading.scripts import send_message
14
+ from bbstrader.trading.utils import send_message
15
15
 
16
16
  try:
17
17
  import MetaTrader5 as MT5
@@ -592,6 +592,9 @@ def _mt5_execution(
592
592
  )
593
593
  _print_exc(debug_mode, msg)
594
594
  continue
595
+ except KeyboardInterrupt:
596
+ logger.info("Stopping the Execution Engine ...")
597
+ break
595
598
 
596
599
 
597
600
  def _tws_execution(*args, **kwargs):
@@ -1,69 +1,155 @@
1
- import asyncio
1
+ import argparse
2
+ import json
3
+ import multiprocessing as mp
4
+ import os
5
+ import sys
2
6
 
3
- from notifypy import Notify
4
- from telegram import Bot
5
- from telegram.error import TelegramError
7
+ from bbstrader.btengine import MT5Strategy, Strategy
8
+ from bbstrader.core.utils import load_class, load_module
9
+ from bbstrader.metatrader.trade import create_trade_instance
10
+ from bbstrader.trading.execution import mt5_engine
6
11
 
12
+ EXECUTION_PATH = os.path.expanduser("~/.bbstrader/execution/execution.py")
13
+ CONFIG_PATH = os.path.expanduser("~/.bbstrader/execution/execution.json")
7
14
 
8
- __all__ = ["send_telegram_message", "send_notification", "send_message"]
9
15
 
16
+ def load_config(config_path, strategy_name, account=None):
17
+ if not os.path.exists(config_path):
18
+ raise FileNotFoundError(f"Configuration file not found at {config_path}")
19
+ with open(config_path, "r") as f:
20
+ config = json.load(f)
21
+ try:
22
+ config = config[strategy_name]
23
+ except KeyError:
24
+ raise ValueError(
25
+ f"Strategy {strategy_name} not found in the configuration file."
26
+ )
27
+ if account is not None:
28
+ try:
29
+ config = config[account]
30
+ except KeyError:
31
+ raise ValueError(f"Account {account} not found in the configuration file.")
32
+ if config.get("symbol_list") is None:
33
+ raise ValueError("symbol_list is required in the configuration file.")
34
+ if config.get("trades_kwargs") is None:
35
+ raise ValueError("trades_kwargs is required in the configuration file.")
36
+ return config
10
37
 
11
- async def send_telegram_message(token, chat_id, text=""):
12
- """
13
- Send a message to a telegram chat
14
38
 
15
- Args:
16
- token: str: Telegram bot token
17
- chat_id: int or str or list: Chat id or list of chat ids
18
- text: str: Message to send
19
- """
20
- try:
21
- bot = Bot(token=token)
22
- if isinstance(chat_id, (int, str)):
23
- chat_id = [chat_id]
24
- for id in chat_id:
25
- await bot.send_message(chat_id=id, text=text)
26
- except TelegramError as e:
27
- print(f"Error sending message: {e}")
39
+ def worker_function(account, args):
40
+ strategy_module = load_module(args.path)
41
+ strategy_class = load_class(strategy_module, args.strategy, (MT5Strategy, Strategy))
28
42
 
43
+ config = load_config(args.config, args.strategy, account)
44
+ symbol_list = config.pop("symbol_list")
45
+ trades_kwargs = config.pop("trades_kwargs")
46
+ trades = create_trade_instance(symbol_list, trades_kwargs)
29
47
 
30
- def send_notification(title, message=""):
31
- """
32
- Send a desktop notification
48
+ kwargs = {
49
+ "symbol_list": symbol_list,
50
+ "trades_instances": trades,
51
+ "strategy_cls": strategy_class,
52
+ "account": account,
53
+ **config,
54
+ }
55
+ mt5_engine(account, **kwargs)
33
56
 
34
- Args:
35
- title: str: Title of the notification
36
- message: str: Message of the notification
37
- """
38
- notification = Notify(default_notification_application_name="bbstrading")
39
- notification.title = title
40
- notification.message = message
41
- notification.send()
42
-
43
-
44
- def send_message(
45
- title="SIGNAL",
46
- message="New signal",
47
- notify_me=False,
48
- telegram=False,
49
- token=None,
50
- chat_id=None,
51
- ):
52
- """
53
- Send a message to the user
54
-
55
- Args:
56
- title: str: Title of the message
57
- message: str: Message of the message
58
- notify_me: bool: Send a desktop notification
59
- telegram: bool: Send a telegram message
60
- token: str: Telegram bot token
61
- chat_id: int or str or list: Chat id or list of chat ids
57
+
58
+ def mt5_terminal(args):
59
+ if args.parallel:
60
+ if len(args.account) == 0:
61
+ raise ValueError(
62
+ "account or accounts are required when running in parallel"
63
+ )
64
+
65
+ processes = []
66
+ try:
67
+ for account in args.account:
68
+ p = mp.Process(target=worker_function, args=(account, args))
69
+ p.start()
70
+ processes.append(p)
71
+
72
+ for p in processes:
73
+ p.join()
74
+ except Exception as e:
75
+ print(f"Error in parallel execution: {e}")
76
+ raise e
77
+ except KeyboardInterrupt:
78
+ print("\nTerminating Execution...")
79
+ for p in processes:
80
+ p.terminate()
81
+ for p in processes:
82
+ p.join()
83
+ print("Execution terminated")
84
+ else:
85
+ worker_function(None, args)
86
+
87
+
88
+ def tws_terminal(args):
89
+ raise NotImplementedError("TWS terminal is not implemented yet")
90
+
91
+
92
+ def execute_strategy(unknown):
93
+ HELP_MSG = """
94
+ Execute a strategy on one or multiple MT5 accounts.
95
+
96
+ Usage:
97
+ python -m bbstrader --run execution [options]
98
+
99
+ Options:
100
+ -s, --strategy: Strategy class name to run
101
+ -a, --account: Account(s) name(s) or ID(s) to run the strategy on (must be the same as in the configuration file)
102
+ -p, --path: Path to the execution file (default: ~/.bbstrader/execution/execution.py)
103
+ -c, --config: Path to the configuration file (default: ~/.bbstrader/execution/execution.json)
104
+ -l, --parallel: Run the strategy in parallel (default: False)
105
+ -t, --terminal: Terminal to use (default: MT5)
106
+ -h, --help: Show this help message and exit
107
+
108
+ Note:
109
+ The configuration file must contain all the required parameters
110
+ to create trade instances for each account and strategy.
111
+ The configuration file must be a dictionary with the following structure:
112
+ If parallel is True:
113
+ {
114
+ "strategy_name": {
115
+ "account_name": {
116
+ "symbol_list": ["symbol1", "symbol2"],
117
+ "trades_kwargs": {"param1": "value1", "param2": "value2"}
118
+ **other_parameters (for the strategy and the execution engine)
119
+ }
120
+ }
121
+ }
122
+ If parallel is False:
123
+ {
124
+ "strategy_name": {
125
+ "symbol_list": ["symbol1", "symbol2"],
126
+ "trades_kwargs": {"param1": "value1", "param2": "value2"}
127
+ **other_parameters (for the strategy and the execution engine)
128
+ }
129
+ }
130
+ See bbstrader.metatrader.trade.create_trade_instance for more details on the trades_kwargs.
131
+ See bbstrader.trading.execution.MT5ExecutionEngine for more details on the other parameters.
132
+
133
+ All other paramaters must be python built-in types.
134
+ If you have custom type you must set them in your strategy class
135
+ or run the MT5ExecutionEngine directly, don't run on CLI.
62
136
  """
63
- if notify_me:
64
- send_notification(title, message=message)
65
- if telegram:
66
- if token is None or chat_id is None:
67
- raise ValueError("Token and chat_id must be provided")
68
- asyncio.run(send_telegram_message(token, chat_id, text=message))
137
+ if "-h" in unknown or "--help" in unknown:
138
+ print(HELP_MSG)
139
+ sys.exit(0)
140
+
141
+ parser = argparse.ArgumentParser()
142
+ parser.add_argument("-s", "--strategy", type=str, required=True)
143
+ parser.add_argument("-a", "--account", type=str, nargs="*", default=[])
144
+ parser.add_argument("-p", "--path", type=str, default=EXECUTION_PATH)
145
+ parser.add_argument("-c", "--config", type=str, default=CONFIG_PATH)
146
+ parser.add_argument("-l", "--parallel", action="store_true")
147
+ parser.add_argument(
148
+ "-t", "--terminal", type=str, default="MT5", choices=["MT5", "TWS"]
149
+ )
150
+ args = parser.parse_args(unknown)
69
151
 
152
+ if args.terminal == "MT5":
153
+ mt5_terminal(args)
154
+ elif args.terminal == "TWS":
155
+ tws_terminal(args)
@@ -0,0 +1,69 @@
1
+ import asyncio
2
+
3
+ from notifypy import Notify
4
+ from telegram import Bot
5
+ from telegram.error import TelegramError
6
+
7
+
8
+ __all__ = ["send_telegram_message", "send_notification", "send_message"]
9
+
10
+
11
+ async def send_telegram_message(token, chat_id, text=""):
12
+ """
13
+ Send a message to a telegram chat
14
+
15
+ Args:
16
+ token: str: Telegram bot token
17
+ chat_id: int or str or list: Chat id or list of chat ids
18
+ text: str: Message to send
19
+ """
20
+ try:
21
+ bot = Bot(token=token)
22
+ if isinstance(chat_id, (int, str)):
23
+ chat_id = [chat_id]
24
+ for id in chat_id:
25
+ await bot.send_message(chat_id=id, text=text)
26
+ except TelegramError as e:
27
+ print(f"Error sending message: {e}")
28
+
29
+
30
+ def send_notification(title, message=""):
31
+ """
32
+ Send a desktop notification
33
+
34
+ Args:
35
+ title: str: Title of the notification
36
+ message: str: Message of the notification
37
+ """
38
+ notification = Notify(default_notification_application_name="bbstrading")
39
+ notification.title = title
40
+ notification.message = message
41
+ notification.send()
42
+
43
+
44
+ def send_message(
45
+ title="SIGNAL",
46
+ message="New signal",
47
+ notify_me=False,
48
+ telegram=False,
49
+ token=None,
50
+ chat_id=None,
51
+ ):
52
+ """
53
+ Send a message to the user
54
+
55
+ Args:
56
+ title: str: Title of the message
57
+ message: str: Message of the message
58
+ notify_me: bool: Send a desktop notification
59
+ telegram: bool: Send a telegram message
60
+ token: str: Telegram bot token
61
+ chat_id: int or str or list: Chat id or list of chat ids
62
+ """
63
+ if notify_me:
64
+ send_notification(title, message=message)
65
+ if telegram:
66
+ if token is None or chat_id is None:
67
+ raise ValueError("Token and chat_id must be provided")
68
+ asyncio.run(send_telegram_message(token, chat_id, text=message))
69
+
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: bbstrader
3
- Version: 0.2.95
3
+ Version: 0.2.96
4
4
  Summary: Simplified Investment & Trading Toolkit
5
5
  Home-page: https://github.com/bbalouki/bbstrader
6
6
  Download-URL: https://pypi.org/project/bbstrader/
@@ -58,6 +58,13 @@ Requires-Dist: lightgbm
58
58
  Requires-Dist: alphalens-reloaded
59
59
  Requires-Dist: pyfiglet
60
60
  Requires-Dist: colorama
61
+ Requires-Dist: praw
62
+ Requires-Dist: tweepy
63
+ Requires-Dist: beautifulsoup4
64
+ Requires-Dist: dash
65
+ Requires-Dist: nltk
66
+ Requires-Dist: textblob
67
+ Requires-Dist: vaderSentiment
61
68
  Provides-Extra: mt5
62
69
  Requires-Dist: MetaTrader5; extra == "mt5"
63
70
  Dynamic: author
@@ -69,6 +76,7 @@ Dynamic: download-url
69
76
  Dynamic: home-page
70
77
  Dynamic: keywords
71
78
  Dynamic: license
79
+ Dynamic: license-file
72
80
  Dynamic: maintainer
73
81
  Dynamic: project-url
74
82
  Dynamic: provides-extra
@@ -1,5 +1,5 @@
1
1
  bbstrader/__ini__.py,sha256=v6zyJHj5FMRL-_P7AwnTGbCF-riMqhqlTvDgfulj7go,621
2
- bbstrader/__main__.py,sha256=Fg-Ft1EXKbAn1FzZ94ak6kbVHarhrCEmm0dH9lDPMlA,1484
2
+ bbstrader/__main__.py,sha256=9KDkv2eXb01wuGW5AB-K6bAecSTXG4eCAErmWxTUx1E,1498
3
3
  bbstrader/compat.py,sha256=djbHMvTvy0HYm1zyZ6Ttp_LMwP2PqTSVw1r7pqbz7So,487
4
4
  bbstrader/config.py,sha256=c2nCUw-bYWf5kkyFls5Nqld8HdMczexSilTni7rYUBw,3973
5
5
  bbstrader/tseries.py,sha256=H4D_A966HdN8YjBfuCcF8QBQdhjOrTcidR98wP2KN_I,68339
@@ -12,9 +12,9 @@ bbstrader/btengine/performance.py,sha256=1ecWrTzHBQbk4ORvbTEKxwCzlL1brcXOEUwgbnj
12
12
  bbstrader/btengine/portfolio.py,sha256=mh2_zNJDmKzb0lo55PXhbXYxXMmXRA4YLkgzwxRMuZE,16110
13
13
  bbstrader/btengine/scripts.py,sha256=8o66dq4Ex4DsH4s8xvJqUOFjLzZJSnbBvvNBzohtzoE,4837
14
14
  bbstrader/btengine/strategy.py,sha256=c-wvotJdhHu5FWAlPkv33LfjoW-7ID2G0Di_hc7CYMM,33217
15
- bbstrader/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
- bbstrader/core/data.py,sha256=0EhB-bI3QRjFRyfDfebrNAAmViXtXFPHbEsGpJKI5oM,430
17
- bbstrader/core/utils.py,sha256=dpP2qPFxo-gEvlzHvhoTH89UkftqiAqUJ6Lz04UDfRs,4079
15
+ bbstrader/core/__init__.py,sha256=GIFzFSStPfE0XM2j7mDeZZQeMTh_AwPsDOQXwMVJLgw,97
16
+ bbstrader/core/data.py,sha256=VPuynoT0uFYduh7la8gZSnEv_Gq8Xu2vJZJ7TfQMll8,18797
17
+ bbstrader/core/utils.py,sha256=lmL-hpaVHxuhX-V5wgBslnA4Ob89iY1omoSvL3FFOro,4120
18
18
  bbstrader/ibkr/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  bbstrader/ibkr/utils.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
20
  bbstrader/metatrader/__init__.py,sha256=A5Ye9tpc2sp9Xk5qjKw-EfYsoRcZtAt8nqvC3tCtZs8,333
@@ -25,20 +25,21 @@ bbstrader/metatrader/risk.py,sha256=pwG4q1_uPGgPlokDGVNtd04O6p28yIbgT-evvHuo-Qc,
25
25
  bbstrader/metatrader/scripts.py,sha256=Yjp7Un-wDTInptHS_rPFpXNKWbVM871VEkaHxsO2MPQ,2115
26
26
  bbstrader/metatrader/trade.py,sha256=6FbFywRPu0_TlB31lTMb3VjACw1GPQsi7RjQNtJnh6w,76780
27
27
  bbstrader/metatrader/utils.py,sha256=lYIvAeiL_ceACmkVNo4-QRopias08KyBUI7THfdj3c0,17103
28
- bbstrader/models/__init__.py,sha256=du7qdXH0RYF_GHmYGcD78QAOlAHYwhEBc2HPkVdv0IY,498
28
+ bbstrader/models/__init__.py,sha256=s2mJrtKePXQaw_PvcrtPCD2mPCdVXP4Myzg0MlLVipo,547
29
29
  bbstrader/models/factors.py,sha256=5kSAOS1MHvTZ-Ti03TtjOxl_EvC-V_9e389xeR_82ak,13020
30
- bbstrader/models/ml.py,sha256=3jPDSQm_XZda6yClGqm6SrTczvWWdmHIU-UKsMohu5g,47519
30
+ bbstrader/models/ml.py,sha256=tCr7YyODl0CDoOUpYqJ1q12ls86Sc-_Fu3b2Y0Z7TJ8,47551
31
+ bbstrader/models/nlp.py,sha256=P7SYaTIqEBldjwYfS6IrO66Y6-ioDXUrCSf3bZxQrDE,28073
31
32
  bbstrader/models/optimization.py,sha256=vnks6uxFZdqXgxaZJNxq8z0IH45KZ8yaXo38JhIVKGc,6399
32
33
  bbstrader/models/portfolio.py,sha256=r-47Zrn2r7iKCHm5YVtwkbBJXAZGM3QYy-rXCWY9-Bg,8079
33
34
  bbstrader/models/risk.py,sha256=Efr7dKcr37n75TXv5rcgSYNDPu2Plzcn65AOOIh9x_8,15007
34
35
  bbstrader/trading/__init__.py,sha256=ycLyuuxN5SujqtzR9X0Q74UQfK93q2va-GGAXdr-KS8,457
35
- bbstrader/trading/execution.py,sha256=UOdXdQ1IYgCTG1GHwjhyLRIJnBDHuhVMyK_qjzdPlYY,34649
36
- bbstrader/trading/script.py,sha256=wR5TUrHn-Cd2kzfURXn14VTCEZ-QA8ydwYHayMPK0oI,5720
37
- bbstrader/trading/scripts.py,sha256=57dKF9dcRu04oU2VRqydRrzW39dCW2wlDWhVt-sZdRw,1857
36
+ bbstrader/trading/execution.py,sha256=cZ--FDEUaFVyLXG3Iym39nwW42xAs5XZIh8BbhdLwhE,34760
37
+ bbstrader/trading/scripts.py,sha256=wR5TUrHn-Cd2kzfURXn14VTCEZ-QA8ydwYHayMPK0oI,5720
38
38
  bbstrader/trading/strategies.py,sha256=yibrXPa8yw8KCNkJEmNaygjfleCNgA_T58vizGS584I,36159
39
- bbstrader-0.2.95.dist-info/LICENSE,sha256=ZwC_RqqGmOPBUiMDKqLyJZ5HBeHq53LpL7TMRzrJY8c,1094
40
- bbstrader-0.2.95.dist-info/METADATA,sha256=NhjLD936Qj-MskepQdXccTqs1M8v1z_K2aT5ylo1MF8,11381
41
- bbstrader-0.2.95.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
42
- bbstrader-0.2.95.dist-info/entry_points.txt,sha256=0yDCbhbgHswOzJnY5wRSM_FjjyMHGvY7lJpSSVh0xtI,54
43
- bbstrader-0.2.95.dist-info/top_level.txt,sha256=Wwj322jZmxGZ6gD_TdaPiPLjED5ReObm5omerwlmZIg,10
44
- bbstrader-0.2.95.dist-info/RECORD,,
39
+ bbstrader/trading/utils.py,sha256=57dKF9dcRu04oU2VRqydRrzW39dCW2wlDWhVt-sZdRw,1857
40
+ bbstrader-0.2.96.dist-info/licenses/LICENSE,sha256=ZwC_RqqGmOPBUiMDKqLyJZ5HBeHq53LpL7TMRzrJY8c,1094
41
+ bbstrader-0.2.96.dist-info/METADATA,sha256=4R54TJMj-pORXTs5xbcH4BvmAkwnacbqatjhJExwZzc,11569
42
+ bbstrader-0.2.96.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
43
+ bbstrader-0.2.96.dist-info/entry_points.txt,sha256=0yDCbhbgHswOzJnY5wRSM_FjjyMHGvY7lJpSSVh0xtI,54
44
+ bbstrader-0.2.96.dist-info/top_level.txt,sha256=Wwj322jZmxGZ6gD_TdaPiPLjED5ReObm5omerwlmZIg,10
45
+ bbstrader-0.2.96.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (76.0.0)
2
+ Generator: setuptools (78.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,155 +0,0 @@
1
- import argparse
2
- import json
3
- import multiprocessing as mp
4
- import os
5
- import sys
6
-
7
- from bbstrader.btengine import MT5Strategy, Strategy
8
- from bbstrader.core.utils import load_class, load_module
9
- from bbstrader.metatrader.trade import create_trade_instance
10
- from bbstrader.trading.execution import mt5_engine
11
-
12
- EXECUTION_PATH = os.path.expanduser("~/.bbstrader/execution/execution.py")
13
- CONFIG_PATH = os.path.expanduser("~/.bbstrader/execution/execution.json")
14
-
15
-
16
- def load_config(config_path, strategy_name, account=None):
17
- if not os.path.exists(config_path):
18
- raise FileNotFoundError(f"Configuration file not found at {config_path}")
19
- with open(config_path, "r") as f:
20
- config = json.load(f)
21
- try:
22
- config = config[strategy_name]
23
- except KeyError:
24
- raise ValueError(
25
- f"Strategy {strategy_name} not found in the configuration file."
26
- )
27
- if account is not None:
28
- try:
29
- config = config[account]
30
- except KeyError:
31
- raise ValueError(f"Account {account} not found in the configuration file.")
32
- if config.get("symbol_list") is None:
33
- raise ValueError("symbol_list is required in the configuration file.")
34
- if config.get("trades_kwargs") is None:
35
- raise ValueError("trades_kwargs is required in the configuration file.")
36
- return config
37
-
38
-
39
- def worker_function(account, args):
40
- strategy_module = load_module(args.path)
41
- strategy_class = load_class(strategy_module, args.strategy, (MT5Strategy, Strategy))
42
-
43
- config = load_config(args.config, args.strategy, account)
44
- symbol_list = config.pop("symbol_list")
45
- trades_kwargs = config.pop("trades_kwargs")
46
- trades = create_trade_instance(symbol_list, trades_kwargs)
47
-
48
- kwargs = {
49
- "symbol_list": symbol_list,
50
- "trades_instances": trades,
51
- "strategy_cls": strategy_class,
52
- "account": account,
53
- **config,
54
- }
55
- mt5_engine(account, **kwargs)
56
-
57
-
58
- def mt5_terminal(args):
59
- if args.parallel:
60
- if len(args.account) == 0:
61
- raise ValueError(
62
- "account or accounts are required when running in parallel"
63
- )
64
-
65
- processes = []
66
- try:
67
- for account in args.account:
68
- p = mp.Process(target=worker_function, args=(account, args))
69
- p.start()
70
- processes.append(p)
71
-
72
- for p in processes:
73
- p.join()
74
- except Exception as e:
75
- print(f"Error in parallel execution: {e}")
76
- raise e
77
- except KeyboardInterrupt:
78
- print("\nTerminating Execution...")
79
- for p in processes:
80
- p.terminate()
81
- for p in processes:
82
- p.join()
83
- print("Execution terminated")
84
- else:
85
- worker_function(None, args)
86
-
87
-
88
- def tws_terminal(args):
89
- raise NotImplementedError("TWS terminal is not implemented yet")
90
-
91
-
92
- def execute_strategy(unknown):
93
- HELP_MSG = """
94
- Execute a strategy on one or multiple MT5 accounts.
95
-
96
- Usage:
97
- python -m bbstrader --run execution [options]
98
-
99
- Options:
100
- -s, --strategy: Strategy class name to run
101
- -a, --account: Account(s) name(s) or ID(s) to run the strategy on (must be the same as in the configuration file)
102
- -p, --path: Path to the execution file (default: ~/.bbstrader/execution/execution.py)
103
- -c, --config: Path to the configuration file (default: ~/.bbstrader/execution/execution.json)
104
- -l, --parallel: Run the strategy in parallel (default: False)
105
- -t, --terminal: Terminal to use (default: MT5)
106
- -h, --help: Show this help message and exit
107
-
108
- Note:
109
- The configuration file must contain all the required parameters
110
- to create trade instances for each account and strategy.
111
- The configuration file must be a dictionary with the following structure:
112
- If parallel is True:
113
- {
114
- "strategy_name": {
115
- "account_name": {
116
- "symbol_list": ["symbol1", "symbol2"],
117
- "trades_kwargs": {"param1": "value1", "param2": "value2"}
118
- **other_parameters (for the strategy and the execution engine)
119
- }
120
- }
121
- }
122
- If parallel is False:
123
- {
124
- "strategy_name": {
125
- "symbol_list": ["symbol1", "symbol2"],
126
- "trades_kwargs": {"param1": "value1", "param2": "value2"}
127
- **other_parameters (for the strategy and the execution engine)
128
- }
129
- }
130
- See bbstrader.metatrader.trade.create_trade_instance for more details on the trades_kwargs.
131
- See bbstrader.trading.execution.MT5ExecutionEngine for more details on the other parameters.
132
-
133
- All other paramaters must be python built-in types.
134
- If you have custom type you must set them in your strategy class
135
- or run the MT5ExecutionEngine directly, don't run on CLI.
136
- """
137
- if "-h" in unknown or "--help" in unknown:
138
- print(HELP_MSG)
139
- sys.exit(0)
140
-
141
- parser = argparse.ArgumentParser()
142
- parser.add_argument("-s", "--strategy", type=str, required=True)
143
- parser.add_argument("-a", "--account", type=str, nargs="*", default=[])
144
- parser.add_argument("-p", "--path", type=str, default=EXECUTION_PATH)
145
- parser.add_argument("-c", "--config", type=str, default=CONFIG_PATH)
146
- parser.add_argument("-l", "--parallel", action="store_true")
147
- parser.add_argument(
148
- "-t", "--terminal", type=str, default="MT5", choices=["MT5", "TWS"]
149
- )
150
- args = parser.parse_args(unknown)
151
-
152
- if args.terminal == "MT5":
153
- mt5_terminal(args)
154
- elif args.terminal == "TWS":
155
- tws_terminal(args)