Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: drift-labs/driftpy
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.7.42
Choose a base ref
...
head repository: drift-labs/driftpy
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Mar 21, 2024

  1. frank/0.7.43 (#150)

    * fixes
    
    * 0.7.43
    soundsonacid authored Mar 21, 2024
    Copy the full SHA
    5789e55 View commit details

Commits on Mar 27, 2024

  1. Copy the full SHA
    5abe350 View commit details
  2. Copy the full SHA
    8877df5 View commit details

Commits on Apr 3, 2024

  1. Copy the full SHA
    360c197 View commit details
  2. Copy the full SHA
    ec7db12 View commit details

Commits on Apr 5, 2024

  1. Copy the full SHA
    5540db0 View commit details
  2. frank/0.7.46 (#153)

    soundsonacid authored Apr 5, 2024
    Copy the full SHA
    059e8fa View commit details
  3. frank/0.7.46

    soundsonacid authored Apr 5, 2024
    Copy the full SHA
    adcc773 View commit details
  4. frank/0.7.46

    soundsonacid authored Apr 5, 2024
    Copy the full SHA
    7f24dea View commit details

Commits on Apr 9, 2024

  1. frank/user stats map (#89)

    * feat: user stats map
    
    * chore: remove unnecessary async
    
    * fix: default factory for order params defaults
    soundsonacid authored Apr 9, 2024
    Copy the full SHA
    45cd32e View commit details
  2. frank/0.7.47 (#155)

    soundsonacid authored Apr 9, 2024
    Copy the full SHA
    94f7b08 View commit details

Commits on Apr 11, 2024

  1. sdk: update market-constants

    0xbigz committed Apr 11, 2024
    Copy the full SHA
    6403ba5 View commit details

Commits on May 15, 2024

  1. frank/0.7.49 (#160)

    soundsonacid authored May 15, 2024
    Copy the full SHA
    97537d1 View commit details
  2. frank/update requirements.txt (#161)

    * 0.7.49
    
    * update requirements.txt
    soundsonacid authored May 15, 2024
    Copy the full SHA
    503c9be View commit details
  3. frank/0.7.50 (#162)

    soundsonacid authored May 15, 2024
    Copy the full SHA
    2216fee View commit details

Commits on May 16, 2024

  1. Copy the full SHA
    784fc8c View commit details
  2. Copy the full SHA
    17f1a8c View commit details

Commits on May 22, 2024

  1. frank/sequencer support (#163)

    * sequencer support
    
    * remove debug print
    
    * fix sequencer logic bug
    
    * add some guardrails
    
    * sequencing per subaccount
    
    * remove this
    
    * remove comment
    soundsonacid authored May 22, 2024
    Copy the full SHA
    73f9c1a View commit details
  2. 0.7.52 (#164)

    soundsonacid authored May 22, 2024
    Copy the full SHA
    05b31df View commit details

Commits on May 29, 2024

  1. Copy the full SHA
    2ad9e0a View commit details

Commits on Jun 11, 2024

  1. Copy the full SHA
    792ec07 View commit details

Commits on Jun 12, 2024

  1. frank/usermap pickle (#168)

    * usermap dump/load
    
    * remove debug print
    
    * compress user data
    soundsonacid authored Jun 12, 2024
    Copy the full SHA
    0c4ae2a View commit details
  2. Copy the full SHA
    f6db8ac View commit details
  3. Copy the full SHA
    84ad89b View commit details

Commits on Jun 14, 2024

  1. vat (#169)

    soundsonacid authored Jun 14, 2024
    Copy the full SHA
    b46ac92 View commit details

Commits on Jun 17, 2024

  1. Copy the full SHA
    83892c4 View commit details
  2. frank/0.7.56 (#171)

    soundsonacid authored Jun 17, 2024
    Copy the full SHA
    eca8cdd View commit details

Commits on Jun 18, 2024

  1. frank/pyth pull (#172)

    soundsonacid authored Jun 18, 2024
    Copy the full SHA
    cd96778 View commit details
  2. frank/0.7.57 (#173)

    soundsonacid authored Jun 18, 2024
    Copy the full SHA
    76428e2 View commit details
  3. frank/resurrection (#175)

    * 0.7.57
    
    * resurrect unpickle into working sdk
    
    * resurrect unpickle into working sdk
    soundsonacid authored Jun 18, 2024
    Copy the full SHA
    6568bb9 View commit details
  4. frank/fix resurrection (#176)

    * fix resurrection
    
    * bump version
    soundsonacid authored Jun 18, 2024
    Copy the full SHA
    e9e687a View commit details

Commits on Jun 19, 2024

  1. Copy the full SHA
    d22d583 View commit details

Commits on Jun 20, 2024

  1. Copy the full SHA
    a8e453f View commit details
  2. frank/update idl (#178)

    soundsonacid authored Jun 20, 2024
    Copy the full SHA
    010f9be View commit details

Commits on Jun 27, 2024

  1. Copy the full SHA
    847d7fd View commit details

Commits on Jun 28, 2024

  1. Copy the full SHA
    ba2819d View commit details

Commits on Jul 1, 2024

  1. Copy the full SHA
    0777154 View commit details

Commits on Jul 3, 2024

  1. Copy the full SHA
    cd22a23 View commit details

Commits on Jul 8, 2024

  1. frank/0.7.65 (#184)

    * update jsonrpcclient
    
    * remove accidental files
    soundsonacid authored Jul 8, 2024
    Copy the full SHA
    cf9e1c8 View commit details

Commits on Jul 9, 2024

  1. frank/fix pyth pull bug (#185)

    * update jsonrpcclient
    
    * remove accidental files
    
    * fix prelaunch bug
    soundsonacid authored Jul 9, 2024
    Copy the full SHA
    d30d730 View commit details

Commits on Jul 11, 2024

  1. frank/fix weird oracle source bug (#186)

    * update jsonrpcclient
    
    * remove accidental files
    
    * fix prelaunch bug
    
    * fix
    soundsonacid authored Jul 11, 2024
    Copy the full SHA
    4e57098 View commit details
  2. Update oracle.py

    soundsonacid authored Jul 11, 2024
    Copy the full SHA
    4085738 View commit details
  3. rerelease (#187)

    soundsonacid authored Jul 11, 2024
    Copy the full SHA
    e6ecf3a View commit details
  4. fix (#188)

    * rerelease
    
    * fix this incredibly stupid oversight of a bug
    soundsonacid authored Jul 11, 2024
    Copy the full SHA
    eae5626 View commit details

Commits on Jul 12, 2024

  1. Copy the full SHA
    ed76ed1 View commit details
  2. Copy the full SHA
    0834b71 View commit details
  3. Copy the full SHA
    97cc183 View commit details

Commits on Jul 16, 2024

  1. frank/new ci (#189)

    soundsonacid authored Jul 16, 2024
    Copy the full SHA
    1a626c6 View commit details
  2. Copy the full SHA
    170d511 View commit details
  3. update release job

    soundsonacid committed Jul 16, 2024
    Copy the full SHA
    a814cd3 View commit details
Showing with 13,926 additions and 10,767 deletions.
  1. +1 −1 .bumpversion.cfg
  2. +120 −0 .github/workflows/main.yml
  3. +1 −1 .pre-commit-config.yaml
  4. +27 −1 CHANGELOG.md
  5. +0 −11 Makefile
  6. +19 −29 README.md
  7. +0 −1 acceptance_test.sh
  8. +176 −0 examples/dump_pickle.py
  9. +40 −16 examples/fetch_all_markets.py
  10. +46 −0 examples/get_borrows.py
  11. +48 −0 examples/get_oracle_devnet.py
  12. +63 −0 examples/high_leverage_users.py
  13. +12 −14 examples/if_stake.py
  14. +23 −16 examples/limit_order_grid.py
  15. +285 −0 examples/place_and_take.py
  16. +54 −0 examples/settle_pnl.py
  17. +30 −26 examples/start_lp.py
  18. +0 −26 new_release.py
  19. +0 −7 noxfile.py
  20. +0 −1 oracle.sh
  21. +0 −130 parse_idl.py
  22. +395 −277 poetry.lock
  23. +0 −1 prelaunch.sh
  24. +1 −1 protocol-v2
  25. +22 −13 pyproject.toml
  26. +4 −4 requirements.txt
  27. +0 −54 scrape.py
  28. +53 −0 scripts/bump.py
  29. +15 −0 scripts/ci.sh
  30. +1 −0 scripts/decode.sh
  31. +1 −0 scripts/dlob.sh
  32. 0 run_math_tests.sh → scripts/math.sh
  33. +1 −6 setup.sh
  34. +1 −1 src/driftpy/__init__.py
  35. +34 −24 src/driftpy/account_subscription_config.py
  36. +21 −6 src/driftpy/accounts/bulk_account_loader.py
  37. +96 −30 src/driftpy/accounts/cache/drift_client.py
  38. +20 −30 src/driftpy/accounts/demo/drift_client.py
  39. +0 −1 src/driftpy/accounts/get_accounts.py
  40. +163 −43 src/driftpy/accounts/oracle.py
  41. +43 −28 src/driftpy/accounts/polling/drift_client.py
  42. +21 −0 src/driftpy/accounts/types.py
  43. +1 −0 src/driftpy/accounts/ws/__init__.py
  44. +10 −4 src/driftpy/accounts/ws/account_subscriber.py
  45. +48 −21 src/driftpy/accounts/ws/drift_client.py
  46. +2 −3 src/driftpy/accounts/ws/program_account_subscriber.py
  47. +16 −0 src/driftpy/accounts/ws/user_stats.py
  48. +51 −7 src/driftpy/addresses.py
  49. +62 −18 src/driftpy/admin.py
  50. +2 −1 src/driftpy/auction_subscriber/auction_subscriber.py
  51. +6 −6 src/driftpy/auction_subscriber/types.py
  52. +46 −35 src/driftpy/constants/config.py
  53. +9 −0 src/driftpy/constants/numeric_constants.py
  54. +457 −83 src/driftpy/constants/perp_markets.py
  55. +214 −35 src/driftpy/constants/spot_markets.py
  56. +44 −0 src/driftpy/decode/pull_oracle.py
  57. +141 −80 src/driftpy/decode/user.py
  58. +94 −0 src/driftpy/decode/user_stat.py
  59. +5 −9 src/driftpy/dlob/dlob.py
  60. +56 −36 src/driftpy/dlob/dlob_helpers.py
  61. +24 −15 src/driftpy/dlob/node_list.py
  62. +5 −2 src/driftpy/dlob/orderbook_levels.py
  63. +884 −129 src/driftpy/drift_client.py
  64. +458 −154 src/driftpy/drift_user.py
  65. +72 −0 src/driftpy/drift_user_stats.py
  66. +10 −5 src/driftpy/events/fetch_logs.py
  67. +4 −2 src/driftpy/events/types.py
  68. +1 −1 src/driftpy/events/websocket_log_provider.py
  69. +3,015 −229 src/driftpy/idl/drift.json
  70. +103 −0 src/driftpy/idl/sequence_enforcer.json
  71. +86 −7,954 src/driftpy/idl/switchboard.json
  72. +3,524 −0 src/driftpy/idl/switchboard_on_demand.json
  73. +97 −6 src/driftpy/market_map/market_map.py
  74. +1 −1 src/driftpy/market_map/websocket_sub.py
  75. +84 −43 src/driftpy/math/amm.py
  76. +2 −1 src/driftpy/math/conversion.py
  77. +0 −1 src/driftpy/math/exchange_status.py
  78. +56 −0 src/driftpy/math/fuel.py
  79. +2 −1 src/driftpy/math/funding.py
  80. +2 −1 src/driftpy/math/oracles.py
  81. +48 −5 src/driftpy/math/perp_position.py
  82. +15 −8 src/driftpy/math/repeg.py
  83. +5 −0 src/driftpy/math/user_status.py
  84. +4 −0 src/driftpy/memcmp.py
  85. +41 −0 src/driftpy/oracles/oracle_id.py
  86. +172 −0 src/driftpy/pickle/vat.py
  87. +7 −3 src/driftpy/priority_fees/priority_fee_subscriber.py
  88. +18 −18 src/driftpy/setup/helpers.py
  89. +106 −0 src/driftpy/tx/jito_subscriber.py
  90. +91 −0 src/driftpy/tx/jito_tx_sender.py
  91. +16 −1 src/driftpy/tx/standard_tx_sender.py
  92. +99 −10 src/driftpy/types.py
  93. +1 −3 src/driftpy/user_map/polling_sub.py
  94. +4 −2 src/driftpy/user_map/types.py
  95. +62 −26 src/driftpy/user_map/user_map.py
  96. +12 −2 src/driftpy/user_map/user_map_config.py
  97. +287 −0 src/driftpy/user_map/userstats_map.py
  98. +1 −3 src/driftpy/user_map/websocket_sub.py
  99. +0 −1 test.sh
  100. 0 tests/__init__.py
  101. +0 −92 tests/acceptance_test.py
  102. 0 tests/ci/__init__.py
  103. +210 −0 tests/ci/devnet.py
  104. +178 −0 tests/ci/mainnet.py
  105. +0 −16 tests/conftest.py
  106. 0 tests/decode/__init__.py
  107. +88 −39 tests/{ → decode}/decode.py
  108. +117 −0 tests/decode/decode_stat.py
  109. +101 −101 tests/{ → decode}/decode_strings.py
  110. +29 −20 tests/{ → decode}/dlob_test_helpers.py
  111. +29 −0 tests/decode/stat_decode_strings.py
  112. 0 tests/dlob/__init__.py
  113. +273 −103 tests/{ → dlob}/dlob.py
  114. +12 −6 tests/dlob_test_constants.py
  115. +0 −2 tests/{ → integration}/events_parser.py
  116. +14 −2 tests/{ → integration}/liq.py
  117. +17 −11 tests/{ → integration}/oracle.py
  118. 0 tests/{ → integration}/prelaunch.py
  119. +69 −0 tests/integration/swb_on_demand.py
  120. +232 −0 tests/integration/test_oracle_diff_sources.py
  121. 0 tests/math/__init__.py
  122. +1 −1 tests/math/amm.py
  123. +1 −1 tests/math/funding.py
  124. +17 −19 tests/math/helpers.py
  125. +1 −1 tests/math/spot.py
  126. +13 −3 tests/math/spreads.py
  127. +2 −2 tests/math/user.py
  128. +0 −494 tests/test.py
  129. +0 −87 tmp.py
  130. +2 −3 update_idl.sh
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.7.42
current_version = 0.7.100
commit = True
tag = True
tag_name = {new_version}
120 changes: 120 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: CI
on:
push:
branches:
- master
pull_request:
branches: [master]

defaults:
run:
shell: bash
working-directory: .

jobs:
black:
runs-on: ubicloud
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff
- name: Run Ruff
run: ruff format --check .

tests:
runs-on: ubicloud
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10.10"
- name: Install and configure Poetry
uses: snok/install-poetry@v1.3.3
with:
version: 1.4.2
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Install dependencies
run: poetry install
- name: Install pytest
run: poetry run pip install pytest
- name: Run tests
env:
MAINNET_RPC_ENDPOINT: ${{ secrets.MAINNET_RPC_ENDPOINT }}
DEVNET_RPC_ENDPOINT: ${{ secrets.DEVNET_RPC_ENDPOINT }}
run: poetry run bash scripts/ci.sh

bump-version:
runs-on: ubicloud
needs: [black, tests]
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10.10"
- name: Run version bump script
run: python scripts/bump.py
- name: Commit changes
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add pyproject.toml src/driftpy/__init__.py .bumpversion.cfg
git commit -m "Bump version [skip ci]"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}

release:
runs-on: ubicloud
needs: [bump-version]
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Pull Latest Changes
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git pull
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10.10"
- name: Install and configure Poetry
uses: snok/install-poetry@v1.3.3
with:
version: 1.4.2
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Build package
run: poetry build
- name: Publish to PyPI
run: poetry publish --username=__token__ --password=${{ secrets.PYPI_TOKEN }}
- name: Get version
id: get_version
run: echo "VERSION=$(poetry version -s)" >> $GITHUB_OUTPUT
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create v${{ steps.get_version.outputs.VERSION }} \
--title "Release v${{ steps.get_version.outputs.VERSION }}" \
--generate-notes \
dist/*.whl dist/*.tar.gz
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 23.11.0
rev: 24.4.2
hooks:
- id: black
language_version: python3.10
28 changes: 27 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -212,4 +212,30 @@ Fix enum interpretaton bug in `get_max_confidence_interval_multiplier`

## [0.7.42] - 2024-3-18

Add W-PERP to `constants/perp_markets.py`
Add W-PERP to `constants/perp_markets.py`

## [0.7.43] - 2024-3-21

Fix minor bugs in `DriftUser` math functions

## [0.7.44] - 2024-3-27

Add `JitoTxSender`

Update `drift.json` IDL

## [0.7.45] - 2024-4-5

Update `perp_market_constants.py`

## [0.7.46] - 2024-4-5

Fix bug where `DriftClient.send_ixs` wasn't properly awaited

## [0.7.47] - 2024-4-9

Add `UserStatsMap`

## [0.7.49] - 2024-5-15

Update `anchorpy`, `anchorpy-core`, `solana`, `jito-searcher-client` to latest versions
11 changes: 0 additions & 11 deletions Makefile

This file was deleted.

48 changes: 19 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,8 @@
<img src="docs/img/drift.png" width="30%" height="30%">
</div>

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.
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/)**

@@ -16,15 +17,21 @@ pip install driftpy

Note: requires Python >= 3.10.

## ⚠️ IMPORTANT ⚠️

## 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")`:

```
```python
# 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

@@ -48,47 +55,30 @@ If you intend to use `AccountSubscriptionConfig("demo)`, you *must* call `get_ma

`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.
# Development

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

- `python new_release.py`
- Create a new release at https://github.com/drift-labs/driftpy/releases.
- (The CI process will upload a new version of the package to [PyPI](https://pypi.org/project/driftpy/))

# Development

Ensure correct python version (using pyenv is recommended):
```
```bash
pyenv install 3.10.11
pyenv global 3.10.11
poetry env use $(pyenv which python)
```

Install dependencies:
```
```bash
poetry install
```

Run tests:
```
poetry run bash test.sh
```
To run tests, first ensure you have set up the RPC url, then run `pytest`:
```bash
export MAINNET_RPC_ENDPOINT="<YOUR_RPC_URL>"
export DEVNET_RPC_ENDPOINT="https://api.devnet.solana.com" # or your own RPC

Run Acceptance Tests
```
poetry run bash acceptance_test.sh
poetry run pytest -v -s -x tests/ci/*.py
poetry run pytest -v -s tests/math/*.py
```
1 change: 0 additions & 1 deletion acceptance_test.sh

This file was deleted.

Loading