Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/drift-labs/driftpy
python sdk to interact with drift v2
https://github.com/drift-labs/driftpy
python solana
Last synced: about 1 month ago
JSON representation
python sdk to interact with drift v2
- Host: GitHub
- URL: https://github.com/drift-labs/driftpy
- Owner: drift-labs
- Created: 2022-01-18T18:11:23.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-02T18:31:46.000Z (about 2 months ago)
- Last Synced: 2024-08-03T16:12:06.777Z (about 1 month ago)
- Topics: python, solana
- Language: Python
- Homepage: https://drift-2.gitbook.io/driftpy-for-dummies/
- Size: 2.88 MB
- Stars: 56
- Watchers: 3
- Forks: 37
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# DriftPy
DriftPy is the Python client for the [Drift](https://www.drift.trade/) protocol. It allows you to trade and fetch data from Drift using Python.
**[Read the full SDK documentation here!](https://drift-labs.github.io/v2-teacher/)**
## 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 breakperp_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
```