search Nothing found
Main Algotrading documentation Trade operations Pending orders

PendingOrders.Open

We send a request to place a pending order with the specified parameters.

There are two ways to call a method:

int PendingOrders.Open(symbolName, oprderType, volume, price, takeProfit, stopLoss, label, out orderId, isJustCheck = false, isAsync = false)

Input parameters

Parameter
Type
Description
SymbolName
string
Symbol name
OrderType
Pending order type (buy stop, buy limit, sell stop, sell limit):
100 – Buy Limit
101 – Sell Limit
102 – Buy Stop
103 – SellStop
volume
double
Position volume in lots
price
double
The price in quoted currency at which a pending order is placed
takeProfit
double
Take profit. Price level in quoted currency for profit fixing.
stopLoss
double
Stoploss. Price level in quoted currency for fixing losses.
label
string
A unique label of a pending order, which is used to identify a pending order in an asynchronous function call method.
orderId
out int
It is possible to set up a variable in the parameter, into which a unique identifier will be recorded after a successful opening of a pending order. The parameter works only for synchronous mode.
isJustCheck
bool
Check mode (enabled or disabled). When the mode is enabled, a request to open a position is not sent, but only the possibility of opening with such parameters is checked. Disabled by default
 = false
isAsync
bool
Asynchronous mode (enabled or disabled).
Disabled by default
= false


int PendingOrders.Open(ref order, isJustCheck = false, isAsync = false)

Input parameters

Parameter
Type
Description
order
An object that contains all operation parameters for placing a pending order
isJustCheck
bool
Check mode (enabled or disabled). When the mode is enabled, a request to open a position is not sent, but only the possibility of opening with such parameters is checked. Disabled by default
 = false
isAsync
bool
Asynchronous mode (enabled or disabled).
Disabled by default
= false


Return value:

If isJustCheck= true

It returns the result code of the operation:

0
Check for the possibility of opening was successful. Check occurs on the client side
-1
Check failed


If isAsync= false (synchronous mode by default), it returns the result code of the operation:

0
Pending order is placed successfully
If an error occurs, it returns the server error code

If the name of the variable is passed to the out parameter orderId and the order is successfully placed, then the unique identifier of the placed order will be recorded to this variable.


If isAsync= true (asynchronous mode)

0
The request to place a pending order was successfully sent to the server. It does not mean that the pending order has already been placed or will definitely be placed.
If an error occurs, it returns the error code received on the client. The codes match the server error codes.

Using the out parameter orderId in asynchronous mode does not make sense. It will always return -1


Example:

// Placing a pending BuyStop order at a distance N from the current price
private void OpenPendingOrder(int N)
{
int orderId;
string line ="";
double price = Math.Round(Symbol.Quote.Ask + N / Math.Pow(10, Symbol.Digits), Symbol.Digits);
double takeProfit = Math.Round(price + N / Math.Pow(10, Symbol.Digits), Symbol.Digits);
double stopLoss = Math.Round(price - N / Math.Pow(10, Symbol.Digits), Symbol.Digits);

int err = PendingOrders.Open(Symbol.SymbolName, OrderType.BuyStop, 0.5, price, takeProfit, stopLoss, "TestOrderLabel", out orderId);
if (err != 0) {
line = " Failed, ServerErrorCode = " + err.ToString() + Environment.NewLine;
}
}




Subscribe to our newsletter and stay up to date with all the news!