Changes to make history work.
authorScott Gasch <[email protected]>
Tue, 21 Feb 2023 19:06:51 +0000 (11:06 -0800)
committerScott Gasch <[email protected]>
Tue, 21 Feb 2023 19:06:51 +0000 (11:06 -0800)
stock_renderer.py

index 2897edb7fb474b872ffa367096f50e19338bcb5f..75014d2cc23f2c48ed56a1e85366f5b13c67a4ce 100644 (file)
@@ -134,12 +134,24 @@ class stock_quote_renderer(renderer.abstaining_renderer):
         )
 
         hist = ticker.history(period=period, interval="1wk")
+        if isinstance(ticker, yq.Ticker):
+            _open = "open"
+            _high = "high"
+            _low = "low"
+            _close = "adjclose"
+        elif isinstance(ticker, yf.Ticker):
+            _open = "Open"
+            _high = "High"
+            _low = "Low"
+            _close = "Close"
+        else:
+            raise Exception("Bad Ticker type")
         chart = go.Figure(
             data=go.Candlestick(
-                open=hist["Open"],
-                high=hist["High"],
-                low=hist["Low"],
-                close=hist["Close"],
+                open=hist[_open],
+                high=hist[_high],
+                low=hist[_low],
+                close=hist[_close],
             ),
             layout=transparent,
         )
@@ -224,9 +236,9 @@ class stock_quote_renderer(renderer.abstaining_renderer):
 
 
 # Test
-x = stock_quote_renderer(
-#    {},
-#    ["MSFT", "GOOG", "BTC-USD", "ABHYX", "GC=F", "VNQ"],
-#    {"BTC-USD": "BTC", "GC=F": "GOLD"},
-)
-x.periodic_render(None)
+x = stock_quote_renderer(
+    {},
+    ["MSFT", "GOOG", "BTC-USD", "ABHYX", "GC=F", "VNQ"],
+    {"BTC-USD": "BTC", "GC=F": "GOLD"},
+)
+x.periodic_render(None)