Coder Social home page Coder Social logo

driftpy's Introduction

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

driftpy's People

Contributors

0xnineteen avatar 0xbigz avatar soundsonacid avatar crispheaney avatar kevinheavey avatar wphan avatar 3thereum avatar tanwaarpornthip avatar ymittal avatar this-username-is-taken avatar tarasmi avatar r-k-h avatar khalidmustafin avatar mcclurejt avatar ljump12 avatar alen-qn avatar 0xsumatt avatar

Watchers

 avatar

Forkers

reid-garner

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.