marketBuyETH

marketBuyETH

function marketBuyETH(
        address base,
        bool isMaker,
        uint32 n,
        address recipient
) external payable returns (uint256 makePrice, uint256 placed, uint32 id);
Executes a market buy order with ETH deposit,
matches ask orders in the orderbook for buying the base asset using the quote asset as ETH at a specified market price,
and makes an order at the market price or increased price on suspension with remainder amount.

Parameters

NameTypeDescription

base

address

Address of the base asset for the trading pair.

isMaker

bool

Boolean indicating if an order should be made at the market price in the orderbook.

n

uint32

The maximum number of orders to match in the orderbook.

recipient

address

Address of recipient to receive funds from trading and ownership of placed order.

Value

This function requires ETH deposit as quote amount from msg.value.

pragma solidity ^0.8.24;

import {IMatchingEngine} from "standard3.0-contracts/src/exchange/interfaces/IMatchingEngine.sol";

contract CLOB {
    IMatchingEngine public matchingEngine;
 
    constructor(address _engine) {
        matchingEngine = IMatchingEngine(_engine);
    }

    function marketBuyETH(address base, bool isMaker, uint32 matchingN, address recipient) public payable {
        matchingEngine.marketBuyETH{value: msg.value}(
            base,
            isMaker,
            matchingN,
            recipient
        );
    }
}

Returns

  • uint256 makePrice : Price which was placed after matching

  • uint256 placed : Remainder mount which is placed in order after matching

  • uint32 id: Placed orderId after matching orders. The id is then used for canceling order.

Last updated