Skip to main content

Paste a target-weights CSV, preview the rebalance, execute it on your brokerage account. Tastytrade + Alpaca + IBKR + Schwab + paper.

Project description

msts-trader

Paste a target-weights CSV, preview the rebalance, execute it on your own brokerage account. Multi-broker, local-only, no key custody.

$ msts-trader
Paste CSV (ticker,weight), then Ctrl+D:
ticker,weight
SPY,0.42
GLD,0.18
SHV,0.20
EEM,0.20
^D
✓ loaded 4 targets.

tastytrade · account 5W******  ·  NAV $48,213.42  ·  cash $2,150.00  ·  BP $46,290.00
Market: open  ·  closes in 23 min

           Rebalance preview
┃ Symbol ┃ Current % ┃ Target % ┃   Δ $ ┃ Action                  ┃ Note ┃
┃ SPY    ┃    18.2%  ┃   42.0%  ┃ +$11k ┃ BUY  22.00 @ ~$521.34   ┃      ┃
┃ EEM    ┃    31.5%  ┃   20.0%  ┃  -$5k ┃ SELL 119.00 @ ~$47.21   ┃      ┃
...

Execute 4 orders on tastytrade? [y/N]: y
[1/4] SPY  BUY  22.00 @ MKT ...  ROUTED  id=4f8...

Done.  sent: 4  ·  failed: 0  ·  log: ~/.msts-trader/fills/

Supported brokers

Broker Status Auth Notes
Paper shipped, tested local file $100k starting cash, no real fills, 14 unit tests
Tastytrade shipped, live-tested OAuth refresh token indefinite token, BYO OAuth app
Alpaca shipped, beta API key + secret paper or live, fractional supported, awaiting live-fill confirmation
IBKR shipped, beta TWS / IB Gateway socket pip install "msts-trader[ibkr]", works with local or Dockerised Gateway, awaiting live-fill confirmation
Schwab shipped, beta OAuth2 + browser callback pip install "msts-trader[schwab]", 7-day refresh, awaiting live-fill confirmation

Beta status: Alpaca, IBKR, and Schwab adapters pass structural protocol conformance tests in CI (signatures, attributes, error handling) but have not yet been verified end-to-end against a real brokerage account by the author. Try them in paper mode first, or file an issue with a fill report if you run them live.

Open a GitHub issue if you want one prioritised.

Install

pip install msts-trader

Python ≥3.11 required.

Optional brokers

IBKR and Schwab require extra dependencies. Install them only if you plan to use that broker:

pip install "msts-trader[ibkr]"      # adds ib_insync + nest_asyncio
pip install "msts-trader[schwab]"    # adds schwab-py
pip install "msts-trader[all]"       # everything

Install from source:

git clone https://github.com/markudevelop/msts-trader.git
cd msts-trader
pip install -e ".[all]"

One-time setup

You provide your own broker credentials. They are stored in your OS keychain (macOS Keychain / Windows Credential Manager / libsecret on Linux) and never leave your machine.

Tastytrade

  1. Sign in at https://developer.tastytrade.comMy Apps
  2. Create an OAuth application — copy the provider secret
  3. Run their OAuth authorization flow to obtain a refresh token
  4. Look up your account number in the Tastytrade web dashboard (optional)
  5. Run:
msts-trader login --broker tastytrade

Alpaca

  1. Sign in at https://alpaca.markets (paper or live)
  2. Account → API keys → generate a new pair
  3. Run:
msts-trader login --broker alpaca

You choose paper vs live at login time.

IBKR

pip install "msts-trader[ibkr]"
msts-trader login --broker ibkr

You'll be asked for host, port, and client id of a running TWS or IB Gateway. Defaults:

  • TWS live: 127.0.0.1:7496
  • TWS paper: 127.0.0.1:7497
  • Gateway live: 127.0.0.1:4001
  • Gateway paper: 127.0.0.1:4002
  • Dockerised Gateway: usually 127.0.0.1:4002 (whatever you mapped)

