Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,31 @@ Obtain your `client_id` and `client_secret` from Schwab, then save to `auth/clie
}
```

### 2. Fetch Data and Generate Chart
### 2. Start the Main Loop and Dashboard

Run the main loop, which will fetch data and automatically launch the Streamlit dashboard:

```bash
python main.py
```

This will:
- Authenticate with Schwab (browser login on first run)
- Fetch account positions and option prices
- Fetch account positions and option prices on each iteration
- Generate `data/gantt.png` showing position timelines
- Cache data locally in `data/positions.json` and `data/tracking.json`
- **Launch the Streamlit dashboard at `http://localhost:8501` after the first data fetch**
- Refresh data every 60 seconds; dashboard reflects updates on page reload

### Running the Dashboard Standalone

### 3. View the Dashboard
If you want to run the dashboard independently:

```bash
streamlit run streamlit_app.py
streamlit run dash.py
```

Opens an interactive dashboard at `http://localhost:8501` showing the Gantt chart and values table.
This reads cached data from the `data/` folder (generated by `main.py`).

## Testing

Expand Down
File renamed without changes.
26 changes: 25 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import subprocess
import sys
import time

import auth
Expand All @@ -25,6 +27,8 @@ def main() -> None:
tokens = auth.get_or_create_tokens()

iteration = 0
streamlit_process = None

try:
while True:
# Check if token needs refreshing
Expand All @@ -44,10 +48,30 @@ def main() -> None:
data.update_tracking()
plot.make_gantt_chart()

# Launch Streamlit dashboard after first iteration
if iteration == 0:
print("Launching Streamlit dashboard (dash.py)...")
try:
streamlit_process = subprocess.Popen(
[sys.executable, "-m", "streamlit", "run", "dash.py", "--logger.level=warning"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
print("Dashboard running at http://localhost:8501")
except Exception as exc:
print(f"Failed to launch Streamlit: {exc}")

iteration += 1
time.sleep(60)
except KeyboardInterrupt:
print("Stopped by user.")
print("\nStopped by user.")
if streamlit_process:
print("Shutting down Streamlit dashboard...")
streamlit_process.terminate()
try:
streamlit_process.wait(timeout=5)
except subprocess.TimeoutExpired:
streamlit_process.kill()


if __name__ == "__main__":
Expand Down
Loading