summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDidierRLopes <dro.lopes@campus.fct.unl.pt>2022-08-29 03:29:21 +0300
committerGitHub <noreply@github.com>2022-08-29 01:29:21 +0100
commit065cd788145782c993e00435372b46e4afb4212e (patch)
treee0701dc7f9f6d4a3e31209f7951945ac991453e3
parent12bf706c7cb45fe6661ed636e94f0f8dd3892f1a (diff)
forex quote to use yahoo finance instead (#2436)
* forex quote to use yahoo finance instead * update docs * add av as secondary source for quote
-rw-r--r--data_sources_default.json6
-rw-r--r--openbb_terminal/forex/forex_controller.py48
-rw-r--r--tests/openbb_terminal/forex/txt/test_forex_controller/test_print_help.txt2
-rw-r--r--website/content/terminal/forex/quote/_index.md21
4 files changed, 45 insertions, 32 deletions
diff --git a/data_sources_default.json b/data_sources_default.json
index af5b217b6e5..86c30d25c31 100644
--- a/data_sources_default.json
+++ b/data_sources_default.json
@@ -208,6 +208,10 @@
"yf",
"av",
"polygon"
+ ],
+ "quote": [
+ "yf",
+ "av"
]
}
-} \ No newline at end of file
+}
diff --git a/openbb_terminal/forex/forex_controller.py b/openbb_terminal/forex/forex_controller.py
index 1f266609b39..05d29f57b75 100644
--- a/openbb_terminal/forex/forex_controller.py
+++ b/openbb_terminal/forex/forex_controller.py
@@ -12,7 +12,7 @@ from prompt_toolkit.completion import NestedCompleter
from openbb_terminal import feature_flags as obbff
from openbb_terminal.decorators import log_start_end
-from openbb_terminal.forex import av_view, forex_helper, fxempire_view
+from openbb_terminal.forex import forex_helper, fxempire_view, av_view
from openbb_terminal.forex.forex_helper import FOREX_SOURCES, SOURCES_INTERVALS
from openbb_terminal.helper_funcs import (
valid_date,
@@ -72,7 +72,7 @@ class ForexController(BaseController):
mt.add_param("_ticker", self.fx_pair)
mt.add_param("_source", FOREX_SOURCES[self.source])
mt.add_raw("\n")
- mt.add_cmd("quote", "AlphaVantage", self.fx_pair)
+ mt.add_cmd("quote", "Yahoo Finance/AlphaVantage", self.fx_pair)
mt.add_cmd("load", "", self.fx_pair)
mt.add_cmd("candle", "", self.fx_pair)
mt.add_cmd("fwd", "FXEmpire", self.fx_pair)
@@ -115,7 +115,7 @@ class ForexController(BaseController):
"--resolution",
choices=["i", "d", "w", "m"],
default="d",
- help="[Alphavantage only] Resolution of data. Can be intraday, daily, weekly or monthly",
+ help="[Alphavantage only] Resolution of data. Can be intraday, daily, weekly or monthly",
dest="resolution",
)
parser.add_argument(
@@ -130,7 +130,7 @@ class ForexController(BaseController):
)
parser.add_argument(
"-s",
- "--start_date",
+ "--start",
default=(datetime.now() - timedelta(days=365)),
type=valid_date,
help="Start date of data.",
@@ -168,11 +168,9 @@ class ForexController(BaseController):
if self.data.empty:
console.print(
- "\n[red]"
- + "No historical data loaded.\n"
- + f"Make sure you have appropriate access for the '{ns_parser.source}' data source "
- + f"and that '{ns_parser.source}' supports the requested range."
- + "[/red]\n"
+ "\n[red]No historical data loaded.\n\n"
+ f"Make sure you have appropriate access for the '{ns_parser.source}' data source "
+ f"and that '{ns_parser.source}' supports the requested range.[/red]\n"
)
else:
self.data.index.name = "date"
@@ -236,11 +234,33 @@ class ForexController(BaseController):
)
ns_parser = self.parse_known_args_and_warn(parser, other_args)
if ns_parser:
- if self.to_symbol and self.from_symbol:
- av_view.display_quote(self.to_symbol, self.from_symbol)
- else:
- logger.error("No forex pair loaded.")
- console.print("[red]Make sure a forex pair is loaded.[/red]\n")
+ if ns_parser.source == "yf":
+ if self.to_symbol and self.from_symbol:
+ self.data = forex_helper.load(
+ to_symbol=self.to_symbol,
+ from_symbol=self.from_symbol,
+ resolution="i",
+ interval="1min",
+ start_date=(datetime.now() - timedelta(days=5)).strftime(
+ "%Y-%m-%d"
+ ),
+ source="yf",
+ )
+ console.print(f"\nQuote for {self.from_symbol}/{self.to_symbol}\n")
+ console.print(
+ f"Last refreshed : {self.data.index[-1].strftime('%Y-%m-%d %H:%M:%S')}"
+ )
+ console.print(f"Last value : {self.data['Adj Close'][-1]}\n")
+ else:
+ logger.error("No forex pair loaded.")
+ console.print("[red]Make sure a forex pair is loaded.[/red]\n")
+
+ elif ns_parser.source == "av":
+ if self.to_symbol and self.from_symbol:
+ av_view.display_quote(self.to_symbol, self.from_symbol)
+ else:
+ logger.error("No forex pair loaded.")
+ console.print("[red]Make sure a forex pair is loaded.[/red]\n")
@log_start_end(log=logger)
def call_fwd(self, other_args: List[str]):
diff --git a/tests/openbb_terminal/forex/txt/test_forex_controller/test_print_help.txt b/tests/openbb_terminal/forex/txt/test_forex_controller/test_print_help.txt
index 9e77e60af03..519ab2f1f06 100644
--- a/tests/openbb_terminal/forex/txt/test_forex_controller/test_print_help.txt
+++ b/tests/openbb_terminal/forex/txt/test_forex_controller/test_print_help.txt
@@ -3,7 +3,7 @@
Ticker:
Source: YahooFinance
-[unvl] quote get last quote[/unvl] [AlphaVantage]
+[unvl] quote get last quote[/unvl] [Yahoo Finance/AlphaVantage]
[unvl] load get historical data[/unvl]
[unvl] candle show candle plot for loaded pair[/unvl]
[unvl] fwd get forward rates for loaded pair[/unvl] [FXEmpire]
diff --git a/website/content/terminal/forex/quote/_index.md b/website/content/terminal/forex/quote/_index.md
index 563eaeadd03..1260c33b5d2 100644
--- a/website/content/terminal/forex/quote/_index.md
+++ b/website/content/terminal/forex/quote/_index.md
@@ -11,20 +11,9 @@ optional arguments:
```
2022 Feb 15, 04:06 (✨) /forex/ $ quote
- USD/EUR Quote
-┌────────────────────┬─────────────────────────────────┐
-│ │ Realtime Currency Exchange Rate │
-├────────────────────┼─────────────────────────────────┤
-│ From_Currency Code │ USD │
-├────────────────────┼─────────────────────────────────┤
-│ To_Currency Code │ EUR │
-├────────────────────┼─────────────────────────────────┤
-│ Last Refreshed │ 2022-02-15 09:07:21 │
-├────────────────────┼─────────────────────────────────┤
-│ Exchange Rate │ 0.88090000 │
-├────────────────────┼─────────────────────────────────┤
-│ Bid Price │ 0.88090000 │
-├────────────────────┼─────────────────────────────────┤
-│ Ask Price │ 0.88090000 │
-└────────────────────┴─────────────────────────────────┘
+
+Quote for AUD/CHF
+
+Last refreshed : 2022-08-26 22:28:00
+Last value : 0.6652299761772156
```