Skip to main content

Unified SDK collection for trading Real World Assets across multiple platforms

Project description

Swarm Collection - Python SDK Suite

Python Version License Package Version

Unified Python SDK collection for trading Real World Assets (RWAs) across multiple platforms with smart routing, automatic fallback, and price optimization.


๐Ÿ“‹ Table of Contents


๐ŸŒŸ Overview

Swarm Collection is a comprehensive Python SDK suite that enables seamless trading of Real World Assets (RWAs) through multiple platforms. The collection provides three distinct SDKs, each optimized for different trading scenarios:

  1. Trading SDK - Unified client with smart routing and automatic price optimization
  2. Market Maker SDK - Decentralized peer-to-peer OTC trading (24/7 availability)
  3. Cross-Chain Access SDK - Centralized stock market trading (market hours only)

All SDKs share common infrastructure including Web3 helpers, authentication, and data models, ensuring consistent behavior and ease of use.

Why Use Swarm Collection?

  • โœ… Smart Routing - Automatically selects optimal trading platform
  • โœ… Best Price Guarantee - Real-time price comparison across platforms
  • โœ… Auto Fallback - Seamless switching if primary platform fails
  • โœ… 24/7 Trading - Access to P2P markets outside traditional hours
  • โœ… Unified API - Consistent interface across all SDKs
  • โœ… Production Ready - Comprehensive error handling and retry logic
  • โœ… Type Safe - Full type hints and mypy validation
  • โœ… Async Native - Built with asyncio for high performance

๐Ÿ—๏ธ SDK Architecture

The Swarm Collection implements a multi-layer hierarchical architecture:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                      Trading SDK                            โ”‚
โ”‚  (Smart routing, price comparison, auto-fallback)           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                โ”‚                           โ”‚
      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
      โ”‚  Market Maker SDK  โ”‚      โ”‚ Cross-Chain Access   โ”‚
      โ”‚  (P2P, 24/7)       โ”‚      โ”‚ SDK (Stock market)   โ”‚
      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                โ”‚                           โ”‚
                โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ”‚
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚   Shared Module  โ”‚
                    โ”‚ (Web3, Auth, etc)โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Layer Responsibilities

Layer Purpose Key Components
Trading SDK Unified interface with smart routing TradingClient, Router, routing strategies
Market Maker SDK P2P on-chain trading RPQClient, MarketMakerWeb3Client, offer management
Cross-Chain Access SDK Stock market integration CrossChainAccessAPIClient, market hours validation
Shared Module Common infrastructure Web3Helper, SwarmAuth, BaseClient, models

๐ŸŽฏ Key Features

Trading SDK (Highest Level)

  • 5 Routing Strategies: BEST_PRICE, CROSS_CHAIN_ACCESS_FIRST, MARKET_MAKER_FIRST, CROSS_CHAIN_ACCESS_ONLY, MARKET_MAKER_ONLY
  • Automatic Price Comparison: Real-time quote aggregation from both platforms
  • Smart Fallback: Automatic retry on alternative platform if primary fails
  • Unified Interface: Single trade() method works across all platforms
  • Platform-Aware: Handles market hours, liquidity checks, and platform-specific requirements

Market Maker SDK

  • 24/7 Availability: Trade anytime, no market hour restrictions
  • P2P On-Chain: Fully decentralized execution via smart contracts
  • Offer Discovery: RPQ API integration for finding available liquidity
  • Create Offers: Become a liquidity provider with custom pricing
  • Dynamic Pricing: Support for price feed-based offers
  • Quote Calculation: Best offer selection with amount optimization

Cross-Chain Access SDK

  • Stock Market Pricing: Real US stock exchange rates
  • Deep Liquidity: Traditional market maker liquidity
  • Market Hours Validation: 14:30-21:00 UTC, weekdays only
  • Account Management: Funds tracking and status checks
  • Email Notifications: Trade confirmation emails
  • KYC Compliant: Regulatory requirements handled

Shared Infrastructure

  • Web3 Operations: Token approvals, balance checks, transaction signing
  • Wallet Authentication: EIP-191 signature-based auth (no passwords)
  • Multi-Network: Polygon, Ethereum, Arbitrum, Base, Optimism support
  • HTTP Client: Automatic retries with exponential backoff
  • Error Handling: Comprehensive exception hierarchy
  • Remote Config: Dynamic configuration loading from remote URLs

