Canli Paper Trading

io.github.arhancanli由 GitHub 帳號 arhancanli 發布v0.3.1更新於 Oct 25, 2026

Agent trading on your Alpaca paper account behind pre-trade checks and confirmation tokens.

已驗證STDIO僅桌面金融安全與監控

概覽

AI 產生的概覽

讓助理只能透過盤前檢查、五分鐘確認權杖與緊急停止開關來操作 Alpaca 模擬(paper)帳戶。

可以做什麼
  • 讀取模擬帳戶:淨值、現金、購買力、持倉、未成交委託、市場時鐘、緊急停止開關與委託紀錄的驗證頭
  • 依限額、即時報價、市場時鐘與停止開關預檢委託,全部通過才回傳五分鐘權杖
  • 把目標投資組合權重換算成整股委託(先賣後買)並加以檢查
  • 憑權杖送出已預檢的委託,或依編號取消未成交的模擬委託
  • 驗證檢查與送出所產生的簽章證明,包括以承諾形式呈現的帳戶數字
適用情境
適合讓 AI 助理在保留自有限額、交易時段與停止開關規範的前提下操作 Alpaca 模擬帳戶,例如把模擬投資組合調整到回測得出的目標權重。不適用於真實資金交易。
執行需求
以 stdio 在本機執行,通常透過 npx 啟動,需要 Node.js。需要 Alpaca 帳戶與其模擬 API 金鑰,透過 ALPACA_PAPER_KEY_ID 與 ALPACA_PAPER_SECRET_KEY 提供。限額檔案位於 CANLI_HOME(預設 ~/.canli),並需能連線至 Alpaca 模擬 API。
安裝前請注意
它會在模擬帳戶送出與取消委託,預檢通過後可能真的產生模擬成交;允許範圍由限額檔案與 KILL 檔案控制。API 金鑰從環境變數讀取,只送往 Alpaca。證明是對承諾的簽章而非零知識證明,公開某項承諾即會揭露其數值。模擬成交比真實市場寬鬆。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Canli Paper Trading,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

canli-paper-trading-mcp

Lets an AI agent trade your Alpaca paper account without being able to skip the checks. Every order is previewed against your own limits, the market clock and a kill switch; only orders that pass get a five-minute confirmation token, and only a token can send them. Paper only: the package contains no live trading host, and live keys are refused.

Local stdio. Your keys stay in your environment; nothing goes anywhere except Alpaca's paper API.

Tools

toolwhat it does
paper_accountEquity, cash, buying power, positions, open orders, market clock, kill switch, and the order log's verified head.
preview_paper_ordersRuns the pre-trade checks on your orders with live paper data; returns a token only if every order passes.
rebalance_to_weightsTurns target weights (e.g. from a backtest) into whole-share orders, sells first, checks them, returns a token.
send_paper_ordersSends previewed orders with their token, or cancels open orders by id. The only tool that changes anything.

The checks

The pre-trade checks are canlicapital's shared core (js/pretrade-core.js, mirrored byte for byte and tested in the repository). Per order: kill switch, allowed symbols and order types, market open or closed, price collar, order and daily notional caps, position, gross and net caps against your whole book, reduce-only integrity, and an estimated cost (half spread; commission and impact when you supply fees and volume). A rejection lists every reason; nothing is resized.

Your limits live in CANLI_HOME/limits.json (default ~/.canli), for example:

json
{ "max_order_notional": 10000, "max_position_frac": 0.2, "max_gross": 1.0, "allowed_types": ["limit"] }

A call can tighten these for one preview, never loosen them. While a file named KILL exists in that directory, every preview fails and every send is refused.

Tokens

  • Bound to the exact orders previewed: change a quantity and the token no longer verifies.
  • Single use and valid for five minutes, so a send never acts on stale checks.
  • Signed with a key that lives only in the running server; a restarted server rejects old tokens.
  • Each sent order carries a client_order_id derived from its token. Alpaca refuses a repeated id, so a retried send cannot fill twice.

