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.

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

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.8.67.tar.gz (203.1 kB view details)

Uploaded Source

Built Distribution

driftpy-0.8.67-py3-none-any.whl (248.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: driftpy-0.8.67.tar.gz
  • Upload date:
  • Size: 203.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.10 Linux/6.8.0-1031-azure

File hashes

Hashes for driftpy-0.8.67.tar.gz
Algorithm Hash digest
SHA256 f95419c486ddd7a446c7310e4a9612d3eb95154c598a296995607484ff624bf2
MD5 140fe76be9ae2ba5073e947ffe9faee5
BLAKE2b-256 6768f33e2a27ef5e8f0d673df35c5535e0795444bf32f3a31613fb9729dd3035

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for driftpy-0.8.67-py3-none-any.whl
Algorithm Hash digest
SHA256 debebdc7a59d59c39cc97df778ebb8528aed6b30de62faf81f41d91642d0dd65
MD5 4e44bf0af93b28d3c5e99fb3a3e8de3e
BLAKE2b-256 061ee6cac865a7e5d11df3429e59bfad7beb0fbcc1cc08b64bb2a000e1ac555a

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