From f6995c78d52e56d3b136f4e6d77625425b71ae78 Mon Sep 17 00:00:00 2001 From: drupman Date: Thu, 23 Nov 2023 17:52:23 -0300 Subject: [PATCH] (feat) improve candles hovertexts --- utils/graphs.py | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/utils/graphs.py b/utils/graphs.py index 46ee75e0..608e1e03 100644 --- a/utils/graphs.py +++ b/utils/graphs.py @@ -54,6 +54,14 @@ def add_candles_graph(self): row=1, col=1, ) else: + hover_text = [] + for i in range(len(self.candles_df)): + hover_text.append( + f"Open: {self.candles_df['open'][i]}
" + f"High: {self.candles_df['high'][i]}
" + f"Low: {self.candles_df['low'][i]}
" + f"Close: {self.candles_df['close'][i]}
" + ) self.base_figure.add_trace( go.Candlestick( x=self.candles_df.index, @@ -61,7 +69,9 @@ def add_candles_graph(self): high=self.candles_df['high'], low=self.candles_df['low'], close=self.candles_df['close'], - name="OHLC" + name="OHLC", + hoverinfo="text", + hovertext=hover_text ), row=1, col=1, ) @@ -79,7 +89,9 @@ def add_buy_trades(self, orders_data: pd.DataFrame): size=12, line=dict(color='black', width=1), opacity=0.7, - )), + ), + hoverinfo="text", + hovertext=orders_data["price"].apply(lambda x: f"Buy Order: {x}
")), row=1, col=1, ) @@ -94,7 +106,9 @@ def add_sell_trades(self, orders_data: pd.DataFrame): color='red', size=12, line=dict(color='black', width=1), - opacity=0.7, )), + opacity=0.7,), + hoverinfo="text", + hovertext=orders_data["price"].apply(lambda x: f"Sell Order: {x}
")), row=1, col=1, ) @@ -223,12 +237,28 @@ def add_pnl(self, strategy_data: SingleMarketStrategyData, row=4): def add_positions(self, position_executor_data: pd.DataFrame, row=1): position_executor_data["close_datetime"] = pd.to_datetime(position_executor_data["close_timestamp"], unit="s") + i = 1 for index, rown in position_executor_data.iterrows(): + i += 1 self.base_figure.add_trace(go.Scatter(name=f"Position {index}", x=[rown.datetime, rown.close_datetime], y=[rown.entry_price, rown.close_price], mode="lines", line=dict(color="lightgreen" if rown.net_pnl_quote > 0 else "red"), + hoverinfo="text", + hovertext=f"Position N°: {i}
" + f"Datetime: {rown.datetime}
" + f"Close datetime: {rown.close_datetime}
" + f"Side: {rown.side}
" + f"Entry price: {rown.entry_price}
" + f"Close price: {rown.close_price}
" + f"Close type: {rown.close_type}
" + f"Stop Loss: {100 * rown.sl:.2f}%
" + f"Take Profit: {100 * rown.tp:.2f}%
" + f"Time Limit: {100 * rown.tl:.2f}
" + f"Open Order Type: {rown.open_order_type}
" + f"Leverage: {rown.leverage}
" + f"Controller name: {rown.controller_name}
", showlegend=False), row=row, col=1)