/// <summary> /// 改变价格条件单的条件价格 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PCOChangeTargetPrice(object sender, RoutedEventArgs e) { e.Handled = true; Button btn = (Button)sender; PriceConditionOrderField cof = (PriceConditionOrderField)btn.DataContext; InstrumentField instrument; this._tradeApi.DictInstrumentField.TryGetValue(cof.InstrumentID, out instrument); double tick = instrument.PriceTick; double Price = 0; StackPanel panel = (StackPanel)btn.Parent; TextBox tbx = (TextBox)panel.FindName("tbxTargetPrice"); if (tbx != null) { double.TryParse(tbx.Text, out Price); //Instrument instrument = btn.TemplatedParent. if (btn.Name == "btnIncTargetPrice") { Price += tick; } else if (btn.Name == "btnDecTargetPrice") { if (Price > 0) { Price -= tick; } } cof.TargetPrice = Price; tbx.Text = Price.ToString(); } }
/// <summary> /// 改变条件单下单数量 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PCOChangeQty(object sender, RoutedEventArgs e) { e.Handled = true; Button btn = (Button)sender; PriceConditionOrderField cof = btn.DataContext as PriceConditionOrderField; StackPanel panel = (StackPanel)btn.Parent; TextBox tbx = (TextBox)panel.FindName("tbxQty"); if (tbx != null) { int Qty = cof.VolumeTotalOriginal; if (btn.Name == "btnIncQty") { Qty++; } else { if (Qty > 0) { Qty--; } } cof.VolumeTotalOriginal = Qty; tbx.Text = Qty.ToString(); } }
/// <summary> /// 新建条件价格单 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCreatePriceConditionOrder_Click(object sender, RoutedEventArgs e) { this.CheckOrder(); PriceConditionOrderField cof = new PriceConditionOrderField(); cof.OrderFieldInstance = this._of.OrderFieldInstance; cof.TargetPrice = this._of.LimitPrice; this._mw._OcAllPriceConditionOrderField.Add(cof); }
/// <summary> /// 价格条件单是否处于运行状态 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void chbPCOIsRunning_Click(object sender, RoutedEventArgs e) { e.Handled = true; CheckBox chb = (CheckBox)sender; PriceConditionOrderField cof = chb.DataContext as PriceConditionOrderField; cof.IsRunning = (bool)chb.IsChecked; if (cof.IsRunning) { cof.ExecutionTrigger += this.SendConditionOrder; this._quoteApi.OnRtnDMD += cof.Run; } else { cof.ExecutionTrigger -= this.SendConditionOrder; this._quoteApi.OnRtnDMD -= cof.Run; } }
/// <summary> /// 删除价格条件单 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnRemovePCO_Click(object sender, RoutedEventArgs e) { Button btn = (Button)sender; PriceConditionOrderField cof = (PriceConditionOrderField)btn.DataContext; //先解除外部绑定 this._quoteApi.OnRtnDMD -= cof.Run; //再将运行状态设置为否 cof.IsRunning = false; //从OC中删除cof if (cof == null || this._OcAllPriceConditionOrderField.Count <= 0) { return; } this._OcAllPriceConditionOrderField.Remove(cof); //GC cof = null; }
/// <summary> /// 条件单下单 /// </summary> /// <param name="cof"></param> private void SendConditionOrder(PriceConditionOrderField cof) { this._tradeApi.SendOrder(cof); }