MakeOrderViewModel.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. using Muchinfo.MTPClient.Data.Enums;
  2. using Muchinfo.MTPClient.Data.Model;
  3. using Muchinfo.MTPClient.Data.Model.Account;
  4. using Muchinfo.MTPClient.Infrastructure.Utilities;
  5. using System;
  6. using System.Collections.Generic;
  7. //----------------------------------------------------------------
  8. //Module Name: $safeprojectname$
  9. //Purpose:
  10. //CopyRight: Muchinfo
  11. //History:
  12. //----------------------------------------------------------------
  13. //DateTime 2016/1/16 10:45:32
  14. //Author
  15. //Description Create
  16. //----------------------------------------------------------------
  17. using System.Windows;
  18. namespace Muchinfo.MTPClient.Trade.ViewModels
  19. {
  20. public class MakeOrderViewModel : TradeOrderBase
  21. {
  22. private List<SpecialMember> _specMemberCodes;
  23. /// <summary>
  24. /// 转单的特别会员
  25. /// </summary>
  26. public List<SpecialMember> SpecMemberCodes
  27. {
  28. get { return _specMemberCodes; }
  29. set { Set(() => SpecMemberCodes, ref _specMemberCodes, value); }
  30. }
  31. private SpecialMember _currentSpecCode;
  32. /// <summary>
  33. /// 当前选择 特别会员代码
  34. /// </summary>
  35. public SpecialMember CurrentSpecCode
  36. {
  37. get { return _currentSpecCode; }
  38. set
  39. {
  40. Set(() => CurrentSpecCode, ref _currentSpecCode, value);
  41. // RaisePropertyChanged(() => ProfitLossPipsSpecCodeVailed);
  42. }
  43. }
  44. private bool _relateSpecMemFlag;
  45. /// <summary>
  46. /// 是否可选择对冲的特别会员
  47. /// </summary>
  48. public bool RelateSpecMemFlag
  49. {
  50. get { return _relateSpecMemFlag; }
  51. set
  52. {
  53. Set(() => RelateSpecMemFlag, ref _relateSpecMemFlag, value);
  54. }
  55. }
  56. private bool _isInvestorAccount = true;
  57. /// <summary>
  58. /// 是否是会员交易员
  59. /// </summary>
  60. public bool IsInvestorAccount
  61. {
  62. get { return _isInvestorAccount; }
  63. set
  64. {
  65. Set(() => IsInvestorAccount, ref _isInvestorAccount, value);
  66. }
  67. }
  68. public Visibility PriceTipsVisibility { get; set; }
  69. public MakeOrderViewModel(QuoteGoods goods, OrderType orderType)
  70. : base(goods, orderType)
  71. {
  72. IsBidMarket = false;
  73. if (UserManager.CurrentTradeAccount.AccountType == eAccountType.ACCOUNTTYPE_TRADER)
  74. {
  75. IsInvestorAccount = false;
  76. this.CurrentOrderType = OrderType.MarketOpenOrder; ////会员交易员只有市价建仓
  77. }
  78. PriceTipsVisibility = Visibility.Collapsed;
  79. ////注册实时行情消息
  80. ApplicationParameter.QuotationMessenger.Register<List<QuoteGoods>>(this, MessengerTokens.ReceiveRealTimeQuote, (quoteList) =>
  81. {
  82. if (CurrentGoods != null)
  83. {
  84. QuotePrice = (IsBidDirection ? CurrentGoods.BidPrice : CurrentGoods.AskPrice);
  85. }
  86. });
  87. }
  88. #region 止盈止损
  89. /// <summary>
  90. /// 止盈跟据买卖设置符号方向
  91. /// </summary>
  92. public string ProfitChar
  93. {
  94. get
  95. {
  96. if (IsBidDirection)
  97. {
  98. // StopProfit = (decimal)(MaxProfit - (decimal)PriceMinUnit);
  99. // StopLoss = (decimal)(MaxLoss + (decimal)PriceMinUnit);
  100. return "<";
  101. }
  102. else
  103. {
  104. return ">";
  105. // StopProfit = (decimal)(MaxProfit + (decimal)PriceMinUnit);
  106. // StopLoss = (decimal)(MaxLoss - (decimal)PriceMinUnit);
  107. }
  108. }
  109. }
  110. /// <summary>
  111. /// 止损跟据买卖设置符号方向
  112. /// </summary>
  113. public string LossChar
  114. {
  115. get
  116. {
  117. if (IsBidDirection)
  118. {
  119. return ">";
  120. }
  121. else
  122. {
  123. return "<";
  124. }
  125. }
  126. }
  127. //private decimal _maxLoss;
  128. //private decimal _maxProfit;
  129. private decimal _stopLoss;
  130. /// <summary>
  131. /// StopLossChecked
  132. /// </summary>
  133. private bool _stopLossChecked;
  134. private decimal _stopProfit;
  135. /// <summary>
  136. /// StopProfitChecked
  137. /// </summary>
  138. private bool _stopProfitChecked;
  139. /// <summary>
  140. /// Sets and gets the StopLoss property.
  141. /// Changes to that property's value raise the PropertyChanged event.
  142. /// </summary>
  143. public decimal StopLoss
  144. {
  145. get
  146. {
  147. return _stopLoss;
  148. }
  149. set
  150. {
  151. Set(() => StopLoss, ref _stopLoss, value);
  152. // RaisePropertyChanged(() => ProfitLossPipsSpecCodeVailed);
  153. }
  154. }
  155. /// <summary>
  156. /// Sets and gets the StopLossChecked property.
  157. /// Changes to that property's value raise the PropertyChanged event.
  158. /// </summary>
  159. public bool StopLossChecked
  160. {
  161. get
  162. {
  163. return _stopLossChecked;
  164. }
  165. set
  166. {
  167. Set(() => StopLossChecked, ref _stopLossChecked, value);
  168. // StopLoss = _stopLossChecked ? ExecutePrice : 0;
  169. //StopLoss = _stopProfitChecked ? 0 : 0;
  170. if (IsBidDirection)
  171. {
  172. StopLoss = (decimal)(MaxLoss - MinUint);
  173. }
  174. else
  175. {
  176. StopLoss = (decimal)(MaxLoss + MinUint);
  177. }
  178. //StopLoss = _stopProfitChecked ? 0 : 0;
  179. }
  180. }
  181. /// <summary>
  182. /// Sets and gets the StopProfit property.
  183. /// Changes to that property's value raise the PropertyChanged event.
  184. /// </summary>
  185. public decimal StopProfit
  186. {
  187. get
  188. {
  189. return _stopProfit;
  190. }
  191. set
  192. {
  193. Set(() => StopProfit, ref _stopProfit, value);
  194. }
  195. }
  196. /// <summary>
  197. /// Sets and gets the StopProfitChecked property.
  198. /// Changes to that property's value raise the PropertyChanged event.
  199. /// </summary>
  200. public bool StopProfitChecked
  201. {
  202. get
  203. {
  204. return _stopProfitChecked;
  205. }
  206. set
  207. {
  208. Set(() => StopProfitChecked, ref _stopProfitChecked, value);
  209. // StopProfit = _stopProfitChecked ? ExecutePrice : 0;
  210. if (IsBidDirection)
  211. {
  212. StopProfit = (decimal)(MaxProfit + MinUint);
  213. }
  214. else
  215. {
  216. StopProfit = (decimal)(MaxProfit - MinUint);
  217. }
  218. }
  219. }
  220. public decimal MinUint
  221. {
  222. get
  223. {
  224. int temp = 0;
  225. if (this.CurrentGoods != null && this.CurrentGoods.GoodsParameters != null)
  226. {
  227. temp = CurrentGoods.GoodsParameters.HqExchFigures;
  228. }
  229. return Convert.ToDecimal(1 / Math.Pow(10, temp));
  230. }
  231. }
  232. /// 设置最大止损价
  233. /// </summary>
  234. public decimal MaxLoss
  235. {
  236. get
  237. {
  238. if (IsBidDirection)
  239. {
  240. //止损价 < 限价-(买点差-卖点差+止损点差) * 最小变动单位
  241. // _currentGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open
  242. if (CurrentGoods == null || CurrentGoods.GoodsParameters == null) return 0;
  243. if (CurrentGoods.GoodsParameters.HqExchFigures < 20 &&
  244. CurrentGoods.GoodsParameters.HqExchFigures > -20)
  245. {
  246. var value = (CurrentGoods.GoodsParameters.BuyptSub -
  247. CurrentGoods.GoodsParameters.SellptSub +
  248. CurrentGoods.GoodsParameters.LimitslBuyptSub) / (decimal)
  249. Math.Pow(10, CurrentGoods.GoodsParameters.HqExchFigures);
  250. return (ExecutePrice - value);
  251. }
  252. return ExecutePrice;
  253. }
  254. else
  255. {
  256. //止损价 > 限价 -(卖点差-买点差-止损点差)* 最小变动单位
  257. //_currentGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open
  258. if (CurrentGoods == null || CurrentGoods.GoodsParameters == null) return 0;
  259. if (CurrentGoods.GoodsParameters.HqExchFigures < 20 &&
  260. CurrentGoods.GoodsParameters.HqExchFigures > -20)
  261. {
  262. var value = (CurrentGoods.GoodsParameters.SellptSub -
  263. CurrentGoods.GoodsParameters.BuyptSub -
  264. CurrentGoods.GoodsParameters.LimitslSellptSub) / (decimal)
  265. Math.Pow(10, CurrentGoods.GoodsParameters.HqExchFigures);
  266. return (ExecutePrice - value);
  267. }
  268. return ExecutePrice;
  269. }
  270. }
  271. }
  272. /// <summary>
  273. /// 格式化最大止损价
  274. /// </summary>
  275. public string DisplayMaxLoss
  276. {
  277. get { return MaxLoss.ToString(PriceFormat); }
  278. }
  279. /// <summary>
  280. /// 格式化最大止盈价
  281. /// </summary>
  282. public string DisplayMaxProfit
  283. {
  284. get { return MaxProfit.ToString(PriceFormat); }
  285. }
  286. /// <summary>
  287. /// 设置最大止盈价
  288. /// </summary>
  289. public decimal MaxProfit
  290. {
  291. get
  292. {
  293. if (IsBidDirection)
  294. {
  295. //限价 + (止盈点差* 最小变动单位)
  296. //止盈价 > 委托价 + (止盈点差 * 最小单位)
  297. if (CurrentGoods == null || CurrentGoods.GoodsParameters == null) return 0;
  298. if (CurrentGoods.GoodsParameters.HqExchFigures < 20 &&
  299. CurrentGoods.GoodsParameters.HqExchFigures > -20)
  300. return ExecutePrice + CurrentGoods.GoodsParameters.LimittpBuyptSub /
  301. (decimal)Math.Pow(10, CurrentGoods.GoodsParameters.HqExchFigures);
  302. return ExecutePrice;
  303. }
  304. else
  305. {
  306. //止盈价 < 委托价 - (止盈点差*最小单位)
  307. if (CurrentGoods == null || CurrentGoods.GoodsParameters == null) return 0;
  308. if (CurrentGoods.GoodsParameters.HqExchFigures < 20 &&
  309. CurrentGoods.GoodsParameters.HqExchFigures > -20)
  310. {
  311. var value = CurrentGoods.GoodsParameters.LimittpSellptSub /
  312. (decimal)Math.Pow(10, CurrentGoods.GoodsParameters.HqExchFigures);
  313. return ExecutePrice - value;
  314. }
  315. return ExecutePrice;
  316. }
  317. }
  318. }
  319. #endregion
  320. public override NewEntrustOrder BuildEntrustOrder()
  321. {
  322. var order = base.BuildEntrustOrder();
  323. if (CurrentOrderType == OrderType.MarketOpenOrder && IsAllowPips)
  324. {
  325. //点差只能设置整数
  326. order.AllowTradeSub = (int)Pips;
  327. }
  328. order.EntrustPrice = CurrentOrderType == OrderType.MarketOpenOrder
  329. ? QuotePrice
  330. : ExecutePrice;
  331. order.CurtQuotePrice = QuotePrice;
  332. // : (OrderDirection == Direction.Ask ? CurrentGoods.AskPrice : CurrentGoods.BidPrice);
  333. order.PriceMode = OrderPriceMode.MarketPrice;
  334. if (CurrentOrderType == OrderType.LimitOpenOrder)
  335. {
  336. order.SLPrice = StopLossChecked ? StopLoss : 0;
  337. order.SPPrice = StopProfitChecked ? StopProfit : 0;
  338. order.PriceMode = OrderPriceMode.LimitPrice;
  339. }
  340. //var goodsPips = UserManager.GetTraderGoodsPips(
  341. // UserManager.CurrentTradeAccount.TradeCode,
  342. // CurrentGoods.GoodsCode);
  343. //if (OrderDirection == Direction.Ask)
  344. //{
  345. // ////委托单点差=商品点差+商品增量点差
  346. // entrustOrder.PtSub = goodsPips.AskPips + CurrentGoods.GoodsParameters.SellptSub;
  347. // entrustOrder.CurtQuotePrice = CurrentGoods.AskPrice;
  348. //}
  349. //else
  350. //{
  351. // ////委托单点差=商品点差+商品增量点差
  352. // entrustOrder.PtSub = goodsPips.BidPips + CurrentGoods.GoodsParameters.BuyptSub;
  353. // entrustOrder.CurtQuotePrice = CurrentGoods.BidPrice;
  354. //}
  355. //if (UserManager.CurrentTradeAccount.AccountType == ClientAccountType.MemberTradeAccount )
  356. //{
  357. // order.SpecialAccount = CurrentSpecCode.TradeCode;
  358. //}
  359. return order;
  360. }
  361. public override void PostOrder(Action<OrderDetail> successAction, Action<Data.ErrorEntity> errorAction)
  362. {
  363. var entrustOrder = BuildEntrustOrder();
  364. _orderService.MakeMarketEntrustOrder(entrustOrder, successAction, errorAction);
  365. }
  366. }
  367. }