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:
- Open positions (Iterates through available markets -> checks for open positions -> prints them in the end)
- Open orders (Prints a list of open orders and their details, incl. nonces)
- Collaterals
- Maintenance margin requirements
- Pair prices
- Funding rate
Execute market orders:
- Closing positions
- Placing market orders
- Placing limit orders
- Placing trigger orders
- 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
libraryrequests
libraryeth-account
libraryeht_abi
librarypython-dotenv
library
Set-up
- Set up a Virtual Environment:
python3 -m venv venv source venv/bin/activate
- Install required packages:
pip install -r requirements.txt
- Set the
PYTHONPATH
environment variable to include theperennial_sdk
andexamples
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
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
perennial_sdk-0.1.0.tar.gz
(50.1 kB
view details)
Built Distribution
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | c89dd7cc0c38ae7c04d79519dc31cd302105268ee059ba975e6e0ff400b1a110 |
|
MD5 | 4584b861edb4758a25262edeee358e8d |
|
BLAKE2b-256 | d9c38ac69fedbafa2ed4e9da7c420bc463c625bb5e9a227b6375f4afcf36b6a6 |
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | cfdc07c2590fdad2152cf0f421ae7d669f89a0bd70bc1118406d3fc2e11a996d |
|
MD5 | 334113762ade6617049fbe5e4aa8af9f |
|
BLAKE2b-256 | eec985c12a9fb86fe11a1c7fcec15bc27f941083a093f444248ad27241a01970 |