cow.quote
Documentation for eth_defi.cow.quote Python module.
Fetching CowSwap quotes.
Functions
|
Fetch a CowSwap quote for a given token pair and amounts. |
Classes
CowSwap quote response. |
- class Quote
Bases:
objectCowSwap quote response.
How does it look like:
{"Buy": "USDC.e", "Price": "3839.194418725202484702282634", "Sell": "WETH", "expiration": "2025-10-31T08:56:32.245289888Z", "from": "0xdcc6d3a3c006bb4a10b448b1ee750966395622c6", "id": 59969377, "quote": {"appData": "0x0000000000000000000000000000000000000000000000000000000000000000", "buyAmount": "374313", "buyToken": "0xff970a61a04b1ca14834a43f5de4533ebddb5cc8", "buyTokenBalance": "erc20", "feeAmount": "2502202500000", "kind": "sell", "partiallyFillable": False, "receiver": None, "sellAmount": "97497797500000", "sellToken": "0x82af49447d8a07e3bd95bd0d56f35241523fbab1", "sellTokenBalance": "erc20", "signingScheme": "presign", "validTo": 1761902192}, "verified": True}
- buy_token: eth_defi.token.TokenDetails
Token we are going to receive (token out)
- sell_token: eth_defi.token.TokenDetails
Token we are losing (token in)
- data: dict
Raw data from CowSwap quote endpoint
See Order structure at https://docs.cow.fi/cow-protocol/reference/apis/orderbook
- get_buy_amount()
Get the buy amount from the quote.
- Return type
- get_sell_amount()
Get the sell amount from the quote.
- Return type
- get_price()
Get the price implied by the quote (buy amount / sell amount).
- Return type
- __init__(buy_token, sell_token, data)
- Parameters
buy_token (eth_defi.token.TokenDetails) –
sell_token (eth_defi.token.TokenDetails) –
data (dict) –
- Return type
None
- fetch_quote(from_, buy_token, sell_token, amount_in, min_amount_out, api_timeout=datetime.timedelta(seconds=30), price_quality='fast')
Fetch a CowSwap quote for a given token pair and amounts.
Note
Work in progress.
https://docs.cow.fi/cow-protocol/reference/apis/quote
Example:
chain_id = web3.eth.chain_id weth = fetch_erc20_details( web3, WRAPPED_NATIVE_TOKEN[chain_id], ) usdce = fetch_erc20_details(web3, BRIDGED_USDC_TOKEN[chain_id]) amount = Decimal("0.0001") quoted_data = fetch_quote( from_="0xdcc6D3A3C006bb4a10B448b1Ee750966395622c6", # Dummy address buy_token=usdce, sell_token=weth, amount_in=amount, min_amount_out=amount / 2, ) assert quoted_data["from"].startswith("0x") # assert quoted_data["expiration"] == "1970-01-01T00:00:00Z" assert quoted_data["id"] is None assert quoted_data["verified"] is False assert quoted_data["quote"]["sellToken"] == "0x82af49447d8a07e3bd95bd0d56f35241523fbab1" assert quoted_data["quote"]["buyToken"] == "0xff970a61a04b1ca14834a43f5de4533ebddb5cc8" assert quoted_data["quote"]["receiver"] is None assert int(quoted_data["quote"]["sellAmount"]) > 1 assert int(quoted_data["quote"]["buyAmount"]) > 1 assert quoted_data["quote"]["validTo"] > 1761863893 assert quoted_data["quote"]["appData"] == "0x0000000000000000000000000000000000000000000000000000000000000000" assert int(quoted_data["quote"]["feeAmount"]) > 1 assert quoted_data["quote"]["kind"] == "sell" assert quoted_data["quote"]["partiallyFillable"] is False assert quoted_data["quote"]["sellTokenBalance"] == "erc20" assert quoted_data["quote"]["buyTokenBalance"] == "erc20" assert quoted_data["quote"]["signingScheme"] == "presign"
- Parameters
from_ (Union[eth_typing.evm.HexAddress, str]) –
buy_token (eth_defi.token.TokenDetails) –
sell_token (eth_defi.token.TokenDetails) –
amount_in (decimal.Decimal) –
min_amount_out (decimal.Decimal) –
api_timeout (datetime.timedelta) –
price_quality (Literal['fast', 'verified', 'optional']) –
- Return type