BidOpenOrderViewModel.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. //----------------------------------------------------------------
  7. //Module Name: $safeprojectname$
  8. //Purpose:
  9. //CopyRight: Muchinfo
  10. //History:
  11. //----------------------------------------------------------------
  12. //DateTime 2016/1/16 10:16:37
  13. //Author
  14. //Description Create
  15. //----------------------------------------------------------------
  16. using System.Windows;
  17. using Muchinfo.MTPClient.Data.Enums;
  18. using Muchinfo.MTPClient.Data.Model;
  19. using Muchinfo.MTPClient.Data.Model.Account;
  20. using Muchinfo.MTPClient.Infrastructure.Utilities;
  21. using Muchinfo.MTPClient.Resources;
  22. namespace Muchinfo.MTPClient.Trade.ViewModels
  23. {
  24. public class BidOpenOrderViewModel : TradeOrderBase
  25. {
  26. private OrderMode _orderMode = OrderMode.STD; //设置成交属性
  27. public BidOpenOrderViewModel(QuoteGoods goods,OrderType orderType):base(goods,orderType)
  28. {
  29. IsBidMarket = true;
  30. AskCommissions = SortCommissions(false, goods.AskList, goods.FormatPrice);
  31. BidCommissions = SortCommissions(true, goods.BidList, goods.FormatPrice);
  32. }
  33. /// <summary>
  34. /// 获取和设置OrderModes
  35. /// </summary>
  36. public Dictionary<OrderMode, string> OrderModes
  37. {
  38. get
  39. {
  40. var types = new Dictionary<OrderMode, string>
  41. {
  42. {OrderMode.STD, Muchinfo.MTPClient.Resources.Muchinfo_Resource.Trade_No},
  43. {OrderMode.FAK, "FAK"},
  44. {OrderMode.FOK,"FOK"}
  45. };
  46. return types;
  47. }
  48. }
  49. /// <summary>
  50. /// 设置成交属性
  51. /// </summary>
  52. public OrderMode OrderMode
  53. {
  54. get
  55. {
  56. return _orderMode;
  57. }
  58. set
  59. {
  60. Set(() => OrderMode, ref _orderMode, value);
  61. }
  62. }
  63. /// <summary>
  64. /// 跌停
  65. /// </summary>
  66. public decimal LowPrice
  67. {
  68. get
  69. {
  70. if (this.CurrentGoods != null && this.CurrentGoods.GoodsParameters != null)
  71. {
  72. FallPriceVisibility = Visibility.Visible;
  73. return this.CurrentGoods.GoodsParameters.FallsPrice;
  74. // return this.CurrentGoods.GoodsParameters.RaisesPrice;
  75. }
  76. FallPriceVisibility = Visibility.Collapsed;
  77. return 0m;
  78. }
  79. }
  80. /// <summary>
  81. /// 涨停
  82. /// </summary>
  83. public decimal UpPrice
  84. {
  85. get
  86. {
  87. if (this.CurrentGoods != null && this.CurrentGoods.GoodsParameters != null)
  88. {
  89. UpPriceVisibility = Visibility.Visible;
  90. return this.CurrentGoods.GoodsParameters.RaisesPrice;
  91. // return this.CurrentGoods.GoodsParameters.RaisesPrice;
  92. }
  93. UpPriceVisibility = Visibility.Collapsed;
  94. return 0m;
  95. }
  96. }
  97. private Visibility _upPriceVisibility;
  98. /// <summary>
  99. /// 是否显示涨停价提示
  100. /// </summary>
  101. public Visibility UpPriceVisibility
  102. {
  103. get { return _upPriceVisibility; }
  104. set { Set(() => UpPriceVisibility, ref _upPriceVisibility, value); }
  105. }
  106. private Visibility _fallPriceVisibility;
  107. /// <summary>
  108. /// 是否显示跌停价
  109. /// </summary>
  110. public Visibility FallPriceVisibility
  111. {
  112. get { return _fallPriceVisibility; }
  113. set { Set(() => FallPriceVisibility, ref _fallPriceVisibility, value); }
  114. }
  115. /// <summary>
  116. /// 格式化涨停
  117. /// </summary>
  118. public string UpPriceDisplay
  119. {
  120. get
  121. {
  122. return UpPrice.ToString(PriceFormat);
  123. }
  124. }
  125. /// <summary>
  126. /// 格式化跌停
  127. /// </summary>
  128. public string LowPriceDisplay
  129. {
  130. get
  131. {
  132. return LowPrice.ToString(PriceFormat);
  133. }
  134. }
  135. private List<Commission> _bidCommissions;
  136. /// <summary>
  137. /// 显示买入档
  138. /// </summary>
  139. public List<Commission> BidCommissions
  140. {
  141. get { return _bidCommissions; }
  142. set { Set(() => BidCommissions, ref _bidCommissions, value); }
  143. }
  144. private List<Commission> _askCommissions;
  145. /// <summary>
  146. /// 显示卖出档
  147. /// </summary>
  148. public List<Commission> AskCommissions
  149. {
  150. get { return _askCommissions; }
  151. set { Set(() => AskCommissions, ref _askCommissions, value); }
  152. }
  153. /// <summary>
  154. /// 设置买卖档
  155. /// </summary>
  156. /// <param name="bid">if set to <c>true</c> [bid].</param>
  157. /// <param name="commissions">The commissions.</param>
  158. /// <returns>List{Commission}.</returns>
  159. private List<Commission> SortCommissions(bool bid, Commission[] commissions, string formatStr)
  160. {
  161. var commissionLsit = new List<Commission>();
  162. int index = 1;
  163. foreach (var commission in commissions)
  164. {
  165. commission.Index = index;
  166. commission.FormatString = formatStr;
  167. commissionLsit.Add(commission);
  168. index++;
  169. }
  170. if (!bid)
  171. {
  172. commissionLsit = commissionLsit.OrderByDescending((item) => item.Index).ToList();
  173. }
  174. return commissionLsit;
  175. }
  176. #region 竞价策略单
  177. private decimal _slTriggerPrice;
  178. private bool _spStrategyEnable;
  179. /// <summary>
  180. /// 是否启用止盈策略
  181. /// </summary>
  182. public bool SpStrategyEnable
  183. {
  184. get
  185. {
  186. return _spStrategyEnable;
  187. }
  188. set
  189. {
  190. Set(() => SpStrategyEnable, ref _spStrategyEnable, value);
  191. }
  192. }
  193. private bool _slStrategyEnable;
  194. /// <summary>
  195. /// 是否使用止损策略
  196. /// </summary>
  197. public bool SlStrategyEnable
  198. {
  199. get
  200. {
  201. return _slStrategyEnable;
  202. }
  203. set
  204. {
  205. Set(() => SlStrategyEnable, ref _slStrategyEnable, value);
  206. }
  207. }
  208. private bool _spEnable = false;
  209. /// <summary>
  210. /// 是否启用止盈
  211. /// </summary>
  212. public bool SpEnable
  213. {
  214. get { return _spEnable; }
  215. set { Set(() => SpEnable, ref _spEnable, value); }
  216. }
  217. private bool _slEnable = false;
  218. /// <summary>
  219. /// 是否启用止损
  220. /// </summary>
  221. public bool SlEnable
  222. {
  223. get { return _slEnable; }
  224. set { Set(() => SlEnable, ref _slEnable, value); }
  225. }
  226. /// <summary>
  227. /// 止损触发价
  228. /// </summary>
  229. public decimal SlTriggerPrice
  230. {
  231. get { return _slTriggerPrice; }
  232. set { Set(() => SlTriggerPrice, ref _slTriggerPrice, value); }
  233. }
  234. private decimal _sPTriggerPrice;
  235. /// <summary>
  236. /// 止盈触发价
  237. /// </summary>
  238. public decimal SPTriggerPrice
  239. {
  240. get
  241. {
  242. return _sPTriggerPrice;
  243. }
  244. set
  245. {
  246. Set(() => SPTriggerPrice, ref _sPTriggerPrice, value);
  247. }
  248. }
  249. private StrategyType _strategyType = StrategyType.None;
  250. /// <summary>
  251. /// 策略类型
  252. /// </summary>
  253. public StrategyType StrategyType
  254. {
  255. get
  256. {
  257. return _strategyType;
  258. }
  259. set
  260. {
  261. Set(() => StrategyType, ref _strategyType, value);
  262. switch (value)
  263. {
  264. case StrategyType.None:
  265. case StrategyType.ReverseOpen:
  266. {
  267. SpStrategyEnable = false;
  268. SlStrategyEnable = false;
  269. }
  270. break;
  271. case StrategyType.MovingStopLoss:
  272. {
  273. SpStrategyEnable = false;
  274. SlStrategyEnable = true;
  275. }
  276. break;
  277. case StrategyType.EntrustStopPL:
  278. case StrategyType.MarketStopPL:
  279. {
  280. SpStrategyEnable = true;
  281. SlStrategyEnable = true;
  282. }
  283. break;
  284. }
  285. }
  286. }
  287. public Dictionary<StrategyType, string> StrategyTypes
  288. {
  289. get
  290. {
  291. var types = new Dictionary<StrategyType, string>
  292. {
  293. {StrategyType.None, Muchinfo.MTPClient.Resources.Muchinfo_Resource.Trade_No},
  294. {StrategyType.MovingStopLoss, Muchinfo.MTPClient.Resources.Muchinfo_Resource.Trade_MobileStop},
  295. {StrategyType.EntrustStopPL,Muchinfo.MTPClient.Resources.Muchinfo_Resource.Trade_CurrentPrice_Stop_Profit},
  296. {StrategyType.MarketStopPL,Muchinfo.MTPClient.Resources.Muchinfo_Resource.Trade_MarkettPrice_Stop_Profit}
  297. };
  298. return types;
  299. }
  300. }
  301. #endregion
  302. public override NewEntrustOrder BuildEntrustOrder()
  303. {
  304. var order= base.BuildEntrustOrder();
  305. if ( CurrentOrderType == OrderType.BidMarketOpen && IsAllowPips)
  306. {
  307. //点差只能设置整数
  308. order.AllowTradeSub = (int)Pips;
  309. }
  310. order.EntrustPrice = ( CurrentOrderType == OrderType.BidMarketOpen)
  311. ? QuotePrice
  312. : ExecutePrice;
  313. // : (OrderDirection == Direction.Ask ? CurrentGoods.AskPrice : CurrentGoods.BidPrice);
  314. order.PriceMode = OrderPriceMode.MarketPrice;
  315. if ( CurrentOrderType == OrderType.BidLimitOpen) ////
  316. {
  317. //todo:竞价策略单
  318. ////order.SLPrice = StopLossChecked && SlEnable ? StopLoss : 0;
  319. ////order.SPPrice = StopProfitChecked && SpEnable ? StopProfit : 0;
  320. ////order.SlTriggerPrice = StopLossChecked ? SlTriggerPrice : 0;
  321. ////order.SpTriggerPrice = StopProfitChecked ? SPTriggerPrice : 0;
  322. order.PriceMode = OrderPriceMode.LimitPrice;
  323. }
  324. order.OrderMode = OrderMode;
  325. // order.TradeCloseMode = TradeCloseMode.IsVailed;
  326. return order;
  327. }
  328. /// <summary>
  329. /// 获取和设置the order types
  330. /// </summary>
  331. public override Dictionary<OrderType, string> OrderTypes
  332. {
  333. get
  334. {
  335. var types = new Dictionary<OrderType, string>
  336. {
  337. {OrderType.BidMarketOpen, Muchinfo_Resource.OrderType_Enum_MarketOpen},
  338. {OrderType.BidLimitOpen, Muchinfo_Resource.OrderType_Enum_LimitOpen}
  339. };
  340. return types;
  341. }
  342. }
  343. protected override void SetQuotePrice()
  344. {
  345. if (CurrentGoods != null)
  346. {
  347. ExecutePrice = IsBidDirection ? CurrentGoods.AskPrice : CurrentGoods.BidPrice;
  348. QuotePrice = ExecutePrice;
  349. }
  350. }
  351. public override void PostOrder(Action<OrderDetail> successAction, Action<Data.ErrorEntity> errorAction)
  352. {
  353. var entrustOrder = BuildEntrustOrder();
  354. _orderService.BidMarketEntrustOrder(entrustOrder, successAction, errorAction);
  355. }
  356. }
  357. }