Skip to content

PriceAlerts

interface cAlgo.API Since 5.2

DesktopCLICloud

Represents a collection of price alerts.

Environment behaviour

Cloud — not supported. Always empty: Count 0, Find null, FindAll empty, Remove false. Added/Removed/Updated/Triggered never raised.

Definition

public interface PriceAlerts

Namespace: cAlgo.API · Group: Price Alert

Examples

using cAlgo.API;

namespace cAlgo.Robots;

public partial class Test : Robot
{
    protected override void OnStart()
    {
        Print($"Price Alerts Count: {PriceAlerts.Count}");

        foreach (var priceAlert in PriceAlerts)
        {
            Print($"Price Alert Id: {priceAlert.Id}, Symbol: {priceAlert.Symbol.Name}, Price: {priceAlert.Price}, Quote Type: {priceAlert.QuoteType}, Condition: {priceAlert.Condition}");
        }

        PriceAlerts.Added += args => Print($"Price Alert added: {args.PriceAlert.Id}");
        PriceAlerts.Removed += args => Print($"Price Alert removed: {args.PriceAlert.Id}");
        PriceAlerts.Updated += args => Print($"Price Alert updated: {args.PriceAlert.Id}");
        PriceAlerts.Triggered += args => Print($"Price Alert triggered: {args.PriceAlert.Id}");

        var newPriceAlert = PriceAlerts.Add(Symbol, Symbol.Bid + (100 * Symbol.PipSize), PriceAlertQuoteType.Bid, PriceAlertCondition.HigherOrEqual);

        newPriceAlert.Update(Symbol, newPriceAlert.Price, newPriceAlert.QuoteType, newPriceAlert.Condition, true, "Price alert message");

        Print($"Finding price alert result: {PriceAlerts.Find(newPriceAlert.Id) == newPriceAlert}");

        PriceAlerts.Remove(newPriceAlert);
    }
}
import clr

clr.AddReference("cAlgo.API")

# Import cAlgo API types
from cAlgo.API import *

# Import trading wrapper functions
from robot_wrapper import *

class Test():
    def on_start(self):
        print(f"Price Alerts Count: {api.PriceAlerts.Count}")

        for priceAlert in api.PriceAlerts:
            print(f"Price Alert Id: {priceAlert.Id}, Symbol: {priceAlert.Symbol.Name}, Price: {priceAlert.Price}, Quote Type: {priceAlert.QuoteType}, Condition: {priceAlert.Condition}")

        api.PriceAlerts.Added += lambda args: print(f"Price Alert added: {args.PriceAlert.Id}")
        api.PriceAlerts.Removed += lambda args: print(f"Price Alert removed: {args.PriceAlert.Id}")
        api.PriceAlerts.Updated += lambda args: print(f"Price Alert updated: {args.PriceAlert.Id}")
        api.PriceAlerts.Triggered += lambda args: print(f"Price Alert triggered: {args.PriceAlert.Id}")

        newPriceAlert = api.PriceAlerts.Add(api.Symbol, api.Symbol.Bid + (100 * api.Symbol.PipSize), PriceAlertQuoteType.Bid, PriceAlertCondition.HigherOrEqual)
        newPriceAlert.Update(api.Symbol, newPriceAlert.Price, newPriceAlert.QuoteType, newPriceAlert.Condition, True, "Price alert message")

        print(f"Finding price alert result: {api.PriceAlerts.Find(newPriceAlert.Id) == newPriceAlert}")

        api.PriceAlerts.Remove(newPriceAlert)
{
  "AccessRights": "None"
}

Methods

Name Description
AddDesktopCLICloudPriceAlert Adds a new price alert.
FindDesktopCLICloudPriceAlert Finds a price alert by its Id.
FindAllDesktopCLICloudPriceAlert[] Finds all price alerts by their symbol.
RemoveDesktopCLICloudbool Removes a price alert.

Properties

Name Description
CountDesktopCLICloudint Gets the total number of active price alerts.

Events

Name Description
AddedDesktopCLICloudAction<PriceAlertAddedEventArgs> Occurs when a new price alert is added.
RemovedDesktopCLICloudAction<PriceAlertRemovedEventArgs> Occurs when a price alert is removed.
TriggeredDesktopCLICloudAction<PriceAlertTriggeredEventArgs> Occurs when a price alert is triggered.
UpdatedDesktopCLICloudAction<PriceAlertUpdatedEventArgs> Occurs when a price alert is updated.