/// <summary> /// Initializes a new instance of the <see cref="DepthCandleBuilderSourceValue"/>. /// </summary> /// <param name="message">Messages containing quotes.</param> /// <param name="type">Type of candle depth based data.</param> public QuoteCandleBuilderSourceValue(QuoteChangeMessage message, DepthCandleSourceTypes type) { QuoteChange = message; Type = type; switch (Type) { case DepthCandleSourceTypes.BestBid: { var bid = message.GetBestBid(); if (bid != null) { _price = bid.Price; _volume = bid.Volume; } break; } case DepthCandleSourceTypes.BestAsk: { var ask = message.GetBestAsk(); if (ask != null) { _price = ask.Price; _volume = ask.Volume; } break; } case DepthCandleSourceTypes.Middle: { var bid = message.GetBestBid(); var ask = message.GetBestAsk(); if (bid != null && ask != null) { _price = (ask.Price + bid.Price) / 2; //_volume = pair.Bid.Volume; } break; } default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Initializes a new instance of the <see cref="DepthCandleBuilderSourceValue"/>. /// </summary> /// <param name="depth">Market depth.</param> /// <param name="type">Type of candle depth based data.</param> public DepthCandleBuilderSourceValue(MarketDepth depth, DepthCandleSourceTypes type) { Depth = depth; Type = type; var pair = Depth.BestPair; if (pair != null) { switch (Type) { case DepthCandleSourceTypes.BestBid: var bid = pair.Bid; if (bid != null) { _price = bid.Price; _volume = bid.Volume; } break; case DepthCandleSourceTypes.BestAsk: var ask = pair.Ask; if (ask != null) { _price = ask.Price; _volume = ask.Volume; } break; case DepthCandleSourceTypes.Middle: _price = pair.MiddlePrice ?? 0; //_volume = pair.Bid.Volume; break; default: throw new ArgumentOutOfRangeException(); } } }
/// <summary> /// Initializes a new instance of the <see cref="CandleBuilderMessageAdapter"/>. /// </summary> /// <param name="innerAdapter">Inner message adapter.</param> /// <param name="exchangeInfoProvider">The exchange boards provider.</param> public CandleBuilderMessageAdapter(IMessageAdapter innerAdapter, IExchangeInfoProvider exchangeInfoProvider) : base(innerAdapter) { if (exchangeInfoProvider == null) { throw new ArgumentNullException(nameof(exchangeInfoProvider)); } _exchangeInfoProvider = exchangeInfoProvider; BuildCandlesFrom = MarketDataTypes.Trades; DepthCandleSourceType = DepthCandleSourceTypes.Middle; _candleBuilders = new CandleBuildersList { new TimeFrameCandleBuilder(exchangeInfoProvider), new TickCandleBuilder(), new VolumeCandleBuilder(), new RangeCandleBuilder(), new RenkoCandleBuilder(), new PnFCandleBuilder(), }; }
/// <summary> /// Initializes a new instance of the <see cref="MarketDepthStorageCandleBuilderSource"/>. /// </summary> /// <param name="type">Type of candle depth based data.</param> public MarketDepthStorageCandleBuilderSource(DepthCandleSourceTypes type) { _type = type; }
/// <summary> /// To create candles from the order books collection. /// </summary> /// <param name="depths">Market depths.</param> /// <param name="series">Candles series.</param> /// <param name="type">Type of candle depth based data.</param> /// <returns>Candles.</returns> public static IEnumerable <CandleMessage> ToCandles(this IEnumerable <QuoteChangeMessage> depths, CandleSeries series, DepthCandleSourceTypes type) { return(depths .ToEntities <QuoteChangeMessage, MarketDepth>(series.Security) .ToCandles(series, type) .ToMessages <Candle, CandleMessage>()); }
/// <summary> /// To create candles from the order books collection. /// </summary> /// <param name="depths">Market depths.</param> /// <param name="series">Candles series.</param> /// <param name="type">Type of candle depth based data.</param> /// <returns>Candles.</returns> public static IEnumerable <Candle> ToCandles(this IEnumerable <MarketDepth> depths, CandleSeries series, DepthCandleSourceTypes type) { return(new CandleEnumerable(series, depths, type)); }
public CandleEnumerable(CandleSeries series, IEnumerable <MarketDepth> depths, DepthCandleSourceTypes type) : base(() => new CandleEnumerator <MarketDepth>(series, depths, d => new DepthCandleBuilderSourceValue(d, type))) { if (series == null) { throw new ArgumentNullException(nameof(series)); } if (depths == null) { throw new ArgumentNullException(nameof(depths)); } }
/// <summary> /// Initializes a new instance of the <see cref="DepthRawConvertableCandleBuilderSource"/>. /// </summary> /// <param name="security">The instrument whose data is passed to the source.</param> /// <param name="from">The first time value.</param> /// <param name="to">The last time value.</param> /// <param name="values">Ready data collection.</param> /// <param name="type">Type of candle depth based data.</param> public DepthRawConvertableCandleBuilderSource(Security security, DateTimeOffset from, DateTimeOffset to, IEnumerable <MarketDepth> values, DepthCandleSourceTypes type) : base(security, from, to, values) { _type = type; }
/// <summary> /// To create candles from the order books collection. /// </summary> /// <param name="depths">Market depths.</param> /// <param name="series">Candles series.</param> /// <param name="type">Type of candle depth based data.</param> /// <param name="onlyFormed">Process only formed candles.</param> /// <returns>Candles.</returns> public static IEnumerable <CandleMessage> ToCandles(this IEnumerable <QuoteChangeMessage> depths, CandleSeries series, DepthCandleSourceTypes type = DepthCandleSourceTypes.Middle, bool onlyFormed = true) { return(new CandleMessageEnumerable(series.ToMarketDataMessage(true), onlyFormed, depths, type)); }
/// <summary> /// To create candles from the order books collection. /// </summary> /// <param name="depths">Market depths.</param> /// <param name="series">Candles series.</param> /// <param name="type">Type of candle depth based data.</param> /// <param name="onlyFormed">Process only formed candles.</param> /// <returns>Candles.</returns> public static IEnumerable <Candle> ToCandles(this IEnumerable <MarketDepth> depths, CandleSeries series, DepthCandleSourceTypes type = DepthCandleSourceTypes.Middle, bool onlyFormed = true) { return(depths .ToMessages <MarketDepth, QuoteChangeMessage>() .ToCandles(series, type, onlyFormed) .ToCandles <Candle>(series.Security, series.CandleType)); }
public CandleMessageEnumerable(MarketDataMessage mdMsg, bool onlyFormed, IEnumerable <QuoteChangeMessage> depths, DepthCandleSourceTypes type) : base(() => new CandleMessageEnumerator(mdMsg, onlyFormed, depths.Select(d => new QuoteCandleBuilderSourceValue(d, type)))) { if (mdMsg == null) { throw new ArgumentNullException(nameof(mdMsg)); } if (depths == null) { throw new ArgumentNullException(nameof(depths)); } }
/// <summary> /// Initializes a new instance of the <see cref="MarketDepthCandleBuilderSource"/>. /// </summary> /// <param name="connector">The connection through which changed order books will be received using the event <see cref="IConnector.MarketDepthsChanged"/>.</param> /// <param name="type">Type of candle depth based data.</param> public MarketDepthCandleBuilderSource(IConnector connector, DepthCandleSourceTypes type) : base(connector) { _type = type; Connector.MarketDepthsChanged += OnMarketDepthsChanged; }