AlgoTreading

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Timers;
using System.Threading;
using System.Windows.Controls;
using StockSharp.Quik;
using StockSharp.BusinessEntities;
using Ecng.Xaml;
namespace QuikStockSharp
{
/// <summary>
/// Логика взаимодействия для MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private QuikTrader _trader;
private Security _security;
private string account = "NL0011100043";
private string secCode = "SBER";
public System.Collections.IEnumerable Securitiees;
public System.Collections.IEnumerable Orders;
public DateTime StockTime;
ManualResetEvent waitHandle = new ManualResetEvent(false);
public MainWindow()
{
InitializeComponent();
}
private void Connect_Click(object sender, RoutedEventArgs e)
{
// Introduce a way to connect
_trader = new QuikTrader(QuikTerminal.GetDefaultPath());
_trader.Connected += () =>
{
_trader.StartExport();
waitHandle.Set();
};
// Connect to Quick
_trader.Connect();
_trader.NewSecurities += securities => this.GuiSync(() =>
{
// Вывод стаканов
Securities.ItemsSource = _trader.Securities;
// Подключение к стакану
_security = _trader.Securities.First(sec => sec.Code == secCode);
//MessageBox.Show(_security.Id.ToString());
// Уведомление
Status.Content = "Инструмент \"" + secCode + "\" появился";
});
// Запускаем экспорт стакана
if (_security != null) { _trader.RegisterMarketDepth(_security); }
_trader.MarketDepthsChanged += depths => this.GuiAsync(() =>
{
MarketDepth _depth = depths.FirstOrDefault(d => d.Security == _security);
MessageBox.Show("Стакан " + _security + " появился.");
});
// Событие на изменение Combo-Box-а
Securities.SelectionChanged += new SelectionChangedEventHandler(comboBox1SelectionChanged);
}
void comboBox1SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Block1.ItemsSource = "test1";
}
private void Buy_Click(object sender, RoutedEventArgs e)
{
var order = new StockSharp.BusinessEntities.Order {
Trader = _trader,
Portfolio = (Portfolio) Portfolios.SelectedItem,
Security = (Security) Securities.SelectedItem,
Price = decimal.Parse(Price.Text),
Volume = 1,
Direction = OrderDirections.Buy
};
_trader.RegisterOrder(order);
}
private void CancelOrders_Click(object sender, RoutedEventArgs e)
{
_trader.CancelOrders();
}
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
if (this._trader.IsConnected)
{
_trader.StopExport();
_trader.Disconnect();
}
base.OnClosing(e);
}
}
}