diff --git a/README.md b/README.md index 5f1f32d..ecd8511 100644 --- a/README.md +++ b/README.md @@ -414,72 +414,72 @@ sudo /usr/bin/xattr -r -d com.apple.quarantine - [x] [AuthSample](samples/API/AuthSample) demonstrates how to connect to an endpoint that requires an authentication token, - subscribe to market data events, and handle periodic token updates. + subscribe to market data events, and handle periodic token updates - [x] [ConnectSample](samples/API/ConnectSample) - demonstrates how to connect to the endpoint and subscribe to various market events. + demonstrates how to connect to the endpoint and subscribe to various market events - [x] [PrintQuoteEventsSample](samples/API/PrintQuoteEventsSample) demonstrates how to subscribe to the `Quote` event, using a `DxFeed` instance singleton - and `dxfeed.system.properties` file. + and `dxfeed.system.properties` file - [x] [QuoteAndTradeSample](samples/API/QuoteAndTradeSample) - demonstrates how to create multiple event listeners and subscribe to `Quote` and `Trade` events. + demonstrates how to create multiple event listeners and subscribe to `Quote` and `Trade` events - [x] [ReconnectSample](samples/API/ReconnectSample) demonstrates how to connect to an endpoint, subscribe to market data events, handle reconnections - and re-subscribing. + and re-subscribing ### Candle - [x] [CandleSample](samples/Candle/CandleSample) - demonstrates how to subscribe to `Candle` events. + demonstrates how to subscribe to `Candle` events - [x] [CandleDataSample](samples/Candle/CandleDataSample) - demonstrates how to parse response from CandleData service. + demonstrates how to parse response from CandleData service - [x] [FetchDailyCandlesSample](samples/Candle/FetchDailyCandlesSample) - demonstrates how to fetch last N-days of candles for a specified symbol. + demonstrates how to fetch last N-days of candles for a specified symbol ### Console - [x] [LastEventConsoleSample](samples/Console/LastEventConsoleSample) demonstrates how to subscribe to various market events with the dxFeed API, cache them in memory, and - take snapshots of these events based on user input. + take snapshots of these events based on user input ### File - [x] [ConvertTapeFileSample](samples/File/ConvertTapeFileSample) - demonstrates how to convert one tape file to another tape file with optional intermediate processing or filtering. + demonstrates how to convert one tape file to another tape file with optional intermediate processing or filtering - [x] [FileParserSample](samples/File/FileParserSample) - demonstrates how to read events from a tape file. + demonstrates how to read events from a tape file - [x] [WriteTapeFileSample](samples/File/WriteTapeFileSample) - demonstrates how to write events to a tape file. + demonstrates how to write events to a tape file ### IPF - [x] [IpfSample](samples/IPF/IpfSample) - demonstrates how to get Instrument Profiles. + demonstrates how to get Instrument Profiles - [x] [IpfLiveSample](samples/IPF/IpfLiveSample) - demonstrates how to get live updates for Instrument Profiles. + demonstrates how to get live updates for Instrument Profiles - [x] [OptionChainSample](samples/IPF/OptionChainSample) - demonstrates how to build option chains, and prints quotes for nearby option strikes. + demonstrates how to build option chains, and prints quotes for nearby option strikes ### Model - [x] [IncOrderSnapshotSample](samples/Model/IncOrderSnapshotSample) - demonstrates how to subscribe to the Order event and handle snapshots and updates. + demonstrates how to subscribe to the Order event and handle snapshots and updates - [x] [MultipleMarketDepthSample](samples/Model/MultipleMarketDepthSample) - demonstrates how to use the `MarketDepthModel` to manage and display order books for multiple symbols. + demonstrates how to use the `MarketDepthModel` to manage and display order books for multiple symbols ### Schedule - [x] [ScheduleSample](samples/Schedule/ScheduleSample) - demonstrates how to get various scheduling information for instruments. + demonstrates how to get various scheduling information for instruments ### UI - [x] [MarketDepthModelSample](samples/UI/MarketDepthModelSample) - demonstrates how to draw a Market Depth using Avalonia UI. + demonstrates how to draw a Market Depth using Avalonia UI - [x] [CandleChartSample](samples/UI/CandleChartSample) - demonstrates how to draw a Candlestick Chart using Avalonia UI. + demonstrates how to draw a Candlestick Chart using Avalonia UI - [x] [PriceLevelBookSample](samples/UI/PriceLevelBookSample) demonstrates how to compile a price level book (market by price) that aggregates individual orders - (market by order). + (market by order) ## Current State diff --git a/samples/UI/PriceLevelBookSample/MainWindow.axaml b/samples/UI/PriceLevelBookSample/MainWindow.axaml index 80c7602..c3be568 100644 --- a/samples/UI/PriceLevelBookSample/MainWindow.axaml +++ b/samples/UI/PriceLevelBookSample/MainWindow.axaml @@ -41,8 +41,8 @@ - - + diff --git a/samples/UI/PriceLevelBookSample/MainWindow.axaml.cs b/samples/UI/PriceLevelBookSample/MainWindow.axaml.cs index e2f65d1..f9ddbb3 100644 --- a/samples/UI/PriceLevelBookSample/MainWindow.axaml.cs +++ b/samples/UI/PriceLevelBookSample/MainWindow.axaml.cs @@ -7,11 +7,11 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.Linq; using Avalonia.Controls; using Avalonia.Input; using Avalonia.Interactivity; using Avalonia.Threading; -using DxFeed.Graal.Net; using DxFeed.Graal.Net.Api; using DxFeed.Graal.Net.Events; using DxFeed.Graal.Net.Events.Market; @@ -26,10 +26,10 @@ namespace PriceLevelBookSample; public partial class MainWindow : Window { private readonly PriceLevels _priceLevels = new(); - private readonly PriceLevelBook.Builder builder; - private string symbol = string.Empty; - private string sources = string.Empty; - private PriceLevelBook? model; + private readonly PriceLevelBook.Builder _builder; + private string _symbol = string.Empty; + private string _source = string.Empty; + private PriceLevelBook? _model; /// /// Initializes a new instance of the MainWindow class. @@ -42,7 +42,7 @@ public MainWindow() BuyTable.Source = _priceLevels.BuyPriceLevels; SellTable.Source = _priceLevels.SellPriceLevels; - builder = PriceLevelBook.NewBuilder() + _builder = PriceLevelBook.NewBuilder() .WithFeed(DXFeed.GetInstance()) .WithListener((buy, sell) => { @@ -62,7 +62,7 @@ public MainWindow() /// /// Event arguments. protected override void OnClosed(EventArgs e) => - model?.Dispose(); + _model?.Dispose(); /// /// Handles the KeyDown event for the TextBox controls. @@ -102,7 +102,7 @@ private void HandleTextChanged(TextBox? textBox) switch (textBox.Name) { case nameof(SymbolTextBox): - case nameof(SourcesTextBox): + case nameof(SourceTextBox): OnSymbolTextChanged(); break; case nameof(DepthLimitTextBox): @@ -120,28 +120,28 @@ private void HandleTextChanged(TextBox? textBox) /// private void OnSymbolTextChanged() { - if (symbol.Equals(SymbolTextBox.Text, StringComparison.Ordinal) && - sources.Equals(SourcesTextBox.Text, StringComparison.Ordinal)) + if (_symbol.Equals(SymbolTextBox.Text, StringComparison.Ordinal) && + _source.Equals(SourceTextBox.Text, StringComparison.Ordinal)) { return; } - symbol = SymbolTextBox.Text ?? string.Empty; - sources = SourcesTextBox.Text ?? string.Empty; + _symbol = SymbolTextBox.Text ?? string.Empty; + _source = SourceTextBox.Text ?? string.Empty; - model?.Dispose(); + _model?.Dispose(); try { - model = builder + _model = _builder .WithSymbol(GetSymbol()) - .WithSources(GetSources()) + .WithSource(GetSource()!) .WithDepthLimit(GetDepthLimit()) .WithAggregationPeriod(GetAggregationPeriod()) .Build(); } - catch + catch(Exception e) { - // ignored + Console.WriteLine(e); } } @@ -149,13 +149,13 @@ private void OnSymbolTextChanged() /// Updates the depth limit of the price level book when the depth limit text changes. /// private void OnDepthLimitTextChanged() => - model?.SetDepthLimit(GetDepthLimit()); + _model?.SetDepthLimit(GetDepthLimit()); /// /// Updates the aggregation period of the price level book when the period text changes. /// private void OnAggregationPeriodTextChanged() => - model?.SetAggregationPeriod(GetAggregationPeriod()); + _model?.SetAggregationPeriod(GetAggregationPeriod()); /// /// Gets the current symbol from the SymbolTextBox. @@ -168,18 +168,18 @@ private string GetSymbol() => /// Gets the list of sources from the SourcesTextBox. /// /// A list of order sources. - private List GetSources() + private IndexedEventSource? GetSource() { var sourceList = new List(); - if (!string.IsNullOrWhiteSpace(SourcesTextBox.Text)) + if (!string.IsNullOrWhiteSpace(SourceTextBox.Text)) { - foreach (var source in SourcesTextBox.Text.Split(",")) + foreach (var source in SourceTextBox.Text.Split(",")) { sourceList.Add(OrderSource.ValueOf(source)); } } - return sourceList; + return sourceList.FirstOrDefault(); } /// diff --git a/samples/UI/PriceLevelBookSample/PriceLevelBook.cs b/samples/UI/PriceLevelBookSample/PriceLevelBook.cs index f345d78..e4c960a 100644 --- a/samples/UI/PriceLevelBookSample/PriceLevelBook.cs +++ b/samples/UI/PriceLevelBookSample/PriceLevelBook.cs @@ -68,6 +68,10 @@ public sealed class PriceLevelBook : IDisposable private PriceLevelBook(Builder builder) { + if (builder.Source == null) + { + throw new InvalidOperationException("The 'source' must not be null."); + } _depthLimit = builder.DepthLimit; _buyPriceLevels.DepthLimit = _depthLimit; _sellPriceLevels.DepthLimit = _depthLimit; @@ -289,6 +293,8 @@ public class Builder { internal IndexedTxModel.Builder TxModelBuilder { get; } = IndexedTxModel.NewBuilder(); + internal IndexedEventSource? Source { get; private set; } + internal Listener? Listener { get; private set; } internal long AggregationPeriodMillis { get; private set; } @@ -332,34 +338,14 @@ public Builder WithListener(Listener? listener) } /// - /// Sets the sources from which to subscribe for indexed events. - /// If no sources have been set, subscriptions will default to all possible sources. - /// - /// - /// The default value for this source is an empty set, - /// which means that this model subscribes to all available sources. - /// - /// The specified sources. - /// this builder. - public Builder WithSources(params IndexedEventSource[] sources) - { - TxModelBuilder.WithSources(sources); - return this; - } - - /// - /// Sets the sources from which to subscribe for indexed events. - /// If no sources have been set, subscriptions will default to all possible sources. + /// Sets the source from which to subscribe for indexed events. /// - /// - /// The default value for this source is an empty set, - /// which means that this model subscribes to all available sources. - /// - /// The specified sources. + /// The specified source. /// this builder. - public Builder WithSources(ICollection sources) + public Builder WithSource(IndexedEventSource source) { - TxModelBuilder.WithSources(sources); + Source = source; + TxModelBuilder.WithSources(source); return this; }