using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; //---------------------------------------------------------------- //Module Name: $safeprojectname$ //Purpose: //CopyRight: Muchinfo //History: //---------------------------------------------------------------- //DateTime 2016/1/16 10:16:37 //Author //Description Create //---------------------------------------------------------------- using System.Windows; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Data.Model; using Muchinfo.MTPClient.Data.Model.Account; using Muchinfo.MTPClient.Infrastructure.Utilities; using Muchinfo.MTPClient.Resources; namespace Muchinfo.MTPClient.Trade.ViewModels { public class BidOpenOrderViewModel : TradeOrderBase { private OrderMode _orderMode = OrderMode.STD; //设置成交属性 public BidOpenOrderViewModel(QuoteGoods goods,OrderType orderType):base(goods,orderType) { IsBidMarket = true; AskCommissions = SortCommissions(false, goods.AskList, goods.FormatPrice); BidCommissions = SortCommissions(true, goods.BidList, goods.FormatPrice); } /// /// 获取和设置OrderModes /// public Dictionary OrderModes { get { var types = new Dictionary { {OrderMode.STD, Muchinfo.MTPClient.Resources.Muchinfo_Resource.Trade_No}, {OrderMode.FAK, "FAK"}, {OrderMode.FOK,"FOK"} }; return types; } } /// /// 设置成交属性 /// public OrderMode OrderMode { get { return _orderMode; } set { Set(() => OrderMode, ref _orderMode, value); } } /// /// 跌停 /// public decimal LowPrice { get { if (this.CurrentGoods != null && this.CurrentGoods.GoodsParameters != null) { FallPriceVisibility = Visibility.Visible; return this.CurrentGoods.GoodsParameters.FallsPrice; // return this.CurrentGoods.GoodsParameters.RaisesPrice; } FallPriceVisibility = Visibility.Collapsed; return 0m; } } /// /// 涨停 /// public decimal UpPrice { get { if (this.CurrentGoods != null && this.CurrentGoods.GoodsParameters != null) { UpPriceVisibility = Visibility.Visible; return this.CurrentGoods.GoodsParameters.RaisesPrice; // return this.CurrentGoods.GoodsParameters.RaisesPrice; } UpPriceVisibility = Visibility.Collapsed; return 0m; } } private Visibility _upPriceVisibility; /// /// 是否显示涨停价提示 /// public Visibility UpPriceVisibility { get { return _upPriceVisibility; } set { Set(() => UpPriceVisibility, ref _upPriceVisibility, value); } } private Visibility _fallPriceVisibility; /// /// 是否显示跌停价 /// public Visibility FallPriceVisibility { get { return _fallPriceVisibility; } set { Set(() => FallPriceVisibility, ref _fallPriceVisibility, value); } } /// /// 格式化涨停 /// public string UpPriceDisplay { get { return UpPrice.ToString(PriceFormat); } } /// /// 格式化跌停 /// public string LowPriceDisplay { get { return LowPrice.ToString(PriceFormat); } } private List _bidCommissions; /// /// 显示买入档 /// public List BidCommissions { get { return _bidCommissions; } set { Set(() => BidCommissions, ref _bidCommissions, value); } } private List _askCommissions; /// /// 显示卖出档 /// public List AskCommissions { get { return _askCommissions; } set { Set(() => AskCommissions, ref _askCommissions, value); } } /// /// 设置买卖档 /// /// if set to true [bid]. /// The commissions. /// List{Commission}. private List SortCommissions(bool bid, Commission[] commissions, string formatStr) { var commissionLsit = new List(); int index = 1; foreach (var commission in commissions) { commission.Index = index; commission.FormatString = formatStr; commissionLsit.Add(commission); index++; } if (!bid) { commissionLsit = commissionLsit.OrderByDescending((item) => item.Index).ToList(); } return commissionLsit; } #region 竞价策略单 private decimal _slTriggerPrice; private bool _spStrategyEnable; /// /// 是否启用止盈策略 /// public bool SpStrategyEnable { get { return _spStrategyEnable; } set { Set(() => SpStrategyEnable, ref _spStrategyEnable, value); } } private bool _slStrategyEnable; /// /// 是否使用止损策略 /// public bool SlStrategyEnable { get { return _slStrategyEnable; } set { Set(() => SlStrategyEnable, ref _slStrategyEnable, value); } } private bool _spEnable = false; /// /// 是否启用止盈 /// public bool SpEnable { get { return _spEnable; } set { Set(() => SpEnable, ref _spEnable, value); } } private bool _slEnable = false; /// /// 是否启用止损 /// public bool SlEnable { get { return _slEnable; } set { Set(() => SlEnable, ref _slEnable, value); } } /// /// 止损触发价 /// public decimal SlTriggerPrice { get { return _slTriggerPrice; } set { Set(() => SlTriggerPrice, ref _slTriggerPrice, value); } } private decimal _sPTriggerPrice; /// /// 止盈触发价 /// public decimal SPTriggerPrice { get { return _sPTriggerPrice; } set { Set(() => SPTriggerPrice, ref _sPTriggerPrice, value); } } private StrategyType _strategyType = StrategyType.None; /// /// 策略类型 /// public StrategyType StrategyType { get { return _strategyType; } set { Set(() => StrategyType, ref _strategyType, value); switch (value) { case StrategyType.None: case StrategyType.ReverseOpen: { SpStrategyEnable = false; SlStrategyEnable = false; } break; case StrategyType.MovingStopLoss: { SpStrategyEnable = false; SlStrategyEnable = true; } break; case StrategyType.EntrustStopPL: case StrategyType.MarketStopPL: { SpStrategyEnable = true; SlStrategyEnable = true; } break; } } } public Dictionary StrategyTypes { get { var types = new Dictionary { {StrategyType.None, Muchinfo.MTPClient.Resources.Muchinfo_Resource.Trade_No}, {StrategyType.MovingStopLoss, Muchinfo.MTPClient.Resources.Muchinfo_Resource.Trade_MobileStop}, {StrategyType.EntrustStopPL,Muchinfo.MTPClient.Resources.Muchinfo_Resource.Trade_CurrentPrice_Stop_Profit}, {StrategyType.MarketStopPL,Muchinfo.MTPClient.Resources.Muchinfo_Resource.Trade_MarkettPrice_Stop_Profit} }; return types; } } #endregion public override NewEntrustOrder BuildEntrustOrder() { var order= base.BuildEntrustOrder(); if ( CurrentOrderType == OrderType.BidMarketOpen && IsAllowPips) { //点差只能设置整数 order.AllowTradeSub = (int)Pips; } order.EntrustPrice = ( CurrentOrderType == OrderType.BidMarketOpen) ? QuotePrice : ExecutePrice; // : (OrderDirection == Direction.Ask ? CurrentGoods.AskPrice : CurrentGoods.BidPrice); order.PriceMode = OrderPriceMode.MarketPrice; if ( CurrentOrderType == OrderType.BidLimitOpen) //// { //todo:竞价策略单 ////order.SLPrice = StopLossChecked && SlEnable ? StopLoss : 0; ////order.SPPrice = StopProfitChecked && SpEnable ? StopProfit : 0; ////order.SlTriggerPrice = StopLossChecked ? SlTriggerPrice : 0; ////order.SpTriggerPrice = StopProfitChecked ? SPTriggerPrice : 0; order.PriceMode = OrderPriceMode.LimitPrice; } order.OrderMode = OrderMode; // order.TradeCloseMode = TradeCloseMode.IsVailed; return order; } /// /// 获取和设置the order types /// public override Dictionary OrderTypes { get { var types = new Dictionary { {OrderType.BidMarketOpen, Muchinfo_Resource.OrderType_Enum_MarketOpen}, {OrderType.BidLimitOpen, Muchinfo_Resource.OrderType_Enum_LimitOpen} }; return types; } } protected override void SetQuotePrice() { if (CurrentGoods != null) { ExecutePrice = IsBidDirection ? CurrentGoods.AskPrice : CurrentGoods.BidPrice; QuotePrice = ExecutePrice; } } public override void PostOrder(Action successAction, Action errorAction) { var entrustOrder = BuildEntrustOrder(); _orderService.BidMarketEntrustOrder(entrustOrder, successAction, errorAction); } } }