Spaces:
Running
Running
Benjamin Consolvo
commited on
Commit
·
86ae79c
1
Parent(s):
3cb68d0
holdings expansion
Browse files
app.py
CHANGED
@@ -428,14 +428,24 @@ class TradingApp:
|
|
428 |
|
429 |
refresh_portfolio()
|
430 |
st.button("Refresh Portfolio", on_click=refresh_portfolio)
|
431 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
432 |
|
433 |
def auto_trade_based_on_sentiment(self, sentiment):
|
434 |
actions = []
|
435 |
symbol_to_name = self.analyzer.symbol_to_name
|
436 |
for symbol, sentiment_value in sentiment.items():
|
437 |
action = None
|
438 |
-
is_market_open = self.alpaca.get_market_status()
|
439 |
if sentiment_value == 'Positive':
|
440 |
order = self.alpaca.buy(symbol, 1, reason="Sentiment: Positive")
|
441 |
action = 'Buy'
|
@@ -488,7 +498,7 @@ def background_auto_trade(app):
|
|
488 |
if not is_market_open:
|
489 |
_, _, next_open, _ = get_market_times(app.alpaca.alpaca)
|
490 |
next_open_time = next_open.strftime('%Y-%m-%d %H:%M:%S') if next_open else "unknown"
|
491 |
-
logger.warning(f"Market is currently closed. The {action.lower
|
492 |
else:
|
493 |
logger.info(f"Order executed: {action} 1 share of {symbol}")
|
494 |
|
@@ -616,6 +626,17 @@ def main():
|
|
616 |
update_holdings()
|
617 |
st.button("Refresh Holdings", on_click=update_holdings)
|
618 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
619 |
# Initialize auto trade log in session state if needed
|
620 |
if AUTO_TRADE_LOG_KEY not in st.session_state:
|
621 |
st.session_state[AUTO_TRADE_LOG_KEY] = []
|
|
|
428 |
|
429 |
refresh_portfolio()
|
430 |
st.button("Refresh Portfolio", on_click=refresh_portfolio)
|
431 |
+
|
432 |
+
# Add an expandable section for detailed holdings
|
433 |
+
with st.expander("View Detailed Holdings"):
|
434 |
+
holdings = self.alpaca.getHoldings() # Use self.alpaca instead of app.alpaca
|
435 |
+
if holdings:
|
436 |
+
detailed_holdings = pd.DataFrame(
|
437 |
+
[{"Ticker": ticker, "Amount (USD)": round(value)} for ticker, value in holdings.items()]
|
438 |
+
)
|
439 |
+
st.table(detailed_holdings)
|
440 |
+
else:
|
441 |
+
st.info("No holdings to display.")
|
442 |
|
443 |
def auto_trade_based_on_sentiment(self, sentiment):
|
444 |
actions = []
|
445 |
symbol_to_name = self.analyzer.symbol_to_name
|
446 |
for symbol, sentiment_value in sentiment.items():
|
447 |
action = None
|
448 |
+
is_market_open = self.alpaca.get_market_status() # Use self.alpaca instead of app.alpaca
|
449 |
if sentiment_value == 'Positive':
|
450 |
order = self.alpaca.buy(symbol, 1, reason="Sentiment: Positive")
|
451 |
action = 'Buy'
|
|
|
498 |
if not is_market_open:
|
499 |
_, _, next_open, _ = get_market_times(app.alpaca.alpaca)
|
500 |
next_open_time = next_open.strftime('%Y-%m-%d %H:%M:%S') if next_open else "unknown"
|
501 |
+
logger.warning(f"Market is currently closed. The {action.lower} order for 1 share of {symbol} has been submitted and will execute when the market opens at {next_open_time}.")
|
502 |
else:
|
503 |
logger.info(f"Order executed: {action} 1 share of {symbol}")
|
504 |
|
|
|
626 |
update_holdings()
|
627 |
st.button("Refresh Holdings", on_click=update_holdings)
|
628 |
|
629 |
+
# Add an expandable section for detailed holdings
|
630 |
+
with st.expander("View Detailed Holdings"):
|
631 |
+
holdings = app.alpaca.getHoldings()
|
632 |
+
if holdings:
|
633 |
+
detailed_holdings = pd.DataFrame(
|
634 |
+
[{"Ticker": ticker, "Amount (USD)": round(value)} for ticker, value in holdings.items()]
|
635 |
+
)
|
636 |
+
st.table(detailed_holdings)
|
637 |
+
else:
|
638 |
+
st.info("No holdings to display.")
|
639 |
+
|
640 |
# Initialize auto trade log in session state if needed
|
641 |
if AUTO_TRADE_LOG_KEY not in st.session_state:
|
642 |
st.session_state[AUTO_TRADE_LOG_KEY] = []
|