Click here to Skip to main content
15,896,606 members
Articles / Programming Languages / C# 4.0

An Introduction to Real-Time Stock Market Data Processing

Rate me:
Please Sign up or sign in to vote.
4.96/5 (64 votes)
20 May 2013CPOL24 min read 333K   57.7K   202  
Discusses how stock market trading works, the different types of market data available, and provides a code example with sample data that processes a market data feed
using System;
using System.Diagnostics;
using System.Text;

namespace SparkAPI.Market
{

    /// <summary>
    /// Contains details of a single order currently in the limit order book for a specific security and exchange
    /// </summary>
    /// <remarks>
    /// This class is called 'LimitOrder' rather than just 'Order' to distinguish it from the other types of order
    /// classes that can be found in a trading system (e.g. parent/client order, market order, etc.). 
    /// </remarks>
    public class LimitOrder
    {

        /// <summary>Order submission side</summary>
        public MarketSide Side { get; private set; }

        /// <summary>Order price</summary>
        public int Price { get; private set; }

        /// <summary>Order submission time</summary>
        public DateTime TimeStamp { get; private set; }

        /// <summary>Order volume</summary>
        public int Volume { get; set; }

        /// <summary>
        /// LimitOrder constructor
        /// </summary>
        public LimitOrder(MarketSide side, int price, int volume, DateTime timeStamp)
        {
            Side = side;
            Price = price;
            Volume = volume;
            TimeStamp = timeStamp;
        }

        /// <summary>
        /// Create duplicate of limit order object
        /// </summary>
        public LimitOrder Clone()
        {
            return new LimitOrder(Side, Price, Volume, TimeStamp);
        }

        /// <summary>
        /// Returns tab-separated string representation of the limit order (price, time, volume, recorded)
        /// </summary>        
        public override string ToString()
        {
            StringBuilder output = new StringBuilder();
            output.Append(Price.ToPriceString());
            output.Append('\t');
            output.Append(TimeStamp.ToMarketDateTime());
            output.Append('\t');
            output.Append(Volume);
            output.Append('\t');
            return output.ToString();
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Australia Australia
Paul Francis currently works as a senior engineer at The Trade Desk.

He holds an undergraduate Honours degree in Finance, and is near completion of a Ph.D. in Market Microstructure, specialising in order flow modelling, and market data processing, reconstruction and analytics.

He is also the creator of Sharp Spark (Spark API SDK), an open source component designed to facilitate the processing of real-time market data from the Spark API: http://sourceforge.net/projects/sparkapi

Paul lives in Sydney, Australia.

Comments and Discussions