No project description provided
Project description
Derive Client
Python client for Derive Protocol - a decentralized derivatives trading platform on its own Ethereum L2
Trade options, perpetuals, and spot with full self-custody through smart contract wallets.
CLI Tool Demo
Here is a quick demonstration of the CLI functionality:
Installation from PyPI
pip install derive-client
Quickstart
Create .env file
DERIVE_SESSION_KEY=0x2ae8be44db8a590d20bffbe3b6872df9b569147d3bf6801a35a28281a4816bbd
DERIVE_WALLET=0xA419f70C696a4b449a4A24F92e955D91482d44e9
DERIVE_SUBACCOUNT_ID=137626
DERIVE_ENV=TEST
Setup client, check market data and place an order.
from derive_client import HTTPClient
from derive_client.data_types import D, Direction, OrderType
# Initialize client
client = HTTPClient.from_env()
# Check market data
ticker = client.markets.get_ticker(instrument_name="ETH-PERP")
# Place an order
order_result = client.orders.create(
instrument_name="ETH-PERP",
amount=D("0.10"), # 0.10 ETH
limit_price=D("1000"), # Buy at $1000
direction=Direction.buy,
order_type=OrderType.limit,
)
Examples
The fastest way to learn is by running the examples:
# Clone the repo (examples are not included in the package)
git clone git@github.com:8ball030/derive_client.git
cd derive_client
# Install editable with pip
pip install -e .
# Run with testnet credentials (pre-configured)
python examples/01_quickstart.py
The examples use .env.template with pre-filled testnet credentials, so you can run them immediately without setup.
- 01_quickstart.py - Connect and Place Your First Trade
- 02_market_data.py - Exploring Available Markets and Price Information
- 03_collateral_management.py - Deposits, Withdrawals, and Margin.
- 04_trading_basics.py - Order Lifecycle and Management
- 05_position_transfer.py - Moving Positions Between Subaccounts
- 06_bridging.py - Moving Assets Between Chains
NOTE: The bridging example cannot be ran using the TEST environment, as bridging is only available in PROD.
Using Your Own Account
To trade on mainnet or with your own testnet account:
- Register at derive.xyz to get your LightAccount wallet
- Create a subaccount
- Register a session key (regular Ethereum private key for an EOA) as session key via the Developers page
- 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
See authentication.md for a more detailed explanation.
Documentation
- Concepts - Account model, authentication, bridging, clients
- API Reference - Public API documentation
- Internal API - Internal API documentation
Development
From Source (for development)
git clone git@github.com:8ball030/derive_client.git
cd derive_client
# Install and spawn the virtual environment
make install
poetry shell
Quick Commands
make fmt # Format code
make lint # Run linters
make typecheck # Type checking
make tests # Run tests
Code Generation
make codegen-all
API Docs Generation
make docs
Or, run all the above make commands sequentially using simply:
make all
Releasing
Bump version and create release:
export new_version=0.1.5
tbump $new_version
The release workflow will automatically create a GitHub release and publish to PyPI.
Contributors
|
Zarathustra |
8ball030 |
Saikat K |
Andrei Augustin |
DomRom |
Mf |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file derive_client-0.3.6.tar.gz.
File metadata
- Download URL: derive_client-0.3.6.tar.gz
- Upload date:
- Size: 366.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ad9d655371af2a330780de1a9abee90cab7ded4c55a20619580ff53c18efd55
|
|
| MD5 |
0d3da55fb97a89ef155c345f69cea1bc
|
|
| BLAKE2b-256 |
2ac04e88d4eb796eed600822b3a85b76beecf698297274dd4cc2ef93460eb818
|
File details
Details for the file derive_client-0.3.6-py3-none-any.whl.
File metadata
- Download URL: derive_client-0.3.6-py3-none-any.whl
- Upload date:
- Size: 681.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7c86eeed265696f367aa3220f05859b5e812cdd8587bb2ac94f8ebc528fb800
|
|
| MD5 |
d9271fce5741938b4fca2beb13cedaa7
|
|
| BLAKE2b-256 |
dfee8e2ec77801ec43af461f8059373dda21fcd8fcb171e7a4dd3c87b3408378
|