Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 24 additions & 5 deletions src/commands/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ pub async fn tui(rt: &Runtime, args: TuiArgs) -> Result<Output> {
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<Output> {
let (tokens, labels) = resolve_tokens(rt, &args).await?;
if tokens.is_empty() {
Expand All @@ -35,7 +46,7 @@ async fn ticks(rt: &Runtime, args: StreamTicksArgs) -> Result<Output> {
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());
}
Expand Down Expand Up @@ -92,10 +103,7 @@ async fn ticks(rt: &Runtime, args: StreamTicksArgs) -> Result<Output> {
}
}
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)),
_ => {}
}
}
Expand Down Expand Up @@ -238,6 +246,17 @@ fn write_tick(out: &mut impl Write, tick: &Tick) -> io::Result<bool> {

#[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]
Expand Down
Loading