feat(accounts): fast add-credential with immediate balances + background bring-up#171
Closed
fengtality wants to merge 2 commits into
Closed
feat(accounts): fast add-credential with immediate balances + background bring-up#171fengtality wants to merge 2 commits into
fengtality wants to merge 2 commits into
Conversation
…und bring-up Adding a connector credential previously blocked on the full trading-connector bring-up before returning. For Hyperliquid perp that is ~85s (a metaAndAssetCtxs call per HIP-3 DEX in both symbol-map init and trading-rules update, plus order-book / websocket startup waits), so the UI sat on "Saving credentials…" for a long time and the new balances only appeared a refresh loop later. Split the bring-up into a fast part and a heavy part: - update_connector_keys now creates the connector, fetches balances only (mirroring the Hummingbot CLI `connect`), CACHES it, and schedules the heavy bring-up (symbol map, trading rules, HIP-3 markets, positions, recorders, network) in the background, in place on the cached connector. Bad keys still fail fast here and the caller deletes the credential. - _create_and_initialize_trading_connector keeps the same end state by calling the same new _finish_trading_connector_init after the fast balances fetch. - add_credentials surfaces the new balances immediately via a scoped update_account_state(account_names=[...], connector_names=[...], skip_gateway=True) instead of a full all-connectors refresh, wrapped so a display-only refresh failure never deletes a just-validated credential. Delete-race guarded: the background task checks list_available_credentials before and after finishing and tears the connector back down if the credential was removed meanwhile, so a removed key can't linger in the cache / portfolio. Background tasks are held in a module-level set so they aren't GC'd mid-run. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…tion probe validate_trading_pair() probes a pair by calling feed.fetch_candles() directly, but fetch_candles() does not run initialize_exchange_data(). Feeds that resolve exchange-specific symbol data there (e.g. Hyperliquid spot builds _coins_dict in _initialize_coins_dict) then dereference uninitialized state in their REST payload — `self._coins_dict[self._trading_pair]` raises 'NoneType' object is not subscriptable, which the endpoint wraps as "Trading pair 'PURR-USDC' appears to be invalid on 'hyperliquid'". Both /market-data/candles and /market-data/historical-candles gate on this validation, so spot pairs failed on both the primary call and the fallback (perp was unaffected — its payload uses the bare base asset). The real fetch path get_historical_candles already initializes exchange data first; mirror that in the validation probe. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
f84963d to
bd454b2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Adding a connector credential blocks on the full trading-connector bring-up before returning. For Hyperliquid perp that is ~85s — a
metaAndAssetCtxscall per HIP-3 DEX in both symbol-map init and trading-rules update, plus order-book / websocket startup waits. The result:update_account_state()over all connectors — including an unreachable Gateway — ran on every add).Change
Split the trading-connector bring-up into a fast part (balances only) and a heavy part (the rest), and finish the heavy part in the background.
update_connector_keysnow creates the connector, fetches balances only (mirroring the Hummingbot CLIconnect), caches it, and schedules the heavy bring-up (symbol map, trading rules, HIP-3 markets, positions, recorders, network) in the background — in place on the cached connector, so it becomes trade-ready without blocking the response or flickering the portfolio. Bad keys still fail fast here and the caller deletes the credential._create_and_initialize_trading_connectorkeeps the exact same end state by calling the new_finish_trading_connector_initafter the fast balances fetch.add_credentialssurfaces the new balances immediately via a scopedupdate_account_state(account_names=[…], connector_names=[…], skip_gateway=True)instead of a full all-connectors / Gateway refresh. It's wrapped in its own try/except so a display-only refresh failure can never delete a just-validated credential.Correctness
list_available_credentialsbefore and after finishing, and tears the connector back down if the credential was removed meanwhile — so a removed key can't linger in the cache / account state / portfolio.setso they aren't garbage-collected mid-run.Result
"Saving credentials" returns in a few seconds and the new balances show up in the portfolio right away; the connector becomes fully trade-ready ~80s later in the background.
Test plan
🤖 Generated with Claude Code