TradeOperation


Summary

Provides access to the properties describing an asynchronous trade operation.

Syntax

public class TradeOperation : Object

Members

NameTypeSummary
IsExecuting PropertyTrue if a trade operation is being executed, false if it completed
SetResult Method
ToString MethodThe description of a trade operation
TradeOperation MethodRepresents the trade operation description and the result of the operation.
TradeResult PropertyThe result of a trade operation

Example 1

TradeOperation operation = ExecuteMarketOrderAsync(TradeType.Buy, Symbol, 10000, "asynchronous");
if (operation.IsExecuting)
{
    Print("Trade is executing");
}
else
{
    if (operation.TradeResult.IsSuccessful)
        Print("Trade executed");
}

Example 2

protected override void OnStart()
{
    Positions.Opened += PositionsOnOpened;
    TradeOperation operation = ExecuteMarketOrderAsync(TradeType.Buy, Symbol, 10000, "asynchronous");
    ExecuteMarketOrder(TradeType.Buy, Symbol, 10000, "synchronous", 10, 10);
    if (operation.IsExecuting)
    {
        Print("Trade is executing");
    }
    else
    {
        if (operation.TradeResult.IsSuccessful)
            Print("Trade executed");
    }
}
private void PositionsOnOpened(PositionOpenedEventArgs args)
{
    var pos = args.Position;
    Print("Position {0} opened at {1}", pos.Label, pos.EntryPrice);
}

Example 3

using cAlgo.API;
namespace cAlgo.Robots
{
    // This sample cBot shows how to use TradeOperation to monitor an async order execution/placement operation
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TradeOperationSample : Robot
    {
        protected override void OnStart()
        {
            var tradeOperation = ExecuteMarketOrderAsync(TradeType.Buy, SymbolName, Symbol.VolumeInUnitsMin, OnTradeResult);
            if (tradeOperation.IsExecuting)
            {
                Print("Executing");
            }
            else
            {
                Print("Completed");
            }
        }
        private void OnTradeResult(TradeResult obj)
        {
            Print("Was Trade Operation Successful: ", obj.IsSuccessful);
        }
    }
}
Reference