/algo-trading-skills:questrade-api-rate-limit-and-account-typesfrom algo-trading-skills
Explains Questrade IQ API token rotation (single-use, 7-day validity), per-category rate limits (30/s account, 20/s market data), and 16 account types for pre-trade eligibility gating.
Ships in algo-trading-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Use this when a bot reads Questrade account or market data, or gates orders by Canadian account type. Questrade punishes three specific mistakes:
GET v1/accounts returns one of sixteen documented
types. Only Margin can borrow, and a short sale is a borrow. Coercing an
unrecognised type to Margin is how a bot approves a short in a LIRA.POST accounts/:id/orders, POST .../impact and DELETE .../orders/:orderId
under the trade scope, documented as "partner developers only". A
personal application receives read_acc and read_md; no order-placement
endpoint appears anywhere in the public REST reference. This skill provides a
pre-submission eligibility gate, not order submission. Confirm your access
tier before designing an execution path around this API.kill-switch-and-drawdown-circuit-breakers and
sec-rule-15c3-5-risk-controls-us for the equivalent control layer.wash-sale-rule-tracking-us and
capital-gains-vs-business-income-classification for adjacent tax topics,
and confirm strategy permissions with the broker.multi-broker-rate-limit-handling for the distributed case.secrets-rotation-without-bot-downtime.login.questrade.com for live,
practicelogin.questrade.com for practice accounts.Redeem the refresh token against the correct host, and persist the successor before using it.
GET https://login.questrade.com/oauth2/token?grant_type=refresh_token&refresh_token={TOKEN}
(Questrade also documents this as a POST; both appear in its own docs).+ and /. Interpolated raw into a query string, +
decodes server-side as a space and the exchange fails with a token that
looks perfectly correct in your logs.refresh_token to durable storage before returning from the exchange,
and treat a persistence failure as fatal. A process that crashes holding
only the spent token has lost API access.expires_in. Questrade's samples show both 300 s and
1800 s. Assuming 1800 when the server said 300 leaves the client
confident about a token that died 25 minutes ago. Missing field → fail.Normalise api_server before building any URL.
https://api01.iq.questrade.com,
https://api01.iq.questrade.com/ and https://api01.iq.questrade.com/v1
in different places. f"{api_server}v1/accounts" therefore produces
...questrade.comv1/accounts or .../v1v1/accounts for two of the three.
Strip trailing slashes and any trailing /v1, then append exactly one /.https value: Questrade refuses plaintext, so a http://
value signals a tampered or misparsed response.Rate-limit per category, across both windows, before dispatch.
time, accounts, accounts/:id/{positions,balances,executions,orders}):
30/sec and 30,000/hour. Market Data calls (markets,
markets/quotes/:id, markets/candles/:id, symbols/:id,
symbols/:id/options): 20/sec and 15,000/hour.GET markets, GET symbols/:id and GET symbols/:id/options sit under
the read_acc scope but are metered as Market Data calls. Categorise
from the rate-limit table, not the scope table.accounts/:id/activities, symbols/search, markets/quotes/options,
markets/quotes/strategies) should inherit the tighter budget. That is
an inference, not a documented figure — over-throttling costs latency,
under-throttling costs a ban.Feed the response headers back into the limiter.
X-RateLimit-Remaining and X-RateLimit-Reset (Unix
timestamp) on every limited call, and the same headers on a 429.X-RateLimit-Remaining and never says which window it
describes. Applying remaining: 29 to the 30,000/hour window charges
29,971 requests and strands the bot for an hour on a single ambiguous
header. Ignore a value larger than that window's capacity. (Inferred —
the header is documented, its scope is not.)"429" in str(exc) also matches order id 429123 and limit price
429.50. See multi-broker-rate-limit-handling for Retry-After-aware
full-jitter backoff once a throttle is correctly identified.Map every account, and fail closed on anything unrecognised.
Cash, Margin, TFSA, RRSP, FHSA, SRRSP,
LRRSP, LIRA, LIF, RIF, SRIF, LRIF, RRIF, PRIF, RESP,
FRESP.Individual is not an account type. It is a
clientAccountType (alongside Joint, Corporation, Formal Trust…).
The two fields are separate and mean different things.Margin. The
enumeration has not been revised since 2015 while Questrade keeps adding
account types. An unrecognised value must be treated as maximally
restricted, not as the one type with full borrowing privileges.status too. Documented values include Suspended (View Only),
Liquidate Only and Closed; routing an opening order to any of those is
a guaranteed rejection at best.Gate order side against account type and status before submission.
Buy, Sell, Short, Cov, BTO,
STC, STO, BTC. SellShort is not a Questrade value.Short and Cov require borrowed stock, so they are permitted only in a
Margin account. Every registered plan is barred from borrowing — ITA
146(4)(a) makes an RRSP trust taxable if it borrows, ITA 146.2(2)(f)
forbids a TFSA trust from borrowing — and a Cash account has no margin
facility.STO) is permitted in a given registered plan depends on Questrade
account approvals the API does not report. Return "review required", not
"allowed" and not "denied", and make the caller resolve it.False.Treat a 200 as ambiguous on any trade call.
HTTP/1.1 200 OK with a non-zero code, a message and an orderId
for an order that was created. A retry driven by "the call did not
look successful" can therefore duplicate a live order. Reconcile by
orderId — see order-placement-idempotency.Full step-by-step procedure: see
references/workflows.md. Verified limits, enumerations and sources: seereferences/standards.md. Printable pre-flight checklist: seeassets/checklist.md.
+ and /; a raw + becomes a space on
the server and the exchange fails for a reason nothing in your logs explains.expires_in to 1800. Questrade documents 300 s too. The client
then believes a dead token is live for 25 minutes and every call 401s.api_server naively. The field
is per-session and arrives with, without, and with a /v1 suffix across
Questrade's own documentation.login.questrade.com. Practice
accounts redeem against practicelogin.questrade.com; the hosts are not
interchangeable.GET markets and GET symbols/:id
are read_acc scope but Market Data rate limits."429" matches order ids and prices;
a false positive retries a call the broker may already have executed.X-RateLimit-Remaining, or trusting it upward. The first wastes
the broker's own feedback; the second lets two processes on one key each claim
the full quota.X-RateLimit-Remaining to every window. Questrade sends one
number for two windows. Charging remaining: 29 against the 30,000/hour
budget throttles the bot for an hour on the strength of one header.Margin. This is the failure
that approves a short sale in a LIRA, RESP or RRIF. Unknown must mean
restricted.Individual as an account type. It is a clientAccountType;
conflating the fields loses the actual plan type.Cash
account cannot short either."SellShort" as the order side. Not a Questrade value; the
documented short side is "Short".status. Liquidate Only and Suspended (View Only)
accounts appear in the list like any other.orderId in the error body.api_server shapes
(…questrade.com, …questrade.com/, …questrade.com/v1) must produce
exactly https://api01.iq.questrade.com/v1/accounts. The naive f-string
produced …comv1/accounts and …/v1v1/accounts for two of them.+ and / must appear in the
request URL as %2B and %2F.expires_in
must raise, never default.X-RateLimit-Remaining: 3 must reduce the 30/sec budget to
3 grants and leave the 30,000/hour window untouched (applying it to both
charged 29,971 hourly requests — that is the regression); a subsequent higher
figure must not restore headroom; a value above the short window's capacity,
or a malformed one, must be ignored rather than corrupt the budget.source="server" and the
parsed X-RateLimit-Reset; an HTTP 400 whose message contains
"Order 429123 rejected" must not be classified as a throttle.source="local" and the transport must record zero additional calls.RDSP and
Individual both resolve to UNKNOWN, never to MARGIN.Short is allowed in Margin and denied in all fourteen
registered types plus Cash plus UNKNOWN; STO outside a margin account
returns review_required and folds to False through the boolean API;
"SellShort" raises.Closed, Suspended (Closed), Suspended (View Only) and
unknown statuses deny every side; Liquidate Only permits Sell and refuses
Buy.repr() of a session must not contain the access or refresh token.python -m unittest discover -s skills/questrade-api-rate-limit-and-account-types/scripts
and confirm all tests pass.multi-broker-rate-limit-handlingorder-placement-idempotencytoken-lifecycle-live-probingsecrets-rotation-without-bot-downtimesandbox-vs-production-endpoint-driftbroker-agnostic-adapter-interfaceupstox-oauth-refresh-token-rotationWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
questrade, broker-api, oauth2, rate-limiting, account-types, token-rotation
36 skills in this plugin
/alpaca-paper-live-key-separationUse when a bot connects to the Alpaca Trading API and must never cross paper keys with the live endpoint; pins the base URL per environment, checks the key prefix, probes /v2/account and requires an explicit ALLOW_LIVE_TRADING flag./api-key-least-privilege-audit-toolUse before deploying a live bot, to audit existing broker API keys for scopes they do not need. Flags withdrawal, transfer and admin rights that turn a leaked execution key into theft./broker-account-margin-call-handlingUse when a bot trades a Reg T, portfolio or futures margin account and must act before the broker liquidates: tiered maintenance-margin warnings cross-checked against broker excess liquidity, initial-margin order gating and liquidity-aware de-leveraging./broker-agnostic-adapter-interfaceUse when strategy code must run across several brokers and should not import kiteconnect, alpaca-py or ibapi directly; defines an adapter contract with Decimal prices, typed exceptions and normalised order status across venues./broker-api-changelog-diffing-toolUse before upgrading a broker SDK or OpenAPI spec, to diff two schema snapshots for removed endpoints, newly required parameters, enum mutations and type changes so CI fails before the change reaches an order path./broker-api-deprecation-notice-monitoringUse when a long-running bot calls REST endpoints a broker may retire; parses RFC 8594 Sunset and RFC 9745 Deprecation headers plus changelog feeds into one dated migration deadline with an escalation tier.npx claudepluginhub himanshuj16/algo-trading-skills --plugin algo-trading-broker-integrationOther plugins' skills for the same job