Skip to content

Analytics: "Trades with no close date" counts open positions as closed trades and blames the core #741

Description

@Alena-Selezneva

Symptom

From the project chat (@Rocket_bunny2, 2026-09-26): the Analytics window shows the notice

Сделки без даты закрытия
102 закрытых сделок (PnL: +1.61 USDT) не входят НИ В ОДИН период — ядро не прислало дату закрытия. Ни одна цифра в этом окне их не учитывает.

while in MoonBot all of that user's trades are closed and they saw no disconnects. Their words: "в отчете в терминале стала появляться инфа о якобы не закрытых сделках, хотя в мб всё закрыто".

What the notice actually counts (verified in code)

undated_closes_on (crates/moon-core/src/db/analytics/mod.rs) counts every replica row matching WHERE_UNDATED = (closedate IS NULL OR closedate <= 0), plus deleted = 0 and the active filters. There is no status or "is this closed" check. So the same set includes:

  1. Positions that are open right now. The core writes an open position into its report as a row with close date 0 and status 0, already carrying the sell-order price and a floating profit. The Report treats exactly these rows as open (report_read.rs: "A trade is CLOSED once it carries a usable positive closedate, and OPEN until then"; footer открыто: N, toggle «Открытые позиции»).
  2. Rows whose close the terminal missed (see the companion issue on open-row rechecks). The core HAS the close date; the terminal never received the update.
  3. Rows left unclosed in the core's own report. Only this case matches "the core never sent a close date".

The notice labels all three as "closed trades" and blames the core. The doc comment on UndatedCloses ("closed for certain (they carry a sell price and a sell reason)") does not hold: an open row already has a sell price. The PnL it shows mixes floating profit into what reads as realized money.

Two windows now contradict each other: Report says these rows are open positions, Analytics says they are closed trades.

Expected

  • The notice does not call open rows closed, and it does not say "the core did not send a close date" when the terminal cannot tell that apart from a missed update.
  • Either exclude rows the replica treats as open positions (as the Report does), or word the notice as "trades with no close date (open or not synced)" and point to the way out: restart the terminal to re-sync them; if they remain, check them in Report with «Открытые позиции» on and delete the ones that have no position on the bot.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions