Skip to main content
async def cancelOrdersBatch(
    marketIds: list[int], openOrderIds: list[int], reduceOnly: list[bool]
):
    contract = retrieveContract()
    w3 = retrieveWeb3Instance()

    retVals = []
    orders = await retrieveOrders()
    for i, order in enumerate(orders, 0):
        if order.order_id in openOrderIds:
            retVals.append(order)

    transaction = contract.functions.cancelOrdersBatch(
        marketIds, openOrderIds, reduceOnly
    ).build_transaction(
        {
            "from": Web3.to_checksum_address(os.getenv("ACCOUNT")),
            "nonce": w3.eth.get_transaction_count(
                Web3.to_checksum_address(os.getenv("ACCOUNT"))
            ),
            "gas": GAS_VALUE,
            "gasPrice": math.ceil(w3.eth.gas_price + (w3.eth.gas_price * 0.25)),
        }
    )

    # TODO: determine how to handle multiple market ids
    await submitTransactionWithOracle(w3, transaction, marketIds[0])
    print("Canceled orders: ", retVals)
    return retVals