๐Ÿš€ Quick Start

# Install the package
pip install swarm-collection

# Import and use
from swarm.trading_sdk import TradingClient
from swarm.shared.models import Network

For detailed usage examples and code samples, see:


๐Ÿ“ฆ Installation & Setup

Prerequisites

  • Python 3.8 or higher
  • pip (Python package manager)
  • Wallet with private key (for transaction signing)
  • Gas tokens (MATIC, ETH, etc. for transaction fees)
  • RPQ API Key (for Market Maker SDK access)
  • User Email (for Cross-Chain Access authentication)

Method 1: Install from PyPI (Production)

pip install swarm-collection

Method 2: Install from Source (Development)

# Clone the repository
git clone https://github.com/SwarmMarkets/python-swarm-sdks.git
cd python-swarm-sdks

# Install in editable mode
pip install -e .

# Or install with development dependencies
pip install -e ".[dev]"

Environment Configuration

โš ๏ธ Important: The .env file is only required for running the examples, not for using the SDKs in your own projects. When integrating the SDKs into your application, pass credentials directly to the client constructors.

For Running Examples Only

If you want to run the provided examples, create a .env file in the project root:

# Copy the example file
cp .env.example .env

Then configure your environment variables in the .env file:

# Required: Your wallet private key (with 0x prefix)
PRIVATE_KEY=0x1234567890123456789012345678901234567890123456789012345678901234

# Required for Cross-Chain Access SDK and Trading SDK
USER_EMAIL=your@email.com

# Required for Market Maker SDK and Trading SDK
RPQ_API_KEY=your-rpq-api-key-here

# Optional: Environment mode (dev or prod, defaults to prod)
SWARM_COLLECTION_MODE=prod

# Optional: Custom RPC endpoint
# RPC_URL=https://polygon-rpc.com

# Optional: Remote configuration URLs (for dynamic config loading)
# SWARM_CONFIG_PROD_URL=https://your-storage.com/config.prod.json
# SWARM_CONFIG_DEV_URL=https://your-storage.com/config.dev.json

For SDK Integration in Your Projects

When using the SDKs in your own code, pass credentials directly to the client:

from swarm.trading_sdk import TradingClient
from swarm.shared.models import Network

# Pass credentials directly - no .env file needed
async with TradingClient(
    network=Network.POLYGON,
    private_key="0x...",           # Your private key
    rpq_api_key="your_rpq_key",    # Your RPQ API key
    user_email="you@example.com"   # Your email
) as client:
    # Use the client
    pass

โš ๏ธ Security Note: Never commit your .env file or private keys to version control!


๐Ÿ“š SDK Descriptions

1. Trading SDK - Unified Smart Routing

Highest-level interface that intelligently combines both Market Maker and Cross-Chain Access platforms with automatic routing, price comparison, and fallback protection.

Best for: Production applications, traders seeking optimal prices and reliability

Key Features: 5 routing strategies, real-time price comparison, automatic fallback, unified API

๐Ÿ“– User Guide | API Reference


2. Market Maker SDK - Decentralized P2P Trading

Decentralized on-chain trading through smart contract-based offers with 24/7 availability and permissionless access.

Best for: Market makers, liquidity providers, 24/7 trading, DeFi applications

Key Features: P2P execution, create/manage offers, fixed & dynamic pricing, no KYC required

๐Ÿ“– User Guide | API Reference


3. Cross-Chain Access SDK - Stock Market Integration

Centralized stock market trading with real US stock exchange rates and traditional market liquidity.

Best for: Stock trading apps, regulated services, traditional finance integration

Key Features: Stock market pricing, deep liquidity, market hours (14:30-21:00 UTC), KYC compliant

โš ๏ธ Requires: KYC verification at https://dotc.eth.limo/

๐Ÿ“– User Guide | API Reference


๐Ÿ“‚ Project Structure

