62 lines
2.1 KiB
C#
62 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Eremex.AvaloniaUI.Charts;
|
|
using MarketData.MarketDataModel;
|
|
using MarketData.Utils;
|
|
using PortfolioManager.DataSeriesViewModels;
|
|
|
|
namespace PortfolioManager.Models
|
|
{
|
|
public class StopLimitCompositeModel
|
|
{
|
|
private StopLimitCompositeModel()
|
|
{
|
|
}
|
|
|
|
public static CompositeDataSource Empty()
|
|
{
|
|
CompositeDataSource compositeDataSource = new CompositeDataSource()
|
|
{
|
|
DataAdapter = new SortedDateTimeDataAdapter()
|
|
};
|
|
return compositeDataSource;
|
|
}
|
|
|
|
public static CompositeDataSource CreateCompositeDataSource(StopLimits stopLimits)
|
|
{
|
|
if (null == stopLimits || 0 == stopLimits.Count) return Empty();
|
|
SortedDateTimeDataAdapter sortedDateTimeDataAdapter = new SortedDateTimeDataAdapter();
|
|
List<StopLimit> sortedStopLimits = stopLimits.OrderBy(x => x.EffectiveDate).ToList();
|
|
foreach (StopLimit stopLimit in sortedStopLimits)
|
|
{
|
|
sortedDateTimeDataAdapter.Add(stopLimit.EffectiveDate, stopLimit.StopPrice);
|
|
}
|
|
CompositeDataSource compositeDataSource = new CompositeDataSource()
|
|
{
|
|
DataAdapter = sortedDateTimeDataAdapter
|
|
};
|
|
return compositeDataSource;
|
|
}
|
|
|
|
public static CompositeDataSource CreateCompositeDataSource(DateTime xSource,StopLimits stopLimits)
|
|
{
|
|
if (null == stopLimits || 0 == stopLimits.Count) return Empty();
|
|
foreach(StopLimit stopLimit in stopLimits)
|
|
{
|
|
stopLimit.EffectiveDate = xSource;
|
|
}
|
|
SortedDateTimeDataAdapter sortedDateTimeDataAdapter = new SortedDateTimeDataAdapter();
|
|
List<StopLimit> sortedStopLimits = stopLimits.OrderBy(x => x.EffectiveDate).ToList();
|
|
foreach (StopLimit stopLimit in sortedStopLimits)
|
|
{
|
|
sortedDateTimeDataAdapter.Add(stopLimit.EffectiveDate, stopLimit.StopPrice);
|
|
}
|
|
CompositeDataSource compositeDataSource = new CompositeDataSource()
|
|
{
|
|
DataAdapter = sortedDateTimeDataAdapter
|
|
};
|
|
return compositeDataSource;
|
|
}
|
|
}
|
|
} |