| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414 |
- 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);
- }
-
- /// <summary>
- /// 获取和设置OrderModes
- /// </summary>
- public Dictionary<OrderMode, string> OrderModes
- {
- get
- {
- var types = new Dictionary<OrderMode, string>
- {
- {OrderMode.STD, Muchinfo.MTPClient.Resources.Muchinfo_Resource.Trade_No},
- {OrderMode.FAK, "FAK"},
- {OrderMode.FOK,"FOK"}
- };
- return types;
- }
- }
- /// <summary>
- /// 设置成交属性
- /// </summary>
- public OrderMode OrderMode
- {
- get
- {
- return _orderMode;
- }
- set
- {
- Set(() => OrderMode, ref _orderMode, value);
- }
- }
- /// <summary>
- /// 跌停
- /// </summary>
- 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;
- }
- }
- /// <summary>
- /// 涨停
- /// </summary>
- 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;
- /// <summary>
- /// 是否显示涨停价提示
- /// </summary>
- public Visibility UpPriceVisibility
- {
- get { return _upPriceVisibility; }
- set { Set(() => UpPriceVisibility, ref _upPriceVisibility, value); }
- }
- private Visibility _fallPriceVisibility;
- /// <summary>
- /// 是否显示跌停价
- /// </summary>
- public Visibility FallPriceVisibility
- {
- get { return _fallPriceVisibility; }
- set { Set(() => FallPriceVisibility, ref _fallPriceVisibility, value); }
- }
- /// <summary>
- /// 格式化涨停
- /// </summary>
- public string UpPriceDisplay
- {
- get
- {
- return UpPrice.ToString(PriceFormat);
- }
- }
- /// <summary>
- /// 格式化跌停
- /// </summary>
- public string LowPriceDisplay
- {
- get
- {
- return LowPrice.ToString(PriceFormat);
- }
- }
- private List<Commission> _bidCommissions;
- /// <summary>
- /// 显示买入档
- /// </summary>
- public List<Commission> BidCommissions
- {
- get { return _bidCommissions; }
- set { Set(() => BidCommissions, ref _bidCommissions, value); }
- }
- private List<Commission> _askCommissions;
- /// <summary>
- /// 显示卖出档
- /// </summary>
- public List<Commission> AskCommissions
- {
- get { return _askCommissions; }
- set { Set(() => AskCommissions, ref _askCommissions, value); }
- }
- /// <summary>
- /// 设置买卖档
- /// </summary>
- /// <param name="bid">if set to <c>true</c> [bid].</param>
- /// <param name="commissions">The commissions.</param>
- /// <returns>List{Commission}.</returns>
- private List<Commission> SortCommissions(bool bid, Commission[] commissions, string formatStr)
- {
- var commissionLsit = new List<Commission>();
- 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;
- /// <summary>
- /// 是否启用止盈策略
- /// </summary>
- public bool SpStrategyEnable
- {
- get
- {
- return _spStrategyEnable;
- }
- set
- {
- Set(() => SpStrategyEnable, ref _spStrategyEnable, value);
-
- }
- }
- private bool _slStrategyEnable;
- /// <summary>
- /// 是否使用止损策略
- /// </summary>
- public bool SlStrategyEnable
- {
- get
- {
- return _slStrategyEnable;
- }
- set
- {
- Set(() => SlStrategyEnable, ref _slStrategyEnable, value);
-
- }
- }
- private bool _spEnable = false;
- /// <summary>
- /// 是否启用止盈
- /// </summary>
- public bool SpEnable
- {
- get { return _spEnable; }
- set { Set(() => SpEnable, ref _spEnable, value); }
- }
- private bool _slEnable = false;
- /// <summary>
- /// 是否启用止损
- /// </summary>
- public bool SlEnable
- {
- get { return _slEnable; }
- set { Set(() => SlEnable, ref _slEnable, value); }
- }
- /// <summary>
- /// 止损触发价
- /// </summary>
- public decimal SlTriggerPrice
- {
- get { return _slTriggerPrice; }
- set { Set(() => SlTriggerPrice, ref _slTriggerPrice, value); }
- }
- private decimal _sPTriggerPrice;
- /// <summary>
- /// 止盈触发价
- /// </summary>
- public decimal SPTriggerPrice
- {
- get
- {
- return _sPTriggerPrice;
- }
- set
- {
- Set(() => SPTriggerPrice, ref _sPTriggerPrice, value);
- }
- }
- private StrategyType _strategyType = StrategyType.None;
- /// <summary>
- /// 策略类型
- /// </summary>
- 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<StrategyType, string> StrategyTypes
- {
- get
- {
- var types = new Dictionary<StrategyType, string>
- {
- {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;
- }
- /// <summary>
- /// 获取和设置the order types
- /// </summary>
- public override Dictionary<OrderType, string> OrderTypes
- {
- get
- {
- var types = new Dictionary<OrderType, string>
- {
- {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<OrderDetail> successAction, Action<Data.ErrorEntity> errorAction)
- {
- var entrustOrder = BuildEntrustOrder();
- _orderService.BidMarketEntrustOrder(entrustOrder, successAction, errorAction);
- }
- }
- }
|