Skip to main content

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.

Full Documentation

CLI Tool Demo

Here is a quick demonstration of the CLI functionality:

Demo of CLI tools

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:

  1. Register at derive.xyz to get your LightAccount wallet
  2. Create a subaccount
  3. Register a session key (regular Ethereum private key for an EOA) as session key via the Developers page
  4. Copy .env.template to .env and 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

📖 Full 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

Karrenbelt
Zarathustra
8ball030
8ball030
Aviksaikat
Saikat K
0xBoringWozniak
xboringwozniak
andreiaugustin
Andrei Augustin
0xdomrom
DomRom
DeBelg
Mf

Supporting This Project

This client library is developed and maintained as an independent open-source project. When you use this library to trade on Derive, we may receive a small referral bonus (configured via the referral_code field in API requests). This helps sustain ongoing development and maintenance. We also set a default client identifier to help Derive track usage statistics across different client implementations. All code is open source and can be audited in this repository.

Metadata

Release files for derive-client 0.3.16

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for derive-client 0.3.16
File Size Uploaded Provenance Actions
derive_client-0.3.16.tar.gz 394.3 kB Without provenance Details for derive_client-0.3.16.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for derive-client 0.3.16
File Interpreter ABI Platform Actions
derive_client-0.3.16-py3-none-any.whl Python 3 none any Details for derive_client-0.3.16-py3-none-any.whl

Total release size: 1.1 MB

Release files / derive_client-0.3.16.tar.gz

Download URL derive_client-0.3.16.tar.gz
Size 394.3 kB
Tags Source
SHA-256 checksum
How to use checksums
20f38b6235977a1b43fc30af4f3a710cfbcc989d907a56e1de347f32bc4d9ad3
BLAKE2b-256 checksum
How to use checksums
3db2e7067b567222d46ab4ba51d70d496ab0f26e13308d66c85bf3fdf41d6400
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / derive_client-0.3.16-py3-none-any.whl

Download URL derive_client-0.3.16-py3-none-any.whl
Size 707.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3bd5a934ba8381588b8412eec17ae4fd20bfe964d4772bf881ac86d2845f74ea
BLAKE2b-256 checksum
How to use checksums
1141bb56f7e45d86192d8ea8ba2b2946ad9eed017085641e8edefb23b795afac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for derive-client 0.3.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.16 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page