Metadata-Version: 2.4
Name: msts-trader
Version: 0.3.0
Summary: Paste a target-weights CSV, preview the rebalance, execute it on your brokerage account. Tastytrade + Alpaca + IBKR + Schwab + paper.
Author: markudevelop
License: # PolyForm Noncommercial License 1.0.0
        
        <https://polyformproject.org/licenses/noncommercial/1.0.0>
        
        ## Acceptance
        
        In order to get any license under these terms, you must agree
        to them as both strict obligations and conditions to all
        your licenses.
        
        ## Copyright License
        
        The licensor grants you a copyright license for the
        software to do everything you might do with the software
        that would otherwise infringe the licensor's copyright
        in it for any permitted purpose. However, you may
        only distribute the software according to [Distribution
        License](#distribution-license) and make changes or new works
        based on the software according to [Changes and New Works
        License](#changes-and-new-works-license).
        
        ## Distribution License
        
        The licensor grants you an additional copyright license
        to distribute copies of the software. Your license
        to distribute covers distributing the software with
        any changes or new works or data you make or have made.
        
        ## Notices
        
        You must ensure that anyone who gets a copy of any part of
        the software from you also gets a copy of these terms or the
        URL for them above, as well as copies of any plain-text lines
        beginning with `Required Notice:` that the licensor provided
        with the software. For example:
        
        > Required Notice: Copyright markudevelop (https://github.com/markudevelop/msts-trader)
        
        ## Changes and New Works License
        
        The licensor grants you the copyright licenses in
        [Copyright License](#copyright-license) for changes and
        new works based on the software you may make, provided
        that you make every change and new work for a permitted
        purpose, and that you keep these terms applied to any
        part of the software you change or use to make a new work.
        
        ## Patent License
        
        The licensor grants you a patent license for the software that
        covers patent claims the licensor can license, or becomes able
        to license, that you would infringe by using the software.
        
        ## Noncommercial Purposes
        
        Any noncommercial purpose is a permitted purpose.
        
        ## Personal Uses
        
        Personal use for research, experiment, and testing for
        the benefit of public knowledge, personal study, private
        entertainment, hobby projects, amateur pursuits, or religious
        observance, without any anticipated commercial application,
        is use for a permitted purpose.
        
        ## Noncommercial Organizations
        
        Use by any charitable organization, educational institution,
        public research organization, public safety or health
        organization, environmental protection organization,
        or government institution is use for a permitted purpose
        regardless of the source of funding or obligations resulting
        from the funding.
        
        ## Fair Use
        
        You may have "fair use" rights for the software under the
        law. These terms do not limit them.
        
        ## No Other Rights
        
        These terms do not allow you to sublicense or transfer any of
        your licenses to anyone else, or prevent the licensor from
        granting licenses to anyone else.  These terms do not imply
        any other licenses.
        
        ## Patent Defense
        
        If you make any written claim that the software infringes or
        contributes to infringement of any patent, your patent license
        for the software granted under these terms ends immediately. If
        your company makes such a claim, your patent license ends
        immediately for work on behalf of your company.
        
        ## Violations
        
        The first time you are notified in writing that you have
        violated any of these terms, or done anything with the software
        not covered by your licenses, your licenses can nonetheless
        continue if you come into full compliance with these terms,
        and take practical steps to correct past violations, within
        32 days of receiving notice.  Otherwise, all your licenses
        end immediately.
        
        ## No Liability
        
        ***As far as the law allows, the software comes as is, without
        any warranty or condition, and the licensor will not be liable
        to you for any damages arising out of these terms or the use
        or nature of the software, under any kind of legal claim.***
        
        ## Definitions
        
        The **licensor** is the individual or entity offering these
        terms, and the **software** is the software the licensor makes
        available under these terms.
        
        **You** refers to the individual or entity agreeing to these
        terms.
        
        **Your company** is any legal entity, sole proprietorship,
        or other kind of organization that you work for, plus all
        organizations that have control over, are under the control of,
        or are under common control with that organization.  **Control**
        means ownership of substantially all the assets of an entity,
        or the power to direct its management and policies by vote,
        contract, or otherwise.  Control can be direct or indirect.
        
        **Your licenses** are all the licenses granted to you for the
        software under these terms.
        
        **Use** means anything you do with the software requiring one
        of your licenses.
        
        ---
        
        Required Notice: Copyright (c) 2026 markudevelop (https://github.com/markudevelop/msts-trader)
        
Project-URL: Homepage, https://github.com/markudevelop/msts-trader
Project-URL: Issues, https://github.com/markudevelop/msts-trader/issues
Keywords: trading,tastytrade,alpaca,ibkr,schwab,rebalance,portfolio,cli
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: License :: Free for non-commercial use
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: tastytrade==11.0.4
Requires-Dist: alpaca-py>=0.30
Requires-Dist: click>=8.1
Requires-Dist: rich>=13.7
Requires-Dist: keyring>=24
Requires-Dist: pydantic>=2.5
Requires-Dist: python-dateutil>=2.9
Provides-Extra: ibkr
Requires-Dist: ib_insync>=0.9.86; extra == "ibkr"
Requires-Dist: nest_asyncio>=1.6; extra == "ibkr"
Provides-Extra: schwab
Requires-Dist: schwab-py>=1.4; extra == "schwab"
Provides-Extra: all
Requires-Dist: ib_insync>=0.9.86; extra == "all"
Requires-Dist: nest_asyncio>=1.6; extra == "all"
Requires-Dist: schwab-py>=1.4; extra == "all"
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: ruff>=0.5; extra == "dev"
Dynamic: license-file

# 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  | local file               | $100k starting cash, no real fills |
| Tastytrade | shipped  | OAuth refresh token       | indefinite token, BYO OAuth app |
| Alpaca     | shipped  | API key + secret         | paper or live, fractional supported |
| IBKR       | shipped  | TWS / IB Gateway socket  | needs `pip install msts-trader[ibkr]`; works with your local Gateway / Dockerised Gateway |
| Schwab     | shipped  | OAuth2 + browser callback | needs `pip install msts-trader[schwab]`; 7-day refresh token |

Open a GitHub issue if you want one prioritised.

## Install

```bash
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:

```bash
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:

```bash
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.com → **My 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:

```bash
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:

```bash
msts-trader login --broker alpaca
```

You choose paper vs live at login time.

### IBKR

```bash
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

```bash
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)

```bash
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:

   ```csv
   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:

```bash
msts-trader                       # uses default broker
msts-trader --broker alpaca       # explicit broker
```

3. Paste the CSV, hit `Ctrl+D` (`Ctrl+Z` then Enter on Windows).
4. Review the preview carefully.
5. Type `y` to execute, anything else to cancel.

### Useful flags

```bash
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

```bash
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.

## 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.

## License

[PolyForm Noncommercial License 1.0.0](LICENSE).

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.
