GetOrderVolume

Returns the volume (lot size) of the currently selected order.

Syntax

GetOrderVolume(): number

Return Value

Returns a number representing the volume (lot size) of the selected order.

Description

The GetOrderVolume method returns the volume or lot size of the currently selected order.

Before using this method, you must first select an order using the SelectOrder method.

Example

// Select an order by ticket number
if (this.api.SelectOrder(12345, EOrderSelectMode.SELECT_ORDER_BY_TICKET)) {
  // Get the order's volume
  const volume = this.api.GetOrderVolume();

  // Get the order's symbol
  const symbol = this.api.GetOrderSymbol();

  console.log(`Order #12345 has a volume of ${volume} lots on ${symbol}`);

  // Calculate the position size in base currency units
  const standardLotSize = 100000; // Standard lot size for forex
  const baseUnits = volume * standardLotSize;
  console.log(`Position size: ${baseUnits} units of base currency`);

  // Calculate required margin based on volume
  if (
    this.api.GetOrderType() === TTradePositionType.BUY ||
    this.api.GetOrderType() === TTradePositionType.SELL
  ) {
    // Example margin calculation (simplified)
    const leverage = this.api.GetLeverageRatio();
    const price = this.api.GetOrderOpenPrice();
    const margin = (baseUnits * price) / leverage;

    console.log(`Approximate margin required: ${margin.toFixed(2)}`);
  }
}

Notes

  • An order must be selected first using SelectOrder before calling this method.

  • This method can be used for both open and historical orders.

Last updated