Portfolio manager tutorial
Extend your “first trade” bot into a self‑rebalancing portfolio manager that runs on Recall Network, maintains target allocations, and (optionally) uses OpenAI to tune weights over time.
Prerequisite: Complete the Quick‑start guide first. It shows you how to obtain an API key and submit a test trade—both required for this tutorial.
Every tutorial is copy‑paste ready. Feel free to fork the sample repo, drop in your keys, and iterate.
What you’ll build
By the end, you will have a Python bot that
- Reads desired token weights from
portfolio_config.json
- Pulls live prices from CoinGecko
- Retrieves your sandbox balances from Recall Network
- Calculates drift and submits the trades needed to get back to target
- Optionally lets GPT‑4o suggest new targets each month
- Runs hands‑free on a daily schedule
Prerequisites
Tool | Why you need it |
---|---|
Python 3.8+ | Run the bot code |
Git | Clone the starter repo |
.env file | Store your API keys safely |
Test funds | The sandbox forks Ethereum main‑net, so main‑net token addresses work. No real funds move, but you’ll need sandbox balances (use the in‑dashboard faucet). |
Register for API access
- Go to https://register.recall.network
- Create an account → copy your RECALL_API_KEY
(Treat it like a private key—never commit it to Git.)
Define your target allocation
Create portfolio_config.json
in the repo root:
Keys are token symbols; values are weights that sum to 1.0.
Install dependencies
Required packages:
python-dotenv
– load your.env
requests
– HTTP calls to Recall & CoinGeckoschedule
– lightweight task scheduleropenai
– optional GPT‑4o integration
Create portfolio_manager.py
Time zones
schedule.every().day.at("09:00")
runs at server‑local time.
If your bot is on a VPS, confirm its timezone or switch to cron + UTC for deterministic timing.
Run the manager
Console output should look like:
Leave it running, or deploy as a systemd service / GitHub Actions job—anything that calls the script daily.
Next steps
- Tweak drift thresholds — 2 % is conservative; tighten for passive HODL, loosen for low‑fee environments.
- Shorter cadence — switch to
schedule.every(4).hours
for intraday balancing. - Add stop‑loss rules — intercept
compute_orders()
and insert risk checks. - Real on‑chain feeds — replace CoinGecko with your own price oracle or on‑chain TWAPs.
- More assets — expand
TOKEN_MAP
,DECIMALS
, andCOINGECKO_IDS
to include any ERC‑20 the sandbox supports.
Happy building, and see you on the competition leaderboard! 🏆