Skip to content

Messages and subscriptions

The Messages and MessageSubscription interfaces provide types that enable communications between algorithms inside a cTrader instance. With these types, you can code one algo to send a message and other algos can subscribe to it.

Warning

Messages API objects work only in .NET 6 algorithms.

An algo can be coded to perform a specific action when a specific message is received from another algo. The messages and actions could be anything.

Example

Consider a plugin that generates signals and sends them to a cBot, which listens for messages and opens positions accordingly.

Send message (trade signal)

1
Messages.Send("TradeSignal", "Buy EURUSD at 1.1200");

Take action (open position)

1
2
3
4
5
6
7
8
9
private void OnTradeSignalReceived(MessageArgs<string> args)
{
    var signal = args.Message;
    if (signal == "Buy EURUSD at 1.1200")
    {
        ExecuteMarketOrder(TradeType.Buy, "EURUSD", 10000);
        Print("Trade executed based on signal");
    }
}