Before logging in, enable Configure → API → Enable ActiveX and Socket Clients in your TWS / Gateway. msts-trader connects, lists your managed accounts, and confirms NAV.

Schwab

pip install "msts-trader[schwab]"
msts-trader login --broker schwab

Requires a Schwab Developer app (https://developer.schwab.com) with the callback URL set to https://127.0.0.1:8182/. msts-trader pops a browser window, you authorize, and the token JSON is written to ~/.msts-trader/schwab_token.json. Schwab refresh tokens expire every 7 days — re-run msts-trader login --broker schwab when that happens.

Paper (offline simulator)

msts-trader login --broker paper

No real money, no broker connection. The book persists in ~/.msts-trader/paper_state.json between sessions. Reset any time with msts-trader paper-reset.

The first login you complete becomes the default broker. Override per command with --broker NAME, or change the default by logging in again.

Daily usage

  1. Get your CSV. Click Copy CSV on the supported weights site, or build your own:

    ticker,weight
    SPY,0.42
    GLD,0.18
    EEM,0.20
    SHV,0.20
    
    • weight is a fraction (0–1), not a percent.
    • Sum should be ≤ 1.0 (the remainder is held as cash).
    • Comments starting with # are ignored.
  2. Run:

msts-trader                       # uses default broker
msts-trader --broker alpaca       # explicit broker
  1. Paste the CSV, hit Ctrl+D (Ctrl+Z then Enter on Windows).
  2. Review the preview carefully.
  3. Type y to execute, anything else to cancel.

Useful flags

msts-trader rebalance --dry-run                       # preview only, never sends
msts-trader rebalance --yes                           # skip the confirm prompt
msts-trader rebalance --threshold 0.02                # tighter rebalance (default 4%)
msts-trader rebalance --csv-file targets.csv          # read from a file
msts-trader --broker paper rebalance --csv-file ...   # test against paper

Other commands

msts-trader status                  # NAV, positions, market status (default broker)
msts-trader --broker alpaca status  # other broker
msts-trader brokers                 # list supported + configured brokers
msts-trader logout --broker alpaca  # clear stored creds for one broker
msts-trader paper-reset             # reset paper book to starting cash
msts-trader --version

What it does

  • Parses your CSV into {ticker: target_weight}.
  • Pulls live NAV, cash, buying power, and current positions from your broker.
  • Quotes every relevant symbol via the broker's market-data API.
  • Computes the dollar delta per ticker, skips anything within the drift threshold (default 4% of NAV).
  • Sells tickers no longer in your targets.
  • Sizes buys at the current quote, rounded to 2 decimals where the broker supports fractional MARKET orders.
  • Shows the full plan and waits for y before sending anything.
  • Submits MARKET DAY orders. Logs results to ~/.msts-trader/fills/.

What it does NOT do (v0.2)

  • Pre-market or after-hours execution. Refuses outside 09:30–16:00 ET.
  • Shorting. Negative weights are rejected.
  • Options, futures, crypto.
  • Multi-account or per-strategy ledger.
  • Active stop management (Hydra/Fusion-style watchers).
  • Automatic CSV polling. You paste each rebalance manually.

Troubleshooting

Can't paste or type during msts-trader login in VS Code / Cursor?

VS Code and Cursor's integrated terminals don't always forward input to hidden-password prompts (Python's getpass returns immediately without reading). msts-trader detects this and falls back to visible input with a warning, so you can still paste your secrets — they'll just be displayed as you type.

If you'd rather not have them displayed at all, three workarounds:

  1. Run from a real terminal. Open Terminal.app (macOS), iTerm, or Windows Terminal and run msts-trader login --broker tastytrade there. Hidden input works correctly outside VS Code.
  2. Use environment variables to skip the prompts entirely:
    export TT_PROVIDER_SECRET="..."
    export TT_REFRESH_TOKEN="..."
    export TT_ACCOUNT_ID="..."
    msts-trader login --broker tastytrade
    
    Equivalents for other brokers: APCA_API_KEY_ID / APCA_API_SECRET_KEY / APCA_PAPER (Alpaca), IBKR_HOST / IBKR_PORT / IBKR_CLIENT_ID / IBKR_ACCOUNT_ID (IBKR), SCHWAB_APP_KEY / SCHWAB_APP_SECRET / SCHWAB_CALLBACK_URL (Schwab), PAPER_STARTING_CASH (paper).
  3. Pipe the values in. When stdin isn't a TTY, msts-trader reads each prompt as a single line, so:
    printf '%s\n%s\n%s\n' "$SECRET" "$TOKEN" "$ACCT" | msts-trader login --broker tastytrade
    

Security

  • Your broker credentials live only in your OS keychain on your own machine. The app does not phone home, does not log credentials, and is not connected to any service operated by the author.
  • The author of this app cannot view, recover, or revoke your broker access. Revoke via your own broker's API-app dashboard if a key leaks.
  • Trades are user-initiated: every execution requires you to paste a CSV and confirm with y. There is no background trading loop.

Disclaimer

This tool sends real orders to your live brokerage account. You are responsible for the CSV you paste and the rebalance you confirm. Past performance of any signal source is not indicative of future results. The author makes no warranty of any kind; use at your own risk.

Development

git clone https://github.com/markudevelop/msts-trader.git
cd msts-trader
pip install -e ".[all,dev]"
pytest -v          # 95 tests, ~2 seconds
ruff check msts_trader

The test suite covers:

  • CSV parser (header validation, weights, comments, dup/neg/>1 guards)
  • Diff math (drift threshold, exits, warnings, blockers, BP overrun)
  • Market hours (RTH/pre/after/closed, holidays through 2027, weekends)
  • Paper broker end-to-end (cash accounting, position lifecycle, dry-run, persistence)
  • Broker protocol conformance (every adapter exposes the required attrs + methods)
  • Keychain (save/load/clear, default broker, broker enumeration)
  • CLI (help, version, brokers list, paper login, no-creds clean exit)

Live brokerage adapters (Tastytrade, Alpaca, IBKR, Schwab) are not exercised against real APIs in CI — they need credentials and can move real money. The tests verify structure; you verify fills.

License

PolyForm Noncommercial License 1.0.0.

You may use, modify, and share this software for any noncommercial purpose — personal trading, research, education, hobby projects. Selling, hosting as a paid service, or otherwise commercializing this software or derivative works is not permitted without a separate commercial license. Contact the author if you need one.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

msts_trader-0.3.4.tar.gz (40.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

msts_trader-0.3.4-py3-none-any.whl (35.9 kB view details)

Uploaded Python 3

File details

Details for the file msts_trader-0.3.4.tar.gz.

File metadata

  • Download URL: msts_trader-0.3.4.tar.gz
  • Upload date:
  • Size: 40.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for msts_trader-0.3.4.tar.gz
Algorithm Hash digest
SHA256 c02a976d6b247f15b549762140f6628aca53ee345a80530e8b7d49f48b3174da
MD5 82da1bf778e45457cb8acf68dc75e8f7
BLAKE2b-256 125281c78753cfdd50d60e41a92362b16f99f78612218c696ed4a7f37b848f8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for msts_trader-0.3.4.tar.gz:

Publisher: release.yml on markudevelop/msts-trader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file msts_trader-0.3.4-py3-none-any.whl.

File metadata

  • Download URL: msts_trader-0.3.4-py3-none-any.whl
  • Upload date:
  • Size: 35.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for msts_trader-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 fc9923d4852045d14dedba532e1d693e7e2fb7ccdc29f39190db5d1774c5fd14
MD5 788274a42b2ee454db84ad9a110f718d
BLAKE2b-256 e9af30e18c3308106fdafc13ee9473d38df1b6783ba2e7a7ffd48ef4beabf2bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for msts_trader-0.3.4-py3-none-any.whl:

Publisher: release.yml on markudevelop/msts-trader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page