private void button_OK_Click(object sender, RoutedEventArgs e)
        {
            var     riskType = this.comboBox_riskTypeSelect.SelectedValue as RiskTypeView;
            decimal riskValue;

            if (!decimal.TryParse(this.textBox_riskValue.Text, out riskValue))
            {
                this.label_Message.DataContext = "許容リスク値が数値ではありません。";
                return;
            }
            var manualClose = this.checkbox_ManualClose.IsChecked ?? true;
            var setting     = new RiskSetting
            {
                Type        = riskType.Model,
                Value       = riskValue,
                ManualClose = manualClose,
            };

            if (this.checkbox_Default.IsChecked ?? false)
            {
                var settings = LineTrader.Properties.Settings.Default;
                settings.DefaultSizeType  = setting.Type.Key;
                settings.DefalutSizeValue = setting.Value;
                settings.ManualClose      = setting.ManualClose;
                settings.Save();
            }
            this.RiskUpdated?.Invoke(setting);
            Dispatcher.Invoke(() => this.Close());
        }
Example #2
0
        private void menuItem_RiskSetting_Click(object sender, RoutedEventArgs e)
        {
            var win = new RiskSettingWindow(this.riskSetting, this.service.Account.Value);

            win.RiskUpdated += setting =>
            {
                this.riskSetting = setting;
                UpdateOrderPreview();
                UpdateCloseButtonVisiblity();
            };
            win.ShowDialog();
        }
        public RiskSettingWindow(RiskSetting current, Model.Oanda.Account account)
        {
            InitializeComponent();

            var riskTypes = Model.RiskType.Values.Select(x =>
            {
                var text = (x == Model.RiskType.Fixed) ? x.Name : string.Format("{0} ({1} {2}) の", x.Name, x.Risk(account, 100), account.accountCurrency);
                return(new RiskTypeView(x, text, x.Unit.Invoke(account)));
            }).ToDictionary(x => x.Model.Key);

            this.comboBox_riskTypeSelect.ItemsSource = Model.RiskType.Values.Select(x => riskTypes[x.Key]);

            this.comboBox_riskTypeSelect.SelectedItem = (riskTypes.ContainsKey(current.Type.Key))
                ? riskTypes[current.Type.Key]
                : riskTypes[Model.RiskType.FreeMarginRatio.Key]
            ;
            this.textBox_riskValue.Text         = current.Value.ToString();
            this.checkbox_ManualClose.IsChecked = current.ManualClose;
        }
Example #4
0
        public MainWindow(Model.Service service)
        {
            InitializeComponent();

            this.riskSetting = RiskSetting.Default;
            this.service     = service;

            this.viewCheckUpdated = new Subject <object>();

            this.instrumentSelected = new Subject <string>();
            this.selectedInstrument = this.instrumentSelected.ToReadOnlyReactiveProperty();

            this.listView_Instruments.DataContext = this.service.Instruments.Keys.OrderBy(x => x);

            var sampling = Observable.Interval(TimeSpan.FromMilliseconds(1000)).Select <long, object>(_ => null);

            this.orderTabSelected = new Subject <int>();
            var orderTabSelected = this.orderTabSelected.Select <int, object>(_ => null);

            this.selectedOrderTab = this.orderTabSelected.ToReadOnlyReactiveProperty();

            this.lines = new Dictionary <string, Lines>();
            foreach (var instrument in this.service.Instruments.Values)
            {
                var lines = new Lines();
                sampling.Subscribe(_ =>
                {
                    var current = instrument.CurrentLine.Value;
                    try
                    {
                        Dispatcher.Invoke(() =>
                        {
                            var focused   = this.dataGrid_Lines.IsKeyboardFocusWithin;
                            var selected  = this.dataGrid_Lines.SelectedItem as Line;
                            lines.Current = (current == null) ? null : new Line(current);
                            if (instrument.Name == this.selectedInstrument.Value)
                            {
                                this.dataGrid_Lines.SelectedItem = lines[selected?.Identity];
                            }
                            if (focused)
                            {
                                this.dataGrid_Lines.Focus();
                            }
                        });
                    }
                    catch (TaskCanceledException)
                    {
                        // do nothing
                    }
                });
                instrument.ChartLines.Subscribe(charts =>
                {
                    Dispatcher.Invoke(() =>
                    {
                        var focused  = this.dataGrid_Lines.IsKeyboardFocusWithin;
                        var selected = this.dataGrid_Lines.SelectedItem as Line;
                        lines.UpdateLines(charts);
                        if (instrument.Name == this.selectedInstrument.Value)
                        {
                            this.dataGrid_Lines.SelectedItem = lines[selected?.Identity];
                        }
                        if (focused)
                        {
                            this.dataGrid_Lines.Focus();
                        }
                    });
                });
                this.lines.Add(instrument.Name, lines);
            }
            this.dataGrid_Lines.DataContext = this.instrumentSelected
                                              .Select(_ => this.ListItems)
                                              .Do(_ =>
            {
                var current = this.lines[this.selectedInstrument.Value].Current;
                if (current == null)
                {
                    return;
                }
                this.dataGrid_Lines.SelectedItem = current;
                this.dataGrid_Lines.Focus();
            })
                                              .Merge(this.viewCheckUpdated.Select(_ => this.ListItems))
                                              .ToReadOnlyReactiveProperty()
            ;

            this.buyPreview  = new OrderPreviewRecords();
            this.sellPreview = new OrderPreviewRecords();
            this.dataGrid_BuyPreview.DataContext  = this.buyPreview;
            this.dataGrid_SellPreview.DataContext = this.sellPreview;
            Observable
            .Merge(
                this.lines
                .Select(x => x.Value.Items.CollectionChangedAsObservable().Select(_ => x.Key))
                .Merge()
                .Where(x => x == this.selectedInstrument.Value),
                this.instrumentSelected,
                orderTabSelected,
                this.service.Account
                )
            .Where(_ => this.selectedOrderTab.Value == 0)
            .Subscribe(_ => UpdateOrderPreview())
            ;
            this.positions = new Positions();
            this.dataGrid_Positions.DataContext = this.positions.Items;
            Observable
            .Merge(
                sampling,
                this.instrumentSelected,
                orderTabSelected,
                this.service.Positions
                )
            .Where(_ => this.selectedOrderTab.Value == 1)
            .Subscribe(_ => UpdatePositions())
            ;
            UpdateCloseButtonVisiblity();
        }