Order log

Every send and cancel is appended to CANLI_HOME/paper-orders.jsonl, each line holding the hash of the one before. paper_account reports whether the chain still verifies; an edited line breaks it.

Signed attestations and private balances

Every preview, rebalance and send returns an attestation: which orders were checked (their hash), against which limits (their hash), the verdict, the kill switch, the time, and commitments to the account's equity and positions, signed with an Ed25519 key made on your machine the first time (CANLI_HOME/attest-ed25519.pem, mode 0600; it never leaves the machine). Give attest-ed25519.pub.pem to an auditor or counterparty; verify_attestation checks a statement was signed by that key and not altered. On Node 24.7 or later each statement is also signed with an ML-DSA-65 key (FIPS 204, a post-quantum signature; attest-ml-dsa-65.pem), over the same statement naming both keys: give both public keys, and both signatures must hold, so a statement stays unforgeable even if one scheme is broken.

Set CANLI_PAPER_PRIVATE=1 and the model never sees the account's figures: paper_account returns commitments (SHA-256 of a random salt and the value) instead of equity, cash, buying power and positions; rebalance_to_weights sizes orders without showing them; numbers in check messages are blanked. The salts are written only to CANLI_HOME/commitments.jsonl, so you can later open a commitment to someone (show its value and salt) and verify_attestation confirms it.

This is a signature over commitments, not a zero-knowledge proof: whoever you open a value to learns it, and the checks are this server's code. Brokers accept API keys, not proofs; the keys stay in the environment and are never shown to the model in either mode.

Quick start

  1. Create an Alpaca account and open the paper trading dashboard; generate paper API keys (the key id starts with PK).
  2. Add the server with your keys in its environment:
bash
claude mcp add canli-paper -e ALPACA_PAPER_KEY_ID=PK... -e ALPACA_PAPER_SECRET_KEY=... -- npx -y canli-paper-trading-mcp

Then ask: "Rebalance my paper account to 60% SPY and 40% TLT, show me the checks, and send it if everything passes."

Pairs with canli-quant-mcp: backtest a strategy there, then move the paper account to its target weights here.

What this does not do

It does not trade real money, and there is no setting that makes it. It does not decide what to trade. Paper fills are Alpaca's simulation and are kinder than real markets (no queue position, no market impact); a strategy that works on paper has not yet shown it works live.

MIT licence.

來源:mcp-paper/README.md,提交 019682d

工具

5

paper_account

Paper account

Read your Alpaca paper account: equity, cash, buying power, positions, open orders, the market clock, the kill switch and the local order log's verified head.

無需輸入參數。

preview_paper_orders

Preview paper orders

Check orders against your paper account, live quotes, the market clock, your limits file and the kill switch; when every order passes, return a five-minute confirmation token for exactly these orders.

輸入參數feeslimitsorders必填

rebalance_to_weights

Rebalance to weights

Turn target portfolio weights into the whole-share orders that move your paper account there (sells first), check them, and return a confirmation token when all pass.

輸入參數feeslimitsallow_shortcash_buffermin_trade_usdallow_leveragetarget_weights必填liquidate_others

verify_attestation

Verify an attestation

Check an attestation a pre-trade check or send returned: that it was signed by the trader's keys (Ed25519 and, where present, post-quantum ML-DSA-65; both must hold) and not altered, and, given openings from the trader's commitments file, that committed account figures are what they claim. Offline; reads nothing from Alpaca.

輸入參數openingsattestation必填public_key_pempq_public_key_pem

send_paper_orders

Send paper orders

Send previewed orders to your Alpaca paper account with their confirmation token (the kill switch is read again first), or cancel open paper orders by id. Every send is logged, hash-chained.

輸入參數tokencancel_order_ids

版本歷史

1
  1. v0.3.1最新Oct 25, 2026

評分

已滿足適用檢查項的 90%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分
  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具必需15 分
  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分