-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathnewstrade_v2.py
47 lines (33 loc) · 1.18 KB
/
newstrade_v2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import streamlit as st
from openbb_terminal.sdk import openbb
import pandas as pd
import plotly.graph_objects as go
cont1, cont2 = st.columns(2)
ticker = cont1.text_input(
label = "Add a stock to track",
value = "META"
)
def get_news_signal(ticker, *args, **kwargs):
signal = {
'buy' : "BUY! Sentiment at ",
'sell' : "SELL Sentiment at "
}
if ticker is not None:
latest_article = openbb.stocks.ba.cnews(f"{ticker}")[0]
else:
st.write("Please add a valid ticker name")
sentiment = openbb.stocks.ba.text_sent(latest_article["summary"])
if sentiment >= 0.5:
cont2.write(signal['buy'] + str(sentiment))
cont2.write("Read the news here")
cont2.write(latest_article["url"])
elif sentiment <= -0.25:
cont2.write(signal['sell'] + str(sentiment))
cont2.write("Read the news here")
cont2.write(latest_article["url"])
else:
cont2.write("No useful signal. Latest news sentiment is at " + str(sentiment))
cont2.write("Read the news here")
cont2.write(latest_article["url"])
return
get_news_signal(ticker)