BuyAtMarket

BuyAtMarket

In the OsEngine BotTabSimple class, there are two overloads of the BuyAtMarket method.

public Position BuyAtMarket(decimal volume)

This public method sends a signal to the connector for a market price purchase. It accepts a single parameter, which is the volume for the transaction. It creates and returns a new position with the state PositionStateType.Opening. The use of the method in the code looks like this:

The second variant takes an additional parameter in the form of a string indicating the signal for opening the position. The method signature:

public Position BuyAtMarket(decimal volume, string signalType)

The signalType parameter can contain any value set in the strategy algorithm. Using a signal for entry is convenient for separating positions within a single robot.

Let's modify our example:

1. Create a string-type variable and, depending on the current market time, initialize it with the corresponding value.

2. Open a market position by passing the name of the signal to the method.

3. Access the SignalTypeOpen field on the created position instance to get its value, and output an informational message in the log about which signal was used.

As a result, we can see the names of the signals in the position tables in the program interface:

It's worth noting that both methods emulate a market order using a limit order if the connector does not support market execution.

If you have any difficulties or questions, please write to the support chat. Link