> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fairground.fi/llms.txt
> Use this file to discover all available pages before exploring further.

# liquidate

> Python SDK reference for liquidate.

Execute liquidations for a market at given price offset.

```python theme={null}
async def liquidate(marketId: int, price_offset: int):
    """Execute liquidations for a market at given price offset."""
    liquidations = await retrieveLiquidations(marketId, price_offset)

    if not liquidations:
        print("No liquidations found for this market at the given price offset.")
        return

    ids = []
    for liquidation_data in liquidations:
        for position_id in liquidation_data.position_ids_to_liquidate:
            ids.append(position_id)

    if not ids:
        print("No position IDs to liquidate.")
        return

    print(f"Found {len(ids)} position(s) to liquidate: {ids}")

    MyStruct = namedtuple(
        "LiquidationPerMarketInput",
        ["marketId", "openOrderIds"],
    )
    my_struct_data = MyStruct(marketId=marketId, openOrderIds=ids)
    contract = retrieveContract()
    w3 = retrieveWeb3Instance()
    transaction = contract.functions.liquidatePositions(
        [my_struct_data]
    ).build_transaction(
        {
            "from": Web3.to_checksum_address(os.getenv("ACCOUNT")),
            "nonce": w3.eth.get_transaction_count(
                Web3.to_checksum_address(os.getenv("ACCOUNT"))
            ),
            "gas": 1000000,
            "gasPrice": w3.eth.gas_price,
        }
    )
    await submitTransactionWithOracle(w3, transaction, marketId)

```
