CLI program that uses the IBKR Client Portal Gateway a Google Sheet to automatically invest in a given portfolio.
- trader.py — main entry
- ibkr_api.py — IBKR client
- googlesheets_api.py — Google Sheets client
- Place the IBKR Client Portal Gateway extracted folder
clientportal.gwin the project root (next to trader.py). The script expects a Windows batch atclientportal.gw/bin/run.batand config atclientportal.gw/root/conf.yaml. - Create a Google Cloud OAuth client and download the credentials file as
google-credentials.jsoninto the project root. See https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment for information. - Create
google-sheet-id.jsonin the project root containing your sheet id, e.g.:{"sheet-id":"1NEy3d-eQ_s_aUt4VNxqYHkhbW1Y67ZaRCw-NsZVWBD0"} - Install Python dependencies (google-auth, google-auth-oauthlib, google-api-python-client, requests). Example:
pip install google-auth google-auth-oauthlib google-api-python-client requests
- Start the script:
python trader.py - The script will launch the local IBKR gateway process from clientportal.gw and prompt you to open the login URL. After you log in, press Enter when prompted.
- The script will:
- Read available funds and current positions from IBKR,
- Write 90% of available funds to the sheet
- Update positions and validate sheet values by comparing the calculated market values in the sheet with the actual values from IBKR,
- fetch calculated purchases,
- then send the order requests to IBKR-
The first Google login will open a browser and save tokens to token.json for subsequent runs.