Skip to content

spot.trade

Public methods exposed through client.spot.trade.

batch_orders

Creates up to 20 orders for the same symbol in one signed request.

Parameters:

Name Type Description Default
batch_orders list[BatchOrderRequest]

List of order objects; maximum 20 orders with the same symbol.

required
recv_window int | None

Optional receive window in milliseconds; maximum 60000.

None
timestamp Timestamp | None

Signed request timestamp in milliseconds.

None
validate bool | None

Validation override for this request.

None

Returns:

Type Description
list[BatchOrdersItem]

The validated endpoint response.

References
Source code in pkg/src/mexc/spot/trade/batch_orders.py
async def batch_orders(
  self,
  *,
  batch_orders: list[BatchOrderRequest],
  recv_window: int | None = None,
  timestamp: Timestamp | None = None,
  validate: bool | None = None
) -> list[BatchOrdersItem]:
  """Creates up to 20 orders for the same symbol in one signed request.

  Args:
    batch_orders: List of order objects; maximum 20 orders with the same symbol.
    recv_window: Optional receive window in milliseconds; maximum 60000.
    timestamp: Signed request timestamp in milliseconds.
    validate: Validation override for this request.

  Returns:
    The validated endpoint response.

  References:
    - [MEXC API docs](https://mexcdevelop.github.io/apidocs/spot_v3_en/#batch-orders)
  """
  if timestamp is None:
    timestamp = ts.now()
  params = {}
  if batch_orders is not None:
    params['batchOrders'] = batch_orders
  if recv_window is not None:
    params['recvWindow'] = recv_window
  if timestamp is not None:
    params['timestamp'] = ts.dump_ms(timestamp)
  r = await self.signed_request('POST', '/api/v3/batchOrders', params=params)
  return self.output(r.text, adapter, validate)

cancel_open_orders

Cancels pending orders for one or more symbols on the signed account.

Parameters:

Name Type Description Default
symbol str

One symbol or up to five comma-separated symbols.

required
recv_window int | None

Optional receive window in milliseconds; maximum 60000.

None
timestamp Timestamp | None

Signed request timestamp in milliseconds.

None
validate bool | None

Validation override for this request.

None

Returns:

Type Description
list[CancelOpenOrdersItem]

The validated endpoint response.

References
Source code in pkg/src/mexc/spot/trade/cancel_open_orders.py
async def cancel_open_orders(
  self,
  *,
  symbol: str,
  recv_window: int | None = None,
  timestamp: Timestamp | None = None,
  validate: bool | None = None
) -> list[CancelOpenOrdersItem]:
  """Cancels pending orders for one or more symbols on the signed account.

  Args:
    symbol: One symbol or up to five comma-separated symbols.
    recv_window: Optional receive window in milliseconds; maximum 60000.
    timestamp: Signed request timestamp in milliseconds.
    validate: Validation override for this request.

  Returns:
    The validated endpoint response.

  References:
    - [MEXC API docs](https://mexcdevelop.github.io/apidocs/spot_v3_en/#cancel-all-open-orders-on-a-symbol)
  """
  if timestamp is None:
    timestamp = ts.now()
  params = {}
  if symbol is not None:
    params['symbol'] = symbol
  if recv_window is not None:
    params['recvWindow'] = recv_window
  if timestamp is not None:
    params['timestamp'] = ts.dump_ms(timestamp)
  r = await self.signed_request('DELETE', '/api/v3/openOrders', params=params)
  return self.output(r.text, adapter, validate)

cancel_order

Cancels one active spot order by order id or original client order id.

Parameters:

Name Type Description Default
symbol str

Spot symbol.

required
order_id str | None

Order id.

None
orig_client_order_id str | None

Original client order id.

None
new_client_order_id str | None

Optional cancel client id.

None
recv_window int | None

Optional receive window in milliseconds; maximum 60000.

None
timestamp Timestamp | None

Signed request timestamp in milliseconds.

None
validate bool | None

Validation override for this request.

None

Returns:

Type Description
CancelOrderResponse

The validated endpoint response.

References
Source code in pkg/src/mexc/spot/trade/cancel_order.py
async def cancel_order(
  self,
  *,
  symbol: str,
  order_id: str | None = None,
  orig_client_order_id: str | None = None,
  new_client_order_id: str | None = None,
  recv_window: int | None = None,
  timestamp: Timestamp | None = None,
  validate: bool | None = None
) -> CancelOrderResponse:
  """Cancels one active spot order by order id or original client order id.

  Args:
    symbol: Spot symbol.
    order_id: Order id.
    orig_client_order_id: Original client order id.
    new_client_order_id: Optional cancel client id.
    recv_window: Optional receive window in milliseconds; maximum 60000.
    timestamp: Signed request timestamp in milliseconds.
    validate: Validation override for this request.

  Returns:
    The validated endpoint response.

  References:
    - [MEXC API docs](https://mexcdevelop.github.io/apidocs/spot_v3_en/#cancel-order)
  """
  if timestamp is None:
    timestamp = ts.now()
  params = {}
  if symbol is not None:
    params['symbol'] = symbol
  if order_id is not None:
    params['orderId'] = order_id
  if orig_client_order_id is not None:
    params['origClientOrderId'] = orig_client_order_id
  if new_client_order_id is not None:
    params['newClientOrderId'] = new_client_order_id
  if recv_window is not None:
    params['recvWindow'] = recv_window
  if timestamp is not None:
    params['timestamp'] = ts.dump_ms(timestamp)
  r = await self.signed_request('DELETE', '/api/v3/order', params=params)
  return self.output(r.text, adapter, validate)

place_order

Creates a live spot order on the signed account.

