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