Skip to content

refactor: broker self-registration + AccountManager lifecycle + account enable/disable#83

Merged
luokerenx4 merged 5 commits intomasterfrom
dev
Mar 23, 2026
Merged

refactor: broker self-registration + AccountManager lifecycle + account enable/disable#83
luokerenx4 merged 5 commits intomasterfrom
dev

Conversation

@luokerenx4
Copy link
Contributor

Summary

  • AccountManager lifecycle: Moved account creation, reconnection, removal from main.ts into AccountManager. main.ts is now pure wiring.
  • Broker self-registration: Each broker declares its own configSchema, configFields (UI descriptors), and fromConfig. New broker registry maps type → class. Factory reduced to a one-line lookup.
  • brokerConfig nested storage: Account config uses generic { id, type, guards, brokerConfig } format. Legacy flat format auto-migrated on read.
  • /broker-types endpoint: Returns all registered broker types with field descriptors, subtitle rules, and guard categories for dynamic frontend rendering.
  • Dynamic frontend: TradingPage renders broker forms dynamically from /broker-types metadata. No hardcoded per-broker components. Adding a new broker requires zero frontend changes.
  • Account enable/disable: enabled field on AccountConfig. Disabled accounts skipped at startup, shown grayed out in UI. PUT auto-detects state changes and starts/stops connections.

Test plan

  • pnpm build passes
  • pnpm test — 880 tests pass
  • Manual: frontend create/edit/disable accounts works

🤖 Generated with Claude Code

Ame and others added 5 commits March 23, 2026 12:21
AccountManager now owns the full account lifecycle:
- initAccount(config): create broker → load git state → build UTA → register
- reconnectAccount(id): close old → re-read config → init new → verify
- removeAccount(id): close + deregister
- registerCcxtToolsIfNeeded(): conditional CCXT tool registration

Extracted git-persistence.ts (loadGitState, createGitPersister) from main.ts.
Removed reconnectAccount from EngineContext — web routes call
accountManager.reconnectAccount() directly.

main.ts reduced to pure wiring: read config → construct AccountManager →
init accounts → assemble context → start plugins.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… fromConfig

Each broker now declares its own config needs:
- static configSchema: Zod schema for validating brokerConfig fields
- static configFields: UI field descriptors for dynamic form rendering
- static fromConfig: construct instance from generic AccountConfig

New broker registry (registry.ts) maps type → broker class with UI
metadata (name, description, badge). Factory simplified to registry
lookup — no more switch-case field mapping.

config.ts uses generic schema with brokerConfig: Record<string, unknown>.
readAccountsConfig() auto-migrates legacy flat format to nested brokerConfig.

New /broker-types endpoint returns registered broker types + field
descriptors for frontend dynamic rendering.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…types

Backend registry now includes subtitleFields and guardCategory per broker.
New /broker-types endpoint returns all metadata for dynamic UI rendering.

Frontend TradingPage fully rewritten:
- DynamicBrokerFields component renders form inputs from BrokerConfigField[]
- CreateWizard fetches broker types, generates platform selector dynamically
- EditDialog renders all broker fields dynamically (no hardcoded components)
- AccountCard subtitle built from subtitleFields metadata
- Deleted CcxtConnectionFields, AlpacaConnectionFields, IbkrConnectionFields
- Deleted per-broker AccountConfig types (CcxtAccountConfig, etc.)
- AccountConfig now uses generic { id, type, guards, brokerConfig }

Adding a new broker now requires zero frontend changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Class static properties aren't enumerable — spread (...CcxtBroker)
doesn't copy them. Reference configSchema, configFields, fromConfig
explicitly on each registry entry.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Accounts can now be temporarily disabled without deleting config:
- AccountConfig gains `enabled: boolean` (default true)
- Disabled accounts skipped at startup, shown grayed out in UI
- PUT /accounts/:id auto-detects enabled state changes — disabling
  closes the broker connection, enabling triggers reconnect
- EditDialog has an Enabled/Disabled toggle in the footer
- E2E setup skips disabled accounts + fixes brokerConfig field access

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@luokerenx4 luokerenx4 merged commit 9a6d62c into master Mar 23, 2026
2 checks passed
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