python-swarm-sdks/
โ”œโ”€โ”€ swarm/                          # Main package
โ”‚   โ”œโ”€โ”€ __init__.py                # Package initialization
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ trading_sdk/               # Trading SDK (Layer 1)
โ”‚   โ”‚   โ”œโ”€โ”€ sdk/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ client.py          # TradingClient - unified interface
โ”‚   โ”‚   โ”œโ”€โ”€ routing.py             # Smart routing logic & strategies
โ”‚   โ”‚   โ””โ”€โ”€ exceptions.py          # Trading-specific exceptions
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ market_maker_sdk/          # Market Maker SDK (Layer 2a)
โ”‚   โ”‚   โ”œโ”€โ”€ sdk/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ client.py          # MarketMakerClient - main interface
โ”‚   โ”‚   โ”œโ”€โ”€ rpq_service/           # RPQ API integration
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ client.py          # Offer discovery & quotes
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ models.py          # Offer data models
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ exceptions.py     # RPQ-specific exceptions
โ”‚   โ”‚   โ”œโ”€โ”€ market_maker_web3/     # On-chain execution
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ client.py          # Smart contract interactions
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ constants.py       # Contract addresses & ABIs
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ exceptions.py     # Web3-specific exceptions
โ”‚   โ”‚   โ””โ”€โ”€ __init__.py
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ cross_chain_access_sdk/    # Cross-Chain Access SDK (Layer 2b)
โ”‚   โ”‚   โ”œโ”€โ”€ sdk/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ client.py          # CrossChainAccessClient - main interface
โ”‚   โ”‚   โ”œโ”€โ”€ cross_chain_access/    # API integration
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ client.py          # HTTP API client
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ models.py          # Quote & order models
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ exceptions.py     # API-specific exceptions
โ”‚   โ”‚   โ”œโ”€โ”€ market_hours/          # Market hours validation
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ market_hours.py   # Trading hours logic
โ”‚   โ”‚   โ””โ”€โ”€ __init__.py
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ shared/                    # Shared infrastructure (Layer 3)
โ”‚       โ”œโ”€โ”€ base_client.py         # HTTP client with retries
โ”‚       โ”œโ”€โ”€ swarm_auth.py          # Wallet-based authentication
โ”‚       โ”œโ”€โ”€ models.py              # Common data models (Network, Quote, etc)
โ”‚       โ”œโ”€โ”€ constants.py           # Token addresses, RPC URLs
โ”‚       โ”œโ”€โ”€ config.py              # Environment configuration
โ”‚       โ”œโ”€โ”€ remote_config.py       # Remote config loader
โ”‚       โ””โ”€โ”€ web3/
โ”‚           โ”œโ”€โ”€ helpers.py         # Web3 operations (approvals, txs)
โ”‚           โ”œโ”€โ”€ constants.py       # Network configs, ABIs
โ”‚           โ””โ”€โ”€ exceptions.py     # Web3 exceptions
โ”‚
โ”œโ”€โ”€ examples/                      # Usage examples
โ”‚   โ”œโ”€โ”€ example_trading.py         # Trading SDK demo
โ”‚   โ”œโ”€โ”€ example_market_maker.py    # Market Maker SDK demo
โ”‚   โ”œโ”€โ”€ example_cross_chain_access.py  # Cross-Chain Access SDK demo
โ”‚   โ”œโ”€โ”€ example_error_handling.py  # Error handling patterns
โ”‚   โ””โ”€โ”€ README.md                  # Examples documentation
โ”‚
โ”œโ”€โ”€ docs/                          # Documentation
โ”‚   โ”œโ”€โ”€ README.md                  # Documentation index
โ”‚   โ”œโ”€โ”€ trading_sdk_doc.md         # Trading SDK user guide
โ”‚   โ”œโ”€โ”€ trading_sdk_references.md         # Trading SDK API reference
โ”‚   โ”œโ”€โ”€ market_maker_sdk_doc.md    # Market Maker SDK user guide
โ”‚   โ”œโ”€โ”€ market_maker_sdk_references.md    # Market Maker SDK API reference
โ”‚   โ”œโ”€โ”€ cross_chain_access_sdk_doc.md     # Cross-Chain Access SDK user guide
โ”‚   โ””โ”€โ”€ cross_chain_access_sdk_references.md     # Cross-Chain Access SDK API reference
โ”‚
โ”œโ”€โ”€ .github/                       # GitHub configuration
โ”‚   โ”œโ”€โ”€ workflows/
โ”‚   โ”‚   โ””โ”€โ”€ publish.yaml          # CI/CD pipeline for PyPI publishing
โ”‚   โ””โ”€โ”€ copilot-instructions.md   # AI assistant instructions
โ”‚
โ”œโ”€โ”€ config.dev.json                # Development environment config
โ”œโ”€โ”€ config.prod.json               # Production environment config
โ”œโ”€โ”€ pyproject.toml                 # Project metadata & dependencies
โ”œโ”€โ”€ Makefile                       # Development commands
โ”œโ”€โ”€ MANIFEST.in                    # Package manifest
โ”œโ”€โ”€ LICENSE                        # Apache 2.0 license
โ”œโ”€โ”€ .env.example                   # Environment variables template
โ”œโ”€โ”€ .gitignore                     # Git ignore rules
โ””โ”€โ”€ README.md                      # This file

