natexcvi commited on
Commit
e451088
1 Parent(s): e0ce4e0

Adapt to API changes

Browse files
Files changed (3) hide show
  1. api.py +11 -0
  2. app.py +10 -0
  3. style.py +3 -3
api.py CHANGED
@@ -52,3 +52,14 @@ class TradeAssistantAPI:
52
  return body
53
  except JSONDecodeError:
54
  raise Exception(response.text)
 
 
 
 
 
 
 
 
 
 
 
 
52
  return body
53
  except JSONDecodeError:
54
  raise Exception(response.text)
55
+
56
+ def get_portfolio(self):
57
+ url = f"{self.url}/portfolio"
58
+ response = requests.get(url, headers=self.base_headers)
59
+ try:
60
+ body = response.json()
61
+ if "message" in body:
62
+ raise Exception(body["message"])
63
+ return body
64
+ except JSONDecodeError:
65
+ raise Exception(response.text)
app.py CHANGED
@@ -40,6 +40,16 @@ except Exception as e:
40
  st.error(e)
41
  st.expander("Details").write(recommendation_res)
42
 
 
 
 
 
 
 
 
 
 
 
43
  st.sidebar.write("## Actions")
44
  schedule_training_res = None
45
  if st.sidebar.button("Train model"):
 
40
  st.error(e)
41
  st.expander("Details").write(recommendation_res)
42
 
43
+ try:
44
+ portfolio_res = api.get_portfolio()
45
+ portfolio = json.loads(portfolio_res["portfolio"])
46
+ portfolio = pd.DataFrame(portfolio)
47
+ st.write("## Portfolio")
48
+ st.dataframe(portfolio)
49
+ except Exception as e:
50
+ st.error(e)
51
+ st.expander("Details").write(portfolio_res)
52
+
53
  st.sidebar.write("## Actions")
54
  schedule_training_res = None
55
  if st.sidebar.button("Train model"):
style.py CHANGED
@@ -1,5 +1,5 @@
1
  def recommendation_table_styler(styler):
2
- styler = styler.background_gradient(subset=["metric"], cmap="viridis_r")
3
- styler = styler.background_gradient(subset=["pred_change"], cmap="viridis")
4
- styler = styler.format({"pred_change": "{:.2%}", "metric": "{:.2f}"})
5
  return styler
 
1
  def recommendation_table_styler(styler):
2
+ styler = styler.background_gradient(subset=["proba_strong_up"], cmap="viridis_r")
3
+ styler = styler.background_gradient(subset=["actual"], cmap="viridis")
4
+ styler = styler.format({"proba_strong_up": "{:.2%}", "actual": "{:.2%}"})
5
  return styler