ZhuLinsen/daily_stock_analysis · error · PortfolioOversellError

portfolio_oversell

portfolio_oversell

Error message

Oversell detected for {symbol}{date_hint}: requested={round(requested_quantity, 8)}, available={round(available_quantity, 8)}

What it means

Error "Oversell detected for {symbol}{date_hint}: requested={round(requested_quantity, 8)}, available={round(available_quantity, 8)}" thrown in ZhuLinsen/daily_stock_analysis.

Source

Thrown at src/services/portfolio_service.py:691

        market: str,
        currency: str,
        trade_date: date,
        quantity: float,
        session: Optional[Any] = None,
    ) -> None:
        key = (
            self._normalize_symbol_for_position(symbol),
            self._normalize_market(market),
            self._normalize_currency(currency),
        )
        available_quantity = self._calculate_available_quantity(
            account_id=account_id,
            key=key,
            as_of_date=trade_date,
            session=session,
        )
        if available_quantity + EPS < quantity:
            raise PortfolioOversellError(
                symbol=key[0],
                trade_date=trade_date,
                requested_quantity=quantity,
                available_quantity=available_quantity,
            )

    def _calculate_available_quantity(
        self,
        *,
        account_id: int,
        key: Tuple[str, str, str],
        as_of_date: date,
        session: Optional[Any] = None,
    ) -> float:
        if session is None:
            trades = self.repo.list_trades(account_id, as_of=as_of_date)
            corporate_actions = self.repo.list_corporate_actions(account_id, as_of=as_of_date)
        else:

View on GitHub (pinned to 5159bd72e8)

Solutions

  1. Reduce the sell quantity to at most the available position.
  2. Check prior trades for the symbol to ensure buys were recorded before sells.
  3. Correct the trade date/order if sells are being applied before their corresponding buys.

When it happens

Trigger: Thrown at src/services/portfolio_service.py:691 when the library encounters an invalid state.

Common situations: Raised when a sell request exceeds the available quantity for the symbol; occurs when the requested sell amount is larger than the computed holdings, preventing overselling.


AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15). Data as JSON: /api/errors/2580a2022f7b9b0d. Report an issue: GitHub.