> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fcontext.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CLI

> fcontext terminal CLI で Financial Context 市場データを使用する

ターミナルから `fcontext` を使用して Financial Context 市場データを照会し、サインインを管理し、スクリプトや agent 向けに JSON を出力します。

CLI はデフォルトで Financial Context に接続します。

```text theme={null}
https://openapi.fcontext.com
```

コマンドは `/api/market-data/*` 配下の読み取り専用市場データエンドポイントを呼び出します。現在の CLI は US 株式データにフォーカスしており、シンボルは `CODE.US` 形式、market フィルターは `US` である必要があります。

## コマンドの基本

どちらのコマンド名も使用できます。`fctx` は `fcontext` の短いエイリアスで、同じサブコマンド、flag、出力形式、schema をサポートします。

```bash theme={null}
fcontext quote AAPL.US MSFT.US --format json
fctx quote AAPL.US MSFT.US --format json
```

## インストール

<Tabs>
  <Tab title="macOS (Homebrew)">
    Aitaport tap から `fcontext-terminal` cask をインストールします。

    ```bash theme={null}
    brew install --cask aitaport/tap/fcontext-terminal
    ```
  </Tab>

  <Tab title="Linux / macOS (Script)">
    ホストされた shell インストーラーを使用します。

    ```bash theme={null}
    curl -sSL https://fcontext.com/fcontext/fcontext-terminal/install | sh
    ```
  </Tab>

  <Tab title="Windows (Scoop)">
    ホストされた `fcontext.json` Scoop manifest からインストールします。

    ```powershell theme={null}
    scoop install https://fcontext.com/fcontext/fcontext-terminal/fcontext.json
    ```
  </Tab>

  <Tab title="Windows (PowerShell)">
    ホストされた PowerShell インストーラーを使用します。

    ```powershell theme={null}
    iwr https://fcontext.com/fcontext/fcontext-terminal/install.ps1 | iex
    ```
  </Tab>
</Tabs>

<Note>
  Release artifact は terminal プロジェクトの `fcontext-terminal-*` パッケージ名を使用します。
  `fcontext-terminal-darwin-amd64.tar.gz`、`fcontext-terminal-darwin-arm64.tar.gz`、
  `fcontext-terminal-linux-musl-amd64.tar.gz`、`fcontext-terminal-linux-musl-arm64.tar.gz`、
  `fcontext-terminal-windows-amd64.zip` が含まれます。shell と PowerShell のインストーラーは対応するアーカイブをダウンロードし、
  `.sha256` checksum を検証して、`fcontext` と `fctx` の両方をインストールします。
</Note>

## 認証

CLI 認証を管理します。サインイン、サインアウト、ローカル token 状態の確認ができます。

### OAuth 2.0 ログイン

OAuth 2.0 authorization-code flow でサインインします。CLI が認可 URL と次に実行するコマンドを表示するため、ローカルターミナル、SSH session、headless server で利用できます。

```bash theme={null}
fcontext auth login
```

表示された認可 URL を任意のブラウザで開き、認可を完了して返された code をコピーし、次のように引き換えます。

```bash theme={null}
fcontext auth login --auth-code YOUR_CODE
```

CLI は token をローカルの fcontext 設定ディレクトリに `oauth-token.json` として保存します。以降のコマンドはその token を自動的に再利用します。

### Authorization Code

現在のマシンでブラウザを使えない場合は、Financial Context Connect から一回限りの authorization code を生成して直接引き換えます。

```bash theme={null}
fcontext auth login --auth-code YOUR_CODE
```

### ログアウト

ローカルに保存された OAuth token を削除します。次の認証済みコマンドでは再ログインが必要です。

```bash theme={null}
fcontext auth logout
```

### 認証ステータス

現在の base URL とサインイン状態を確認します。

```bash theme={null}
fcontext auth status
fcontext auth status --format json
```

## チェック

アクティブな市場セッションに依存せず、サインインと Financial Context API 接続性を検証します。レポートには endpoint ステータスとレイテンシが含まれます。

```bash theme={null}
fcontext check
fcontext check --format json
fctx check --format json
```

## 更新

公式インストーラースクリプトをダウンロードして実行し、現在の CLI binary を最新リリースに置き換えます。

```bash theme={null}
fcontext update
fctx update
```

## 最初のコマンド

