Check if Symbol Code Exists

Created at 26 Mar 2015, 19:30
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
deklin's avatar

deklin

Joined 31.12.2014

Check if Symbol Code Exists
26 Mar 2015, 19:30


What is the best way to find out if a specific symbol is supported by looking up its code?

For example, this does NOT work:

if(MarketData.GetSymbol("XYZUSD") == true) {
  Print("Symbol Supported");
}
else {
  Print("Symbol Not Supported");
}


 


@deklin
Replies

Invalid
27 Mar 2015, 09:29

RE:

Check if it is null instead of true.

MarketData.GetSymbol("holaamigos")!=null;

Or you can create an extension:

 

    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        protected override void OnStart()
        {
            Print("Symbol exists: {0}", MarketData.SymbolExists("E33URGBP"));
        }
    }

    public static class Ext
    {
        public static bool SymbolExists(this MarketData marketData, string symbol)
        {
            return marketData.GetSymbol(symbol) != null;
        }
    }

 


@Invalid