Skip to content

Commit

Permalink
(feat) improve candles hovertexts
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasgaudino committed Nov 23, 2023
1 parent 52c7067 commit f6995c7
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions utils/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,24 @@ 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]} <br>"
f"High: {self.candles_df['high'][i]} <br>"
f"Low: {self.candles_df['low'][i]} <br>"
f"Close: {self.candles_df['close'][i]} <br>"
)
self.base_figure.add_trace(
go.Candlestick(
x=self.candles_df.index,
open=self.candles_df['open'],
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,
)
Expand All @@ -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} <br>")),
row=1, col=1,
)

Expand All @@ -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} <br>")),
row=1, col=1,
)

Expand Down Expand Up @@ -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} <br>"
f"Datetime: {rown.datetime} <br>"
f"Close datetime: {rown.close_datetime} <br>"
f"Side: {rown.side} <br>"
f"Entry price: {rown.entry_price} <br>"
f"Close price: {rown.close_price} <br>"
f"Close type: {rown.close_type} <br>"
f"Stop Loss: {100 * rown.sl:.2f}% <br>"
f"Take Profit: {100 * rown.tp:.2f}% <br>"
f"Time Limit: {100 * rown.tl:.2f} <br>"
f"Open Order Type: {rown.open_order_type} <br>"
f"Leverage: {rown.leverage} <br>"
f"Controller name: {rown.controller_name} <br>",
showlegend=False),
row=row, col=1)

Expand Down

0 comments on commit f6995c7

Please sign in to comment.