Docs

PerpCity Python SDK

Python SDK for interacting with Perp City perpetual futures contracts on Base.

The PerpCity Python SDK is a Python library for interacting with Perp City perpetual futures markets. It provides a synchronous API built on web3.py for creating perp markets, managing positions, and querying market data.

Installation

pip install perpcity-sdk

See the Installation Guide for detailed setup instructions.

Quick Example

from perpcity_sdk import PerpCityContext, open_taker_position, OpenTakerPositionParams

# Initialize context
context = PerpCityContext(
    rpc_url="https://your-rpc-endpoint.example/v2/YOUR_KEY",
    private_key="0xYOUR_PRIVATE_KEY",
    perp_manager_address="0xPERP_MANAGER",
    usdc_address="0xUSDC",
)

# Fetch market data
perp_id = "0xYOUR_PERP_ID"  # the perp market identifier
perp_data = context.get_perp_data(perp_id)
print(f"Mark price: {perp_data.mark}")

# Open a long position
position = open_taker_position(
    context,
    perp_id,
    OpenTakerPositionParams(
        is_long=True,
        margin=100,
        leverage=5,
        unspecified_amount_limit=0,
    ),
)
print(f"Position ID: {position.position_id}")

# Check live details
details = position.live_details()
print(f"PnL: ${details.pnl:.2f}")

Guides

Resources