InNoobWeTrust
commited on
Commit
·
445d48c
1
Parent(s):
cf1b1b4
feat: add tradingview charts
Browse files- df.py +47 -3
- pyproject.toml +1 -0
- requirements.txt +0 -9
- streamlit_app.py +10 -5
df.py
CHANGED
@@ -2,6 +2,7 @@ import pandas as pd
|
|
2 |
import pytz
|
3 |
import cloudscraper
|
4 |
import yfinance as yf
|
|
|
5 |
|
6 |
from typing import List
|
7 |
from types import SimpleNamespace
|
@@ -168,9 +169,21 @@ def fetch_etf_volumes(funds: List[str], start_time=None):
|
|
168 |
|
169 |
|
170 |
def fetch_asset_price(ticker: str, start_time=None):
|
171 |
-
price = yf.download(ticker, interval="1d", period="max", start=start_time)
|
172 |
-
price =
|
173 |
-
price.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
print(price.head())
|
175 |
|
176 |
return price
|
@@ -203,8 +216,39 @@ def fetch(asset):
|
|
203 |
}
|
204 |
)
|
205 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
return SimpleNamespace(
|
207 |
url=etf_url,
|
|
|
208 |
etf_flow=etf_flow,
|
209 |
etf_volumes=etf_volumes,
|
210 |
price=price,
|
|
|
2 |
import pytz
|
3 |
import cloudscraper
|
4 |
import yfinance as yf
|
5 |
+
from rich import print
|
6 |
|
7 |
from typing import List
|
8 |
from types import SimpleNamespace
|
|
|
169 |
|
170 |
|
171 |
def fetch_asset_price(ticker: str, start_time=None):
|
172 |
+
price = yf.download(ticker, interval="1d", period="max", start=start_time)
|
173 |
+
price = price.droplevel("Ticker", axis=1)
|
174 |
+
price.columns = [c[0] if isinstance(c, list) else c for c in price.columns]
|
175 |
+
price.rename(
|
176 |
+
columns={
|
177 |
+
"Price_Date": "Date",
|
178 |
+
"Open": "open",
|
179 |
+
"High": "high",
|
180 |
+
"Low": "low",
|
181 |
+
"Close": "close",
|
182 |
+
"Volume": "volume",
|
183 |
+
},
|
184 |
+
inplace=True,
|
185 |
+
)
|
186 |
+
price.reset_index(names="Date", inplace=True)
|
187 |
print(price.head())
|
188 |
|
189 |
return price
|
|
|
216 |
}
|
217 |
)
|
218 |
|
219 |
+
tdv = f"""
|
220 |
+
<!-- TradingView Widget BEGIN -->
|
221 |
+
<div class="tradingview-widget-container">
|
222 |
+
<div class="tradingview-widget-container__widget"></div>
|
223 |
+
<div class="tradingview-widget-copyright"><a href="https://www.tradingview.com/" rel="noopener nofollow" target="_blank"><span class="blue-text">Track all markets on TradingView</span></a></div>
|
224 |
+
<script type="text/javascript" src="https://s3.tradingview.com/external-embedding/embed-widget-advanced-chart.js" async>
|
225 |
+
{{
|
226 |
+
"width": "100%",
|
227 |
+
"height": "640",
|
228 |
+
"symbol": "INDEX:{asset}USD",
|
229 |
+
"interval": "D",
|
230 |
+
"timezone": "Etc/UTC",
|
231 |
+
"theme": "dark",
|
232 |
+
"style": "1",
|
233 |
+
"locale": "en",
|
234 |
+
"withdateranges": true,
|
235 |
+
"hide_side_toolbar": false,
|
236 |
+
"allow_symbol_change": true,
|
237 |
+
"details": false,
|
238 |
+
"calendar": false,
|
239 |
+
"studies": [
|
240 |
+
"STD;RSI"
|
241 |
+
],
|
242 |
+
"support_host": "https://www.tradingview.com"
|
243 |
+
}}
|
244 |
+
</script>
|
245 |
+
</div>
|
246 |
+
<!-- TradingView Widget END -->
|
247 |
+
"""
|
248 |
+
|
249 |
return SimpleNamespace(
|
250 |
url=etf_url,
|
251 |
+
tdv=tdv,
|
252 |
etf_flow=etf_flow,
|
253 |
etf_volumes=etf_volumes,
|
254 |
price=price,
|
pyproject.toml
CHANGED
@@ -10,6 +10,7 @@ dependencies = [
|
|
10 |
"lxml>=5.3.1",
|
11 |
"pandas>=2.2.3",
|
12 |
"pygwalker>=0.4.9.14",
|
|
|
13 |
"streamlit>=1.43.2",
|
14 |
"vega>=4.1.0",
|
15 |
"workalendar>=17.0.0",
|
|
|
10 |
"lxml>=5.3.1",
|
11 |
"pandas>=2.2.3",
|
12 |
"pygwalker>=0.4.9.14",
|
13 |
+
"rich>=13.9.4",
|
14 |
"streamlit>=1.43.2",
|
15 |
"vega>=4.1.0",
|
16 |
"workalendar>=17.0.0",
|
requirements.txt
DELETED
@@ -1,9 +0,0 @@
|
|
1 |
-
streamlit
|
2 |
-
pandas
|
3 |
-
lxml
|
4 |
-
yfinance[nospam,repair]==0.2.54
|
5 |
-
altair
|
6 |
-
vega
|
7 |
-
workalendar
|
8 |
-
pygwalker
|
9 |
-
cloudscraper
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
streamlit_app.py
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
import pandas as pd
|
4 |
|
5 |
import streamlit as st
|
6 |
-
from streamlit.components.v1 import iframe
|
7 |
import altair as alt
|
8 |
|
9 |
from pygwalker.api.streamlit import StreamlitRenderer, init_streamlit_comm
|
@@ -44,7 +44,7 @@ def gen_charts(asset, chart_size={"width": 560, "height": 150}):
|
|
44 |
axis=alt.Axis(tickCount={"interval": "month", "step": 1}),
|
45 |
title="",
|
46 |
),
|
47 |
-
y=alt.Y("
|
48 |
color=alt.value("crimson"),
|
49 |
)
|
50 |
)
|
@@ -275,11 +275,14 @@ def app():
|
|
275 |
st.altair_chart(btc_charts, use_container_width=True)
|
276 |
with eth_chart_col:
|
277 |
st.altair_chart(eth_charts, use_container_width=True)
|
|
|
278 |
# Display iframes
|
279 |
btc_col, eth_col = st.columns(2)
|
280 |
with btc_col:
|
|
|
281 |
iframe(btc.url, height=1200, scrolling=True)
|
282 |
with eth_col:
|
|
|
283 |
iframe(eth.url, height=1200, scrolling=True)
|
284 |
with single_view:
|
285 |
asset = st.selectbox(
|
@@ -288,27 +291,29 @@ def app():
|
|
288 |
)
|
289 |
charts = asset_charts(asset, chart_size={"width": "container", "height": 300})
|
290 |
st.altair_chart(charts, use_container_width=True)
|
|
|
|
|
|
|
|
|
|
|
291 |
iframe(fetch_asset(asset).url, height=1200, scrolling=True)
|
292 |
with flow_tab:
|
293 |
btc_flow, eth_flow = btc.etf_flow, eth.etf_flow
|
294 |
btc_flow["Asset"] = "BTC"
|
295 |
eth_flow["Asset"] = "ETH"
|
296 |
df = pd.concat([btc_flow, eth_flow])
|
297 |
-
df.Date = df.Date.astype(str)
|
298 |
StreamlitRenderer(df).explorer()
|
299 |
with volume_tab:
|
300 |
btc_volume, eth_volume = btc.etf_volumes, eth.etf_volumes
|
301 |
btc_volume["Asset"] = "BTC"
|
302 |
eth_volume["Asset"] = "ETH"
|
303 |
df = pd.concat([btc_volume, eth_volume])
|
304 |
-
df.Date = df.Date.astype(str)
|
305 |
StreamlitRenderer(df).explorer()
|
306 |
with price_tab:
|
307 |
btc_price, eth_price = btc.price, eth.price
|
308 |
btc_price["Asset"] = "BTC"
|
309 |
eth_price["Asset"] = "ETH"
|
310 |
df = pd.concat([btc_price, eth_price])
|
311 |
-
df.Date = df.Date.astype(str)
|
312 |
StreamlitRenderer(df).explorer()
|
313 |
|
314 |
|
|
|
3 |
import pandas as pd
|
4 |
|
5 |
import streamlit as st
|
6 |
+
from streamlit.components.v1 import iframe, html
|
7 |
import altair as alt
|
8 |
|
9 |
from pygwalker.api.streamlit import StreamlitRenderer, init_streamlit_comm
|
|
|
44 |
axis=alt.Axis(tickCount={"interval": "month", "step": 1}),
|
45 |
title="",
|
46 |
),
|
47 |
+
y=alt.Y("close:Q").scale(zero=False),
|
48 |
color=alt.value("crimson"),
|
49 |
)
|
50 |
)
|
|
|
275 |
st.altair_chart(btc_charts, use_container_width=True)
|
276 |
with eth_chart_col:
|
277 |
st.altair_chart(eth_charts, use_container_width=True)
|
278 |
+
|
279 |
# Display iframes
|
280 |
btc_col, eth_col = st.columns(2)
|
281 |
with btc_col:
|
282 |
+
html(btc.tdv, height=640)
|
283 |
iframe(btc.url, height=1200, scrolling=True)
|
284 |
with eth_col:
|
285 |
+
html(eth.tdv, height=640)
|
286 |
iframe(eth.url, height=1200, scrolling=True)
|
287 |
with single_view:
|
288 |
asset = st.selectbox(
|
|
|
291 |
)
|
292 |
charts = asset_charts(asset, chart_size={"width": "container", "height": 300})
|
293 |
st.altair_chart(charts, use_container_width=True)
|
294 |
+
match asset:
|
295 |
+
case "BTC":
|
296 |
+
html(btc.tdv, height=640)
|
297 |
+
case "ETH":
|
298 |
+
html(eth.tdv, height=640)
|
299 |
iframe(fetch_asset(asset).url, height=1200, scrolling=True)
|
300 |
with flow_tab:
|
301 |
btc_flow, eth_flow = btc.etf_flow, eth.etf_flow
|
302 |
btc_flow["Asset"] = "BTC"
|
303 |
eth_flow["Asset"] = "ETH"
|
304 |
df = pd.concat([btc_flow, eth_flow])
|
|
|
305 |
StreamlitRenderer(df).explorer()
|
306 |
with volume_tab:
|
307 |
btc_volume, eth_volume = btc.etf_volumes, eth.etf_volumes
|
308 |
btc_volume["Asset"] = "BTC"
|
309 |
eth_volume["Asset"] = "ETH"
|
310 |
df = pd.concat([btc_volume, eth_volume])
|
|
|
311 |
StreamlitRenderer(df).explorer()
|
312 |
with price_tab:
|
313 |
btc_price, eth_price = btc.price, eth.price
|
314 |
btc_price["Asset"] = "BTC"
|
315 |
eth_price["Asset"] = "ETH"
|
316 |
df = pd.concat([btc_price, eth_price])
|
|
|
317 |
StreamlitRenderer(df).explorer()
|
318 |
|
319 |
|