Symbol USDCAD = MarketData.GetSymbol("CADUSD"); Return?

Created at 24 Oct 2013, 20:43
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!
Hyperloop's avatar

Hyperloop

Joined 23.10.2013

Symbol USDCAD = MarketData.GetSymbol("CADUSD"); Return?
24 Oct 2013, 20:43


That case where the GetSymbol method is called and the parameter is an invalid string (see title for example), what would the return be? null?


@Hyperloop
Replies

fzlogic
25 Oct 2013, 16:56

RE:

Hyperloop said:

That case where the GetSymbol method is called and the parameter is an invalid string (see title for example), what would the return be? null?

No, the method will crash:
Crashed in OnBar with ArgumentException: Symbol "CADUSD" does not exist 
use try... catch block

try
{
    Symbol USDCAD = MarketData.GetSymbol("CADUSD");
    Print("USDCAD {0}", USDCAD);
}
catch (Exception ex)
{
    Print("Invalid Symbol code.  {0}", ex.Message);
}

@fzlogic

Hyperloop
25 Oct 2013, 22:13

Thanks for the help. I appreciate it. Coming from a Python/C background into C# so still getting used to this side of things. :)


@Hyperloop

Hyperloop
30 Oct 2013, 01:00

string CurrencyOne = "CAD";
string CurrencyTwo = "USD";
try
{
	Symbol USDCAD = MarketData.GetSymbol(CurrencyOne + CurrencyTwo);
	Print("USDCAD {0}", USDCAD);
}
finally
{
	Symbol USDCAD = MarketData.GetSymbol(CurrencyTwo + CurrencyOne);
	Print("USDCAD {0}", USDCAD);
}

I am trying to make use of the try...finally block. Upon testing it, it seems like the finally block isn't executing. The above shows an example of what I am doing. Where am I going wrong?

Thanks. :)


@Hyperloop

Spotware
30 Oct 2013, 11:49

We've decided to change GetSymbol() method, in future versions it will return null if symbol not found.


@Spotware

Kate
30 Oct 2013, 11:53

Just use my code posted here: /forum/cbot-support/1793


@Kate