MarketDepth


Summary

Access to MarketDepth Ask Entries, Bid Entries and the event at which the market depth gets updated

Syntax

public interface MarketDepth

Members

NameTypeSummary
AskEntries PropertyThe total number of Ask entries
BidEntries PropertyThe total number of Bid entries
Updated EventThe event at which the market depth gets updated

Example 1

using System;
using System.Text;
using cAlgo.API;
namespace cAlgo.Indicators
{
    [Indicator]
    public class MarketDepthIndicator : Indicator
    {
        private MarketDepth _marketDepth;
        public override void Calculate(int index){}
        protected override void Initialize()
        {
            //  Get Market Depth
            _marketDepth = MarketData.GetMarketDepth(Symbol);
            // subscribe to event Updated
            _marketDepth.Updated += MarketDepthUpdated;
        }
        void MarketDepthUpdated()
        {
            // Draw Market Depth Entries in the indicator panel
            var se = new StringBuilder();
            se.Append("Bid");
            se.Append("                              ");
            se.Append("Ask");
            ChartObjects.DrawText("DOM", se.ToString(), StaticPosition.TopLeft, Colors.White);
            se.Clear();
            se.AppendLine();
            se.AppendLine();
            foreach (var entry in _marketDepth.BidEntries)
            {
                double dVolume  = Math.Round(entry.Volume / 1000000.0, 2);
                string volume = string.Format("{0}{1}", dVolume, "m");
                double entryPrice = entry.Price;
                string askText = string.Format("{0}    {1}", entryPrice.ToString("0.00000"), volume);
                se.AppendLine(askText);
            }
            ChartObjects.DrawText("Bid", se.ToString(), StaticPosition.TopLeft, Colors.Red);
            
            se.Clear();
            se.AppendLine();
            se.AppendLine();
            foreach (var entry in _marketDepth.AskEntries)
            {
                double dVolume = Math.Round(entry.Volume / 1000000.0, 2);
                string volume = string.Format("{0}{1}", dVolume, "m");
                double entryPrice = entry.Price;
                se.Append("                                    ");
                string bidText = string.Format("{0}     {1}", entryPrice.ToString("0.00000"), volume);
                se.AppendLine(bidText);
            }
            ChartObjects.DrawText("Ask", se.ToString(), StaticPosition.TopLeft, Colors.Turquoise);
            
        }
    }
}   

Example 2

using cAlgo.API;
namespace cAlgo.Indicators
{
    [Indicator]
    public class Level2 : Indicator
    {
        [Output("BidEntries", Color = Colors.Red, PlotType = PlotType.Histogram, Thickness = 5)]
        public IndicatorDataSeries BidResult { get; set; }
        [Output("AskEntries", Color = Colors.Blue, PlotType = PlotType.Histogram, Thickness = 5)]
        public IndicatorDataSeries AskResult { get; set; }
        MarketDepth GBPUSD;
        private int _askNo;
        private int _bidNo;
        protected override void Initialize()
        {
            GBPUSD = MarketData.GetMarketDepth(Symbol);
            GBPUSD.Updated += OnGbpUsdUpdated;
        }
        void OnGbpUsdUpdated()
        {
            _askNo = 0;
            _bidNo = 0;
            var index = MarketSeries.Close.Count - 1;
            for (var i = 0; i < GBPUSD.AskEntries.Count; i++)
                AskResult[index - i] = double.NaN;
            foreach (var entry in GBPUSD.AskEntries)
            {
                AskResult[index - _askNo] = (-1) * entry.Volume;
                _askNo++;
            }
            for (var i = 0; i < GBPUSD.BidEntries.Count; i++)
                BidResult[index - i] = double.NaN;
            foreach (var entry in GBPUSD.BidEntries)
            {
                BidResult[index - _bidNo] = entry.Volume;
                _bidNo++;
            }
        }
        public override void Calculate(int index){}
    }
}