Skip to main content

An SDK to interact with the Perennial derivatives protocol.

Project description

Perennial Python SDK

Overview

This tool is designed to communicate with the Perennial exchange from Python and read/write the following data:

Read account and market information:

  1. Open positions (Iterates through available markets -> checks for open positions -> prints them in the end)
  2. Open orders (Prints a list of open orders and their details, incl. nonces)
  3. Collaterals
  4. Maintenance margin requirements
  5. Pair prices
  6. Funding rate

Execute market orders:

  1. Closing positions
  2. Placing market orders
  3. Placing limit orders
  4. Placing trigger orders
  5. Canceling orders
  • When closing positions - Doesnt automatically withdraw the collateral, you should use the last step in the example to do so.
  • When placing market/limit order - Approves collateral (62.5$ min), commits price to MultiInvoker, places order.
  • When placing trigger orders -
    • Placing collateral is optional,
    • Commits price and places order.
    • If you are holding a Long position you should choose side 1 - Buy; Even though you need it to short. Same for short position.
    • The delta is with how much you want to reduce the position size , so it should be negative.
    • For full close delta = 0.
  • To cancel orders, you will need the nonce fo the order (from MultiInvoker side). You can get this by using fetch_open_orders.py.

Features

  • Connects to an Arbitrum node using a provided RPC URL
  • Retrieves oracle information for specified markets
  • Fetches VAAs from the Pyth Network
  • Creates market snapshots using a Lens contract
  • Supports multiple markets and optional account specification
  • Reads all needed information from the snapshot

Prerequisites

  • Infura account (in .env)
  • Wallet private key (in .env)
  • Python 3.7+
  • Required Libraries:
  • web3 library
  • requests library
  • eth-account library
  • eht_abi library
  • python-dotenv library

Set-up

  1. Set up a Virtual Environment:
     python3 -m venv venv
     source venv/bin/activate
    
  2. Install required packages:
    pip install -r requirements.txt
    
  3. Set the PYTHONPATH environment variable to include the perennial_sdk and examples directories.

Set path of the root of the repo as PYTHONPATH.

cd ~/my_repos/perennial_py_sdk

export PYTHONPATH=$(pwd)

Example usage can be found in the examples directory:

Private key and Infura url will need to be added first to .env.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

perennial_sdk-0.1.0.tar.gz (50.1 kB view details)

Uploaded Source

Built Distribution

perennial_sdk-0.1.0-py3-none-any.whl (59.9 kB view details)

Uploaded Python 3

File details

Details for the file perennial_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: perennial_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 50.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/23.5.0

File hashes

Hashes for perennial_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c89dd7cc0c38ae7c04d79519dc31cd302105268ee059ba975e6e0ff400b1a110
MD5 4584b861edb4758a25262edeee358e8d
BLAKE2b-256 d9c38ac69fedbafa2ed4e9da7c420bc463c625bb5e9a227b6375f4afcf36b6a6

See more details on using hashes here.

File details

Details for the file perennial_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: perennial_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 59.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/23.5.0

File hashes

Hashes for perennial_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cfdc07c2590fdad2152cf0f421ae7d669f89a0bd70bc1118406d3fc2e11a996d
MD5 334113762ade6617049fbe5e4aa8af9f
BLAKE2b-256 eec985c12a9fb86fe11a1c7fcec15bc27f941083a093f444248ad27241a01970

See more details on using hashes here.

Supported by

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