| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- 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 16:27:18
- //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;
- using GalaSoft.MvvmLight.Ioc;
- using Muchinfo.MTPClient.IService;
- namespace Muchinfo.MTPClient.Trade.ViewModels
- {
- public class BidCloseViewModel : CloseOrderBase
- {
- private bool _executePriceGotFocus;
- private OrderMode _orderMode = OrderMode.STD; //设置成交属性
- // private HoldingSummary _holdingSummary; //持仓汇总记录。
- private decimal _pips = 5;
- private Visibility _isTimeVisibility = Visibility.Collapsed;
-
- //修改止盈/止损
- private bool canProfitCharChange = false;
- private bool canLossCharChange = false;
- /// <summary>
- /// 最大手数
- /// </summary>
- private decimal _maxLot;
- private decimal _minPips = 0m;
- private decimal _maxPips = 100m;
- private decimal _incrementPips = 10m;
- private decimal _marketPrice;
- private Direction _openDirection;
-
- private bool _isAllowEnsturt; //是否允许限价平仓
-
- // private readonly int BidMarketHideType = ApplicationParameter.BidMarketHideType;//竞价商品卖方向隐藏方式
-
- public BidCloseViewModel(HoldingOrder holdOrder,QuoteGoods goods, OrderType orderType = OrderType.BidMarketClose)
- : base(holdOrder,goods, orderType)
- {
- IsBidMarket = true;
- SetCommissions(goods);
- IsBidDirection = holdOrder.Direction == Direction.Ask;
- IsAskDirection = !IsBidDirection;
- }
- /// <summary>
- /// 汇总平仓
- /// </summary>
- /// <param name="holdingSummary"></param>
- /// <param name="goods"></param>
- public BidCloseViewModel(HoldingSummary holdingSummary, QuoteGoods goods,OrderType orderType=OrderType.BidMarketClose )
- : base(holdingSummary,goods)
- {
- IsBidMarket = true;
- this._holdingSummary = holdingSummary;
- CurrentOrderType = orderType;
- SetCommissions(goods);
- IsBidDirection = holdingSummary.Direction == Direction.Ask;
-
- IsAskDirection = !IsBidDirection;
- }
- /// <summary>
- /// 按商品平仓
- /// </summary>
- /// <param name="goods"></param>
- public BidCloseViewModel(QuoteGoods goods, List<HoldingSummary> holdingSummaries, bool isDirection)
- : base(goods)
- {
- IsBidMarket = true;
- CurrentOrderType = OrderType.BidMarketClose;
- IsDirectionEnable = isDirection;
- _holdingSummaries = holdingSummaries;
-
- var holdingSummary= holdingSummaries.FirstOrDefault();
- if (holdingSummary != null)
- {
- IsBidDirection = holdingSummary.Direction == Direction.Ask;
- SetHoldingSummay(holdingSummary);
- IsAskDirection = !IsBidDirection;
- }
- SetCommissions(goods);
- }
- private TradeCloseMode _tradeCloseMode;
- /// <summary>
- /// 平仓范围
- /// </summary>
- public TradeCloseMode TradeCloseMode
- {
- get
- {
- return _tradeCloseMode;
- }
- set
- {
- Set(() => TradeCloseMode, ref _tradeCloseMode, value);
- // TradeCloseModeChange();
- }
- }
- private Dictionary<TradeCloseMode, string> _tradeCloseModes;
- /// <summary>
- /// 平仓范围枚举
- /// </summary>
- public Dictionary<TradeCloseMode, string> TradeCloseModes
- {
- get
- {
- //todo:显示平仓类型
- var diction = new Dictionary<TradeCloseMode, string>();
- diction.Add(TradeCloseMode.CloseAll, Muchinfo.MTPClient.Resources.Muchinfo_Resource.Trade_No);
- diction.Add(TradeCloseMode.CloseToday, Muchinfo.MTPClient.Resources.Muchinfo_Resource.Trade_CloseToday);
- diction.Add(TradeCloseMode.CloseHistory, Muchinfo.MTPClient.Resources.Muchinfo_Resource.Trade_CloseHistory);
- return diction;
- // return _tradeCloseModes;
- }
- set
- {
- Set(() => TradeCloseModes, ref _tradeCloseModes, value);
- }
- }
- /// <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); }
- }
- 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);
- }
- }
- #region 竞价策略单
- private bool _reverseOpenChecked;
- public bool ReverseOpenChecked
- {
- get
- {
- return _reverseOpenChecked;
- }
- set
- {
- Set(() => ReverseOpenChecked, ref _reverseOpenChecked, value);
- }
- }
- #endregion
- #region 竞价报价
- 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)
- {
- var commissionLsit = new List<Commission>();
- int index = 1;
- foreach (var commission in commissions)
- {
- commission.Index = index;
- commission.FormatString = this.PriceFormat;
- commissionLsit.Add(commission);
- index++;
- }
- if (!bid)
- {
- commissionLsit = commissionLsit.OrderByDescending((item) => item.Index).ToList();
- }
- return commissionLsit;
- }
- private void SetCommissions(QuoteGoods goods)
- {
- BidCommissions = SortCommissions(true, goods.BidList);
- AskCommissions = SortCommissions(false, goods.AskList);
- }
- #endregion
- #region 虚函数
- /// <summary>
- /// 获取和设置the order types
- /// </summary>
- public override Dictionary<OrderType, string> OrderTypes
- {
- get
- {
- var types = new Dictionary<OrderType, string>
- {
- {OrderType.BidMarketClose, Muchinfo_Resource.OrderType_Enum_MarketClose},
- {OrderType.BidLimitClose, Muchinfo_Resource.OrderType_Enum_LimitClose}
- };
- return types;
-
- }
- }
- public override NewEntrustOrder BuildEntrustOrder()
- {
- var entrustOrder = base.BuildEntrustOrder();
- if (CurrentOrderType == OrderType.BidLimitClose)
- {
- entrustOrder.EntrustPrice = ExecutePrice;
- entrustOrder.PriceMode = OrderPriceMode.LimitPrice;
- }
- else
- {
- entrustOrder.EntrustPrice = QuotePrice;
- entrustOrder.PriceMode = OrderPriceMode.MarketPrice;
- }
- if (this.HoldOrder != null)
- {
- entrustOrder.RelationTicket = HoldOrder.OrderID;
- }
- // entrustOrder.TradeCloseMode = TradeCloseMode;
- entrustOrder.OrderMode = OrderMode;
- //entrustOrder.StrategyType = ReverseOpenChecked ? StrategyType.ReverseOpen : StrategyType.None;
- //entrustOrder.ReverseOpenPrice = entrustOrder.EntrustPrice;
- entrustOrder.AllowTradeSub = Pips;
-
- return entrustOrder;
- }
- public override void PostOrder(Action<OrderDetail> successAction, Action<Data.ErrorEntity> errorAction)
- {
- var entrustOrder = BuildEntrustOrder();
- var orderService = SimpleIoc.Default.GetInstance<IOrderService>();
- orderService.BidMarketEntrustOrder(entrustOrder, successAction, errorAction);
- }
- #endregion
- }
- }
|