Тиковые данные в OpenECry
Здравствуйте, вот уже неделю мучаюсь с проблемой, никаким образом не удается получить тиковые данные в openecry.
Скажите пожалуйста тики в openECry вообще работают ?
Подскажите пожалуйста кто-нибудь в чем дело может быть.... очень прошу =(
Code
using ConsoleDump;
using Ecng.Common;
using Ecng.Xaml;
using StockSharp.Algo;
using StockSharp.Algo.Candles;
using StockSharp.BusinessEntities;
using StockSharp.Localization;
using StockSharp.Messages;
using StockSharp.OpenECry;
using StockSharp.Xaml;
using StockSharp.Xaml.Charting;
using System;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using WpfApp1.Service;
namespace WpfApp1
{
/// <summary>
/// Логика взаимодействия для MainWindow.xaml
/// </summary>
public partial class MainWindow
{
/// <summary>
/// Название коннетора
/// </summary>
private string selectedConnector;
/// <summary>
/// Выбранный инструмент
/// </summary>
private Security selectedSecurity;
/// <summary>
/// Сервис коннеторов
/// </summary>
private ConnectorServiceInterface ConnectorService;
/// <summary>
///
/// </summary>
private readonly ChartCandleElement candlesElem;
private CandleManager candleManager;
private CandleSeries candleSeries;
private ChartTradeElement tradesElem;
private ScalperStrategy strategy;
private Connector Trader;
private Portfolio portfolio;
public MainWindow()
{
InitializeComponent();
CandleSettingsEditor.Settings = new CandleSeries
{
CandleType = typeof(TimeFrameCandle),
Arg = TimeSpan.FromMinutes(5),
};
CandleSettingsEditor.SettingsChanged += CandleSettingsChanged;
ConnectorService = new ConnectorService();
var area = new ChartArea();
Chart.Areas.Add(area);
candlesElem = new ChartCandleElement();
area.Elements.Add(candlesElem);
tradesElem = new ChartTradeElement { FullTitle = LocalizedStrings.Str985 };
area.Elements.Add(tradesElem);
}
private void SecurityPicker_OnSecuritySelected(Security security)
{
if (security == null)
return;
if (candleSeries != null)
{
candleManager.Stop(candleSeries); // give back series memory
strategy.Start();
}
Chart.Reset(new[] { candlesElem });
selectedSecurity = security;
StartBotButton.IsEnabled = true;
Trader.RegisterSecurity(security);
Trader.RegisterTrades(security);
Trader.RegisterMarketDepth(security);
candleSeries = new CandleSeries(CandleSettingsEditor.Settings.CandleType, security, CandleSettingsEditor.Settings.Arg);
// create strategy based on 80 5-min и 10 5-min
strategy = new ScalperStrategy(
Chart, candlesElem, tradesElem,
candleManager, candleSeries)
{
Volume = 1,
Portfolio = portfolio,
Security = security,
Connector = Trader,
};
strategy.Start();
candleManager.Start(candleSeries);
}
private void CandleSettingsChanged()
{
SecurityPicker_OnSecuritySelected(SecurityPicker.SelectedSecurity);
}
private void FindClick(object sender, RoutedEventArgs e)
{
var wnd = new SecurityLookupWindow { Criteria = new Security { Code = "ES" } };
if (!wnd.ShowModal())
{
return;
}
Trader.Lookup(wnd.Criteria);
Trader.LookupSecurities(wnd.Criteria);
this.GuiAsync(() => {
});
}
private void StartBot(object sender, RoutedEventArgs e)
{
}
private void OnSelectConnector(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
ComboBoxItem item = (ComboBoxItem)ConnectorName.SelectedItem;
selectedConnector = item.Name.ToString();
Login.IsEnabled = true;
Password.IsEnabled = true;
ConnectButton.IsEnabled = true;
}
/// <summary>
/// Информация о стакане
/// </summary>
/// <param name="depth"></param>
private void OnDepth(MarketDepth depth)
{
if (depth.Security != selectedSecurity)
{
return;
}
DepthControl.UpdateDepth(depth);
}
private void ConnectButton_Click(object sender, System.Windows.RoutedEventArgs e)
{
Console.WriteLine("send connect");
Trader = ConnectorService.Connect(Login.Text, Password.Password, selectedConnector);
// подписываемся на событие успешного соединения
Trader.Connected += () =>
{
Console.WriteLine("Bot connected...");
candleManager = new CandleManager(Trader);
//Security Criteria = new Security { Code = "ES" };
//Trader.LookupSecurities(Criteria);
// update gui labels
this.GuiAsync(() => {
FindButton.IsEnabled = true;
});
// subscribe on news
Trader.RegisterNews();
};
// событие успешного отключения
Trader.Disconnected += () =>
{
Console.WriteLine("Bot disconnected...");
this.GuiAsync(() => {
FindButton.IsEnabled = false;
});
};
// подписываемся на событие разрыва соединения
Trader.ConnectionError += error => this.GuiAsync(() =>
{
MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2959);
});
// событие ошибки обработки данных
Trader.Error += error => this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2955));
Trader.NewSecurity += security =>
{
SecurityPicker.Securities.Add(security);
};
Trader.NewMyTrade += trades =>
{
trades.Dump();
};
Trader.NewTrade += trade =>
{
trade.Dump();
};
Trader.NewTrades += trade =>
{
trade.Dump();
};
Trader.NewOrder += order =>
{
// order.Dump();
};
Trader.NewPosition += position =>
{
position.Dump();
};
Trader.NewSecurities += securities =>
{
// Console.WriteLine("Получены инструменты...");
//securities.Dump();
//Connector.Securities.Dump();
};
Trader.NewPortfolio += _portfolio =>
{
portfolio = _portfolio;
// подписываемся на обновление портфеля
Trader.RegisterPortfolio(_portfolio);
};
Trader.SecurityChanged += sec =>
{
sec.Dump();
};
Trader.NewMarketDepth += OnDepth;
Trader.MarketDepthChanged += OnDepth;
SecurityPicker.MarketDataProvider = Trader;
Trader.Connect();
}
}
}