Moadip
|
Date: 2/25/2012
|
|
|
|
Вот еще один скрин, скотировалось 2 лота из 5, после чего MQS остановилась. Код, проще некуда, для того чтобы проверить работу MQS. В чем проблема я понять не могу. Выкладываю полностью весь код. MainWindow.xaml.csCode
using System.Linq;
using System.Windows;
using Ecng.Collections;
using Ecng.Xaml;
using StockSharp.BusinessEntities;
using StockSharp.Quik;
using StockSharp.Xaml;
using StockSharp.Algo.Logging;
using System.Windows.Forms;
using MessageBox = System.Windows.MessageBox;
using System.ComponentModel;
namespace Kotirovanie
{
public partial class MainWindow : Window
{
public QuikTrader trader;
static Security instr1;
public static MarketDepth depth1;
const string secCode1 = "SBER";
myStrategy myStrat;
readonly LogManager logManager;
public MainWindow()
{
InitializeComponent();
//Path.Text = QuikTerminal.GetDefaultPath();
Path.Text = "c:\\Program Files\\QUIK-Junior\\";
var monitor = new MonitorWindow() { Topmost = true };
monitor.Show();
logManager = new LogManager();
logManager.Listeners.Add(new GuiLogListener(monitor));
}
private void FindPath_Click(object sender, RoutedEventArgs e)
{
var dlg = new FolderBrowserDialog();
if (!Path.Text.IsEmpty()) dlg.SelectedPath = Path.Text;
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) Path.Text = dlg.SelectedPath;
}
bool isConnected;
private void btnConnect_Click(object sender, RoutedEventArgs e)
{
if (!isConnected)
{
if (Path.Text.IsEmpty())
MessageBox.Show(this, "Путь к Quik не выбран");
else
{
if (trader == null)
{
trader = new QuikTrader(Path.Text) { IsAsyncMode = false };
logManager.Sources.Add(trader);
trader.ReConnectionSettings.Interval = TimeSpan.FromSeconds(10);
trader.ReConnectionSettings.WorkingTime = Exchange.Rts.WorkingTime;
trader.ReConnectionSettings.ConnectionRestored += () => this.GuiAsync(() => MessageBox.Show(this, "Соединение восстановлено"));
trader.ConnectionError += error => this.GuiAsync(() => MessageBox.Show(this, error.ToString()));
trader.Connected += () => this.GuiAsync(() => btnExportDde.IsEnabled = true);
trader.NewPortfolios += portfolios => this.GuiAsync(() => Portfolio.Portfolios.AddRange(portfolios));
trader.NewSecurities += securities =>
{
if (instr1 == null)
{
instr1 = securities.FirstOrDefault(sec => sec.Code == secCode1);
instr1.Exchange.IsSupportAtomicReRegister = false;
}
};
trader.QuotesChanged += depths =>
{
if (depth1 == null && instr1 != null)
{
depth1 = depths.FirstOrDefault(d => d.Security == instr1);
}
};
}
trader.Connect();
isConnected = true;
btnConnect.Content = "Отключиться";
}
}
else
{
trader.Disconnect();
isConnected = false;
btnConnect.Content = "Подключиться";
}
}
private void btnExportDde_Click(object sender, RoutedEventArgs e)
{
if (isDdeStarted) StopDde();
else StartDde();
}
bool isDdeStarted;
private void StartDde()
{
trader.StartExport();
isDdeStarted = true;
}
private void StopDde()
{
trader.StopExport();
isDdeStarted = false;
}
private void Window_Closing(object sender, CancelEventArgs e)
{
if (trader != null)
{
if (isDdeStarted) StopDde();
trader.Dispose();
}
}
private void btnExportStakan_Click(object sender, RoutedEventArgs e)
{
trader.RegisterQuotes(instr1);
}
private void btnParent_Click(object sender, RoutedEventArgs e)
{
//Создаем и запускаем основную стратегию
myStrat = new myStrategy() { Trader = trader, Portfolio = Portfolio.SelectedPortfolio, Security = instr1};
logManager.Sources.Add(myStrat);
myStrat.Start();
}
private void btnChild_Click(object sender, RoutedEventArgs e)
{
//Добавляем дочернюю
myStrat.addChildStrategy(OrderDirections.Buy, 5, 1);
}
}
}
myStrategy.csCode
using System;
using System.Collections.Generic;
using StockSharp.Algo.Strategies;
using StockSharp.BusinessEntities;
namespace Kotirovanie
{
class myStrategy : Strategy
{
protected override void OnStarting()
{
RemoveChildStrategies = false;
base.OnStarting();
}
public void addChildStrategy(OrderDirections direct, decimal quotingVol, decimal vol)
{
var strt = new MarketQuotingStrategy(direct, quotingVol) { PriceOffset = Security.MinStepSize, Volume = vol };
ChildStrategies.Add(strt);
}
}
}
MainWindow.xamlCode
<Window x:Class="Kotirovanie.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:EcngTradingXaml="clr-namespace:StockSharp.Xaml;assembly=StockSharp.Xaml"
Title="" Height="173" Width="478" Closing="Window_Closing" Topmost="True" WindowStartupLocation="CenterScreen">
<Grid>
<TextBox Height="23" HorizontalAlignment="Left" Margin="12,12,0,0" Name="Path" VerticalAlignment="Top" Width="277" />
<Button Content="..." Height="23" HorizontalAlignment="Left" Margin="295,12,0,0" Name="FindPath" VerticalAlignment="Top" Width="23" Click="FindPath_Click" />
<Button Content="Подключиться" Height="23" HorizontalAlignment="Left" Margin="12,41,0,0" Name="btnConnect" VerticalAlignment="Top" Width="98" Click="btnConnect_Click" />
<Button Content="Экспорт DDE" Height="23" HorizontalAlignment="Left" Margin="116,41,0,0" Name="btnExportDde" VerticalAlignment="Top" Width="98" Click="btnExportDde_Click" IsEnabled="False" />
<EcngTradingXaml:PortfolioComboBox x:Name="Portfolio" Height="23" HorizontalAlignment="Left" Margin="324,41,0,0" VerticalAlignment="Top" Width="120" />
<Button Content="Экспорт Стаканы" Height="23" HorizontalAlignment="Left" Margin="220,41,0,0" Name="btnExportStakan" VerticalAlignment="Top" Width="98" Click="btnExportStakan_Click" />
<Button Content="Основная" Height="23" HorizontalAlignment="Left" Margin="12,99,0,0" Name="btnParent" VerticalAlignment="Top" Width="98" Click="btnParent_Click" />
<Button Content="Дочерняя" Height="23" HorizontalAlignment="Left" Margin="116,99,0,0" Name="btnChild" VerticalAlignment="Top" Width="98" Click="btnChild_Click" />
</Grid>
</Window>
Михаил, посмотрите пожалуйста что я не так делаю?
|