(feat) improve visualization of executors

This commit is contained in:
cardosofede
2024-05-17 15:20:30 -04:00
parent 1caaa36b45
commit ad6df97f32

View File

@@ -2,6 +2,8 @@ import plotly.graph_objects as go
import pandas as pd
from decimal import Decimal
from hummingbot.connector.connector_base import TradeType
def add_executors_trace(fig, executors, row, col):
for executor in executors:
@@ -9,15 +11,16 @@ def add_executors_trace(fig, executors, row, col):
entry_price = executor.custom_info["current_position_average_price"]
exit_time = pd.to_datetime(executor.close_timestamp, unit='ms')
exit_price = executor.custom_info["close_price"]
name = "Buy Executor" if executor.config.side == TradeType.BUY else "Sell Executor"
if executor.filled_amount_quote == 0:
fig.add_trace(go.Scatter(x=[entry_time, exit_time], y=[entry_price, exit_price], mode='lines',
line=dict(color='blue', width=2, dash="dash"), name='Buy Entry/Exit'), row=row, col=col)
fig.add_trace(go.Scatter(x=[entry_time, exit_time], y=[entry_price, entry_price], mode='lines',
line=dict(color='blue', width=2, dash="dash"), name=name), row=row, col=col)
else:
if executor.net_pnl_quote > Decimal(0):
fig.add_trace(go.Scatter(x=[entry_time, exit_time], y=[entry_price, exit_price], mode='lines',
line=dict(color='green', width=2), name='Buy Entry/Exit'), row=row, col=col)
line=dict(color='green', width=2), name=name), row=row, col=col)
else:
fig.add_trace(go.Scatter(x=[entry_time, exit_time], y=[entry_price, exit_price], mode='lines',
line=dict(color='red', width=2), name='Sell Entry/Exit'), row=row, col=col)
line=dict(color='red', width=2), name=name), row=row, col=col)
return fig