Skip to content

TradeResult

Summary

The result of a trade operation.

Signature

1
public sealed class TradeResult

Namespace

cAlgo.API

Examples

1
2
3
 TradeResult result = ExecuteMarketOrder(TradeType.Sell, Symbol.Name, 20000);
 if (result.IsSuccessful)
     Print("Sell at {0}", result.Position.EntryPrice);
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 using cAlgo.API;
 namespace cAlgo.Robots
 {
     // This sample cBot shows how to get a trade operation result
     [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
     public class Test : Robot
     {
         protected override void OnStart()
         {
             var tradeResult = ExecuteMarketOrder(TradeType.Buy, SymbolName, Symbol.VolumeInUnitsMin);
             if (tradeResult.IsSuccessful)
             {
                 Print("Market order execution was successful");
                 var position = tradeResult.Position;
                 Print("A new position opend with ID ", position.Id);
             }
             else
             {
                 Print("Market order execution was not successful");
             }
         }
     }
 }
1
2
3
 result = api.ExecuteMarketOrder(TradeType.Sell, api.Symbol.Name, 20000)
 if result.IsSuccessful:
     print(f"Sell at {result.Position.EntryPrice}")
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
 import clr
 clr.AddReference("cAlgo.API")
 # Import cAlgo API types
 from cAlgo.API import *
 # Import trading wrapper functions
 from robot_wrapper import *
 class TradeResultSample():
     def on_start(self):
         tradeResult = api.ExecuteMarketOrder(TradeType.Buy, api.SymbolName, api.Symbol.VolumeInUnitsMin)
         if tradeResult.IsSuccessful:
             print("Market order execution was successful")
             position = tradeResult.Position
             print(f"A new position opend with ID: {position.Id} ")
         else:
             print(f"Market order execution was not successful: {tradeResult.Error}")

Methods

ToString

Summary

The description of a trade result.

Signature

1
public string ToString()

Return Value

string

Examples

1
2
3
 TradeResult result = PlaceLimitOrder(TradeType.Sell, Symbol.Name, 50000, Symbol.Ask);
 if (result.IsSuccessful)
     Print(result.ToString());
1
2
3
 result = api.PlaceLimitOrder(TradeType.Sell, api.Symbol.Name, 50000, api.Symbol.Ask)
 if result.IsSuccessful:
     print(result.ToString())

Properties

IsSuccessful

Summary

True if the trade is successful, false if there is an error.

Signature

1
public bool IsSuccessful {get;}

Return Value

bool

Examples

1
2
3
 TradeResult result = ExecuteMarketOrder(TradeType.Buy, Symbol.Name, 20000);
 if (result.IsSuccessful)
     Print("Buy at {0}", result.Position.EntryPrice);
1
2
3
 result = api.ExecuteMarketOrder(TradeType.Buy, api.Symbol.Name, 20000)
 if result.IsSuccessful:
     print(f"Buy at {result.Position.EntryPrice}")

Error

Summary

The error code of an unsuccessful trade.

Signature

1
public ErrorCode? Error {get;}

Return Value

ErrorCode?

Examples

1
2
3
4
 var mySymbol = MarketData.GetSymbol("EURUSD");
 TradeResult result = ExecuteMarketOrder(TradeType.Sell, mySymbol, 1);
 if(!result.IsSuccessful)
     Print("Error: {0}", result.Error);
1
2
3
4
 mySymbol = api.MarketData.GetSymbol("EURUSD")
 result = api.ExecuteMarketOrder(TradeType.Sell, mySymbol, 1)
 if result.IsSuccessful == False:
     print(f"Error: {result.Error}")

Position

Summary

The resulting position of a trade request.

Signature

1
public Position Position {get;}

Return Value

Position

Examples

1
2
3
 TradeResult result = ExecuteMarketOrder(TradeType.Sell, Symbol.Name, 50000);
 if (result.IsSuccessful)
     Print("Sell at {0}", result.Position.EntryPrice);
1
2
3
 result = api.ExecuteMarketOrder(TradeType.Sell, api.Symbol.Name, 50000)
 if result.IsSuccessful:
     print(f"Sell at {result.Position.EntryPrice}")

PendingOrder

Summary

The resulting pending order of a trade request.

Signature

1
public PendingOrder PendingOrder {get;}

Return Value

PendingOrder

Examples

1
2
3
 TradeResult result = PlaceLimitOrder(TradeType.Sell, Symbol.Name, 50000, Symbol.Ask, "myLabel", 10, null, ProtectionType.Relative);
 if(result.IsSuccessful)
     Print("Order placed. SL: {0}", result.PendingOrder.StopLoss);
1
2
3
 result = api.PlaceLimitOrder(TradeType.Sell, api.Symbol.Name, 50000, api.Symbol.Ask, "myLabel", 10, None, ProtectionType.Relative)
 if result.IsSuccessful:
     print(f"Order placed. SL: {result.PendingOrder.StopLoss}")