AI trading task guides

Paper trade a SPY strategy with Codex

Create a separate simulated SPY deployment, verify type=paper and preserve its running identity and forward history with Codex.

1. Connect Codex in the workspace you will use

In the desktop app, open Settings, MCP servers and Add server. Name it nexustrade, choose Streamable HTTP and paste the endpoint below. Save, select Restart, then Authenticate and complete NexusTrade sign-in. In the composer, /mcp shows connected servers.

For CLI use, run the commands below in your research workspace, finish browser OAuth, then start codex. Desktop and CLI configuration is local; verify tools in the task where you will run the workflow.

shell
codex mcp add nexustrade --url https://nexustrade.io/api/mcp
codex mcp login nexustrade
codex mcp list

2. Confirm access with an owned-resource read

Ask the client to discover tools and call fetch_portfolios, then pass one returned portfolioId as portfolio_id to get_portfolio. Inspect portfolioId, type, name, isActive and strategies; compare them with the same saved book in NexusTrade. Do not copy IDs from a demonstration. An empty list can be valid for a new account.

A tool-not-found error means revisit discovery. An authorization error means check the selected NexusTrade environment/account and OAuth connection. Do not ask the model to invent a replacement identifier.

text
Use only NexusTrade read tools. Call fetch_portfolios, then pass one returned portfolioId as the portfolio_id input to get_portfolio. Show portfolioId, type, name, isActive and complete strategies. Do not create, edit, backtest, deploy or place orders.

3. Create a new candidate and observation record

Daily SPY long/cash proposal: buy 10 shares only when no SPY position is held and price is above its 200-day simple moving average; sell the entire SPY position when price is below that average. Equal values take no action. Do not add another 10 shares every day the threshold remains true.

Create paper/spy-observation.md with the draft ID, exact configuration, intended $10,000 simulated starting capital, activation date and a review date 30 calendar days later. Those are proposed observation inputs, not recorded performance. Historical testing should be reviewed separately before activation.

Ask Codex to call build_portfolio with the complete candidate. Inspect valid, canonical portfolio and each issue path, component and message. Fix issues and preview again. After valid is true and you have reviewed the rule, pass the same JSON to create_portfolio and read the saved draft with get_portfolio. Verify type=chat and isActive=false. Keep the generated JSON and returned ID in the record; a portfolio name containing paper does not establish deployment type.

4. Review the paper deployment operation

Show the actual update_portfolio operation before activation: operations contains a deploy entry whose portfolioId is the newly authored chat draft ID. Deploying a chat draft creates a separate paper book. An existing live ID can reactivate brokerage trading, so verify the draft type immediately before the call.

text
Preview a new candidate with build_portfolio using this rule: Daily SPY long/cash proposal: buy 10 shares only when no SPY position is held and price is above its 200-day simple moving average; sell the entire SPY position when price is below that average. Equal values take no action. Do not add another 10 shares every day the threshold remains true. Inspect valid, issues and canonical portfolio; fix issues and preview again. When valid and reviewed, pass the same JSON to create_portfolio. Save its full JSON and actual returned ID in paper/spy-observation.md. Use get_portfolio to verify type=chat and isActive=false. Show operations with type deploy and portfolioId equal to that chat ID. Wait for my approval. After activation, find the new deployment with fetch_portfolios and read it with get_portfolio. Stop if type is not paper. Do not deploy an existing live ID.

Create and monitor a separate paper deployment

Deploying an existing live portfolio ID can reactivate real brokerage trading. For this workflow use the newly authored chat candidate and verify the returned deployment is paper. The SDK also separates saved draft IDs from deployment.portfolioId.

Preview the candidatebuild_portfolioReview the canonical configuration and fix validation issues before saving
Author the candidatecreate_portfolioA newly authored chat portfolio, not an existing live account
Inspect the targetget_portfolioRead the exact returned ID and strategies before activation
Deploy the chat bookupdate_portfoliooperations: [{type: "deploy", portfolioId: returnedChatId}] creates paper
Find the running bookfetch_portfoliosKeep the resulting deployment ID separately from the original chat/draft ID
Read actual paper historyquery_portfolio_historyThe deployed portfolio curve; never substitute a backtest curve

5. Verify the running identity and capital

After the approved deployment, use fetch_portfolios to find the new running book and get_portfolio on its returned ID. Confirm type=paper, isActive, strategies, initialValue and the returned deployment settings. Record the actual deployment frequency: Constant and OpenClose are evaluation schedules. A Day backtest interval or a day-based moving-average window does not set the paper evaluation cadence. Compare the capital and rules with the approved record before treating the experiment as started. Keep the chat draft ID and running portfolioId separately.

If several portfolios share a name, use returned IDs and the exact strategies rather than selecting by name alone. A transport timeout does not prove deployment failed. Read the account resources before attempting another deploy; duplicate deployments can create separate experiments.

6. Observe recorded paper history and recover

If the server is missing, inspect the selected local MCP configuration. If it requires OAuth, use Authenticate in the app or codex mcp login nexustrade in the CLI. After updating the desktop entry select Restart, then check /mcp. Reopen the saved artifact before continuing a new Codex task; a fresh conversation does not establish which operation was accepted.

Use query_portfolio_history with the verified running portfolio_id for the observation period. It returns recorded time/value points from the deployed book. get_portfolio_performance returns aggregates, while query_backtest_history reads historical simulations; neither replaces the deployed curve.

If history is empty, check type, activation time, active state and whether observations have been recorded. Do not backtest the same rules and label that curve paper performance. Record actual positions, activity and any rule/cash changes beside the curve. At the review date compare behavior with the frozen plan. When the observation ends, review update_portfolio with operations containing type undeploy and portfolioId equal to the verified running paper ID. After the approved pause, call get_portfolio again and require type=paper and isActive=false. Keep the recorded history; pausing does not require deleting the book.

Pause the verified paper book

Replace the placeholder with the running paper ID you have just read with get_portfolio. Submit this operation only after reviewing that identity and approving the pause. Read the same ID afterward and require type=paper and isActive=false.

json
{
  "operations": [
    {
      "type": "undeploy",
      "portfolioId": "<verified-running-paper-id>"
    }
  ]
}

Costs and the next task

The local file and proposed rule are planning artifacts. Research and backtest submissions can consume credits; detailed backtest events increase cost. Check your plan and the proposed operation before submitting. OAuth confirms account access, not that a strategy will succeed.

For live deployment, review the separate broker guide, exact trading account and permissions. This client connection does not prove a native brokerage connector or a completed live workflow.

Continue exploring