Market Maker SDK — API Reference
Full technical reference for all classes, methods, models, and exceptions in the Market Maker SDK.
MarketMakerClient
Location: swarm/market_maker_sdk/sdk/client.py
Main entry point. Orchestrates authentication, offer discovery via RPQ Service, and on-chain execution.
Constructor
MarketMakerClient(
network: Network,
private_key: str,
rpq_api_key: str,
user_email: Optional[str] = None,
rpc_url: Optional[str] = None,
)
| Parameter | Type | Required | Description |
|---|---|---|---|
| network | Network | ✅ | Blockchain network |
| private_key | str | ✅ | Wallet private key (with 0x prefix) |
| rpq_api_key | str | ✅ | API key for RPQ Service |
| user_email | str | ❌ | Email for Swarm authentication |
| rpc_url | str | ❌ | Custom RPC endpoint |
Attributes: network, rpq_client (RPQClient), web3_client (MarketMakerWeb3Client), auth, user_email
authenticate()
async def authenticate() -> None
Signs an authentication message with the wallet private key and obtains an access token. Called automatically when using async with.
Raises: AuthenticationError
get_quote()
async def get_quote(
from_token: str,
to_token: str,
from_amount: Optional[Decimal] = None,
to_amount: Optional[Decimal] = None,
) -> Quote
| Parameter | Type | Required | Description |
|---|---|---|---|
| from_token | str | ✅ | Token address to sell |
| to_token | str | ✅ | Token address to buy |
| from_amount | Decimal | ⚠️ | Amount to sell (provide this or to_amount) |
| to_amount | Decimal | ⚠️ | Amount to buy (provide this or from_amount) |
Returns: Quote
Raises: NoOffersAvailableException, QuoteUnavailableException, ValueError
trade()
async def trade(
from_token: str,
to_token: str,
from_amount: Optional[Decimal] = None,
to_amount: Optional[Decimal] = None,
affiliate: Optional[str] = None,
) -> TradeResult
| Parameter | Type | Required | Description |
|---|---|---|---|
| from_token | str | ✅ | Token to sell (withdrawal asset) |
| to_token | str | ✅ | Token to buy (deposit asset) |
| from_amount | Decimal | ⚠️ | Amount to sell |
| to_amount | Decimal | ⚠️ | Amount to buy |
| affiliate | str | ❌ | Optional affiliate address for fee sharing |
Trade flow: finds best offers → approves tokens → detects pricing type → executes on-chain → waits for confirmation.
Returns: TradeResult
Raises: ValueError, NoOffersAvailableException, OfferNotFoundError, OfferInactiveError, InsufficientOfferBalanceError, OfferExpiredError, MarketMakerWeb3Exception
make_offer()
async def make_offer(
sell_token: str,
sell_amount: Decimal,
buy_token: str,
buy_amount: Decimal,
is_dynamic: bool = False,
expires_at: Optional[int] = None,
) -> TradeResult
| Parameter | Type | Required | Description |
|---|---|---|---|
| sell_token | str | ✅ | Token you are offering |
| sell_amount | Decimal | ✅ | Amount of that token |
| buy_token | str | ✅ | Token you want to receive |
| buy_amount | Decimal | ✅ | Amount you want to receive |
| is_dynamic | bool | ❌ | Use dynamic (oracle) pricing (default: False) |
| expires_at | int | ❌ | Unix timestamp for offer expiry |
Approves tokens, deposits them into escrow, and creates the offer on-chain.
Returns: TradeResult (includes the new order_id / offer ID)
cancel_offer()
async def cancel_offer(offer_id: str) -> str
Returns: Transaction hash (str)
Raises: UnauthorizedError if caller is not the offer creator.
close()
async def close() -> None
Closes HTTP clients and cleans up resources. Called automatically with async with.
RPQClient
Location: swarm/market_maker_sdk/rpq_service/client.py
REST client for the RPQ (Request for Quote) Service. Accessible via client.rpq_client.
get_offers()
async def get_offers(
buy_asset_address: str,
sell_asset_address: str,
page: int = 0,
limit: int = 10,
) -> list[Offer]
Returns a paginated list of active offers for the token pair.
get_best_offers()
async def get_best_offers(
buy_asset_address: str,
sell_asset_address: str,
target_sell_amount: Optional[str] = None,
target_buy_amount: Optional[str] = None,
) -> BestOffersResponse
Returns the optimal combination of offers to fill a given target amount. Provide either target_sell_amount or target_buy_amount.
get_quote()
async def get_quote(
buy_asset_address: str,
sell_asset_address: str,
sell_amount: str,
) -> QuoteResponse
get_price_feeds()
async def get_price_feeds() -> PriceFeedsResponse
Returns available oracle price feeds — needed for creating dynamic offers.
MarketMakerWeb3Client
Location: swarm/market_maker_sdk/market_maker_web3/client.py
Smart contract client. Accessible via client.web3_client.
take_offer_fixed()
async def take_offer_fixed(
offer_id: str,
amount_to_take: int,
affiliate: Optional[str] = None,
) -> str
Executes a fixed-price offer on-chain. Returns the transaction hash.
take_offer_dynamic()
async def take_offer_dynamic(
offer_id: str,
amount_to_take: int,
deposit_to_withdrawal_rate: int,
affiliate: Optional[str] = None,
) -> str
Executes a dynamic-price offer with slippage protection via deposit_to_withdrawal_rate.
make_offer()
async def make_offer(
deposit_asset: dict,
withdrawal_asset: dict,
offer_fill_type: str,
expiry_timestamp: int,
timelocked_counter: int,
special_address: str,
pricing: dict,
) -> str
Creates an offer on-chain. Returns the transaction hash.
cancel_offer()
async def cancel_offer(offer_id: str) -> str
get_offer_details()
async def get_offer_details(offer_id: str) -> dict
Returns raw on-chain offer data.
Data models
Offer
Location: swarm/market_maker_sdk/rpq_service/models.py
| Field | Type | Description |
|---|---|---|
| id | str | Offer ID |
| deposit_asset | Asset | Token the maker deposited (you receive) |
| withdrawal_asset | Asset | Token the maker wants (you pay) |
| amount_in | str | Deposit amount |
| amount_out | str | Withdrawal amount |
| available_amount | str | Remaining fillable amount |
| offer_type | OfferType | PartialOffer or BlockOffer |
| offer_status | OfferStatus | NotTaken, PartiallyTaken, or Taken |
| offer_price | OfferPrice | Pricing information |
SelectedOffer
| Field | Type | Description |
|---|---|---|
| id | str | Offer ID |
| withdrawal_amount_paid | str | Amount you pay for this offer |
| price_per_unit | str | Price per unit |
| pricing_type | PricingType | Fixed or dynamic |
BestOffersResponse
| Field | Type | Description |
|---|---|---|
| result.target_amount | str | Target amount requested |
| result.total_withdrawal_amount_paid | str | Total cost |
| result.selected_offers | list[SelectedOffer] | Offers selected |
Asset
| Field | Type | Description |
|---|---|---|
| id | str | Asset ID |
| name | str | Asset name |
| symbol | str | Asset symbol |
| address | str | Contract address |
| decimals | int | Token decimals |
| asset_type | AssetType | Security, Gold, or NoType |
| token_standard | str | e.g. "ERC20" |
OfferPrice
| Field | Type | Description |
|---|---|---|
| pricing_type | PricingType | Fixed or dynamic |
| percentage | float | Price adjustment (optional) |
| percentage_type | PercentageType | Plus or Minus (optional) |
| unit_price | str | Fixed unit price (optional) |
| deposit_asset_price | dict | Oracle price feed for deposit asset |
| withdrawal_asset_price | dict | Oracle price feed for withdrawal asset |
Quote / TradeResult
Shared with the Trading SDK. See Trading SDK API Reference — Data Models.
Enumerations
OfferType
class OfferType(str, Enum):
PARTIAL_OFFER = "PartialOffer" # Can be taken in parts
BLOCK_OFFER = "BlockOffer" # Must be taken all at once
OfferStatus
class OfferStatus(str, Enum):
NOT_TAKEN = "NotTaken"
PARTIALLY_TAKEN = "PartiallyTaken"
TAKEN = "Taken"
PricingType
class PricingType(str, Enum):
FIXED_PRICING = "FixedPricing"
DYNAMIC_PRICING = "DynamicPricing"
PercentageType
class PercentageType(str, Enum):
PLUS = "Plus"
MINUS = "Minus"
AssetType
class AssetType(str, Enum):
SECURITY = "Security"
GOLD = "Gold"
NO_TYPE = "NoType"
Exceptions
Exception hierarchy
RPQServiceException (base)
├── NoOffersAvailableException
├── QuoteUnavailableException
├── InvalidTokenPairException
└── PriceFeedNotFoundException
MarketMakerWeb3Exception (base)
├── OfferNotFoundError
├── OfferInactiveError
├── InsufficientOfferBalanceError
├── OfferExpiredError
└── UnauthorizedError
| Exception | Location | Description |
|---|---|---|
| RPQServiceException | rpq_service/exceptions.py | Base for all RPQ errors |
| NoOffersAvailableException | No offers for this token pair | |
| QuoteUnavailableException | Quote cannot be generated | |
| InvalidTokenPairException | Token pair not supported | |
| PriceFeedNotFoundException | No oracle price feed for token | |
| MarketMakerWeb3Exception | market_maker_web3/exceptions.py | Base for all on-chain errors |
| OfferNotFoundError | Offer doesn't exist on-chain | |
| OfferInactiveError | Offer is cancelled or fully taken | |
| InsufficientOfferBalanceError | Maker has insufficient balance | |
| OfferExpiredError | Offer has passed expiration | |
| UnauthorizedError | Caller is not the offer creator |
Supported networks
| Network | Chain ID | Supported |
|---|---|---|
| Polygon | 137 | ✅ |
| Ethereum | 1 | ✅ |
| Arbitrum | 42161 | ✅ |
| Base | 8453 | ✅ |
| Optimism | 10 | ✅ |
Contract addresses are loaded dynamically from remote config. Set SWARM_COLLECTION_MODE=dev (default) or prod.
.png)