Method: openPosition
The openPosition method is used to open a trading position with various parameters such as position side, take profit, stop loss, leverage, and maximum time to open the position. There are multiple overloads of this method to accommodate different trading scenarios.
Overloads
openPosition(PositionSide positionSide, double? takeProfit, double? stopLoss)openPosition(PositionSide positionSide, double? takeProfit, int leverage)openPosition(PositionSide positionSide, double takeProfit, double stopLoss, string openMaxTime)
1. openPosition(PositionSide positionSide, double? takeProfit, double? stopLoss)
Description
Opens a trading position specifying the side (long or short), with optional take profit and stop loss levels.
Parameters
-
positionSide (
PositionSide): The direction of the position to open.PositionSide.BUY: Indicates a long position.PositionSide.SELL: Indicates a short position.
-
takeProfit (
double?): (Optional) The price level at which to take profit. Set tonullif no take profit is desired. -
stopLoss (
double?): (Optional) The price level at which to stop loss. Set tonullif no stop loss is desired.
Usage Example
// Open a long position with take profit at 1.1500 and stop loss at 1.1200
openPosition(PositionSide.BUY, 1.1500, 1.1200);
// Open a short position without take profit or stop loss
openPosition(PositionSide.SELL, null, null);
Notes
- If both
takeProfitandstopLossare omitted (null), the position will be opened without any profit or loss targets. - Use this overload when leverage is not a concern or defaults to the account's standard leverage.