Key Directories

Directory Purpose
swarm/trading_sdk/ Smart routing and unified trading interface
swarm/market_maker_sdk/ P2P on-chain trading implementation
swarm/cross_chain_access_sdk/ Stock market API integration
swarm/shared/ Common utilities used by all SDKs
examples/ Complete working examples for each SDK
docs/ User guides and API references
.github/workflows/ CI/CD pipelines and automation

๐Ÿ› ๏ธ Development Setup

Setting Up Virtual Environment

The project uses Python virtual environments for dependency isolation. Follow these steps:

Method 1: Using Makefile (Recommended)

# Setup venv and install package with dev dependencies
make setup

# Activate the virtual environment
source venv/bin/activate  # On macOS/Linux
# or
.\venv\Scripts\activate   # On Windows

# Verify installation
python -c "import swarm; print(swarm.__version__)"

Method 2: Manual Setup

# Create virtual environment
python3 -m venv venv

# Activate virtual environment
source venv/bin/activate  # On macOS/Linux
# or
.\venv\Scripts\activate   # On Windows

# Upgrade pip
pip install --upgrade pip

# Install package in editable mode with dev dependencies
pip install -e ".[dev]"

Development Commands

The project includes a comprehensive Makefile with common development tasks:

# Show all available commands
make help

# Installation
make install         # Install package (production mode)
make install-dev     # Install with dev dependencies

# Code Quality
make format          # Format code with black & isort
make lint            # Run flake8 & mypy
make clean           # Remove build artifacts and cache

# Building
make build           # Build distribution packages (sdist, wheel)

# Publishing
make upload          # Upload to PyPI (production)
make upload-test     # Upload to TestPyPI (testing)

# Running Examples
make example-trading              # Run Trading SDK example
make example-market-maker         # Run Market Maker SDK example
make example-cross-chain-access   # Run Cross-Chain Access SDK example
make example-errors               # Run error handling example

Code Style & Quality

The project enforces consistent code style:

  • Black: Code formatting (100 char line length)
  • isort: Import sorting
  • flake8: Linting
  • mypy: Type checking
# Format code before committing
make format

# Check for issues
make lint

Configuration Files

File Purpose
pyproject.toml Project metadata, dependencies, build config
.env Environment variables (not in git)
.env.example Template for environment variables
config.dev.json Development environment addresses
config.prod.json Production environment addresses

๐Ÿš€ Deployment & CI/CD

GitHub Actions Workflow

The project uses GitHub Actions for automated publishing to PyPI. The workflow is defined in .github/workflows/publish.yaml.

Workflow Triggers

Branch Action Destination
main Push PyPI (production)
test Push TestPyPI (testing)

Workflow Steps

  1. Checkout Code - Pull latest code from repository
  2. Setup Python - Install Python 3.11
  3. Install Build Tools - Install build package
  4. Build Package - Create source distribution and wheel
  5. Publish - Upload to PyPI or TestPyPI based on branch
# Simplified workflow structure
on:
  push:
    branches: [main, test]

jobs:
  build-and-publish:
    - Checkout code
    - Setup Python 3.11
    - Install build backend
    - Build package (python -m build)
    - Publish to TestPyPI (if branch = test)
    - Publish to PyPI (if branch = main)

