| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419 |
- using Muchinfo.MTPClient.Data.Enums;
- using Muchinfo.MTPClient.Data.Model;
- using Muchinfo.MTPClient.Data.Model.Account;
- using Muchinfo.MTPClient.Infrastructure.Utilities;
- using System;
- using System.Collections.Generic;
- //----------------------------------------------------------------
- //Module Name: $safeprojectname$
- //Purpose:
- //CopyRight: Muchinfo
- //History:
- //----------------------------------------------------------------
- //DateTime 2016/1/16 10:45:32
- //Author
- //Description Create
- //----------------------------------------------------------------
- using System.Windows;
- namespace Muchinfo.MTPClient.Trade.ViewModels
- {
- public class MakeOrderViewModel : TradeOrderBase
- {
- private List<SpecialMember> _specMemberCodes;
- /// <summary>
- /// 转单的特别会员
- /// </summary>
- public List<SpecialMember> SpecMemberCodes
- {
- get { return _specMemberCodes; }
- set { Set(() => SpecMemberCodes, ref _specMemberCodes, value); }
- }
- private SpecialMember _currentSpecCode;
- /// <summary>
- /// 当前选择 特别会员代码
- /// </summary>
- public SpecialMember CurrentSpecCode
- {
- get { return _currentSpecCode; }
- set
- {
- Set(() => CurrentSpecCode, ref _currentSpecCode, value);
- // RaisePropertyChanged(() => ProfitLossPipsSpecCodeVailed);
- }
- }
- private bool _relateSpecMemFlag;
- /// <summary>
- /// 是否可选择对冲的特别会员
- /// </summary>
- public bool RelateSpecMemFlag
- {
- get { return _relateSpecMemFlag; }
- set
- {
- Set(() => RelateSpecMemFlag, ref _relateSpecMemFlag, value);
- }
- }
- private bool _isInvestorAccount = true;
- /// <summary>
- /// 是否是会员交易员
- /// </summary>
- public bool IsInvestorAccount
- {
- get { return _isInvestorAccount; }
- set
- {
- Set(() => IsInvestorAccount, ref _isInvestorAccount, value);
- }
- }
- public Visibility PriceTipsVisibility { get; set; }
- public MakeOrderViewModel(QuoteGoods goods, OrderType orderType)
- : base(goods, orderType)
- {
- IsBidMarket = false;
- if (UserManager.CurrentTradeAccount.AccountType == eAccountType.ACCOUNTTYPE_TRADER)
- {
- IsInvestorAccount = false;
- this.CurrentOrderType = OrderType.MarketOpenOrder; ////会员交易员只有市价建仓
- }
- PriceTipsVisibility = Visibility.Collapsed;
- ////注册实时行情消息
- ApplicationParameter.QuotationMessenger.Register<List<QuoteGoods>>(this, MessengerTokens.ReceiveRealTimeQuote, (quoteList) =>
- {
- if (CurrentGoods != null)
- {
- QuotePrice = (IsBidDirection ? CurrentGoods.BidPrice : CurrentGoods.AskPrice);
- }
- });
- }
- #region 止盈止损
- /// <summary>
- /// 止盈跟据买卖设置符号方向
- /// </summary>
- public string ProfitChar
- {
- get
- {
- if (IsBidDirection)
- {
- // StopProfit = (decimal)(MaxProfit - (decimal)PriceMinUnit);
- // StopLoss = (decimal)(MaxLoss + (decimal)PriceMinUnit);
- return "<";
- }
- else
- {
- return ">";
- // StopProfit = (decimal)(MaxProfit + (decimal)PriceMinUnit);
- // StopLoss = (decimal)(MaxLoss - (decimal)PriceMinUnit);
- }
- }
- }
- /// <summary>
- /// 止损跟据买卖设置符号方向
- /// </summary>
- public string LossChar
- {
- get
- {
- if (IsBidDirection)
- {
- return ">";
- }
- else
- {
- return "<";
- }
- }
- }
- //private decimal _maxLoss;
- //private decimal _maxProfit;
- private decimal _stopLoss;
- /// <summary>
- /// StopLossChecked
- /// </summary>
- private bool _stopLossChecked;
- private decimal _stopProfit;
- /// <summary>
- /// StopProfitChecked
- /// </summary>
- private bool _stopProfitChecked;
- /// <summary>
- /// Sets and gets the StopLoss property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public decimal StopLoss
- {
- get
- {
- return _stopLoss;
- }
- set
- {
- Set(() => StopLoss, ref _stopLoss, value);
- // RaisePropertyChanged(() => ProfitLossPipsSpecCodeVailed);
- }
- }
- /// <summary>
- /// Sets and gets the StopLossChecked property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public bool StopLossChecked
- {
- get
- {
- return _stopLossChecked;
- }
- set
- {
- Set(() => StopLossChecked, ref _stopLossChecked, value);
- // StopLoss = _stopLossChecked ? ExecutePrice : 0;
- //StopLoss = _stopProfitChecked ? 0 : 0;
- if (IsBidDirection)
- {
- StopLoss = (decimal)(MaxLoss - MinUint);
- }
- else
- {
- StopLoss = (decimal)(MaxLoss + MinUint);
- }
- //StopLoss = _stopProfitChecked ? 0 : 0;
- }
- }
- /// <summary>
- /// Sets and gets the StopProfit property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public decimal StopProfit
- {
- get
- {
- return _stopProfit;
- }
- set
- {
- Set(() => StopProfit, ref _stopProfit, value);
- }
- }
- /// <summary>
- /// Sets and gets the StopProfitChecked property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public bool StopProfitChecked
- {
- get
- {
- return _stopProfitChecked;
- }
- set
- {
- Set(() => StopProfitChecked, ref _stopProfitChecked, value);
- // StopProfit = _stopProfitChecked ? ExecutePrice : 0;
- if (IsBidDirection)
- {
- StopProfit = (decimal)(MaxProfit + MinUint);
- }
- else
- {
- StopProfit = (decimal)(MaxProfit - MinUint);
- }
- }
- }
- public decimal MinUint
- {
- get
- {
- int temp = 0;
- if (this.CurrentGoods != null && this.CurrentGoods.GoodsParameters != null)
- {
- temp = CurrentGoods.GoodsParameters.HqExchFigures;
- }
- return Convert.ToDecimal(1 / Math.Pow(10, temp));
- }
- }
- /// 设置最大止损价
- /// </summary>
- public decimal MaxLoss
- {
- get
- {
- if (IsBidDirection)
- {
- //止损价 < 限价-(买点差-卖点差+止损点差) * 最小变动单位
- // _currentGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open
- if (CurrentGoods == null || CurrentGoods.GoodsParameters == null) return 0;
- if (CurrentGoods.GoodsParameters.HqExchFigures < 20 &&
- CurrentGoods.GoodsParameters.HqExchFigures > -20)
- {
- var value = (CurrentGoods.GoodsParameters.BuyptSub -
- CurrentGoods.GoodsParameters.SellptSub +
- CurrentGoods.GoodsParameters.LimitslBuyptSub) / (decimal)
- Math.Pow(10, CurrentGoods.GoodsParameters.HqExchFigures);
- return (ExecutePrice - value);
- }
- return ExecutePrice;
- }
- else
- {
- //止损价 > 限价 -(卖点差-买点差-止损点差)* 最小变动单位
- //_currentGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open
- if (CurrentGoods == null || CurrentGoods.GoodsParameters == null) return 0;
- if (CurrentGoods.GoodsParameters.HqExchFigures < 20 &&
- CurrentGoods.GoodsParameters.HqExchFigures > -20)
- {
- var value = (CurrentGoods.GoodsParameters.SellptSub -
- CurrentGoods.GoodsParameters.BuyptSub -
- CurrentGoods.GoodsParameters.LimitslSellptSub) / (decimal)
- Math.Pow(10, CurrentGoods.GoodsParameters.HqExchFigures);
- return (ExecutePrice - value);
- }
- return ExecutePrice;
- }
- }
- }
- /// <summary>
- /// 格式化最大止损价
- /// </summary>
- public string DisplayMaxLoss
- {
- get { return MaxLoss.ToString(PriceFormat); }
- }
- /// <summary>
- /// 格式化最大止盈价
- /// </summary>
- public string DisplayMaxProfit
- {
- get { return MaxProfit.ToString(PriceFormat); }
- }
- /// <summary>
- /// 设置最大止盈价
- /// </summary>
- public decimal MaxProfit
- {
- get
- {
- if (IsBidDirection)
- {
- //限价 + (止盈点差* 最小变动单位)
- //止盈价 > 委托价 + (止盈点差 * 最小单位)
- if (CurrentGoods == null || CurrentGoods.GoodsParameters == null) return 0;
- if (CurrentGoods.GoodsParameters.HqExchFigures < 20 &&
- CurrentGoods.GoodsParameters.HqExchFigures > -20)
- return ExecutePrice + CurrentGoods.GoodsParameters.LimittpBuyptSub /
- (decimal)Math.Pow(10, CurrentGoods.GoodsParameters.HqExchFigures);
- return ExecutePrice;
- }
- else
- {
- //止盈价 < 委托价 - (止盈点差*最小单位)
- if (CurrentGoods == null || CurrentGoods.GoodsParameters == null) return 0;
- if (CurrentGoods.GoodsParameters.HqExchFigures < 20 &&
- CurrentGoods.GoodsParameters.HqExchFigures > -20)
- {
- var value = CurrentGoods.GoodsParameters.LimittpSellptSub /
- (decimal)Math.Pow(10, CurrentGoods.GoodsParameters.HqExchFigures);
- return ExecutePrice - value;
- }
- return ExecutePrice;
- }
- }
- }
- #endregion
- public override NewEntrustOrder BuildEntrustOrder()
- {
- var order = base.BuildEntrustOrder();
- if (CurrentOrderType == OrderType.MarketOpenOrder && IsAllowPips)
- {
- //点差只能设置整数
- order.AllowTradeSub = (int)Pips;
- }
- order.EntrustPrice = CurrentOrderType == OrderType.MarketOpenOrder
- ? QuotePrice
- : ExecutePrice;
- order.CurtQuotePrice = QuotePrice;
- // : (OrderDirection == Direction.Ask ? CurrentGoods.AskPrice : CurrentGoods.BidPrice);
- order.PriceMode = OrderPriceMode.MarketPrice;
- if (CurrentOrderType == OrderType.LimitOpenOrder)
- {
- order.SLPrice = StopLossChecked ? StopLoss : 0;
- order.SPPrice = StopProfitChecked ? StopProfit : 0;
- order.PriceMode = OrderPriceMode.LimitPrice;
- }
- //var goodsPips = UserManager.GetTraderGoodsPips(
- // UserManager.CurrentTradeAccount.TradeCode,
- // CurrentGoods.GoodsCode);
- //if (OrderDirection == Direction.Ask)
- //{
- // ////委托单点差=商品点差+商品增量点差
- // entrustOrder.PtSub = goodsPips.AskPips + CurrentGoods.GoodsParameters.SellptSub;
- // entrustOrder.CurtQuotePrice = CurrentGoods.AskPrice;
- //}
- //else
- //{
- // ////委托单点差=商品点差+商品增量点差
- // entrustOrder.PtSub = goodsPips.BidPips + CurrentGoods.GoodsParameters.BuyptSub;
- // entrustOrder.CurtQuotePrice = CurrentGoods.BidPrice;
- //}
- //if (UserManager.CurrentTradeAccount.AccountType == ClientAccountType.MemberTradeAccount )
- //{
- // order.SpecialAccount = CurrentSpecCode.TradeCode;
- //}
- return order;
- }
- public override void PostOrder(Action<OrderDetail> successAction, Action<Data.ErrorEntity> errorAction)
- {
- var entrustOrder = BuildEntrustOrder();
- _orderService.MakeMarketEntrustOrder(entrustOrder, successAction, errorAction);
- }
- }
- }
|