Skip to content

Commit

Permalink
[MDAPI-124] [.NET] Remove the ability to pass multiple sources for Pr…
Browse files Browse the repository at this point in the history
…iceLeveBookSample
  • Loading branch information
Konstantin Ivaschenko committed Aug 15, 2024
1 parent 7a4884e commit a541e9b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 71 deletions.
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,72 +414,72 @@ sudo /usr/bin/xattr -r -d com.apple.quarantine <directory_with_tools>

- [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

Expand Down
4 changes: 2 additions & 2 deletions samples/UI/PriceLevelBookSample/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
<TextBox x:Name="SymbolTextBox" Text="AAPL" FontSize="12" Width="180" KeyDown="OnKeyDown" LostFocus="OnLostFocus"
Grid.Column="1" Margin="5" />

<TextBlock Text="Sources" Margin="5" FontSize="12" VerticalAlignment="Center" Grid.Column="2" />
<TextBox x:Name="SourcesTextBox" Text="NTV" FontSize="12" Width="180" KeyDown="OnKeyDown" LostFocus="OnLostFocus"
<TextBlock Text="Source" Margin="5" FontSize="12" VerticalAlignment="Center" Grid.Column="2" />
<TextBox x:Name="SourceTextBox" Text="NTV" FontSize="12" Width="180" KeyDown="OnKeyDown" LostFocus="OnLostFocus"
Grid.Column="3" Margin="5" />

<TextBlock Text="Depth Limit" Margin="5" FontSize="12" VerticalAlignment="Center" Grid.Column="4" />
Expand Down
46 changes: 23 additions & 23 deletions samples/UI/PriceLevelBookSample/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,10 +26,10 @@ namespace PriceLevelBookSample;
public partial class MainWindow : Window
{
private readonly PriceLevels _priceLevels = new();
private readonly PriceLevelBook<Order>.Builder builder;
private string symbol = string.Empty;
private string sources = string.Empty;
private PriceLevelBook<Order>? model;
private readonly PriceLevelBook<Order>.Builder _builder;
private string _symbol = string.Empty;
private string _source = string.Empty;
private PriceLevelBook<Order>? _model;

/// <summary>
/// Initializes a new instance of the MainWindow class.
Expand All @@ -42,7 +42,7 @@ public MainWindow()
BuyTable.Source = _priceLevels.BuyPriceLevels;
SellTable.Source = _priceLevels.SellPriceLevels;

builder = PriceLevelBook<Order>.NewBuilder()
_builder = PriceLevelBook<Order>.NewBuilder()
.WithFeed(DXFeed.GetInstance())
.WithListener((buy, sell) =>
{
Expand All @@ -62,7 +62,7 @@ public MainWindow()
/// </summary>
/// <param name="e">Event arguments.</param>
protected override void OnClosed(EventArgs e) =>
model?.Dispose();
_model?.Dispose();

/// <summary>
/// Handles the KeyDown event for the TextBox controls.
Expand Down Expand Up @@ -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):
Expand All @@ -120,42 +120,42 @@ private void HandleTextChanged(TextBox? textBox)
/// </summary>
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);
}
}

/// <summary>
/// Updates the depth limit of the price level book when the depth limit text changes.
/// </summary>
private void OnDepthLimitTextChanged() =>
model?.SetDepthLimit(GetDepthLimit());
_model?.SetDepthLimit(GetDepthLimit());

/// <summary>
/// Updates the aggregation period of the price level book when the period text changes.
/// </summary>
private void OnAggregationPeriodTextChanged() =>
model?.SetAggregationPeriod(GetAggregationPeriod());
_model?.SetAggregationPeriod(GetAggregationPeriod());

/// <summary>
/// Gets the current symbol from the SymbolTextBox.
Expand All @@ -168,18 +168,18 @@ private string GetSymbol() =>
/// Gets the list of sources from the SourcesTextBox.
/// </summary>
/// <returns>A list of order sources.</returns>
private List<IndexedEventSource> GetSources()
private IndexedEventSource? GetSource()
{
var sourceList = new List<IndexedEventSource>();
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();
}

/// <summary>
Expand Down
36 changes: 11 additions & 25 deletions samples/UI/PriceLevelBookSample/PriceLevelBook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public sealed class PriceLevelBook<TE> : 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;
Expand Down Expand Up @@ -289,6 +293,8 @@ public class Builder
{
internal IndexedTxModel<TE>.Builder TxModelBuilder { get; } = IndexedTxModel<TE>.NewBuilder();

internal IndexedEventSource? Source { get; private set; }

internal Listener? Listener { get; private set; }

internal long AggregationPeriodMillis { get; private set; }
Expand Down Expand Up @@ -332,34 +338,14 @@ public Builder WithListener(Listener? listener)
}

/// <summary>
/// Sets the sources from which to subscribe for indexed events.
/// If no sources have been set, subscriptions will default to all possible sources.
/// </summary>
/// <remarks>
/// The default value for this source is an empty set,
/// which means that this model subscribes to all available sources.
/// </remarks>
/// <param name="sources">The specified sources.</param>
/// <returns><c>this</c> builder.</returns>
public Builder WithSources(params IndexedEventSource[] sources)
{
TxModelBuilder.WithSources(sources);
return this;
}

/// <summary>
/// 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.
/// </summary>
/// <remarks>
/// The default value for this source is an empty set,
/// which means that this model subscribes to all available sources.
/// </remarks>
/// <param name="sources">The specified sources.</param>
/// <param name="source">The specified source.</param>
/// <returns><c>this</c> builder.</returns>
public Builder WithSources(ICollection<IndexedEventSource> sources)
public Builder WithSource(IndexedEventSource source)
{
TxModelBuilder.WithSources(sources);
Source = source;
TxModelBuilder.WithSources(source);
return this;
}

Expand Down

0 comments on commit a541e9b

Please sign in to comment.