Skip to content

Commit 4890f67

Browse files
committed
feat(install): add Windows PowerShell installer (install.ps1)
1 parent d391236 commit 4890f67

2 files changed

Lines changed: 173 additions & 2 deletions

File tree

install.ps1

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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 ""

install.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,18 @@ OS=$(uname -s)
5353
case "$OS" in
5454
Linux*) OS="linux" ;;
5555
Darwin*) OS="macos" ;;
56-
MINGW*|MSYS*|CYGWIN*) OS="windows" ;;
56+
MINGW*|MSYS*|CYGWIN*)
57+
OS="windows"
58+
printf '%s\n' ""
59+
printf '%s\n' "${yellow} Windows detected.${reset}"
60+
printf '%s\n' " This shell script works under Git Bash / MSYS2 / Cygwin, but"
61+
printf '%s\n' " the native Windows installer (PowerShell) is recommended:"
62+
printf '%s\n' ""
63+
printf '%s\n' " ${cyan}irm https://raw.githubusercontent.com/tigerfintech/openapi-python-sdk/master/install.ps1 | iex${reset}"
64+
printf '%s\n' ""
65+
printf '%s\n' " Continuing with shell installer..."
66+
printf '%s\n' ""
67+
;;
5768
*) warn "unrecognized OS: $OS — proceeding anyway" ;;
5869
esac
5970

@@ -142,8 +153,10 @@ if [ -z "$TIGEROPEN_BIN" ]; then
142153
"$HOME/.local/bin" \
143154
"$HOME/Library/Python/${PY_VERSION}/bin" \
144155
"$HOME/.local/share/pipx/venvs/tigeropen/bin" \
156+
"$APPDATA/Python/Scripts" \
157+
"$LOCALAPPDATA/Programs/Python/Python${PY_MAJOR}${PY_MINOR}/Scripts" \
145158
; do
146-
if [ -x "$dir/tigeropen" ]; then
159+
if [ -x "$dir/tigeropen" ] || [ -x "$dir/tigeropen.exe" ]; then
147160
TIGEROPEN_BIN="$dir/tigeropen"
148161
break
149162
fi

0 commit comments

Comments
 (0)