# Synology KIS Data Collection Setup

This note answers how to run:

```powershell
$env:KIS_APP_Key="..."
$env:KIS_APP_Secret="..."
python tools/run_kis_data_collection_v1.py --input-json GatherTradingData.json --sqlite-db src/quant_engine/kis_data_collection.db --output-json Temp/kis_data_collection_v1.json --kis-account real
```

on Synology DSM.

## Rule

Synology is Linux-based, so use `export` or a sourced env file. Do not use Windows `$env:` syntax.

The code reads these exact, case-sensitive names for real accounts:

- `KIS_APP_Key`
- `KIS_APP_Secret`

For mock accounts, the names are:

- `KIS_APP_Key_TEST`
- `KIS_APP_Secret_TEST`

## Recommended DSM Task Scheduler script

Create a `User-defined script` task and run:

```bash
#!/bin/sh
set -eu

ROOT_DIR="/volume1/projects/data_feed"

export KIS_APP_Key="your_real_app_key"
export KIS_APP_Secret="your_real_app_secret"

cd "$ROOT_DIR"
python tools/run_kis_data_collection_v1.py \
  --input-json GatherTradingData.json \
  --sqlite-db src/quant_engine/kis_data_collection.db \
  --output-json Temp/kis_data_collection_v1.json \
  --kis-account real
```

## Better practice for secrets

Store secrets in a private env file and source it from the task:

```bash
set -eu
ROOT_DIR="/volume1/projects/data_feed"
SECRETS_FILE="/volume1/projects/data_feed/.secrets/kis_real.env"

. "$SECRETS_FILE"
cd "$ROOT_DIR"
python tools/run_kis_data_collection_v1.py \
  --input-json GatherTradingData.json \
  --sqlite-db src/quant_engine/kis_data_collection.db \
  --output-json Temp/kis_data_collection_v1.json \
  --kis-account real
```

Suggested file permissions:

- owner-only read/write
- no shared group access
- no commit to git

## Mock account variant

```bash
export KIS_APP_Key_TEST="your_mock_app_key"
export KIS_APP_Secret_TEST="your_mock_app_secret"
python tools/run_kis_data_collection_v1.py \
  --input-json GatherTradingData.json \
  --sqlite-db src/quant_engine/kis_data_collection.db \
  --output-json Temp/kis_data_collection_v1.json \
  --kis-account mock \
  --no-live-kis
```

## What the collector writes

- SQLite: `src/quant_engine/kis_data_collection.db`
- JSON summary: `Temp/kis_data_collection_v1.json`

The latest collected summary in this workspace shows:

- `row_count = 25`
- `kis_open_api = 21`
- `gathertradingdata_json = 25`

