Skip to main content

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 OracleInfos 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

Building the docs

Local Docs: mkdocs serve

Updating public docs: poetry run mkdocs gh-deploy --force

Releasing a new version of the package

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.sh

Run Acceptance Tests

poetry run bash acceptance_test.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

driftpy-0.7.48.tar.gz (136.3 kB view details)

Uploaded Source

Built Distribution

driftpy-0.7.48-py3-none-any.whl (167.5 kB view details)

Uploaded Python 3

File details

Details for the file driftpy-0.7.48.tar.gz.

File metadata

  • Download URL: driftpy-0.7.48.tar.gz
  • Upload date:
  • Size: 136.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.10 Linux/6.5.0-1017-azure

File hashes

Hashes for driftpy-0.7.48.tar.gz
Algorithm Hash digest
SHA256 915bea3cbdca03fe63ff2afbfb8675c31930fff4feca68e313c00265bb92f7ec
MD5 59675c39249143755859b6c052b9a70e
BLAKE2b-256 707c36704295b41349983f4c09cf7302d3be27207fe7b028b3e62f90ca41f91a

See more details on using hashes here.

File details

Details for the file driftpy-0.7.48-py3-none-any.whl.

File metadata

  • Download URL: driftpy-0.7.48-py3-none-any.whl
  • Upload date:
  • Size: 167.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.10 Linux/6.5.0-1017-azure

File hashes

Hashes for driftpy-0.7.48-py3-none-any.whl
Algorithm Hash digest
SHA256 fccd4827caa171a08ee205d723b12b2eabf6e13da2e2b5a882b64443408097aa
MD5 94a91015a2db896e5f3281e8f58a3270
BLAKE2b-256 28d280b0461024d23d5f3afb1cc8608e747838f50d564b86a512bfdb89076381

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page