Skip to content

fix(strategy-center): enable live trading mode for crypto portfolios (#225) - #9

Open
mwaleedta wants to merge 3 commits into
OpenByteInc:mainfrom
mwaleedta:fix-225-crypto-portfolio-live
Open

fix(strategy-center): enable live trading mode for crypto portfolios (#225)#9
mwaleedta wants to merge 3 commits into
OpenByteInc:mainfrom
mwaleedta:fix-225-crypto-portfolio-live

Conversation

@mwaleedta

Copy link
Copy Markdown

Summary

Fixes OpenByteInc/QuantDinger#225.

The web deployment editor was blocking executionMode=live for any Strategy API V2 portfolio unless the asset class was USStock, even though the backend explicitly supports same-market live deployments (see backend_api_python/app/services/strategy_v2/deployment.py::_validate_execution_account — Crypto + USStock both pass; only mixed-market is rejected).

For a multi-instrument crypto portfolio (e.g. BTC/USDT@swap + ETH/USDT@swap), users could only choose signal mode in the deployment wizard. Single-instrument CTA crypto strategies worked fine.

Root cause

In src/views/strategy-center/components/LiveStrategyEditor.vue:

  • supportsLive (line 370) hard-coded isPortfolioStrategy → marketCategory === 'USStock', disabling the radio for crypto portfolios.
  • compatibleCredentials (line 420) hard-coded isPortfolioStrategy → exchange === 'alpaca', hiding binance/okx/etc. credentials.

Fix

Two surgical changes:

  1. supportsLive now delegates to supportsLiveExecutionMode(manifest) — permits any same-market Crypto or USStock manifest, regardless of strategy type.
  2. compatibleCredentials now delegates to credentialMatchesLiveStrategy(manifest, exchange_id) — accepts crypto exchanges for Crypto manifests, alpaca/ibkr for USStock manifests, rejects everything else.

Both helpers live in a new src/utils/liveTradingEligibility.js module so they can be unit-tested without mounting the Vue SFC.

Tests

  • 10 new exhaustive specs in tests/unit/liveTradingEligibility.test.mjs covering CTA vs. portfolio × Crypto/USStock/mixed and credential matching across the supported exchanges.
  • Extended tests/unit/liveStrategyCurrentContract.test.mjs with a source-scan regression test that asserts the old hard-blocks are gone and the new helpers are wired in.
  • Full pnpm test:unit passes (55/55), plus the new files run 13/13 green.

Verification

Per the issue's repro, a strategy like:

def initialize(context):
    context.set_universe([
        "Crypto:BTC/USDT@swap",
        "Crypto:ETH/USDT@swap",
    ])
    context.subscribe(frequency="4h")

...now shows "Live Automated Trading" as an available option in the deploy wizard and accepts a crypto exchange credential.

Out of scope

  • IBKR for USStock portfolios (still alpaca-credentialed in the portfolio picker — unchanged, separate concern).
  • Mixed-market portfolios still blocked, matching the backend's strategyV2.mixedMarketLiveUnsupported.

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.

[Bug] Crypto portfolio strategies can be backtested but cannot enable live automated trading

1 participant