diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f5024d..f37db41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - The TUI shows rupee totals to the paisa, as Kite does: the Positions P&L summary, the Overview tiles and panel totals, the Holdings title, Funds and the available margin in the header. They were rounded to whole rupees, so a P&L of +619.16 read +₹619. - SSE IPO rows show Applied only when an application is live. Any order object in Kite's reply used to mark the issue applied, even after every application had failed or been cancelled. - The IPO & Bids sections use Kite web's labels: Place bid for GSecs and corporate actions without an order, Give back or Pre-apply for open SSE issues, and order statuses in capitals. +- `kite stream ticks` always suggests `kite auth login` when Kite rejects the session. If the rejection arrived before the subscription went out, the hint was left off. ## [0.2.3] - 2026-11-12 diff --git a/src/commands/stream.rs b/src/commands/stream.rs index 091882e..84f4758 100644 --- a/src/commands/stream.rs +++ b/src/commands/stream.rs @@ -21,6 +21,17 @@ pub async fn tui(rt: &Runtime, args: TuiArgs) -> Result { Ok(Output::None) } +/// The error for a ticker that closed, with a login hint when Kite rejected +/// the session. A close can arrive before or after the subscribe call. +fn closed(reason: CloseReason) -> anyhow::Error { + match reason { + CloseReason::AuthRejected(message) => { + anyhow::anyhow!("{message}; run `kite auth login`") + } + reason => anyhow::anyhow!(reason), + } +} + async fn ticks(rt: &Runtime, args: StreamTicksArgs) -> Result { let (tokens, labels) = resolve_tokens(rt, &args).await?; if tokens.is_empty() { @@ -35,7 +46,7 @@ async fn ticks(rt: &Runtime, args: StreamTicksArgs) -> Result { let (ticker, mut rx) = client.ticker().url(url).spawn()?; if let Err(error) = ticker.subscribe(&tokens, args.mode.into()) { if let Some(TickerEvent::Closed(reason)) = rx.recv().await { - bail!(reason); + return Err(closed(reason)); } return Err(error.into()); } @@ -92,10 +103,7 @@ async fn ticks(rt: &Runtime, args: StreamTicksArgs) -> Result { } } TickerEvent::Closed(CloseReason::Requested) => break, - TickerEvent::Closed(CloseReason::AuthRejected(message)) => { - bail!("{message}; run `kite auth login`") - } - TickerEvent::Closed(reason) => bail!(reason), + TickerEvent::Closed(reason) => return Err(closed(reason)), _ => {} } } @@ -238,6 +246,17 @@ fn write_tick(out: &mut impl Write, tick: &Tick) -> io::Result { #[cfg(test)] mod tests { + #[test] + fn a_rejected_session_asks_for_login_whenever_the_close_arrives() { + use kiteconnect::ticker::CloseReason; + assert_eq!( + super::closed(CloseReason::AuthRejected("WebSocket auth rejected".into())).to_string(), + "WebSocket auth rejected; run `kite auth login`" + ); + let refused = super::closed(CloseReason::HandshakeRejected("refused".into())).to_string(); + assert!(!refused.contains("kite auth login"), "{refused}"); + } + use super::*; #[test]