-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·206 lines (183 loc) · 6.21 KB
/
setup.sh
File metadata and controls
executable file
·206 lines (183 loc) · 6.21 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/bin/bash
# Open Trading Algo Setup Script
# This script provides an alternative to Makefile commands for setting up the repository
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Helper functions
log_info() {
echo -e "${BLUE}ℹ️ $1${NC}"
}
log_success() {
echo -e "${GREEN}✅ $1${NC}"
}
log_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
log_error() {
echo -e "${RED}❌ $1${NC}"
}
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Setup virtual environment
setup_venv() {
log_info "Setting up Python virtual environment..."
if [ ! -d ".venv" ]; then
python3 -m venv .venv
log_success "Virtual environment created"
else
log_info "Virtual environment already exists"
fi
}
# Setup Poetry
setup_poetry() {
log_info "Setting up Poetry..."
if ! command_exists poetry; then
curl -sSL https://install.python-poetry.org | python3 -
export PATH="$HOME/.local/bin:$PATH"
log_success "Poetry installed"
else
log_info "Poetry already installed"
fi
poetry config virtualenvs.in-project true
}
# Setup configuration files
setup_config() {
log_info "Setting up configuration files..."
if [ ! -f "secrets.env" ]; then
cp secrets.env.example secrets.env
log_success "Created secrets.env from template"
log_warning "Please edit secrets.env and add your API keys"
else
log_info "secrets.env already exists"
fi
if [ ! -f ".env" ]; then
cp .env.example .env 2>/dev/null || echo "# Add your environment variables here" > .env
log_success "Created .env file"
else
log_info ".env already exists"
fi
# Create cache directories for different cache types
mkdir -p data/cache/sqlite # For SQLite cache files/metadata
mkdir -p data/cache/parquet # For Parquet columnar cache files
mkdir -p data/cache/influxdb # For InfluxDB cache metadata
mkdir -p logs
log_success "Cache directories created"
}
# Setup SQLite database (main database file, not cache files)
setup_sqlite() {
log_info "Setting up SQLite database..."
# Create the main database file directory if it doesn't exist
mkdir -p data
if [ ! -f "data/tv_data_cache.sqlite3" ]; then
# Create empty database file
touch data/tv_data_cache.sqlite3
log_success "SQLite database file created at data/tv_data_cache.sqlite3"
else
log_info "SQLite database already exists at data/tv_data_cache.sqlite3"
fi
# Note: Actual database table creation happens when DataCache is first used
log_info "Database tables will be created automatically on first use"
}
# Setup InfluxDB
setup_influxdb() {
log_info "Setting up InfluxDB..."
if command_exists docker; then
if [ "$(docker ps -q -f name=influxdb)" ]; then
log_info "InfluxDB container already running"
elif [ "$(docker ps -aq -f status=exited -f name=influxdb)" ]; then
docker start influxdb
log_success "InfluxDB container started"
else
docker run -d --name influxdb -p 8086:8086 influxdb:2.0
log_success "InfluxDB container created and started"
log_info "Waiting for InfluxDB to be ready..."
sleep 5
fi
# Initialize InfluxDB
if curl -X POST http://localhost:8086/api/v2/setup \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "password", "org": "trading", "bucket": "market_data", "token": "my-token"}' 2>/dev/null; then
log_success "InfluxDB initialized"
else
log_warning "Could not initialize InfluxDB (may already be initialized)"
fi
else
log_warning "Docker not found. Please install Docker to use InfluxDB."
log_info "Manual setup: docker run -d --name influxdb -p 8086:8086 influxdb:2.0"
fi
}
# Install dependencies
install_deps() {
log_info "Installing dependencies..."
poetry install
log_success "Dependencies installed"
log_info "Setting up pre-commit hooks..."
poetry run pre-commit install
poetry run pre-commit run --all-files
log_success "Pre-commit hooks configured"
}
# Main setup function
main() {
echo -e "${BLUE}🚀 Open Trading Algo Setup${NC}"
echo "=========================="
echo "This script sets up the repository with the following structure:"
echo " data/tv_data_cache.sqlite3 - Main SQLite database"
echo " data/cache/sqlite/ - SQLite cache files"
echo " data/cache/parquet/ - Parquet cache files"
echo " data/cache/influxdb/ - InfluxDB cache metadata"
echo ""
case "${1:-all}" in
"venv")
setup_venv
;;
"poetry")
setup_poetry
;;
"config")
setup_config
;;
"sqlite")
setup_sqlite
;;
"influxdb")
setup_influxdb
;;
"deps")
install_deps
;;
"all")
setup_venv
setup_poetry
setup_config # Creates cache directories
setup_sqlite # Creates main database file
setup_influxdb
install_deps
log_success "Complete setup finished!"
echo ""
log_info "Next steps:"
echo " 1. Edit secrets.env and add your API keys"
echo " 2. Run: source .venv/bin/activate"
echo " 3. Run: make dev_env"
;;
*)
log_error "Usage: $0 {venv|poetry|config|sqlite|influxdb|deps|all}"
echo " venv - Setup Python virtual environment"
echo " poetry - Setup Poetry package manager"
echo " config - Setup config files and cache directories"
echo " sqlite - Setup main SQLite database file"
echo " influxdb - Setup InfluxDB (requires Docker)"
echo " deps - Install Python dependencies"
echo " all - Complete setup (recommended)"
exit 1
;;
esac
}
# Run main function with all arguments
main "$@"