A Python client for the Drift DEX
Project description
DriftPy
DriftPy is the Python client for the Drift protocol. It allows you to trade and fetch data from Drift using Python.
Read the full SDK documentation here!
Installation
pip install driftpy
Note: requires Python >= 3.10.
⚠️ IMPORTANT ⚠️
If you are using QuickNode free plan, you must use AccountSubscriptionConfig("demo")
, and you can only subscribe to 1 perp market and 1 spot market at a time.
Non-QuickNode free RPCs (including the public mainnet-beta url) can use cached
as well.
Example setup for AccountSubscriptionConfig("demo")
:
# This example will listen to perp markets 0 & 1 and spot market 0
# If you are listening to any perp markets, you must listen to spot market 0 or the SDK will break
perp_markets = [0, 1]
spot_market_oracle_infos, perp_market_oracle_infos, spot_market_indexes = get_markets_and_oracles(perp_markets = perp_markets)
oracle_infos = spot_market_oracle_infos + perp_market_oracle_infos
drift_client = DriftClient(
connection,
wallet,
"mainnet",
perp_market_indexes = perp_markets,
spot_market_indexes = spot_market_indexes,
oracle_infos = oracle_infos,
account_subscription = AccountSubscriptionConfig("demo"),
)
await drift_client.subscribe()
If you intend to use AccountSubscriptionConfig("demo)
, you must call get_markets_and_oracles
to get the information you need.
get_markets_and_oracles
will return all the necessary OracleInfo
s and market_indexes
in order to use the SDK.
SDK Examples
examples/
folder includes more examples of how to use the SDK including how to provide liquidity/become an lp, stake in the insurance fund, etc.
Setting Up Dev Env
bash setup.sh
Development
Ensure correct python version (using pyenv is recommended):
pyenv install 3.10.11
pyenv global 3.10.11
poetry env use $(pyenv which python)
Install dependencies:
poetry install
Run tests:
poetry run bash test-scripts/integration_test.sh
poetry run bash test-scripts/math_tests.sh
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
File details
Details for the file driftpy-0.7.82.tar.gz
.
File metadata
- Download URL: driftpy-0.7.82.tar.gz
- Upload date:
- Size: 141.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.10.10 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8c46205ca12b9cde5ef80089f9fe14fbd30235bf1d91f01e09deb3822a4f8c8 |
|
MD5 | bd8e11a7e6ed10a6de12456b5b57cc7e |
|
BLAKE2b-256 | 31e060f6333f0da797f9141f1be3a92267063ec660e33a823d7431e5f40f4abe |
File details
Details for the file driftpy-0.7.82-py3-none-any.whl
.
File metadata
- Download URL: driftpy-0.7.82-py3-none-any.whl
- Upload date:
- Size: 174.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.10.10 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e1aeb27a659ec345d9ed5434ab542ce41adbac617c258034f7c0e0833a6dd55 |
|
MD5 | 0f07ca48a43663f91e833f5187606eb4 |
|
BLAKE2b-256 | f47a9e309e4265da462948e4cdbfba67406969e9e3346614351f49b2c87afc9d |