What's the best way to detect whether the market is open?

Discussion in 'Automated Trading' started by kubilai, Jul 3, 2008.

  1. kubilai

    kubilai

    How do you do this in an automated system, for holidays and short sessions like today? Thanks.
     
  2. if your broker/platform provides a decent api it will usually have calendar functions.

    alternatively, since the nyse posts it's schedule way in advance you can roll your own:



    public static bool isEarlyClose(int today)
    {
    try
    {
    return GetCloseTime().Contains(today);
    }
    catch (Exception) { return false; }
    }
    public static int GetEarlyClose(int today)
    {
    try
    {
    return (int)GetCloseTime()[today];
    }
    catch (Exception) { return 0; }
    }
    public static Hashtable GetCloseTime()
    {
    StreamReader f = new StreamReader("EarlyClose.csv");
    string[] r = new string[2];
    string line = "";
    Hashtable h = new Hashtable();
    while ((line = f.ReadLine())!=null)
    {
    r = line.Split(',');
    h.Add(Convert.ToInt32(r[0]),Convert.ToInt32(r[1]));
    }
    f.Close();
    return h;
    }

    http://tradelink.googlecode.com/svn/trunk/TradeLib/Util.cs
     
  3. kubilai

    kubilai

  4. kubilai

    kubilai

    Got it, thanks!