File size: 2,975 Bytes
3cfd4fb
 
 
1a2d125
4508d2e
 
3cfd4fb
 
 
 
 
4d2df04
 
 
e1128ec
 
3cfd4fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e4043cb
3cfd4fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4d2df04
 
e2e5ea7
4d2df04
 
 
e2e5ea7
4d2df04
e4043cb
 
 
 
e1128ec
 
 
 
8f253b3
 
 
 
 
 
e1128ec
4d2df04
 
 
 
3cfd4fb
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
#!/bin/bash
set -e

STOCKEX_VERSION="2.3.0"
echo "===== StockEx v${STOCKEX_VERSION} β€” Application Startup at $(date '+%Y-%m-%d %H:%M:%S') ====="

KAFKA_DIR=/opt/kafka

export PYTHONPATH=/app
export KAFKA_BOOTSTRAP=localhost:9092
export MATCHER_URL=http://localhost:6000
export PORT=5000
export FIX_CONFIG=/app/fix_ui/client_hf.cfg
export UI_PORT=5002
export FRONTEND_PORT=5003
export FRONTEND_URL=/frontend/

# ── Kafka (KRaft) ─────────────────────────────────────────────────────────────
echo "[startup] Formatting Kafka storage (KRaft)..."
CLUSTER_ID=$($KAFKA_DIR/bin/kafka-storage.sh random-uuid)
$KAFKA_DIR/bin/kafka-storage.sh format \
  -t "$CLUSTER_ID" \
  -c $KAFKA_DIR/config/kraft/server.properties \
  --ignore-formatted

echo "[startup] Starting Kafka..."
$KAFKA_DIR/bin/kafka-server-start.sh $KAFKA_DIR/config/kraft/server.properties &
KAFKA_PID=$!

echo "[startup] Waiting for Kafka to be ready..."
RETRIES=30
until $KAFKA_DIR/bin/kafka-topics.sh \
      --list --bootstrap-server localhost:9092 &>/dev/null 2>&1; do
  RETRIES=$((RETRIES - 1))
  if [ $RETRIES -le 0 ]; then
    echo "[startup] ERROR: Kafka did not start in time"
    exit 1
  fi
  sleep 3
  echo "[startup] Still waiting for Kafka... ($RETRIES retries left)"
done
echo "[startup] Kafka ready."

# Create topics
for TOPIC in orders trades snapshots control ai_insights; do
  $KAFKA_DIR/bin/kafka-topics.sh \
    --create --if-not-exists \
    --topic "$TOPIC" \
    --partitions 1 \
    --replication-factor 1 \
    --bootstrap-server localhost:9092
done
echo "[startup] Topics created."

# ── Python services ────────────────────────────────────────────────────────────
echo "[startup] Starting Matcher on port 6000..."
python3 /app/matcher.py &
sleep 8

echo "[startup] Starting MD Feeder..."
python3 /app/mdf_simulator.py &

echo "[startup] Starting FIX OEG on port 5001..."
(cd /app/fix_oeg && python3 /app/fix_oeg/fix_oeg_server.py) &
sleep 6

echo "[startup] Starting FIX UI Client on port 5002..."
python3 /app/fix_ui/fix_ui_client.py &
sleep 3

echo "[startup] Starting AI Analyst (interval=1800s)..."
python3 /app/ai_analyst.py &
sleep 1

echo "[startup] Starting Frontend on port 5003..."
PORT=$FRONTEND_PORT TEMPLATE_FOLDER=/app/frontend_templates python3 /app/frontend.py &
sleep 2

echo "[startup] Starting Clearing House on port 5004..."
CH_PORT=5004 CH_SERVICE_URL=http://localhost:5004 \
  MATCHER_URL=http://localhost:6000 \
  PYTHONPATH=/app python3 /app/clearing_house/app.py &
sleep 3

# ── nginx (reverse proxy: port 7860 β†’ dashboard:5000 + fix-ui:5002 + frontend:5003) ──
echo "[startup] Starting nginx on port 7860..."
nginx

echo "[startup] Starting Dashboard on port 5000..."
exec python3 /app/dashboard.py