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

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

Installation

Using pip

You can install the SDK using pip:

pip install perennial_sdk==0.1.0

Using Poetry

If you prefer using Poetry for dependency management, you can add the SDK to your project with:

poetry add perennial_sdk@0.1.0

Development

If you are using Poetry, you can set up your environment with:

  1. Install Poetry if you haven't already:

    curl -sSL https://install.python-poetry.org | python3 -
    
  2. Install dependencies:

    poetry install
    
  3. Activate the virtual environment:

    poetry run python <command here>
    

Example usage can be found in the examples directory:

Private key and RPC 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.2.tar.gz (52.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

perennial_sdk-0.1.2-py3-none-any.whl (63.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: perennial_sdk-0.1.2.tar.gz
  • Upload date:
  • Size: 52.3 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.2.tar.gz
Algorithm Hash digest
SHA256 52a4a635bf6681c7e0e06fe77dfa5f1163af5760f29fa21944eb4bd199e887ef
MD5 4e237ec4f162260fc7582fa2d5a6897b
BLAKE2b-256 f9314c213b73bcac1f745b3d0f7d718a39445768d4b460512a8d55e571409b13

See more details on using hashes here.

File details

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

File metadata

  • Download URL: perennial_sdk-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 63.4 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0fac63e3e2cf5fed30ebfd5104d50ad5a0d28de8364c9101324738c385d062f7
MD5 2a2e16897e25e8dd511bd77267cc7367
BLAKE2b-256 d3da53f834f6b41b9c411e49885591b063eec1c7666891a3310092abbf87e559

See more details on using hashes here.

Supported by

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