Skip to content

TradeOperation

class cAlgo.API

DesktopCLICloud

Provides access to the properties describing an asynchronous trade operation.

Definition

public sealed class TradeOperation

Namespace: cAlgo.API · Group: Trading

Examples

Example 1

var operation = ExecuteMarketOrderAsync(TradeType.Buy, SymbolName, 10000, "myLabel", result => Print("Order completed: {0}", result.IsSuccessful));
Print("Operation is executing: {0}", operation.IsExecuting);
operation = api.ExecuteMarketOrderAsync(TradeType.Buy, api.SymbolName, 10000, "myLabel", lambda result: api.Print(f"Order completed: {result.IsSuccessful}"))
api.Print(f"Operation is executing: {operation.IsExecuting}")

Example 2

private TradeOperation _operation;

protected override void OnStart()
{
    _operation = ExecuteMarketOrderAsync(TradeType.Buy, SymbolName, Symbol.VolumeInUnitsMin, OnTradeResult);
}

protected override void OnTick()
{
    if (_operation != null && !_operation.IsExecuting)
    {
        Print(_operation.ToString());
        _operation = null;
    }
}

private void OnTradeResult(TradeResult result)
{
    Print("Trade operation successful: {0}", result.IsSuccessful);
}
def on_start(self):
    self.operation = api.ExecuteMarketOrderAsync(TradeType.Buy, api.SymbolName, api.Symbol.VolumeInUnitsMin, self.on_trade_result)

def on_tick(self):
    if self.operation is not None and not self.operation.IsExecuting:
        api.Print(self.operation.ToString())
        self.operation = None

def on_trade_result(self, result):
    api.Print(f"Trade operation successful: {result.IsSuccessful}")

Properties

Name Description
IsExecutingDesktopCLICloudbool True if a trade operation is being executed, false if it completed
TradeResultDesktopCLICloudTradeResult The result of a trade operation