Required GitHub Secrets

Configure these secrets in your GitHub repository settings:

Secret Purpose
PYPI_API_TOKEN_PROD PyPI API token for production releases
PYPI_API_TOKEN_TEST TestPyPI API token for test releases

To get API tokens:

  1. PyPI: Go to https://pypi.org/manage/account/token/
  2. TestPyPI: Go to https://test.pypi.org/manage/account/token/

Manual Deployment

You can also deploy manually using the Makefile:

# Build distribution packages
make build

# Upload to TestPyPI (testing)
make upload-test

# Upload to PyPI (production)
make upload

# Or use twine directly
pip install twine
python -m build
twine upload dist/*

Version Management

Version is managed in pyproject.toml:

[project]
name = "swarm-collection"
version = "1.0.0b1"  # Update this for new releases

Version Numbering:

  • 1.0.0b1 - Beta release 1
  • 1.0.0 - Stable release
  • 1.1.0 - Minor version (new features)
  • 1.1.1 - Patch version (bug fixes)

Release Checklist

Before creating a new release:

  • Update version in pyproject.toml
  • Update CHANGELOG.md (if exists)
  • Run make test to ensure all tests pass
  • Run make lint to check code quality
  • Update documentation if needed
  • Commit changes: git commit -m "Release vX.Y.Z"
  • Create git tag: git tag vX.Y.Z
  • Push to test branch first: git push origin test
  • Verify TestPyPI deployment
  • Push to main: git push origin main
  • Push tags: git push --tags

๐Ÿ“– Documentation

Available Documentation

The project includes comprehensive documentation in the docs/ directory:

SDK User Guides (Beginner-Friendly)

API References (Technical)

Examples

Documentation Structure

Each SDK has two documentation files:

Type Purpose Audience
User Guide Setup, concepts, tutorials, troubleshooting All users
API Reference Class methods, parameters, return types, exceptions Developers

Quick Links

  • Getting Started: Start with Trading SDK User Guide
  • Advanced Features: Check individual SDK user guides
  • Technical Details: Refer to API reference documents
  • Code Examples: See examples/ directory

๐Ÿ’ก Examples

The project includes comprehensive working examples for all SDKs in the examples/ directory.

Running Examples

# Using Makefile (recommended)
make example-trading              # Trading SDK with smart routing
make example-market-maker         # Market Maker P2P trading
make example-cross-chain-access   # Cross-Chain Access stock trading
make example-errors               # Error handling patterns

# Or run directly
python examples/example_trading.py

โš ๏ธ Note: Examples require a .env file with credentials. See Environment Configuration section.

๐Ÿ“– Full documentation: examples/README.md


๐Ÿค Contributing

We welcome contributions! Here's how to get started:

Development Workflow

  1. Fork the repository

  2. Clone your fork

    git clone https://github.com/YOUR_USERNAME/python-swarm-sdks.git
    cd python-swarm-sdks
    
  3. Set up development environment

    make setup
    source venv/bin/activate
    
  4. Create a feature branch

    git checkout -b feature/your-feature-name
    
  5. Make your changes

    • Write code following project style
    • Add tests for new features
    • Update documentation if needed
  6. Run quality checks

    make format  # Format code
    make lint    # Check for issues
    make test    # Run tests
    
  7. Commit your changes

    git add .
    git commit -m "Add: your feature description"
    
  8. Push and create PR

    git push origin feature/your-feature-name
    

    Then create a Pull Request on GitHub

Code Standards

  • Python Version: 3.8+
  • Code Style: Black (100 char line length)
  • Import Sorting: isort
  • Linting: flake8
  • Type Hints: mypy

Commit Message Convention

Use descriptive commit messages:

Add: New feature description
Fix: Bug fix description
Update: Changes to existing features
Docs: Documentation updates
Test: Test additions or modifications
Refactor: Code refactoring
Style: Code style changes

Areas for Contribution

  • ๐Ÿ› Bug Fixes - Fix issues reported in GitHub Issues
  • โœจ New Features - Add new functionality to SDKs
  • ๐Ÿ“š Documentation - Improve guides and API docs
  • ๐Ÿงช Tests - Increase test coverage
  • ๐ŸŽจ Examples - Add more usage examples
  • ๐Ÿ”ง Tooling - Improve development workflow

Before Submitting PR

  • Code follows project style (run make format)
  • All tests pass (run make test)
  • New tests added for new features
  • Documentation updated if needed
  • No linting errors (run make lint)
  • Commit messages are clear and descriptive

๐ŸŒ Supported Networks

All SDKs support the following networks:

Network Chain ID
Ethereum 1
Polygon 137
Base 8453
BSC 56

Network Configuration

Networks are defined in swarm/shared/models.py:

from swarm.shared.models import Network

Network.ETHEREUM   # 1
Network.POLYGON    # 137
Network.BASE       # 8453
Network.BSC        # 56

RPC endpoints are configured in swarm/shared/web3/constants.py and can be overridden with the rpc_url parameter when initializing clients.


๐Ÿ” Security

Best Practices

  • โœ… Never commit private keys - use environment variables
  • โœ… Verify token addresses before trading
  • โœ… Test with small amounts first
  • โœ… Use context managers for proper cleanup

Reporting Security Issues

Email: developers@swarm.com (do NOT create public GitHub issues for vulnerabilities)


โš ๏ธ Important Caveats

Decimal Usage (CRITICAL)

  • โœ… Always use Decimal for token amounts - never floats
  • โŒ Floats cause precision loss: Use Decimal("100") not 100.0
  • โœ… SDKs handle wei conversion automatically

Async Context Managers Required

All SDK clients must be used with async context managers:

async with TradingClient(...) as client:
    # Use client here
    pass  # Automatic cleanup on exit

Platform-Specific Requirements

  • Market Maker: Requires RPQ API key for offer discovery
  • Cross-Chain Access: Requires KYC verification + operates only during market hours (14:30-21:00 UTC, weekdays)
  • Trading SDK: Benefits from both credentials but can work with just one platform

Security Warnings

  • ๐Ÿ” Never commit private keys or .env files to version control
  • ๐Ÿ” Always verify token addresses before trading
  • ๐Ÿ” Test with small amounts first
  • ๐Ÿ” Private keys are used locally only - never sent to servers

๐Ÿ“„ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Copyright 2025 Swarm

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

๐Ÿ”— Links & Resources


๐Ÿ’ฌ Support


๐ŸŽ‰ Acknowledgments

Built by the Swarm Markets team using Web3.py, httpx, and pytest.


Made with โค๏ธ by Swarm Markets

Last Updated: November 21, 2025

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

swarm_collection-1.0.0b3.tar.gz (75.2 kB view details)

Uploaded Source

Built Distribution

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

swarm_collection-1.0.0b3-py3-none-any.whl (73.2 kB view details)

Uploaded Python 3

File details

Details for the file swarm_collection-1.0.0b3.tar.gz.

File metadata

  • Download URL: swarm_collection-1.0.0b3.tar.gz
  • Upload date:
  • Size: 75.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for swarm_collection-1.0.0b3.tar.gz
Algorithm Hash digest
SHA256 3e638f87e4af00150def352efe28ecf369616895199fab5534fe0ab3dae314cc
MD5 f2c00479b6b4efe2c0e1895f11696caa
BLAKE2b-256 48d8617114f29cf4a0a5a695c42d85ab24fcf45015bd4c68eb8f23dacaee8e6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for swarm_collection-1.0.0b3.tar.gz:

Publisher: publish.yaml on SwarmMarkets/python-swarm-sdks

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file swarm_collection-1.0.0b3-py3-none-any.whl.

File metadata

File hashes

Hashes for swarm_collection-1.0.0b3-py3-none-any.whl
Algorithm Hash digest
SHA256 6d190120ff93083c5dcbbc1095f5539024e80fb10e4aa24369bbeef1636b0b42
MD5 3a0e1e35e10e9de3d16feb3dcf263737
BLAKE2b-256 8a4d41f56a26aad48e7a0e88757b9f9584f255372f5a516a704d64bc4296067c

See more details on using hashes here.

Provenance

The following attestation bundles were made for swarm_collection-1.0.0b3-py3-none-any.whl:

Publisher: publish.yaml on SwarmMarkets/python-swarm-sdks

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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