```bash theme={null}
# リアルタイムクォート
fcontext quote AAPL.US MSFT.US

# 短いエイリアス
fctx quote AAPL.US MSFT.US

# スクリプトと agent 向け JSON 出力
fcontext quote AAPL.US MSFT.US --format json

# 静的な証券情報
fcontext static AAPL.US MSFT.US

# 日足ローソク足
fcontext kline AAPL.US --period day --count 100

# 日付範囲で過去ローソク足を取得
fcontext kline history AAPL.US --start 2024-01-01 --end 2024-12-31
```

## 市場データ

```bash theme={null}
fcontext market-status
fcontext top-movers --market US --sort hot --count 20
fcontext market-temp US
fcontext market-temp US --history --start 2024-01-01 --end 2024-12-31
fcontext trading session
fcontext trading days US --start 2026-01-01 --end 2026-01-31
fcontext security-list US
```

`fear-greed` を使用すると Fear & Greed Index を確認できます。これは投資家のリスク選好を extreme fear から extreme greed までの尺度で要約する市場センチメント指標です。

```bash theme={null}
fcontext fear-greed
fcontext fear-greed --history-count 90 --indicator-history-count 10 --format json
```

## 企業データ

```bash theme={null}
fcontext company AAPL.US
fcontext fundamental-compare AAPL.US
fcontext compare AAPL.US MSFT.US NVDA.US --currency USD
fcontext consensus AAPL.US
fcontext dividend AAPL.US
fcontext forecast-eps AAPL.US
fcontext insider-trades AAPL.US --count 20
fcontext institution-rating AAPL.US
fcontext institution-rating detail AAPL.US
fcontext operating AAPL.US
fcontext shareholder AAPL.US
fcontext shareholder AAPL.US --top --periods 4
fcontext valuation AAPL.US
fcontext valuation AAPL.US --history
```

## ニュースとイベント

```bash theme={null}
fcontext news AAPL.US
fcontext filing AAPL.US
fcontext topic AAPL.US
fcontext finance-calendar report --market US
fcontext finance-calendar dividend --market US
```

## 取引アクティビティ

```bash theme={null}
fcontext trades AAPL.US --count 50
fcontext trade-stats AAPL.US
fcontext short-positions AAPL.US
fcontext short-trades AAPL.US
```

## スクリーナー

```bash theme={null}
fcontext screener strategies --market US
fcontext screener mine --market US
fcontext screener strategy 19
fcontext screener run 19 --count 20
fcontext screener filter pettm:10:50 roe:5: --market US
fcontext screener indicators
```

## エンドポイントへの直接アクセス

専用コマンドがまだないサポート済みの読み取り専用エンドポイントには、`api get` を使用します。

```bash theme={null}
fcontext api get /api/market-data/market/status --format json
```

CLI はリクエスト送信前に、絶対 URL、streaming endpoint、US 以外の market フィルター、サポートされていないアカウントまたは取引パスを拒否します。

## Agent 向け出力

すべてのコマンドは JSON 出力をサポートします。

```bash theme={null}
fcontext company AAPL.US --format json
```

`--schema` で機械可読なレスポンス schema を出力します。

```bash theme={null}
fcontext company --schema
fcontext quote --schema
fctx quote --schema
```

shell completions を生成します。

```bash theme={null}
fcontext completion zsh > ~/.zfunc/_fcontext
fcontext completion bash > ~/.local/share/bash-completion/completions/fcontext
fcontext completion fish > ~/.config/fish/completions/fcontext.fish
```

## トラブルシューティング

| 問題                             | 確認すること                                                                                                 |
| ------------------------------ | ------------------------------------------------------------------------------------------------------ |
| `Missing fcontext credentials` | `fcontext auth login` を実行するか、`fcontext auth login --auth-code YOUR_CODE` で authorization code を引き換えます。 |
| `fcontext API error (401)`     | `fcontext auth status` を実行し、ローカル token がない、または期限切れの場合は `fcontext auth login` で再度サインインします。              |
| US 以外の symbol が拒否される           | `AAPL.US` のような symbol を使用します。CLI は意図的に US 以外の市場を公開していません。                                              |
| リクエスト詳細が必要                     | `--verbose` を追加すると、リクエスト URL と経過時間が stderr に出力されます。                                                    |
