|
| 1 | +# Tiger Open API Python SDK — Windows Installer (PowerShell) |
| 2 | +# |
| 3 | +# Usage: |
| 4 | +# irm https://raw.githubusercontent.com/tigerfintech/openapi-python-sdk/master/install.ps1 | iex |
| 5 | +# |
| 6 | +# Options (via environment variables): |
| 7 | +# $env:TIGEROPEN_INSTALL_METHOD = "uv" -- force install method (uv|pipx|pip) |
| 8 | +# $env:TIGEROPEN_NO_MODIFY_PATH = "1" -- skip PATH modification |
| 9 | + |
| 10 | +$ErrorActionPreference = "Stop" |
| 11 | + |
| 12 | +# ─── Colors ────────────────────────────────────────────────────────────────── |
| 13 | + |
| 14 | +function Write-Info { param($msg) Write-Host "info: $msg" -ForegroundColor Green } |
| 15 | +function Write-Warn { param($msg) Write-Host "warn: $msg" -ForegroundColor Yellow } |
| 16 | +function Write-Err { param($msg) Write-Host "error: $msg" -ForegroundColor Red; exit 1 } |
| 17 | + |
| 18 | +function Has-Command { param($cmd) return [bool](Get-Command $cmd -ErrorAction SilentlyContinue) } |
| 19 | + |
| 20 | +# ─── Banner ────────────────────────────────────────────────────────────────── |
| 21 | + |
| 22 | +Write-Host "" |
| 23 | +Write-Host " Tiger Open API Python SDK Installer" -ForegroundColor Cyan |
| 24 | +Write-Host " ─────────────────────────────────────" |
| 25 | +Write-Host "" |
| 26 | + |
| 27 | +# ─── Python Detection ──────────────────────────────────────────────────────── |
| 28 | + |
| 29 | +$PYTHON = $null |
| 30 | +foreach ($candidate in @("python", "python3", "py")) { |
| 31 | + if (Has-Command $candidate) { |
| 32 | + $PYTHON = $candidate |
| 33 | + break |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +if (-not $PYTHON) { |
| 38 | + Write-Err "Python not found. Install Python 3.8+ first:`n https://www.python.org/downloads/`n Or: winget install Python.Python.3" |
| 39 | +} |
| 40 | + |
| 41 | +$PY_VERSION = & $PYTHON -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')" 2>$null |
| 42 | +$PY_MAJOR = & $PYTHON -c "import sys; print(sys.version_info.major)" 2>$null |
| 43 | +$PY_MINOR = & $PYTHON -c "import sys; print(sys.version_info.minor)" 2>$null |
| 44 | + |
| 45 | +if (-not $PY_VERSION) { Write-Err "Could not determine Python version" } |
| 46 | +if ([int]$PY_MAJOR -lt 3 -or ([int]$PY_MAJOR -eq 3 -and [int]$PY_MINOR -lt 8)) { |
| 47 | + Write-Err "Python 3.8+ required, found $PY_VERSION" |
| 48 | +} |
| 49 | + |
| 50 | +Write-Info "Found Python $PY_VERSION ($PYTHON)" |
| 51 | + |
| 52 | +# ─── Choose Install Method ─────────────────────────────────────────────────── |
| 53 | + |
| 54 | +$METHOD = $env:TIGEROPEN_INSTALL_METHOD |
| 55 | + |
| 56 | +if (-not $METHOD) { |
| 57 | + if (Has-Command "uv") { $METHOD = "uv" } |
| 58 | + elseif (Has-Command "pipx") { $METHOD = "pipx" } |
| 59 | + else { $METHOD = "pip" } |
| 60 | +} |
| 61 | + |
| 62 | +Write-Info "Install method: $METHOD" |
| 63 | + |
| 64 | +# ─── Install ───────────────────────────────────────────────────────────────── |
| 65 | + |
| 66 | +switch ($METHOD) { |
| 67 | + "uv" { |
| 68 | + if (-not (Has-Command "uv")) { Write-Err "uv not found. Install with: irm https://astral.sh/uv/install.ps1 | iex" } |
| 69 | + Write-Info "Installing tigeropen via uv..." |
| 70 | + & uv pip install tigeropen --upgrade |
| 71 | + } |
| 72 | + "pipx" { |
| 73 | + if (-not (Has-Command "pipx")) { Write-Err "pipx not found. Install with: pip install pipx" } |
| 74 | + Write-Info "Installing tigeropen via pipx..." |
| 75 | + & pipx install tigeropen --force |
| 76 | + } |
| 77 | + "pip" { |
| 78 | + Write-Info "Installing tigeropen via pip..." |
| 79 | + & $PYTHON -m pip install tigeropen --upgrade |
| 80 | + } |
| 81 | + default { |
| 82 | + Write-Err "Unknown install method: $METHOD (use uv, pipx, or pip)" |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +# ─── Verify Installation ───────────────────────────────────────────────────── |
| 87 | + |
| 88 | +$SDK_VERSION = & $PYTHON -c "from tigeropen import __VERSION__; print(__VERSION__)" 2>$null |
| 89 | +if (-not $SDK_VERSION) { |
| 90 | + Write-Err "Installation failed — could not import tigeropen" |
| 91 | +} |
| 92 | + |
| 93 | +Write-Info "tigeropen v$SDK_VERSION installed successfully" |
| 94 | + |
| 95 | +# ─── PATH Setup ────────────────────────────────────────────────────────────── |
| 96 | + |
| 97 | +if ($env:TIGEROPEN_NO_MODIFY_PATH -ne "1") { |
| 98 | + $TIGEROPEN_BIN = Get-Command "tigeropen" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source |
| 99 | + |
| 100 | + if (-not $TIGEROPEN_BIN) { |
| 101 | + # Check common pip/uv install locations on Windows |
| 102 | + $candidates = @( |
| 103 | + "$env:APPDATA\Python\Scripts\tigeropen.exe", |
| 104 | + "$env:LOCALAPPDATA\Programs\Python\Python$($PY_MAJOR)$($PY_MINOR)\Scripts\tigeropen.exe", |
| 105 | + "$env:LOCALAPPDATA\Programs\Python\Python$($PY_MAJOR)$($PY_MINOR.PadLeft(2,'0'))\Scripts\tigeropen.exe" |
| 106 | + ) |
| 107 | + foreach ($path in $candidates) { |
| 108 | + if (Test-Path $path) { |
| 109 | + $TIGEROPEN_BIN = $path |
| 110 | + break |
| 111 | + } |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + if ($TIGEROPEN_BIN) { |
| 116 | + Write-Info "CLI installed at: $TIGEROPEN_BIN" |
| 117 | + $BIN_DIR = Split-Path $TIGEROPEN_BIN |
| 118 | + |
| 119 | + # Check if already in PATH |
| 120 | + $currentPath = [Environment]::GetEnvironmentVariable("PATH", "User") |
| 121 | + if ($currentPath -notlike "*$BIN_DIR*") { |
| 122 | + [Environment]::SetEnvironmentVariable("PATH", "$BIN_DIR;$currentPath", "User") |
| 123 | + Write-Info "Added $BIN_DIR to user PATH" |
| 124 | + Write-Warn "Restart your terminal (or open a new PowerShell window) for PATH changes to take effect" |
| 125 | + } |
| 126 | + } else { |
| 127 | + Write-Warn "tigeropen installed but CLI not found on PATH" |
| 128 | + Write-Warn "You may need to add pip's Scripts directory to your PATH manually" |
| 129 | + Write-Warn "Run: & $PYTHON -m site --user-site (then look for the Scripts sibling dir)" |
| 130 | + } |
| 131 | +} |
| 132 | + |
| 133 | +# ─── Success Message ───────────────────────────────────────────────────────── |
| 134 | + |
| 135 | +Write-Host "" |
| 136 | +Write-Host " Installation complete!" -ForegroundColor Green |
| 137 | +Write-Host "" |
| 138 | +Write-Host " Getting started:" |
| 139 | +Write-Host "" |
| 140 | +Write-Host " # Set up your API credentials" -ForegroundColor Cyan |
| 141 | +Write-Host " tigeropen config init" |
| 142 | +Write-Host "" |
| 143 | +Write-Host " # Or set environment variables" -ForegroundColor Cyan |
| 144 | +Write-Host " `$env:TIGEROPEN_TIGER_ID = 'your_tiger_id'" |
| 145 | +Write-Host " `$env:TIGEROPEN_PRIVATE_KEY = 'your_private_key'" |
| 146 | +Write-Host " `$env:TIGEROPEN_ACCOUNT = 'your_account'" |
| 147 | +Write-Host "" |
| 148 | +Write-Host " # Query market data" -ForegroundColor Cyan |
| 149 | +Write-Host " tigeropen quote briefs AAPL TSLA" |
| 150 | +Write-Host " tigeropen quote bars AAPL --period day --limit 10" |
| 151 | +Write-Host "" |
| 152 | +Write-Host " # Manage orders" -ForegroundColor Cyan |
| 153 | +Write-Host " tigeropen trade order list" |
| 154 | +Write-Host " tigeropen account assets" |
| 155 | +Write-Host "" |
| 156 | +Write-Host " Documentation: https://docs.itigerup.com/docs/" -ForegroundColor Cyan |
| 157 | +Write-Host " GitHub: https://github.com/tigerfintech/openapi-python-sdk" -ForegroundColor Cyan |
| 158 | +Write-Host "" |
0 commit comments