Market Maker SDK — API Reference

Full technical reference for all classes, methods, models, and exceptions in the Market Maker SDK.

→ User Guide


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,
)

ParameterTypeRequiredDescription
networkNetwork✅Blockchain network
private_keystr✅Wallet private key (with 0x prefix)
rpq_api_keystr✅API key for RPQ Service
user_emailstr❌Email for Swarm authentication
rpc_urlstr❌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

ParameterTypeRequiredDescription
from_tokenstr✅Token address to sell
to_tokenstr✅Token address to buy
from_amountDecimal⚠️Amount to sell (provide this or to_amount)
to_amountDecimal⚠️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

ParameterTypeRequiredDescription
from_tokenstr✅Token to sell (withdrawal asset)
to_tokenstr✅Token to buy (deposit asset)
from_amountDecimal⚠️Amount to sell
to_amountDecimal⚠️Amount to buy
affiliatestr❌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

ParameterTypeRequiredDescription
sell_tokenstr✅Token you are offering
sell_amountDecimal✅Amount of that token
buy_tokenstr✅Token you want to receive
buy_amountDecimal✅Amount you want to receive
is_dynamicbool❌Use dynamic (oracle) pricing (default: False)
expires_atint❌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

FieldTypeDescription
idstrOffer ID
deposit_assetAssetToken the maker deposited (you receive)
withdrawal_assetAssetToken the maker wants (you pay)
amount_instrDeposit amount
amount_outstrWithdrawal amount
available_amountstrRemaining fillable amount
offer_typeOfferTypePartialOffer or BlockOffer
offer_statusOfferStatusNotTaken, PartiallyTaken, or Taken
offer_priceOfferPricePricing information

SelectedOffer

FieldTypeDescription
idstrOffer ID
withdrawal_amount_paidstrAmount you pay for this offer
price_per_unitstrPrice per unit
pricing_typePricingTypeFixed or dynamic

BestOffersResponse

FieldTypeDescription
result.target_amountstrTarget amount requested
result.total_withdrawal_amount_paidstrTotal cost
result.selected_offerslist[SelectedOffer]Offers selected

Asset

FieldTypeDescription
idstrAsset ID
namestrAsset name
symbolstrAsset symbol
addressstrContract address
decimalsintToken decimals
asset_typeAssetTypeSecurity, Gold, or NoType
token_standardstre.g. "ERC20"

OfferPrice

FieldTypeDescription
pricing_typePricingTypeFixed or dynamic
percentagefloatPrice adjustment (optional)
percentage_typePercentageTypePlus or Minus (optional)
unit_pricestrFixed unit price (optional)
deposit_asset_pricedictOracle price feed for deposit asset
withdrawal_asset_pricedictOracle 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

ExceptionLocationDescription
RPQServiceExceptionrpq_service/exceptions.pyBase for all RPQ errors
NoOffersAvailableExceptionNo offers for this token pair
QuoteUnavailableExceptionQuote cannot be generated
InvalidTokenPairExceptionToken pair not supported
PriceFeedNotFoundExceptionNo oracle price feed for token
MarketMakerWeb3Exceptionmarket_maker_web3/exceptions.pyBase for all on-chain errors
OfferNotFoundErrorOffer doesn't exist on-chain
OfferInactiveErrorOffer is cancelled or fully taken
InsufficientOfferBalanceErrorMaker has insufficient balance
OfferExpiredErrorOffer has passed expiration
UnauthorizedErrorCaller is not the offer creator

Supported networks

NetworkChain IDSupported
Polygon137✅
Ethereum1✅
Arbitrum42161✅
Base8453✅
Optimism10✅

Contract addresses are loaded dynamically from remote config. Set SWARM_COLLECTION_MODE=dev (default) or prod.