Support:
Пожалуйста, пришлите ваш код для воспроизведения ошибки.
В спойлере - код. :::spoiler
using System;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Ecng.Common;
using Ecng.Configuration;
using StockSharp.Algo.Candles;
using StockSharp.Algo.Expressions;
using StockSharp.Algo.Storages;
using StockSharp.Algo.Testing;
using StockSharp.BusinessEntities;
using StockSharp.Logging;
using StockSharp.Messages;
using StockSharp.Xaml.Charting;
namespace FirstConsole.XAML
{
///
/// Логика взаимодействия для Index.xaml
///
public partial class Index : UserControl
{
private HistoryEmulationConnector _connector;
private ChartCandleElement _candleElement;
private CandleManager _candleManager; // создадим менеджер свечей - из него будем получать свечи
private CandleSeries _candleSeries;
private Security _security;
private Security _indexSecurity;
private Portfolio _portfolio;
private readonly LogManager _logManager;
private readonly string _pathHistory = @"G:\Sharp\Hydra\CSVFromFinamReady\".ToFullPath();
public Index()
{
InitializeComponent();
//здесь без разницы какую службу включать, в Shell работает только Fw40
// ConfigManager.RegisterService<ICompilerService>(new RoslynCompilerService());
ConfigManager.RegisterService<ICompilerService>(new Fw40CompilerService(Directory.GetCurrentDirectory(), Directory.GetCurrentDirectory()));
_logManager = new LogManager();
_logManager.Listeners.Add(new FileLogListener("log.txt"));
_logManager.Listeners.Add(Monitor);
CandleSettingsEditor.Settings = new CandleSeries()
{
CandleType = typeof(TimeFrameCandle),
Arg = TimeSpan.FromMinutes(5)
};
DatePickerBegin.SelectedDate = new DateTime(2019, 03, 23);
DatePickerEnd.SelectedDate = new DateTime(2019, 05, 10);
}
private void Start_Click(object sender, RoutedEventArgs e)
{
//здесь без разницы какую службу включать, в Shell работает только Fw40
// ConfigManager.RegisterService<ICompilerService>(new Fw40CompilerService(Directory.GetCurrentDirectory(), Directory.GetCurrentDirectory()));
// ConfigManager.RegisterService<ICompilerService>(new RoslynCompilerService());
_security = new Security
{
Id = "RIM9@FORTS",
Code = "RTS",
PriceStep = 10m,
Board = ExchangeBoard.Micex,
};
_indexSecurity = new ExpressionIndexSecurity()
{
Id = "IndexInstr@FORTS",
Code = "IndexInstr",
Expression = "RIM9@FORTS/2",
Board = ExchangeBoard.Micex,
};
_portfolio = new Portfolio { Name = "test portfolio", BeginValue = 10000000 };
var storageRegistry = new StorageRegistry
{
DefaultDrive = new LocalMarketDataDrive(_pathHistory),
};
_connector = new HistoryEmulationConnector(new[] { _security, _indexSecurity }, new[] { _portfolio })
{
HistoryMessageAdapter =
{
StorageRegistry = storageRegistry,
StorageFormat = StorageFormats.Csv,
StartDate = DatePickerBegin.SelectedDate.Value.ChangeKind(DateTimeKind.Utc),
StopDate = DatePickerEnd.SelectedDate.Value.ChangeKind(DateTimeKind.Utc),
},
LogLevel = LogLevels.Info,
};
_logManager.Sources.Add(_connector);
//зарегистрируем в менеджере конфигураций коннектор как источник инструментов
//в версии 4.15 4.16 работает и без регистрации
// ConfigManager.RegisterService<ISecurityProvider>(_connector);
_candleSeries = new CandleSeries(CandleSettingsEditor.Settings.CandleType, _indexSecurity, CandleSettingsEditor.Settings.Arg)
{
BuildCandlesMode = MarketDataBuildModes.Build,
BuildCandlesFrom = MarketDataTypes.Trades,
};
InitCart();
_candleManager = new CandleManager(_connector);
_candleManager.Processing += Processing;
_connector.NewSecurity += Connector_NewSecurity;
_connector.Connect();
}
private void Connector_NewSecurity(Security security)
{
if (_connector.Securities.Count() < 2) return;
//в версии 4.15, 4.16 работает и без этого
_connector.RegisterTrades(_indexSecurity);
//запускаем менеджер свечей на получение свечей по индексу
_candleManager.Start(_candleSeries);
_connector.Start();
}
private void Processing(CandleSeries candleSeries, Candle candle)
{
//в методе отрисовки свечей нужно проверять - является ли свеча индекса или нет и только их отрисовывать на графике
if (candleSeries.Security != _indexSecurity) return;
Chart.Draw(_candleElement, candle);
}
private void InitCart()
{
Chart.ClearAreas();
var area = new ChartArea();
_candleElement = new ChartCandleElement();
Chart.AddArea(area);
Chart.AddElement(area, _candleElement);
}
}
}