Skip to content

TradeOperation

Summary

Provides access to the properties describing an asynchronous trade operation.

Signature

1
public sealed class TradeOperation

Namespace

cAlgo.API

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
 TradeOperation operation = ExecuteMarketOrderAsync(TradeType.Buy, Symbol, 10000, "asynchronous");
 if (operation.IsExecuting)
 {
     Print("Trade is executing");
 }
 else
 {
     if (operation.TradeResult.IsSuccessful)
         Print("Trade executed");
 }
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
 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);
 }
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 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);
         }
     }
 }

Methods

ToString

Summary

The description of a trade operation

Signature

1
public string ToString()

Return Value

string

Examples

1
2
 TradeOperation operation = ExecuteMarketOrderAsync(TradeType.Buy, Symbol, 10000, "asynchronous");
 Print(operation.ToString());

Properties

IsExecuting

Summary

True if a trade operation is being executed, false if it completed

Signature

1
public bool IsExecuting {get;}

Return Value

bool

Examples

1
2
3
4
5
6
 TradeOperation operation = ExecuteMarketOrderAsync(TradeType.Buy, Symbol, 20000, "myLabel");
 // ...
 if (!operation.IsExecuting)
 {
     Print("Trade executed");
 }

TradeResult

Summary

The result of a trade operation

Signature

1
public TradeResult TradeResult {get;}

Return Value

TradeResult

Examples

1
2
3
4
5
6
 TradeOperation operation = ExecuteMarketOrderAsync(TradeType.Buy, Symbol, 20000, "myLabel");
 // ...
 if (!operation.IsExecuting && operation.TradeResult.IsSuccessful)
 {
     Print("Trade {0} executed", operation.TradeResult.Position.Label);
 }