Fix forex bugs (#3131)

* normalized way moving average is treated and prevent huge exception prompt

* changed descriptions on docs

* change to check_positive_float

* fix linting

* fix linting
This commit is contained in:
Henrique Joaquim
2022-10-28 11:32:02 +01:00
committed by GitHub
parent 440ed10e63
commit eaa0a96f7e
7 changed files with 49 additions and 16 deletions

View File

@@ -521,7 +521,10 @@ class ETFController(BaseController):
"--ma",
dest="mov_avg",
type=str,
help="Add moving averaged to plot",
help=(
"Add moving average in number of days to plot and separate by a comma. "
"Value for ma (moving average) keyword needs to be greater than 1."
),
default="",
)
@@ -550,11 +553,23 @@ class ETFController(BaseController):
else:
data = stocks_helper.process_candle(self.etf_data)
mov_avgs = (
tuple(int(num) for num in ns_parser.mov_avg.split(","))
if ns_parser.mov_avg
else None
)
mov_avgs = []
if ns_parser.mov_avg:
mov_list = (num for num in ns_parser.mov_avg.split(","))
for num in mov_list:
try:
num = int(num)
if num <= 1:
raise ValueError
mov_avgs.append(num)
except ValueError:
console.print(
f"[red]{num} is not a valid moving average, must be an integer greater than 1."
)
stocks_helper.display_candle(
symbol=self.etf_name,

View File

@@ -229,7 +229,10 @@ class ForexController(BaseController):
"--ma",
dest="mov_avg",
type=str,
help=translate("stocks/CANDLE_mov_avg"),
help=translate(
"Add moving average in number of days to plot and separate by a comma. "
"Value for ma (moving average) keyword needs to be greater than 1."
),
default=None,
)
ns_parser = self.parse_known_args_and_warn(parser, other_args)
@@ -241,11 +244,17 @@ class ForexController(BaseController):
for num in mov_list:
try:
mov_avgs.append(int(num))
num = int(num)
if num <= 1:
raise ValueError
mov_avgs.append(num)
except ValueError:
console.print(
f"{num} is not a valid moving average, must be integer"
f"[red]{num} is not a valid moving average, must be an integer greater than 1."
)
forex_helper.display_candle(
self.data, self.to_symbol, self.from_symbol, mov_avgs
)

View File

@@ -27,6 +27,7 @@ from openbb_terminal.helper_funcs import (
EXPORT_BOTH_RAW_DATA_AND_FIGURES,
check_positive,
check_positive_list,
check_positive_float,
valid_date,
)
from openbb_terminal.forex.forex_helper import FOREX_SOURCES
@@ -812,7 +813,7 @@ class TechnicalAnalysisController(StockBaseController):
"--std",
action="store",
dest="n_std",
type=check_positive,
type=check_positive_float,
default=2,
help="std",
)

View File

@@ -432,7 +432,10 @@ class StocksController(StockBaseController):
"--ma",
dest="mov_avg",
type=str,
help="Add moving average in number of days to plot and separate by a comma",
help=(
"Add moving average in number of days to plot and separate by a comma. "
"Value for ma (moving average) keyword needs to be greater than 1."
),
default=None,
)
parser.add_argument(
@@ -491,10 +494,15 @@ class StocksController(StockBaseController):
for num in mov_list:
try:
mov_avgs.append(int(num))
num = int(num)
if num <= 1:
raise ValueError
mov_avgs.append(num)
except ValueError:
console.print(
f"{num} is not a valid moving average, must be integer"
f"[red]{num} is not a valid moving average, must be an integer greater than 1."
)
stocks_helper.display_candle(

View File

@@ -12,7 +12,7 @@ optional arguments:
--raw Shows raw data instead of chart (default: False)
-n NUM, --num NUM Number to show if raw selected (default: 20)
-t, --trend Flag to add high and low trends to candle. (default: False)
--ma MOV_AVG Add moving averaged to plot (default: )
--ma MOV_AVG Add moving average in number of days to plot and separate by a comma. Value for ma (moving average) keyword needs to be greater than 1. (default: )
-h, --help show this help message (default: False)
--export {csv,json,xlsx}
Export raw data into csv, json, xlsx (default: )

View File

@@ -6,7 +6,7 @@ Show candle for loaded fx data
```
optional arguments:
--ma MOV_AVG Add moving average in number of days to plot and separate by a comma (default: None)
--ma MOV_AVG Add moving average in number of days to plot and separate by a comma. Value for ma (moving average) keyword needs to be greater than 1. (default: )
-h, --help show this help message (default: False)
```

View File

@@ -10,7 +10,7 @@ optional arguments:
-d, --descending Sort selected column descending. Only works when raw data is displayed. (default: True)
--raw Shows raw data instead of chart. If sort is set those are the top ones, otherwise we grab latest data to date (default: False)
-t, --trend Flag to add high and low trends to candle (default: False)
--ma MOV_AVG Add moving average in number of days to plot and separate by a comma (default: None)
--ma MOV_AVG Add moving average in number of days to plot and separate by a comma. Value for ma (moving average) keyword needs to be greater than 1. (default: None)
--log Plot with y axis on log scale (default: False)
-h, --help show this help message (default: False)
--export EXPORT Export raw data into csv, json, xlsx (default: )