Parameters:

Name Type Description Default
symbol str

Spot symbol.

required
side Literal['BUY', 'SELL']

Order side.

required
type_ Literal['LIMIT', 'MARKET', 'LIMIT_MAKER', 'IMMEDIATE_OR_CANCEL', 'FILL_OR_KILL']

Order type.

required
quantity str | None

Base-asset quantity.

None
quote_order_qty str | None

Quote-asset amount.

None
price str | None

Limit price.

None
new_client_order_id str | None

Client order id.

None
recv_window int | None

Optional receive window in milliseconds; maximum 60000.

None
timestamp Timestamp | None

Signed request timestamp in milliseconds.

None
validate bool | None

Validation override for this request.

None

Returns:

Type Description
PlaceOrderResponse

The validated endpoint response.

References
Source code in pkg/src/mexc/spot/trade/place_order.py
async def place_order(
  self,
  *,
  symbol: str,
  side: Literal['BUY', 'SELL'],
  type_: Literal['LIMIT', 'MARKET', 'LIMIT_MAKER', 'IMMEDIATE_OR_CANCEL', 'FILL_OR_KILL'],
  quantity: str | None = None,
  quote_order_qty: str | None = None,
  price: str | None = None,
  new_client_order_id: str | None = None,
  recv_window: int | None = None,
  timestamp: Timestamp | None = None,
  validate: bool | None = None
) -> PlaceOrderResponse:
  """Creates a live spot order on the signed account.

  Args:
    symbol: Spot symbol.
    side: Order side.
    type_: Order type.
    quantity: Base-asset quantity.
    quote_order_qty: Quote-asset amount.
    price: Limit price.
    new_client_order_id: Client order id.
    recv_window: Optional receive window in milliseconds; maximum 60000.
    timestamp: Signed request timestamp in milliseconds.
    validate: Validation override for this request.

  Returns:
    The validated endpoint response.

  References:
    - [MEXC API docs](https://mexcdevelop.github.io/apidocs/spot_v3_en/#new-order)
  """
  if timestamp is None:
    timestamp = ts.now()
  params = {}
  if symbol is not None:
    params['symbol'] = symbol
  if side is not None:
    params['side'] = side
  if type_ is not None:
    params['type'] = type_
  if quantity is not None:
    params['quantity'] = quantity
  if quote_order_qty is not None:
    params['quoteOrderQty'] = quote_order_qty
  if price is not None:
    params['price'] = price
  if new_client_order_id is not None:
    params['newClientOrderId'] = new_client_order_id
  if recv_window is not None:
    params['recvWindow'] = recv_window
  if timestamp is not None:
    params['timestamp'] = ts.dump_ms(timestamp)
  r = await self.signed_request('POST', '/api/v3/order', params=params)
  return self.output(r.text, adapter, validate)

test_order

Validates a new order without sending it to the matching engine.

Parameters:

Name Type Description Default
symbol str

Spot symbol.

required
side Literal['BUY', 'SELL']

Order side.

required
type_ Literal['LIMIT', 'MARKET', 'LIMIT_MAKER', 'IMMEDIATE_OR_CANCEL', 'FILL_OR_KILL']

Order type.

required
quantity str | None

Base-asset quantity.

None
quote_order_qty str | None

Quote-asset amount.

None
price str | None

Limit price.

None
new_client_order_id str | None

Client order id.

None
recv_window int | None

Optional receive window in milliseconds; maximum 60000.

None
timestamp Timestamp | None

Signed request timestamp in milliseconds.

None
validate bool | None

Validation override for this request.

None

Returns:

Type Description
TestOrderResponse

The validated endpoint response.

References
Source code in pkg/src/mexc/spot/trade/test_order.py
async def test_order(
  self,
  *,
  symbol: str,
  side: Literal['BUY', 'SELL'],
  type_: Literal['LIMIT', 'MARKET', 'LIMIT_MAKER', 'IMMEDIATE_OR_CANCEL', 'FILL_OR_KILL'],
  quantity: str | None = None,
  quote_order_qty: str | None = None,
  price: str | None = None,
  new_client_order_id: str | None = None,
  recv_window: int | None = None,
  timestamp: Timestamp | None = None,
  validate: bool | None = None
) -> TestOrderResponse:
  """Validates a new order without sending it to the matching engine.

  Args:
    symbol: Spot symbol.
    side: Order side.
    type_: Order type.
    quantity: Base-asset quantity.
    quote_order_qty: Quote-asset amount.
    price: Limit price.
    new_client_order_id: Client order id.
    recv_window: Optional receive window in milliseconds; maximum 60000.
    timestamp: Signed request timestamp in milliseconds.
    validate: Validation override for this request.

  Returns:
    The validated endpoint response.

  References:
    - [MEXC API docs](https://mexcdevelop.github.io/apidocs/spot_v3_en/#test-new-order)
  """
  if timestamp is None:
    timestamp = ts.now()
  params = {}
  if symbol is not None:
    params['symbol'] = symbol
  if side is not None:
    params['side'] = side
  if type_ is not None:
    params['type'] = type_
  if quantity is not None:
    params['quantity'] = quantity
  if quote_order_qty is not None:
    params['quoteOrderQty'] = quote_order_qty
  if price is not None:
    params['price'] = price
  if new_client_order_id is not None:
    params['newClientOrderId'] = new_client_order_id
  if recv_window is not None:
    params['recvWindow'] = recv_window
  if timestamp is not None:
    params['timestamp'] = ts.dump_ms(timestamp)
  r = await self.signed_request('POST', '/api/v3/order/test', params=params)
  return self.output(r.text, adapter, validate)