Examples
Examples¶
The best way to learn Derive is by running the example scripts. All examples are complete, runnable Python scripts with detailed comments.
Prerequisites¶
The examples use .env.template with pre-configured testnet credentials - you can run them immediately without setup!
git clone git@github.com:8ball030/derive_client.git
cd derive_client
python examples/01_quickstart.py
Example Scripts¶
01_quickstart.py¶
Your first trade in 5 minutes
Learn how to:
- Set up the client
- Check your balance
- View available markets
- Place a simple order
- Check order status
02_market_data.py¶
Real-time market data
Learn how to:
- Discovering available currencies and instruments
- Finding trading opportunities (bid-ask spreads)
- Monitoring market conditions across assets
- Comparing perpetual vs option markets
03_collateral_management.py¶
Manage your collateral
Learn how to:
- Viewing current collateral balances
- Depositing assets from LightAccount to subaccount
- Withdrawing assets from subaccount to LightAccount
- Checking margin requirements
- Simulating collateral changes (what-if scenarios)
04_trading_basics.py¶
Advanced order types and strategies
Learn how to:
- Placing different order types (limit, market, post-only)
- Modifying orders (replace)
- Cancelling orders (single, batch, by label)
- Monitoring order status and fills
- Viewing trade history
05_position_transfer.py¶
Transfer positions between subaccounts
Learn how to:
- Viewing positions across multiple subaccounts
- Transferring a single position between subaccounts
- Batch transferring multiple positions
- Simulating margin impact before transfers
- Viewing collateral distribution after transfers
06_bridging.py¶
Bridge assets to Derive L2
Learn how to:
- Bridging native ETH from Mainnet to Derive EOA (for gas)
- Depositing ERC20 assets to Derive LightAccount
- Withdrawing ERC20 assets from Derive LightAccount to external chains
Using Your Own Account¶
To trade on mainnet or with your own testnet account:
- Register at derive.xyz
- Create a session key at app.derive.xyz/developers
- Copy
.env.templateto.envand add your credentials:
DERIVE_WALLET=0x... # Your LightAccount address
DERIVE_SESSION_KEY=0x... # Session key private key
DERIVE_SUBACCOUNT_ID=1 # Your subaccount ID
DERIVE_ENV=PROD # TEST or PROD
Next Steps¶
- Need conceptual background? Read the Concepts guides
- Want API details? See the API Reference
- Have questions? Check GitHub Issues