etrade
by jasonfeliz
README.md
# etrade
MCP server and command-line client for the [official E*TRADE developer API](https://developer.etrade.com/).
It signs OAuth 1.0a requests and calls the documented account, balance, portfolio, quote, and order preview, place, and cancel resources. It does not decide what to trade. You supply a developer key. This repository contains no keys and no tokens.
Details of the endpoints, base URLs, and limits are in [docs/API.md](docs/API.md).
## Requirements
- Node.js 22.18 or newer
- An E*TRADE account and a consumer key from [developer.etrade.com](https://developer.etrade.com/)
- Sandbox keys come from [the sandbox key page](https://us.etrade.com/etx/ris/apikey). Production keys are a separate pair. An individual key works only with the E*TRADE user it was issued to.
The default environment is sandbox (`https://apisb.etrade.com`). Sandbox responses are stored samples and do not execute a market trade.
## Install
```bash
git clone https://github.com/jasonfeliz/etrade.git
cd etrade
npm install
npm test
npm run build
```
Run the CLI from the checkout:
```bash
node dist/cli.js --help
```
Or link it onto your `PATH`:
```bash
npm link
etrade --help
```
## Credentials
Export these in your shell. A template with empty values is in `.env.example`. Do not commit a filled-in copy.
| Variable | Used for |
| --- | --- |
| `ETRADE_ENV` | `sandbox` (default) or `production` |
| `ETRADE_CONSUMER_KEY` | Consumer key |
| `ETRADE_CONSUMER_SECRET` | Consumer secret |
| `ETRADE_ACCESS_TOKEN` | Access token, after login |
| `ETRADE_ACCESS_TOKEN_SECRET` | Access token secret, after login |
| `ETRADE_REQUEST_TOKEN` | Request token, only until login finishes |
| `ETRADE_REQUEST_TOKEN_SECRET` | Request token secret, only until login finishes |
If a command needs a variable that is missing or blank, it exits with an error that names the variable. It does not print values that are already set.
```bash
export ETRADE_ENV=sandbox
export ETRADE_CONSUMER_KEY="your key"
export ETRADE_CONSUMER_SECRET="your secret"
etrade auth login
# Open the printed authorizeUrl, approve access, and copy the verification code.
export ETRADE_REQUEST_TOKEN="printed request token"
export ETRADE_REQUEST_TOKEN_SECRET="printed request token secret"
etrade auth complete --verifier CODE
export ETRADE_ACCESS_TOKEN="printed access token"
export ETRADE_ACCESS_TOKEN_SECRET="printed access token secret"
```
`auth login` can be completed in the same process by passing the request token on the command line instead of exporting it:
```bash
etrade auth complete --verifier CODE --request-token REQ --request-token-secret SECRET
```
The access token expires at midnight US Eastern. If it sits unused for two hours it goes inactive; `etrade auth renew` reactivates it and does not mint a new token. `etrade auth revoke` invalidates it. `etrade auth status` reports which variables are set and does not call E*TRADE.
## CLI
```bash
etrade accounts
etrade balance --account ACCOUNT_ID_KEY
etrade balance --account ACCOUNT_ID_KEY --realtime --account-type CASH
etrade positions --account ACCOUNT_ID_KEY --view QUICK
etrade quotes AAPL MSFT --detail FUNDAMENTAL
etrade orders list --account ACCOUNT_ID_KEY --status OPEN
etrade orders preview --account ACCOUNT_ID_KEY \
--symbol AAPL --action BUY --quantity 10 --price-type LIMIT \
--limit-price 188.51 --client-order-id sdfer333
etrade orders place --account ACCOUNT_ID_KEY \
--symbol AAPL --action BUY --quantity 10 --price-type LIMIT \
--limit-price 188.51 --client-order-id sdfer333 \
--preview-id PREVIEW_ID
etrade orders cancel --account ACCOUNT_ID_KEY --order-id ORDER_ID
```
`portfolio` is an alias of `positions`.
Equity flags build the single-stock `PreviewOrderRequest` / `PlaceOrderRequest` JSON from the official samples. For any other order, pass the documented JSON body:
```bash
etrade orders preview --account ACCOUNT_ID_KEY --file preview.json
etrade orders place --account ACCOUNT_ID_KEY --file place.json
```
`--file` and equity flags cannot be combined. Place and cancel against `ETRADE_ENV=production` require `--yes`, because those calls can submit or cancel a live order. The preview id from a preview must be used within 3 minutes, and the place request has to match that preview.
Successful responses are JSON on stdout. Errors go to stderr and the process exits 1.
## MCP server
The server speaks MCP over stdio. Point your client at the built CLI:
```json
{
"mcpServers": {
"etrade": {
"command": "node",
"args": ["/absolute/path/to/etrade/dist/cli.js", "mcp"],
"env": {
"ETRADE_ENV": "sandbox",
"ETRADE_CONSUMER_KEY": "",
"ETRADE_CONSUMER_SECRET": "",
"ETRADE_ACCESS_TOKEN": "",
"ETRADE_ACCESS_TOKEN_SECRET": ""
}
}
}
}
```
After `npm link`, `command` can be `etrade` and `args` can be `["mcp"]`.
Do not write real keys into a file you commit. Leave the values empty in shared config and inject them from your environment, or fill them only in a private client config.
Tools:
| Tool | What it calls |
| --- | --- |
| `etrade_auth_status` | Local check of which variables are set |
| `etrade_auth_login_start` | Get Request Token, returns the authorize URL |
| `etrade_auth_login_complete` | Get Access Token |
| `etrade_auth_renew` | Renew Access Token |
| `etrade_auth_revoke` | Revoke Access Token |
| `etrade_accounts` | List Accounts |
| `etrade_balance` | Account balance |
| `etrade_positions` | Portfolio |
| `etrade_quotes` | Quotes |
| `etrade_orders_list` | List Orders |
| `etrade_order_preview` | Preview Order |
| `etrade_order_place` | Place Order (`confirm` must be true) |
| `etrade_order_cancel` | Cancel Order (`confirm` must be true) |
Place and cancel refuse to run until `confirm` is true. With `ETRADE_ENV=production` they act on a live account.
The server writes the MCP protocol to stdout. Do not wrap it in a logger that also writes to stdout.
## Tests
```bash
npm test
```
Tests cover OAuth signing against the signature example in the E*TRADE developer guide, URL construction, and CLI parsing. They use fixtures and a mock HTTP client. They do not call E*TRADE.
## License
MIT. See [LICENSE](LICENSE).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessOutdated data