bbstrader 0.2.91__py3-none-any.whl → 0.2.93__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.

@@ -1,17 +1,20 @@
1
1
  from datetime import datetime
2
2
  from typing import Optional, Union
3
3
 
4
- from bbstrader import compat # noqa: F401
5
- import MetaTrader5 as Mt5
6
4
  import pandas as pd
7
5
  from exchange_calendars import get_calendar, get_calendar_names
8
6
  from pandas.tseries.holiday import USFederalHolidayCalendar
9
7
  from pandas.tseries.offsets import CustomBusinessDay
10
8
 
11
-
12
9
  from bbstrader.metatrader.account import AMG_EXCHANGES, Account, check_mt5_connection
13
10
  from bbstrader.metatrader.utils import TIMEFRAMES, TimeFrame, raise_mt5_error
14
11
 
12
+ try:
13
+ import MetaTrader5 as Mt5
14
+ except ImportError:
15
+ import bbstrader.compat # noqa: F401
16
+
17
+
15
18
  __all__ = [
16
19
  "Rates",
17
20
  "download_historical_data",
@@ -2,14 +2,18 @@ import random
2
2
  from datetime import datetime
3
3
  from typing import Any, Dict, Optional, Union
4
4
 
5
- from bbstrader import compat # noqa: F401
6
- import MetaTrader5 as Mt5
7
5
  from scipy.stats import norm
8
6
 
9
7
  from bbstrader.metatrader.account import Account
10
8
  from bbstrader.metatrader.rates import Rates
11
9
  from bbstrader.metatrader.utils import TIMEFRAMES, TimeFrame
12
10
 
11
+ try:
12
+ import MetaTrader5 as Mt5
13
+ except ImportError:
14
+ import bbstrader.compat # noqa: F401
15
+
16
+
13
17
  _COMMD_SUPPORTED_ = [
14
18
  "GOLD",
15
19
  "SILVER",
@@ -28,8 +32,19 @@ _COMMD_SUPPORTED_ = [
28
32
  "USOIL",
29
33
  "SpotCrude",
30
34
  "SpotBrent",
31
- "NatGas",
32
35
  "Soybeans",
36
+ "Wheat",
37
+ "SoyOil",
38
+ "LeanHogs",
39
+ "LDSugar",
40
+ "Coffee",
41
+ "OJ",
42
+ "Cocoa",
43
+ "Cattle",
44
+ "Copper",
45
+ "XCUUSD",
46
+ "NatGas",
47
+ "Gasoline",
33
48
  ]
34
49
 
35
50
  _ADMIRAL_MARKETS_FUTURES_ = [
@@ -196,7 +211,7 @@ class RiskManagement(Account):
196
211
  self.pchange = pchange_sl
197
212
  self.var_level = var_level
198
213
  self.var_tf = var_time_frame
199
- self.daily_dd = round(daily_risk, 5)
214
+ self.daily_dd = round(daily_risk, 5) if daily_risk is not None else None
200
215
  self.max_risk = max_risk
201
216
  self.rr = rr
202
217
  self.sl = sl
@@ -490,10 +505,6 @@ class RiskManagement(Account):
490
505
  supported = _COMMD_SUPPORTED_
491
506
  if "." in self.symbol:
492
507
  symbol = self.symbol.split(".")[0]
493
- elif self.symbol.endswith("xx"):
494
- symbol = self.symbol[:-2]
495
- elif self.symbol.endswith("-"):
496
- symbol = self.symbol[:-1]
497
508
  else:
498
509
  symbol = self.symbol
499
510
  if str(symbol) not in supported:
@@ -0,0 +1,81 @@
1
+ import argparse
2
+ import sys
3
+
4
+ from bbstrader.metatrader.copier import RunCopier, config_copier
5
+
6
+
7
+ def copier_args(parser: argparse.ArgumentParser):
8
+ parser.add_argument(
9
+ "-s", "--source", type=str, nargs="?", default=None, help="Source section name"
10
+ )
11
+ parser.add_argument(
12
+ "-d",
13
+ "--destinations",
14
+ type=str,
15
+ nargs="*",
16
+ default=None,
17
+ help="Destination section names",
18
+ )
19
+ parser.add_argument(
20
+ "-i", "--interval", type=float, default=0.1, help="Update interval in seconds"
21
+ )
22
+ parser.add_argument(
23
+ "-c",
24
+ "--config",
25
+ nargs="?",
26
+ default=None,
27
+ type=str,
28
+ help="Config file name or path",
29
+ )
30
+ parser.add_argument(
31
+ "-t",
32
+ "--start",
33
+ type=str,
34
+ nargs="?",
35
+ default=None,
36
+ help="Start time in HH:MM format",
37
+ )
38
+ parser.add_argument(
39
+ "-e",
40
+ "--end",
41
+ type=str,
42
+ nargs="?",
43
+ default=None,
44
+ help="End time in HH:MM format",
45
+ )
46
+ return parser
47
+
48
+
49
+ def copy_trades(unknown):
50
+ HELP_MSG = """
51
+ Usage:
52
+ python -m bbstrader --run copier [options]
53
+
54
+ Options:
55
+ -s, --source: Source Account section name
56
+ -d, --destinations: Destination Account section names (multiple allowed)
57
+ -i, --interval: Update interval in seconds
58
+ -c, --config: .ini file or path (default: ~/.bbstrader/copier/copier.ini)
59
+ -t, --start: Start time in HH:MM format
60
+ -e, --end: End time in HH:MM format
61
+ """
62
+ if "-h" in unknown or "--help" in unknown:
63
+ print(HELP_MSG)
64
+ sys.exit(0)
65
+
66
+ copy_parser = argparse.ArgumentParser("Trades Copier", add_help=False)
67
+ copy_parser = copier_args(copy_parser)
68
+ copy_args = copy_parser.parse_args(unknown)
69
+
70
+ source, destinations = config_copier(
71
+ source_section=copy_args.source,
72
+ dest_sections=copy_args.destinations,
73
+ inifile=copy_args.config,
74
+ )
75
+ RunCopier(
76
+ source,
77
+ destinations,
78
+ copy_args.interval,
79
+ copy_args.start,
80
+ copy_args.end,
81
+ )