# MT5 Python order_send()

Independent and unofficial. Not affiliated with or endorsed by any broker or platform named here. Educational only: nothing here is advice, and nothing here recommends a broker or a trade.

This is the markdown version of https://openbrokerapi.com/platforms/metatrader-5/functions/python-order-send, written from the same records as that page.

Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.

Sends a trade request from the terminal to the trade server. One call covers a market order, a pending order, a change to an order or position, a cancellation and a close: the request's action field says which.

- Function: `order_send()`
- Interface: MetaTrader5 Python package
- Group: Orders
- Status: verified. Source: [mql5.com](https://www.mql5.com/en/docs/python_metatrader5/mt5ordersend_py), checked 2026-10-12.

This is a Python function, not an HTTP endpoint. It has no method, no path and no address to send a request to: the package talks to a MetaTrader 5 terminal running on the same computer. It is in no OpenAPI file on this site and the request builder does not list it.

Note: This call can place a real order on whichever account the terminal is logged in to, demo or live. The page says a request goes through several checks on the trade server and that a request being accepted is not the same as the trade being done. The action field takes a value of the TRADE_REQUEST_ACTIONS enumeration. The page for order_check() lists them: TRADE_ACTION_DEAL, TRADE_ACTION_PENDING, TRADE_ACTION_SLTP, TRADE_ACTION_MODIFY, TRADE_ACTION_REMOVE and TRADE_ACTION_CLOSE_BY.

## Signature

The form of the call on the vendor's page, with the vendor's comments taken out.

```python
order_send(
  request
)
```

## Arguments

- `request` (type MqlTradeRequest structure, required): The trade request. In Python it is written as a dictionary, as the page's example does. The page lists its fields: action, magic, order, symbol, volume, price, stoplimit, sl, tp, deviation, type, type_filling, type_time, expiration, comment, position and position_by. Which are needed depends on the action.

## Return value

- Type: `MqlTradeResult structure`
- What comes back: The result of the request. Its request field holds the request that was passed in, and its retcode field holds the trade server's return code. The page's example output prints it as OrderSendResult, with retcode, deal, order, volume, price, bid, ask, comment and request_id.

## Sample

Written by this site from the signature and arguments recorded on this page. It has not been run against a terminal, a server or an account, and the values in it are placeholders. No credential is typed into it: where one is needed it is read from an environment variable on your own machine. Nothing is entered on this site.

```python
import MetaTrader5 as mt5

if not mt5.initialize():
    raise SystemExit(f"initialize() failed: {mt5.last_error()}")

# Run this only against a demo account. It sends a market order.
symbol = "EURUSD"
tick = mt5.symbol_info_tick(symbol)
request = {
    "action": mt5.TRADE_ACTION_DEAL,
    "symbol": symbol,
    "volume": 0.1,
    "type": mt5.ORDER_TYPE_BUY,
    "price": tick.ask,
    "deviation": 20,
    "magic": 234000,
    "comment": "sample",
    "type_time": mt5.ORDER_TIME_GTC,
    "type_filling": mt5.ORDER_FILLING_RETURN,
}
result = mt5.order_send(request)
if result is None:
    print("order_send() failed:", mt5.last_error())
elif result.retcode != mt5.TRADE_RETCODE_DONE:
    print("not done, retcode", result.retcode)
else:
    print("done, order", result.order)

mt5.shutdown()
```

## Return codes documented for this function

The page says the call returns the MqlTradeResult structure, and its example tests that result's retcode field against TRADE_RETCODE_DONE. The values that field can hold are the MetaTrader 5 trade server return codes, each recorded below from MetaQuotes' own list of them. Status: verified. Source: [mql5.com](https://www.mql5.com/en/docs/python_metatrader5/mt5ordersend_py), checked 2026-10-12.

- [TRADE_RETCODE_REQUOTE (10004)](https://openbrokerapi.com/errors/mt5/trade-retcode-requote): The price changed and the server offered a new one.
- [TRADE_RETCODE_REJECT (10006)](https://openbrokerapi.com/errors/mt5/trade-retcode-reject): The server rejected the request.
- [TRADE_RETCODE_CANCEL (10007)](https://openbrokerapi.com/errors/mt5/10007-trade-retcode-cancel): The request was cancelled by the trader.
- [TRADE_RETCODE_PLACED (10008)](https://openbrokerapi.com/errors/mt5/10008-trade-retcode-placed): The order was placed.
- [TRADE_RETCODE_DONE (10009)](https://openbrokerapi.com/errors/mt5/10009-trade-retcode-done): The request was completed.
- [TRADE_RETCODE_DONE_PARTIAL (10010)](https://openbrokerapi.com/errors/mt5/10010-trade-retcode-done-partial): Only part of the request was completed.
- [TRADE_RETCODE_ERROR (10011)](https://openbrokerapi.com/errors/mt5/10011-trade-retcode-error): The server reports an error in processing the request.
- [TRADE_RETCODE_TIMEOUT (10012)](https://openbrokerapi.com/errors/mt5/10012-trade-retcode-timeout): The request was cancelled because it timed out.
- [TRADE_RETCODE_INVALID (10013)](https://openbrokerapi.com/errors/mt5/trade-retcode-invalid): The trade request is malformed.
- [TRADE_RETCODE_INVALID_VOLUME (10014)](https://openbrokerapi.com/errors/mt5/trade-retcode-invalid-volume): Volume is outside min, max or step for the symbol.
- [TRADE_RETCODE_INVALID_PRICE (10015)](https://openbrokerapi.com/errors/mt5/trade-retcode-invalid-price): The price is not valid.
- [TRADE_RETCODE_INVALID_STOPS (10016)](https://openbrokerapi.com/errors/mt5/trade-retcode-invalid-stops): Stop loss or take profit is invalid, often too close to price.
- [10017 TRADE_RETCODE_TRADE_DISABLED](https://openbrokerapi.com/errors/mt5/10017): Trading is disabled.
- [TRADE_RETCODE_MARKET_CLOSED (10018)](https://openbrokerapi.com/errors/mt5/trade-retcode-market-closed): The market is closed.
- [TRADE_RETCODE_NO_MONEY (10019)](https://openbrokerapi.com/errors/mt5/trade-retcode-no-money): Insufficient margin.
- [TRADE_RETCODE_PRICE_CHANGED (10020)](https://openbrokerapi.com/errors/mt5/10020-trade-retcode-price-changed): Prices changed while the request was being handled.
- [TRADE_RETCODE_PRICE_OFF (10021)](https://openbrokerapi.com/errors/mt5/10021-trade-retcode-price-off): There are no quotes to process the request.
- [10022 TRADE_RETCODE_INVALID_EXPIRATION](https://openbrokerapi.com/errors/mt5/10022): The order expiration date in the request is invalid.
- [TRADE_RETCODE_ORDER_CHANGED (10023)](https://openbrokerapi.com/errors/mt5/10023-trade-retcode-order-changed): The state of the order changed.
- [10024 TRADE_RETCODE_TOO_MANY_REQUESTS](https://openbrokerapi.com/errors/mt5/10024): Requests are being sent too often.
- [TRADE_RETCODE_NO_CHANGES (10025)](https://openbrokerapi.com/errors/mt5/10025-trade-retcode-no-changes): The request contains no changes.
- [10026 TRADE_RETCODE_SERVER_DISABLES_AT](https://openbrokerapi.com/errors/mt5/10026): Autotrading is disabled by the server.
- [TRADE_RETCODE_CLIENT_DISABLES_AT (10027)](https://openbrokerapi.com/errors/mt5/trade-retcode-client-disables-at): Algo trading is switched off in the terminal.
- [TRADE_RETCODE_LOCKED (10028)](https://openbrokerapi.com/errors/mt5/10028-trade-retcode-locked): The request is locked for processing.
- [TRADE_RETCODE_FROZEN (10029)](https://openbrokerapi.com/errors/mt5/10029-trade-retcode-frozen): The order or position is frozen.
- [10030](https://openbrokerapi.com/errors/mt5/10030): Invalid order filling type: order_send asked for a filling mode the symbol does not allow.
- [TRADE_RETCODE_CONNECTION (10031)](https://openbrokerapi.com/errors/mt5/10031-trade-retcode-connection): There is no connection with the trade server.
- [TRADE_RETCODE_ONLY_REAL (10032)](https://openbrokerapi.com/errors/mt5/10032-trade-retcode-only-real): The operation is allowed only for live accounts.
- [TRADE_RETCODE_LIMIT_ORDERS (10033)](https://openbrokerapi.com/errors/mt5/10033-trade-retcode-limit-orders): The number of pending orders has reached the limit.
- [TRADE_RETCODE_LIMIT_VOLUME (10034)](https://openbrokerapi.com/errors/mt5/10034-trade-retcode-limit-volume): The volume of orders and positions for the symbol has reached the limit.
- [TRADE_RETCODE_INVALID_ORDER (10035)](https://openbrokerapi.com/errors/mt5/10035-trade-retcode-invalid-order): The order type is incorrect or prohibited.
- [10036 TRADE_RETCODE_POSITION_CLOSED](https://openbrokerapi.com/errors/mt5/10036): The position with the specified POSITION_IDENTIFIER has already been closed.
- [10038 TRADE_RETCODE_INVALID_CLOSE_VOLUME](https://openbrokerapi.com/errors/mt5/10038): The close volume is larger than the current volume of the position.
- [10039 TRADE_RETCODE_CLOSE_ORDER_EXIST](https://openbrokerapi.com/errors/mt5/10039): A close order already exists for the position.
- [10040 TRADE_RETCODE_LIMIT_POSITIONS](https://openbrokerapi.com/errors/mt5/10040): The number of open positions on the account has reached a limit set on the server.
- [TRADE_RETCODE_REJECT_CANCEL (10041)](https://openbrokerapi.com/errors/mt5/10041-trade-retcode-reject-cancel): The request to activate a pending order was rejected and the order was cancelled.
- [TRADE_RETCODE_LONG_ONLY (10042)](https://openbrokerapi.com/errors/mt5/10042-trade-retcode-long-only): The request was rejected because the symbol has the rule "Only long positions are allowed" (POSITION_TYPE_BUY).
- [TRADE_RETCODE_SHORT_ONLY (10043)](https://openbrokerapi.com/errors/mt5/10043-trade-retcode-short-only): The request was rejected because the symbol has the rule "Only short positions are allowed" (POSITION_TYPE_SELL).
- [TRADE_RETCODE_CLOSE_ONLY (10044)](https://openbrokerapi.com/errors/mt5/10044-trade-retcode-close-only): The request was rejected because the symbol has the rule "Only position closing is allowed".
- [TRADE_RETCODE_FIFO_CLOSE (10045)](https://openbrokerapi.com/errors/mt5/10045-trade-retcode-fifo-close): The request was rejected because the trading account has the flag "Position closing is allowed only by FIFO rule" set (ACCOUNT_FIFO_CLOSE=true).
- [10046 TRADE_RETCODE_HEDGE_PROHIBITED](https://openbrokerapi.com/errors/mt5/10046): The request was rejected because the trading account has the rule "Opposite positions on a single symbol are disabled".

## Related MT5 Python functions: Orders

- [order_calc_margin()](https://openbrokerapi.com/platforms/metatrader-5/functions/python-order-calc-margin): Works out the margin, in the account's currency, that a trade of a given type, symbol, volume and price would need.
- [order_calc_profit()](https://openbrokerapi.com/platforms/metatrader-5/functions/python-order-calc-profit): Works out the profit or loss, in the account's currency, of a trade opened at one price and closed at another.
- [order_check()](https://openbrokerapi.com/platforms/metatrader-5/functions/python-order-check): Checks whether the account has the funds for a trade request without sending it, and returns what the balance, equity and margin would be.
- [orders_get()](https://openbrokerapi.com/platforms/metatrader-5/functions/python-orders-get): Returns the active pending orders on the account: all of them, those in one symbol, those whose symbol matches a filter, or the one with a given ticket.
- [orders_total()](https://openbrokerapi.com/platforms/metatrader-5/functions/python-orders-total): Returns how many pending orders are active on the account.

## More on MetaTrader 5

- [All MetaTrader 5 functions](https://openbrokerapi.com/platforms/metatrader-5/functions): 78 documented here, grouped by what they do.
- [Place an order: the call at each API](https://openbrokerapi.com/endpoints/place-order): The same job at every broker and platform API recorded here, HTTP or not.
- [Amend an order: the call at each API](https://openbrokerapi.com/endpoints/amend-order): The same job at every broker and platform API recorded here, HTTP or not.
- [Cancel an order: the call at each API](https://openbrokerapi.com/endpoints/cancel-order): The same job at every broker and platform API recorded here, HTTP or not.
- [Close a position: the call at each API](https://openbrokerapi.com/endpoints/close-position): The same job at every broker and platform API recorded here, HTTP or not.
- [MetaTrader 5 API quickstart](https://openbrokerapi.com/platforms/metatrader-5/quickstart)
- [All MetaTrader 5 error codes](https://openbrokerapi.com/errors/mt5)
- [MetaTrader 5 API page](https://openbrokerapi.com/platforms/metatrader-5): The full record: access, authentication, limits and the source for each.

## Licence and how to cite

The records behind this page are all rights reserved. This file is the page itself, at its own address, in another format. It is not part of the CC BY 4.0 downloads listed at https://openbrokerapi.com/data. Quote from it with a link to the page.

Cite as: MT5 Python order_send(). Broker API Hub, https://openbrokerapi.com/platforms/metatrader-5/functions/python-order-send, newest check 2026-10-12.

Where you rely on a single figure, cite the source and the checked date printed beside it as well. Where this page and a broker's own documentation differ, the documentation wins.
