Show realized trade PnL in Android app
This commit is contained in:
+29
-4
@@ -358,10 +358,35 @@ class CryptoSpotBot:
|
||||
|
||||
def positions_snapshot(self) -> list[dict]:
|
||||
prices = self.market.prices()
|
||||
return [
|
||||
position.as_dict(mark_price=prices.get(position.symbol, position.entry_price))
|
||||
for position in self.broker.open_positions()
|
||||
]
|
||||
items: list[dict] = []
|
||||
for position in self.broker.open_positions():
|
||||
mark_price = prices.get(position.symbol, position.entry_price)
|
||||
item = position.as_dict(mark_price=mark_price)
|
||||
exit_signal = self.strategy.exit_signal(
|
||||
position=position,
|
||||
candles=self.market.candles.get(position.symbol, []),
|
||||
ticker=self.market.tickers.get(position.symbol),
|
||||
learning=self.learner.state.as_dict(),
|
||||
forecast=self.market.forecasts.get(position.symbol, {}),
|
||||
)
|
||||
diagnostics = exit_signal.diagnostics or {}
|
||||
fallback_stop_loss = position.stop_loss if self.settings.stop_loss_exit_enabled else None
|
||||
item["exit_plan"] = {
|
||||
"action": exit_signal.action,
|
||||
"reason": exit_signal.reason,
|
||||
"confidence": exit_signal.confidence,
|
||||
"stop_loss": diagnostics.get("stop_loss", fallback_stop_loss),
|
||||
"take_profit": diagnostics.get("take_profit", position.take_profit),
|
||||
"trailing_stop": diagnostics.get("trailing_stop"),
|
||||
"atr_trailing_stop": diagnostics.get("atr_trailing_stop"),
|
||||
"highest_price": diagnostics.get("highest_price", position.highest_price),
|
||||
"stop_loss_exit_enabled": diagnostics.get(
|
||||
"stop_loss_exit_enabled",
|
||||
self.settings.stop_loss_exit_enabled,
|
||||
),
|
||||
}
|
||||
items.append(item)
|
||||
return items
|
||||
|
||||
def learning_snapshot(self) -> dict:
|
||||
snapshot = self.learner.state.as_dict()
|
||||
|
||||
Reference in New Issue
Block a user