In some cases you would like to find out the exchange (e.g. NYSE, XETRA) where a given symbol is traded at. One of the possible ways would be to grab a bulky symbol list from the Internet, save into file on your disk (and don't forget to update it periodically), run a query in your Strategy and optionally place the result in Wealth-Lab's global memory.
However, one don't always have the need in a complex solution like that. As shown in other KB articles (
#1,
#2), downloading historical data and fundamental items is a hands down task. The same technique can be applied to symbol lookup.
Using the same .NET classes as we did before, let's figure out the exchange where a given symbol is trading at by using trusty Yahoo! Finance:
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using System.Net; // access the Internet
using System.Text.RegularExpressions; // regular expressions
namespace WealthLab.Strategies
{
public class ExchangeDemo : WealthScript
{
public string GetExchange( string symbol )
{
string URI = @"http://download.finance.yahoo.com/d/quotes.csv?s=" + symbol + "&f=x";
WebClient client = new WebClient();
string text = client.DownloadString(URI);
if( !String.IsNullOrEmpty(text) )
return Regex.Replace(text, @"[^\w\.@-]", ""); else
return "Yahoo! Connection failed";
}
protected override void Execute()
{
PrintDebug( GetExchange( Bars.Symbol ) );
}
}
}