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.
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.
Note on using QuickNode
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 OracleInfos and market_indexes in order to use the SDK.
Development
Setting Up Dev Env
bash setup.sh
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
To run tests, first ensure you have set up the RPC url, then run pytest:
export MAINNET_RPC_ENDPOINT="<YOUR_RPC_URL>"
export DEVNET_RPC_ENDPOINT="https://api.devnet.solana.com" # or your own RPC
poetry run pytest -v -s -x tests/ci/*.py
poetry run pytest -v -s tests/math/*.py
Metadata
Release files for driftpy 0.8.89
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| driftpy-0.8.89.tar.gz | 213.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| driftpy-0.8.89-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 474.8 kB
Release files / driftpy-0.8.89.tar.gz
| Download URL | driftpy-0.8.89.tar.gz |
|---|---|
| Size | 213.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
54503f8ff855c28f23d7c43404d978ce025fe46813cf9330a8933e832be8563f
|
|
BLAKE2b-256 checksum How to use checksums |
395dd3987708ea3fce00595635344557b851995e1b45e0f7c93abc276e549e2a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.2 CPython/3.10.10 Linux/6.14.0-1017-azure
|
Release files / driftpy-0.8.89-py3-none-any.whl
| Download URL | driftpy-0.8.89-py3-none-any.whl |
|---|---|
| Size | 261.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8734263981ee9e0fa4de3eeb65abb211e6c0fdad6f8de979415e0a3202cb2fa4
|
|
BLAKE2b-256 checksum How to use checksums |
599cb73c42d9750784fc4f6da99d5067130bc8f86a81ea8356011638685759da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.2 CPython/3.10.10 Linux/6.14.0-1017-azure
|