Skip to content

Let reconnect change a connection's access level - #16

Open
chang020202 wants to merge 2 commits into
mainfrom
chang/reconnect-connection-type
Open

Let reconnect change a connection's access level#16
chang020202 wants to merge 2 commits into
mainfrom
chang/reconnect-connection-type

Conversation

@chang020202

Copy link
Copy Markdown

Problem

A read-only connection could not be upgraded to trading from the CLI. reconnect accepted no connection type, and handleConnect explicitly sent connectionType: undefined for every reconnect ("Don't modify connection type if reconnecting"), so the API always kept the existing level.

That left users with only read-only connections in a loop (SNAP-9604):

  1. trade … option callNo valid accounts available… fix your disabled connections with snaptrade reconnect
  2. reconnectNo disabled connections found, therefore there's no need to reconnect (it only listed disabled connections)
  3. passing the connection id by hand → error: too many arguments for 'reconnect'

The reporter's own session confirms step 3's dead end: his Questrade reconnect completed successfully and the connection stayed read.

The upstream cause — the personal dashboard minting read-only connections — is fixed in passiv#14210. This PR is the remedy for connections that already exist.

Change

  • reconnect --connection-type <read|trade>, forwarded through handleConnect. Omitting it still preserves the current level, so existing behaviour is unchanged.
  • Without an id, --connection-type trade also lists active read-only connections, not just disabled ones, filtered to brokerages that can actually trade.
  • With an id, validate the brokerage supports trading before launching the portal. The login call rejects connectionType=trade for a brokerage with no trade auth type and there's no global error handler in main.ts, so that would otherwise print a raw stack.
  • selectAccount reports the per-account rejection reasons it already computes and names the matching remedy, instead of pointing every failure at disabled-connection repair.

Before / after for the reporter's case:

No valid accounts available. Connect an account with snaptrade connect or fix
your disabled connections with snaptrade reconnect.
No valid accounts available.
  • Read-only connection
  • Option trading not supported

Give an existing connection trading access with snaptrade reconnect --connection-type trade.

Run snaptrade connections to review them, or snaptrade connect to add another.

Tests

npm run verify green — lint, 28 tests, build. Six new: the upgrade path, explicit-id forwarding, the trade-incapable guard (both interactive and by-id), invalid type rejection, and three on handleConnect pinning that reconnect-without-type stays undefined, reconnect-with-type forwards, and new connections still default to trade-if-available.

Note

Options are still gated by the hardcoded brokers_with_mleg_options list, so Questrade and IBKR can't place option orders through the CLI even with a trade connection. Fixing that means exposing Brokerage.has_option_trading_support on the brokerage API — separate change, spans api.yaml and an SDK regen.

A read-only connection could not be upgraded to trading from the CLI:
`reconnect` took no connection type and `handleConnect` explicitly sent
`connectionType: undefined` for every reconnect, so the API always kept
the existing level. Users with only read-only connections hit
"No valid accounts available" on `trade` and were then told to run
`reconnect`, which reported nothing to do because it only listed
disabled connections.

- `reconnect --connection-type <read|trade>`, forwarded to the login call.
  Omitting it still preserves the current level.
- Without an id, `--connection-type trade` also lists active read-only
  connections, skipping brokerages that cannot trade.
- With an id, validate the brokerage supports trading first; the API
  error for this has no handler and would print a raw stack.
- `selectAccount` now reports the per-account rejection reasons it
  already computes, and names the matching remedy.
@chang020202

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 093e180643

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/commands/reconnect.ts Outdated
The candidate filter only added healthy connections for a trade upgrade,
so `reconnect --connection-type read` without an id considered disabled
connections only. An active trade connection was never offered and the
command reported nothing to do, even though the requested downgrade was
available.

Select on whether the requested level differs from the current one, in
either direction, and keep the allows_trading check on upgrades only.
@chang020202

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: ffe72ceebb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant