TradeBaseViewModel.cs 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. //----------------------------------------------------------------
  6. //Module Name: $safeprojectname$
  7. //Purpose:
  8. //CopyRight: Muchinfo
  9. //History:
  10. //----------------------------------------------------------------
  11. //DateTime 2016/7/22 16:04:40
  12. //Author
  13. //Description Create
  14. //----------------------------------------------------------------
  15. using System.Windows;
  16. using System.Windows.Controls;
  17. using System.Windows.Input.StylusPlugIns;
  18. using System.Windows.Media;
  19. using GalaSoft.MvvmLight;
  20. using GalaSoft.MvvmLight.Command;
  21. using GalaSoft.MvvmLight.Ioc;
  22. using Muchinfo.MTPClient.Data;
  23. using Muchinfo.MTPClient.Data.Enums;
  24. using Muchinfo.MTPClient.Data.Helper;
  25. using Muchinfo.MTPClient.Data.Model;
  26. using Muchinfo.MTPClient.Data.Model.Account;
  27. using Muchinfo.MTPClient.Data.Model.GoodRules;
  28. using Muchinfo.MTPClient.Infrastructure.Cache;
  29. using Muchinfo.MTPClient.Infrastructure.Utilities;
  30. using Muchinfo.MTPClient.IService;
  31. using Muchinfo.MTPClient.Infrastructure.Helpers;
  32. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  33. using Muchinfo.MTPClient.Resources;
  34. namespace Muchinfo.MTPClient.Trade.ViewModels
  35. {
  36. public class TradeBaseViewModel : ViewModelBase
  37. {
  38. protected const int defaut_minLot = 1;
  39. protected const int defaut_maxLot = 88;
  40. protected IOrderService _orderService;
  41. protected IGoodsService _goodsService;
  42. private bool _isfristInit; //是否第一次初始化
  43. protected QuoteGoods _currentGoods; //当前下单的商品
  44. private Direction _direction; ////买卖方向
  45. private OpenCloseMode _openCloseMode = OpenCloseMode.BUILDTYPE_OPEN; ////建仓平方式
  46. private eListingSelectType _listingSelectModel = eListingSelectType.LISTINGSELECTTYPE_LISTING; ////挂牌点选类型
  47. private eDelistingType _delistingModel = eDelistingType.DELISTINGTYPE_PRICE;//摘牌类型
  48. protected GoodsOrderMode _goodsOrderMode = GoodsOrderMode.Goods; ///平仓时按单还是商品
  49. private bool _isBusy;
  50. private ExpirationType _currentExpirationType = ExpirationType.Today; //有效期
  51. private OrderMethods _orderFlag; ////下单方式【正常单、预埋单】
  52. private OrderModel _orderModel = OrderModel.Normal;
  53. private string _channelBuyPrice = "";
  54. private string _channelSellPrice = "";
  55. private ICommonQueryService _commonQueryService;
  56. private List<SPSLOrderModel> _spslOrders;
  57. public virtual bool ShowOpenCloseOrder
  58. {
  59. get { return ApplicationParameter.ShowOpenCloseOrder; }
  60. }
  61. private void Init()
  62. {
  63. if (_commonQueryService == null)
  64. {
  65. _commonQueryService = SimpleIoc.Default.GetInstance<ICommonQueryService>();
  66. }
  67. }
  68. public TradeBaseViewModel(QuoteGoods goods, Direction direction)
  69. {
  70. _currentGoods = goods;
  71. _direction = direction;
  72. LockEditTextMaxMin();
  73. _orderService = SimpleIoc.Default.GetInstance<IOrderService>();
  74. _goodsService = SimpleIoc.Default.GetInstance<IGoodsService>();
  75. TriggerListingOrder();
  76. GetHoldDetails();
  77. SetInitVaules();
  78. Init();
  79. OpenCloseMode = (OpenCloseMode)ApplicationParameter.DefaultOpenMode;
  80. //所有商品默认为限价
  81. //PriceMode = ePriceMode.PRICEMODE_LIMIT;
  82. setDefaultPriceMode();
  83. //初始化多资金账号信息
  84. CurrentUserFundsList = CacheManager.CacheTAAcountList.Select(x => x.FundsAccounts.AccountId.ToString()).ToList();
  85. //UserManager.CurrentTradeAccount.FundsAccountId = 0;
  86. //单据成交时需重新计算委托数据
  87. MessengerHelper.DefaultRegister<TradeAccount>(this, MessengerTokens.HolderRefresh, (e) =>
  88. {
  89. GetHoldDetails();
  90. SetMinMaxQtyVaule();
  91. });
  92. ////资金变化计算数量
  93. MessengerHelper.DefaultRegister<string>(this, MessengerTokens.MoneyNoticeToken, (e) =>
  94. {
  95. GetHoldDetails();
  96. SetMinMaxQtyVaule();
  97. });
  98. MessengerHelper.DefaultRegister<string>(this, MessengerTokens.OrderChangeToRefeshTrade, (e) =>
  99. {
  100. OpenCloseMode = (OpenCloseMode) ApplicationParameter.DefaultOpenMode;
  101. });
  102. }
  103. /// <summary>
  104. /// 平仓ty
  105. /// </summary>
  106. /// <param name="goods"></param>
  107. /// <param name="orderBase"></param>
  108. public TradeBaseViewModel(QuoteGoods goods, OrderBase orderBase)
  109. : this(goods, orderBase.Direction == Direction.Ask ? Direction.Bid : Direction.Ask)
  110. {
  111. //初始化多资金账号信息
  112. CurrentUserFundsList = CacheManager.CacheTAAcountList.Select(x => x.FundsAccounts.AccountId.ToString()).ToList();
  113. RaisePropertyChanged(() => Direction);
  114. Init();
  115. //TriggerListingOrder();
  116. }
  117. /// <summary>
  118. /// 触发挂牌下单属性
  119. /// </summary>
  120. private void TriggerListingOrder()
  121. {
  122. //挂牌下单
  123. if (CacheManager.FromType == eOrderFormType.Listting)
  124. {
  125. FormType = eOrderFormType.Listting;
  126. }
  127. else
  128. {
  129. FormType = eOrderFormType.Commom;
  130. }
  131. }
  132. #region 是否忙
  133. /// <summary>
  134. /// 是否忙
  135. /// </summary>
  136. public bool IsBusy
  137. {
  138. get { return _isBusy; }
  139. set { Set(() => IsBusy, ref _isBusy, value); }
  140. }
  141. #endregion
  142. #region 是否是复杂下单
  143. private bool _isComplex;
  144. /// <summary>
  145. /// 是否是复杂下单
  146. /// </summary>
  147. public bool IsComplex
  148. {
  149. get { return _isComplex; }
  150. set { Set(() => IsComplex, ref _isComplex, value); }
  151. }
  152. #endregion
  153. #region 冻结头寸数量
  154. /// <summary>
  155. /// 冻结头寸数量
  156. /// </summary>
  157. private decimal _positionFzQty;
  158. /// <summary>
  159. /// 冻结头寸数量
  160. /// </summary>
  161. public decimal PositionFzQty
  162. {
  163. get { return _positionFzQty; }
  164. set { _positionFzQty = value; }
  165. }
  166. #endregion
  167. #region 持仓汇总
  168. /// <summary>
  169. /// 持仓汇总
  170. /// </summary>
  171. private decimal _totalHoldDetails;
  172. /// <summary>
  173. /// 持仓汇总
  174. /// </summary>
  175. /// <value>The total hold details.</value>
  176. public decimal TotalHoldDetails
  177. {
  178. get
  179. {
  180. return _totalHoldDetails;
  181. }
  182. set
  183. {
  184. Set(() => TotalHoldDetails, ref _totalHoldDetails, value);
  185. }
  186. }
  187. #endregion
  188. #region 可用持仓数量
  189. private decimal _availHoldQty = decimal.Zero;
  190. /// <summary>
  191. /// 可用持仓数量
  192. /// </summary>
  193. public decimal AvailHoldQty
  194. {
  195. get
  196. {
  197. return _availHoldQty;
  198. }
  199. set
  200. {
  201. Set(() => AvailHoldQty, ref _availHoldQty, value);
  202. }
  203. }
  204. #endregion
  205. #region 【10倍/20倍/30倍】保证金比例
  206. private MarginRate _marginRate = MarginRate.Margin10;
  207. /// <summary>
  208. /// 保证金比例
  209. /// </summary>
  210. public MarginRate MarginRate
  211. {
  212. get { return _marginRate; }
  213. set { Set(() => MarginRate, ref _marginRate, value); }
  214. }
  215. #endregion
  216. #region 【大于/小于/大于或等于/小于或等于】触发类型绑定
  217. private Dictionary<eTriggerType, string> _dicTriggerType;
  218. /// <summary>
  219. /// 触发类型绑定
  220. /// </summary>
  221. public Dictionary<eTriggerType, string> DicTriggerType
  222. {
  223. get
  224. {
  225. _dicTriggerType = new Dictionary<eTriggerType, string>();
  226. _dicTriggerType.Add(eTriggerType.TRIGGERTYPE_GREATER_OR_EQUAL, TriggerPriceType.GreaterThanOrEqual.Discription());
  227. _dicTriggerType.Add(eTriggerType.TRIGGERTYPE_LESS_OR_EQUAL, TriggerPriceType.LessThanOrEqual.Discription());
  228. _dicTriggerType.Add(eTriggerType.TRIGGERTYPE_LESS, TriggerPriceType.LessThan.Discription());
  229. _dicTriggerType.Add(eTriggerType.TRIGGERTYPE_GREATER, TriggerPriceType.GreaterThan.Discription());
  230. return _dicTriggerType;
  231. }
  232. }
  233. #endregion
  234. #region 【买人/卖出】买卖方向
  235. /// <summary>
  236. /// 买卖方向
  237. /// </summary>
  238. public Direction Direction
  239. {
  240. get
  241. {
  242. return _direction;
  243. }
  244. set
  245. {
  246. if (value == Direction.unSet)
  247. {
  248. return;
  249. }
  250. Set(() => Direction, ref _direction, value);
  251. CheckedVisibleEnable();
  252. SetMinMaxQtyVaule(); //设置数量
  253. GetHoldDetails();
  254. DefautEntrustPrice(this.CurrentChannelPriceMode != ChannelPriceMode.LimitPrice);//设置默认值
  255. SetSellCloseBuyOpen();
  256. }
  257. }
  258. #endregion
  259. #region 是否支持预埋单选项
  260. //private bool _isEnableByPrePostOrder = false;
  261. ///// <summary>
  262. ///// Sets and gets the IsEnableByPrePostOrder property.
  263. ///// Changes to that property's value raise the PropertyChanged event.
  264. ///// </summary>
  265. //public bool IsEnableByPrePostOrder
  266. //{
  267. // get
  268. // {
  269. // return _isEnableByPrePostOrder;
  270. // }
  271. // set
  272. // {
  273. // Set(() => IsEnableByPrePostOrder, ref _isEnableByPrePostOrder, value);
  274. // }
  275. //}
  276. public virtual bool IsEnableByPrePostOrder
  277. {
  278. get { return true; }
  279. }
  280. #endregion
  281. #region 【正常单/预埋单】下单方式
  282. /// <summary>
  283. /// 下单方式
  284. /// </summary>
  285. public OrderMethods OrderFlag
  286. {
  287. get
  288. {
  289. return _orderFlag;
  290. }
  291. set
  292. {
  293. if (value == OrderMethods.unSelect)
  294. {
  295. return;
  296. }
  297. Set(() => OrderFlag, ref _orderFlag, value);
  298. }
  299. }
  300. #endregion
  301. #region 正常下\SPSL下单
  302. /// <summary>
  303. /// Gets or sets the order model.
  304. /// </summary>
  305. /// <value>The order model.</value>
  306. public OrderModel OrderModel
  307. {
  308. get
  309. {
  310. return _orderModel;
  311. }
  312. set
  313. {
  314. Set(() => OrderModel, ref _orderModel, value);
  315. RaisePropertyChanged(() => IsSPSLModel);
  316. RaisePropertyChanged(() => IsNormalModel);
  317. }
  318. }
  319. #endregion
  320. //===============挂牌下单属性↓=======================
  321. #region 挂牌点选类型
  322. /// <summary>
  323. /// 挂牌点选类型
  324. /// </summary>
  325. public eListingSelectType ListingSelectModel
  326. {
  327. get
  328. {
  329. return _listingSelectModel;
  330. }
  331. set
  332. {
  333. Set(() => ListingSelectModel, ref _listingSelectModel, value);
  334. RaisePropertyChanged(() => IsVisibility_DelistingModel);
  335. RaisePropertyChanged(() => IsExecutePriceVbs);
  336. RaisePropertyChanged(() => IsVisibility_ListingInfo);
  337. RaisePropertyChanged(() => IsExecutePrice);
  338. //RaisePropertyChanged(() => Lot);
  339. RaisePropertyChanged(() => IsEnableChangeLot);
  340. RaisePropertyChanged(() => IsVisibility_ListingSelect);
  341. ResetDelistingModel();
  342. }
  343. }
  344. #endregion
  345. /// <summary>
  346. /// 重置摘牌类型
  347. /// </summary>
  348. public void ResetDelistingModel()
  349. {
  350. if (ListingSelectModel != eListingSelectType.LISTINGSELECTTYPE_LISTING)
  351. {
  352. DelistingModel = eDelistingType.DELISTINGTYPE_PRICE;
  353. RaisePropertyChanged(() => DelistingModel);
  354. }
  355. }
  356. #region 摘牌类型
  357. /// <summary>
  358. /// 摘牌类型
  359. /// </summary>
  360. public eDelistingType DelistingModel
  361. {
  362. get
  363. {
  364. if (_delistingModel != eDelistingType.DELISTINGTYPE_SELECTED)
  365. {
  366. _delistingModel = eDelistingType.DELISTINGTYPE_PRICE;
  367. }
  368. return _delistingModel;
  369. }
  370. set
  371. {
  372. Set(() => DelistingModel, ref _delistingModel, value);
  373. RaisePropertyChanged(() => IsExecutePriceVbs);
  374. RaisePropertyChanged(() => IsVisibility_ListingInfo);
  375. RaisePropertyChanged(() => IsExecutePrice);
  376. RaisePropertyChanged(() => IsEnableChangeLot);
  377. // RaisePropertyChanged(() => Lot);
  378. }
  379. }
  380. #endregion
  381. #region 下单类型。普通下单/摘牌下单
  382. private eOrderFormType _formType = eOrderFormType.Commom;
  383. /// <summary>
  384. /// 下单类型。普通下单/摘牌下单
  385. /// </summary>
  386. public eOrderFormType FormType
  387. {
  388. get
  389. {
  390. return _formType;
  391. }
  392. set
  393. {
  394. Set(() => FormType, ref _formType, value);
  395. IsVisibility_Listing = Visibility.Collapsed;
  396. if (CurrentGoods.TradeMode == eTradeMode.TRADEMODE_LISTING_SELECT)
  397. {
  398. IsVisibility_Listing = Visibility.Visible;
  399. }
  400. else
  401. {
  402. IsVisibility_Listing = Visibility.Collapsed;
  403. }
  404. }
  405. }
  406. #endregion
  407. #region 摘牌下单是否可见
  408. private Visibility _isVisibility_Listing = Visibility.Collapsed;
  409. /// <summary>
  410. /// 摘牌下单是否可见
  411. /// </summary>
  412. public Visibility IsVisibility_Listing
  413. {
  414. get
  415. {
  416. return _isVisibility_Listing;
  417. }
  418. set
  419. {
  420. Set(() => IsVisibility_Listing, ref _isVisibility_Listing, value);
  421. }
  422. }
  423. #endregion
  424. #region 摘牌委托单号=》来自点选数据
  425. private string _orderIdListing = CacheManager.OrderId_Listing.ToString();
  426. /// <summary>
  427. /// 摘牌委托单号=》来自点选数据
  428. /// </summary>
  429. public string OrderId_Listing
  430. {
  431. get
  432. {
  433. return _orderIdListing;
  434. }
  435. set
  436. {
  437. Set(() => OrderId_Listing, ref _orderIdListing, value);
  438. }
  439. }
  440. #endregion
  441. #region 摘牌委托价格=》来自点选数据
  442. private string _orderPrice_Listing = CacheManager.OrderPrice_Listing.ToString();
  443. /// <summary>
  444. /// 摘牌委托价格=》来自点选数据
  445. /// </summary>
  446. public string OrderPrice_Listing
  447. {
  448. get
  449. {
  450. return _orderPrice_Listing;
  451. }
  452. set
  453. {
  454. Set(() => OrderPrice_Listing, ref _orderPrice_Listing, value);
  455. }
  456. }
  457. #endregion
  458. #region 是否显示摘牌单据信息
  459. private Visibility _isVisibility_ListingInfo = Visibility.Collapsed;
  460. /// <summary>
  461. /// 是否显示摘牌单据信息
  462. /// </summary>
  463. public Visibility IsVisibility_ListingInfo
  464. {
  465. get
  466. {
  467. if (CacheManager.FromType == eOrderFormType.Listting && CacheManager.OrderId_Listing != 0
  468. && ListingSelectModel == eListingSelectType.LISTINGSELECTTYPE_DELISTING && DelistingModel == eDelistingType.DELISTINGTYPE_SELECTED)
  469. {
  470. return Visibility.Visible;
  471. }
  472. return _isVisibility_ListingInfo;
  473. }
  474. set
  475. {
  476. Set(() => IsVisibility_ListingInfo, ref _isVisibility_ListingInfo, value);
  477. }
  478. }
  479. #endregion
  480. //===============挂牌下单属性↑=======================
  481. #region 【建仓/平仓/先平后建/取消订单】建平仓方式
  482. /// <summary>
  483. /// 建平仓方式
  484. /// </summary>
  485. public OpenCloseMode OpenCloseMode
  486. {
  487. get
  488. {
  489. if (_openCloseMode != OpenCloseMode.BUILDTYPE_CLOSE && _openCloseMode != OpenCloseMode.BUILDTYPE_OPEN && _openCloseMode != OpenCloseMode.BUILDTYPE_CLOSETHENOPEN)// 完全不考虑拓展的吗?我现在加了一个BUILDTYPE_CLOSETHENOPEN,怎么办?
  490. {
  491. _openCloseMode = OpenCloseMode.BUILDTYPE_OPEN;
  492. }
  493. return _openCloseMode;
  494. }
  495. set
  496. {
  497. var needInit = value != _openCloseMode && (_openCloseMode == OpenCloseMode.BUILDTYPE_CLOSE || value == OpenCloseMode.BUILDTYPE_CLOSE);
  498. Set(() => OpenCloseMode, ref _openCloseMode, value);
  499. /* // 90663需求
  500. if (_openCloseMode == OpenCloseMode.BUILDTYPE_CLOSETHENOPEN) // 如果现在选择的自动开平,那就存一个标志位
  501. {
  502. ApplicationParameter.DefaultOpenMode = (int) OpenCloseMode.BUILDTYPE_CLOSETHENOPEN;
  503. }
  504. else
  505. {
  506. ApplicationParameter.DefaultOpenMode = (int)OpenCloseMode.BUILDTYPE_OPEN;
  507. }
  508. */
  509. CheckedVisibleEnable();
  510. SetMinMaxQtyVaule(); //设置数量
  511. SetEntrustPriceRange();
  512. if (needInit)
  513. {
  514. SetInitVaules();
  515. }
  516. ChangeBuySellBackground(Direction.unSet);
  517. }
  518. }
  519. /// <summary>
  520. /// 点击openCloseradio Button按钮触发的事件,和枚举绑定不同的事件,必须是由手动点击触发的事件
  521. /// </summary>
  522. public RelayCommand<Int16> SelectOpenCloseCommand
  523. {
  524. get
  525. {
  526. return new RelayCommand<Int16>(i =>
  527. {
  528. if (i == 3)
  529. {
  530. ApplicationParameter.DefaultOpenMode = (int) OpenCloseMode.BUILDTYPE_CLOSETHENOPEN;
  531. }
  532. else
  533. {
  534. ApplicationParameter.DefaultOpenMode = (int)OpenCloseMode.BUILDTYPE_OPEN;
  535. }
  536. });
  537. }
  538. }
  539. #endregion
  540. #region 【市价/限价】取价方式
  541. protected ePriceMode _priceMode;
  542. /// <summary>
  543. /// 取价方式
  544. /// </summary>
  545. public virtual ePriceMode PriceMode
  546. {
  547. get
  548. {
  549. return _priceMode;
  550. }
  551. set
  552. {
  553. if ((int)value == -1) return;
  554. Set(() => PriceMode, ref _priceMode, value);
  555. DefautEntrustPrice();
  556. CheckedVisibleEnable();
  557. SetMinMaxQtyVaule(); //设置数量
  558. }
  559. }
  560. #endregion
  561. #region 【按商品/按单】平仓方式
  562. /// <summary>
  563. /// 平仓方式
  564. /// </summary>
  565. public virtual GoodsOrderMode GoodsOrderMode
  566. {
  567. get { return _goodsOrderMode; }
  568. set
  569. {
  570. if (value == GoodsOrderMode.unSet)
  571. {
  572. return;
  573. }
  574. var needInit = value != _goodsOrderMode;
  575. Set(() => GoodsOrderMode, ref _goodsOrderMode, value);
  576. SetMinMaxQtyVaule(); //设置数量
  577. if (needInit)
  578. {
  579. SetInitVaules();
  580. }
  581. }
  582. }
  583. #endregion
  584. #region 委托价格
  585. protected decimal _executePrice;
  586. /// <summary>
  587. /// 委托价格
  588. /// </summary>
  589. public virtual decimal ExecutePrice
  590. {
  591. get
  592. {
  593. return _executePrice;
  594. }
  595. set
  596. {
  597. Set(() => ExecutePrice, ref _executePrice, value);
  598. if(OrderModel == OrderModel.Normal) SetMinMaxQtyVaule();
  599. ChannelBuyPrice = Convert.ToString(value);
  600. ChannelSellPrice = Convert.ToString(value);
  601. }
  602. }
  603. #endregion
  604. #region 当前选择触发价格类型
  605. private eTriggerType _currentTriggerType = eTriggerType.TRIGGERTYPE_GREATER_OR_EQUAL;
  606. /// <summary>
  607. /// Sets and gets the 当前选择触发价格类型 property.
  608. /// Changes to that property's value raise the PropertyChanged event.
  609. /// </summary>
  610. public eTriggerType CurrentTirrgerType
  611. {
  612. get
  613. {
  614. return _currentTriggerType;
  615. }
  616. set
  617. {
  618. Set(() => CurrentTirrgerType, ref _currentTriggerType, value);
  619. }
  620. }
  621. #endregion
  622. #region 合约单位名称枚举
  623. /// <summary>
  624. /// 合约单位名称枚举
  625. /// </summary>
  626. public string AgreeUnitType
  627. {
  628. get
  629. {
  630. if (_currentGoods == null)
  631. {
  632. return string.Empty;
  633. }
  634. var goodsUnit = CacheManager.TradeGoodsUnit.FirstOrDefault((x) => x.UNITID == _currentGoods.GoodsParameters.AgreeUnitType);
  635. if (goodsUnit != null)
  636. {
  637. return goodsUnit.GOODSUNITNAME;
  638. }
  639. return string.Empty;
  640. }
  641. }
  642. #endregion
  643. #region 触发价格
  644. private decimal _triggerPrice = 0;
  645. /// <summary>
  646. /// Sets and gets the 触发价格 property.
  647. /// Changes to that property's value raise the PropertyChanged event.
  648. /// </summary>
  649. public decimal TriggerPrice
  650. {
  651. get
  652. {
  653. return _triggerPrice;
  654. }
  655. set
  656. {
  657. Set(() => TriggerPrice, ref _triggerPrice, value);
  658. }
  659. }
  660. #endregion
  661. #region 【置灰】设置按键不可用
  662. private bool _oKButtonEnabled = true;
  663. /// <summary>
  664. ///设置按键不可用IsBidAskVsb
  665. /// </summary>
  666. public bool OKButtonEnabled
  667. {
  668. get
  669. {
  670. return _oKButtonEnabled;
  671. }
  672. set
  673. {
  674. Set(() => OKButtonEnabled, ref _oKButtonEnabled, value);
  675. }
  676. }
  677. #endregion
  678. #region 【置灰】是否可平仓
  679. /// <summary>
  680. /// 是否可平仓
  681. /// </summary>
  682. public virtual bool IsCloseEnable
  683. {
  684. get
  685. {
  686. var buyOrSell = Direction == Direction.Ask ? Direction.Bid : Direction.Ask;
  687. //查询是否有反方向持仓
  688. var hasHoldSummary = UserManager.HasGoodsHoldSummary(UserManager.CurrentTradeAccount.AccountId, buyOrSell,
  689. _currentGoods.GoodsId);
  690. //var holdersNum = CacheManager.GetGoodsPositionAvailableQty(dirction, _currentGoods.GoodsId, CurrentGoods.TradeProperty);
  691. //if (holdersNum > 0)
  692. //{
  693. // _isCloseEnable = true;
  694. //}
  695. return hasHoldSummary && ApplicationParameter.ShowCloseOrder;
  696. //return true;
  697. }
  698. }
  699. #endregion
  700. #region 【当日有效/本周有效】过期类型
  701. /// <summary>
  702. /// Sets and gets the 过期类型 property.
  703. /// Changes to that property's value raise the PropertyChanged event.
  704. /// </summary>
  705. public ExpirationType CurrentExpirationType
  706. {
  707. get
  708. {
  709. return _currentExpirationType;
  710. }
  711. set
  712. {
  713. Set(() => CurrentExpirationType, ref _currentExpirationType, value);
  714. }
  715. }
  716. #endregion
  717. #region 最大数量
  718. private decimal _maxLot;
  719. /// <summary>
  720. /// 最大数量
  721. /// </summary>
  722. public decimal MaxLot
  723. {
  724. get { return _maxLot; }
  725. set { Set(() => MaxLot, ref _maxLot, value); }
  726. }
  727. #endregion
  728. #region 最小数量
  729. private decimal _minLot;
  730. /// <summary>
  731. /// 最小数量
  732. /// </summary>
  733. public decimal MinLot
  734. {
  735. get { return _minLot; }
  736. set { Set(() => MinLot, ref _minLot, value); }
  737. }
  738. #endregion
  739. #region 最大限制数量
  740. private decimal _limitMaxLot = Int32.MaxValue;
  741. /// <summary>
  742. /// 最大限制数量
  743. /// </summary>
  744. public decimal LimitMaxLot
  745. {
  746. get { return _limitMaxLot; }
  747. set { Set(() => LimitMaxLot, ref _limitMaxLot, value); }
  748. }
  749. #endregion
  750. #region 最大预埋单数量
  751. private decimal _maxPreOrderLot = decimal.Zero;
  752. /// <summary>
  753. /// 最大预埋单数量
  754. /// </summary>
  755. public decimal MaxPreOrderLot
  756. {
  757. get { return _maxPreOrderLot; }
  758. set { Set(() => MaxPreOrderLot, ref _maxPreOrderLot, value); }
  759. }
  760. #endregion
  761. #region 最大买持仓量
  762. private decimal _maxHolderBuyLot;
  763. /// <summary>
  764. /// 最大买持仓量
  765. /// </summary>
  766. public decimal MaxHolderBuyLot
  767. {
  768. get { return _maxHolderBuyLot; }
  769. set { Set(() => MaxHolderBuyLot, ref _maxHolderBuyLot, value); }
  770. }
  771. #endregion
  772. #region 最大卖持仓量
  773. private decimal _maxHolderSellLot;
  774. /// <summary>
  775. /// 最大卖持仓量
  776. /// </summary>
  777. public decimal MaxHolderSellLot
  778. {
  779. get { return _maxHolderSellLot; }
  780. set { Set(() => MaxHolderSellLot, ref _maxHolderSellLot, value); }
  781. }
  782. #endregion
  783. #region 最大持仓量
  784. private decimal _maxHolderLot;
  785. /// <summary>
  786. /// 最大卖仓量
  787. /// </summary>
  788. public decimal MaxHolderLot
  789. {
  790. get { return _maxHolderLot; }
  791. set { Set(() => MaxHolderLot, ref _maxHolderLot, value); }
  792. }
  793. #endregion
  794. #region 数量
  795. private decimal _lot = decimal.Zero;
  796. /// <summary>
  797. /// 数量
  798. /// </summary>
  799. public decimal Lot
  800. {
  801. get
  802. {
  803. //#region 挂牌下单属性赋值=》数量
  804. //if (CacheManager.FromType == eOrderFormType.Listting && CacheManager.OrderId_Listing != 0)
  805. //{
  806. // if (ListingSelectModel == eListingSelectType.LISTINGSELECTTYPE_DELISTING && DelistingModel == eDelistingType.DELISTINGTYPE_SELECTED)
  807. // {
  808. // return CacheManager.OrderLot_Listing;
  809. // }
  810. //}
  811. //#endregion
  812. return _lot;
  813. }
  814. set
  815. {
  816. Set(() => Lot, ref _lot, value);
  817. RaisePropertyChanged(() => RelationNum);
  818. }
  819. }
  820. /// <summary>
  821. /// 单位
  822. /// </summary>
  823. public string RelationNum
  824. {
  825. get
  826. {
  827. if (_currentGoods != null)
  828. {
  829. return (_currentGoods.GoodsParameters.AgreeUnit * _lot).ToString();
  830. }
  831. else
  832. {
  833. return "-";
  834. }
  835. }
  836. }
  837. #endregion
  838. #region 价格格式化
  839. /// <summary>
  840. /// 价格格式化
  841. /// </summary>
  842. public string PriceFormat
  843. {
  844. get
  845. {
  846. if (this._currentGoods != null)
  847. {
  848. return _currentGoods.FormatPrice;
  849. }
  850. else
  851. {
  852. return "F0";
  853. }
  854. }
  855. }
  856. #endregion
  857. #region MyRegion小数位数据
  858. /// <summary>
  859. ///
  860. /// </summary>
  861. public int DecimalCount
  862. {
  863. get { return _currentGoods.GoodsParameters.HqExchFigures; }
  864. }
  865. #endregion
  866. #region 可输入小数位数
  867. /// <summary>
  868. /// 可输入小数位数
  869. /// </summary>
  870. public decimal PriceMinUnit
  871. {
  872. get
  873. {
  874. int temp = 0;
  875. uint quoteMinUnit = 1;
  876. if (this._currentGoods != null && this._currentGoods.GoodsParameters != null)
  877. {
  878. //temp = _currentGoods.GoodsParameters.HqExchFigures;
  879. temp = _currentGoods.DecimalPlaces;
  880. quoteMinUnit = _currentGoods.QuoteMinUnit;
  881. }
  882. //return Convert.ToDecimal(1 / Math.Pow(10, temp));
  883. return Convert.ToDecimal(quoteMinUnit / Math.Pow(10, temp));
  884. }
  885. }
  886. #endregion
  887. #region 当前商品的持仓单
  888. private List<HoldingOrder> _holdDetails;
  889. /// <summary>
  890. /// 当前商品的持仓单
  891. /// </summary>
  892. public List<HoldingOrder> HoldDetails
  893. {
  894. get { return _holdDetails; }
  895. set
  896. {
  897. Set(() => HoldDetails, ref _holdDetails, value);
  898. CheckedVisibleEnable();
  899. }
  900. }
  901. #endregion
  902. #region 当前持仓明细表
  903. private HoldingOrder _selectOrder;
  904. /// <summary>
  905. /// 当前持仓明细表商品
  906. /// </summary>
  907. public HoldingOrder SelectOrder
  908. {
  909. get { return _selectOrder; }
  910. set
  911. {
  912. Set(() => SelectOrder, ref _selectOrder, value);
  913. SetMinMaxQtyVaule();
  914. CheckedVisibleEnable();
  915. // SetInitVaules();
  916. }
  917. }
  918. #endregion
  919. #region 最小偏移
  920. private decimal _minUsedMargin;
  921. /// <summary>
  922. /// 最小偏移
  923. /// </summary>
  924. public decimal MinUsedMargin
  925. {
  926. get { return _minUsedMargin; }
  927. set { Set(() => MinUsedMargin, ref _minUsedMargin, value); }
  928. }
  929. #endregion
  930. #region 标题
  931. public virtual string SellTitle
  932. {
  933. get
  934. {
  935. return Muchinfo.MTPClient.Resources.Client_Resource.Order_OTC_Sell;
  936. }
  937. }
  938. public virtual string BuyTitle
  939. {
  940. get
  941. {
  942. return Muchinfo.MTPClient.Resources.Client_Resource.Order_OTC_Buy;
  943. }
  944. }
  945. private string _winTitle;
  946. /// <summary>
  947. /// 标题
  948. /// </summary>
  949. public string WinTitle
  950. {
  951. get
  952. {
  953. if (OrderModel == OrderModel.SPSL) return "止盈止损";
  954. return Muchinfo.MTPClient.Resources.Client_Resource.Order_Entruct_Titile + (Direction == Direction.Ask ? SellTitle : BuyTitle);
  955. }
  956. }
  957. #endregion
  958. #region 当前选择商品/所属市场【[混合]竞价/即期/竞价全额】
  959. /// <summary>
  960. /// 当前选择商品
  961. /// </summary>
  962. public QuoteGoods CurrentGoods
  963. {
  964. get { return _currentGoods; }
  965. }
  966. #endregion
  967. #region 界面项目是否显示控制 默认根据类型,如需修改刚重写
  968. /// <summary>
  969. /// 是否显示价格类型可见 默认显示
  970. /// </summary>
  971. public virtual bool IsPriceModeVisible
  972. {
  973. get { return true; }
  974. }
  975. /// <summary>
  976. /// 是否可显示允许点差 默认不显示
  977. /// </summary>
  978. public virtual bool IsAllowPipsVsb
  979. {
  980. get { return false; }
  981. }
  982. private bool _isStopPLVsb;
  983. /// <summary>
  984. /// 是否显示止盈止损可见 默认不显示
  985. /// </summary>
  986. public virtual bool IsStopPLVsb
  987. {
  988. get { return false; }
  989. }
  990. /// <summary>
  991. /// 是否有效期可见 默认不显示
  992. /// </summary>
  993. public virtual bool IsExpirationVsb
  994. {
  995. get { return false; }
  996. }
  997. /// <summary>
  998. /// 触发类型是否可显示 默认不显示
  999. /// </summary>
  1000. public virtual bool IsTriggerTypeVsb
  1001. {
  1002. get { return false; }
  1003. }
  1004. /// <summary>
  1005. /// 是否可显示人价格范围 默认不显示
  1006. /// </summary>
  1007. public virtual bool IsPriceRangeVsb
  1008. {
  1009. get { return false; }
  1010. }
  1011. /// <summary>
  1012. /// 是否显示买卖五档
  1013. /// </summary>
  1014. public virtual bool IsBidQueueVsb
  1015. {
  1016. get { return false; }
  1017. }
  1018. /// <summary>
  1019. /// 是否显示买卖价
  1020. /// </summary>
  1021. public virtual bool IsBidAskVsb
  1022. {
  1023. get { return false; }
  1024. }
  1025. /// <summary>
  1026. /// 是否可按单平 (不可按单平)
  1027. /// </summary>
  1028. public virtual bool IsCanOrderEdit
  1029. {
  1030. get
  1031. {
  1032. return true;// OpenCloseMode != OpenCloseMode.BUILDTYPE_CLOSETHENOPEN;
  1033. }
  1034. }
  1035. /// <summary>
  1036. /// 平仓是否可见
  1037. /// </summary>
  1038. public virtual bool IsCloseTypeVsb
  1039. {
  1040. get
  1041. {
  1042. return OpenCloseMode != OpenCloseMode.BUILDTYPE_OPEN;
  1043. }
  1044. }
  1045. /// <summary>
  1046. /// 是否卖选项可见
  1047. /// </summary>
  1048. public virtual bool IsSellVsb
  1049. {
  1050. get
  1051. {
  1052. return true;
  1053. }
  1054. }
  1055. /// <summary>
  1056. /// 是否可卖出
  1057. /// </summary>
  1058. public virtual bool IsSellEnable
  1059. {
  1060. get
  1061. {
  1062. return true;
  1063. }
  1064. }
  1065. /// <summary>
  1066. /// 是否可买入
  1067. /// </summary>
  1068. public virtual bool IsBuyEnable
  1069. {
  1070. get
  1071. {
  1072. return true;
  1073. }
  1074. }
  1075. /// <summary>
  1076. /// 是否最大可下单数量
  1077. /// </summary>
  1078. public virtual bool IsLotMaxVsb
  1079. {
  1080. get
  1081. {
  1082. if (OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE)
  1083. {
  1084. return true;
  1085. }
  1086. return false;
  1087. }
  1088. }
  1089. /// <summary>
  1090. /// 是否显示-建仓,平仓,先平后建
  1091. /// </summary>
  1092. public virtual bool IsOpenCloseVisible
  1093. {
  1094. get
  1095. {
  1096. return true;//_currentGoods!=null&&_currentGoods.GoodsParameters.MoneyMode==eMoneyMode.MONEYMODE_MARGIN;
  1097. }
  1098. }
  1099. public virtual string IsOpenCloseVisibleMargin
  1100. {
  1101. get
  1102. {
  1103. return IsOpenCloseVisible == true ? "0,0,0,0" : "0,25,0,0";
  1104. }
  1105. }
  1106. /// <summary>
  1107. /// 多资金与单资金布局变化
  1108. /// </summary>
  1109. public string ShowMultUserFundsMargin
  1110. {
  1111. get
  1112. {
  1113. return IsShowUserMultFundsList == Visibility.Visible ? "25,0,0,0" : "0,0,0,0";
  1114. }
  1115. }
  1116. /// <summary>
  1117. /// 是否显示高级下单
  1118. /// </summary>
  1119. public virtual bool IsOrderOptionVisible
  1120. {
  1121. get
  1122. {
  1123. return _currentGoods != null && _currentGoods.TradeMode != eTradeMode.TRADEMODE_SALE;
  1124. }
  1125. }
  1126. #region 价格是否可编辑
  1127. /// <summary>
  1128. /// 价格是否可编辑
  1129. /// </summary>
  1130. public virtual bool IsExecutePrice
  1131. {
  1132. get { return this.PriceMode == ePriceMode.PRICEMODE_LIMIT && this.CurrentChannelPriceMode == ChannelPriceMode.LimitPrice; }
  1133. }
  1134. #endregion
  1135. #region 渠道交易时候买入、卖出的价格
  1136. public virtual string ChannelBuyPrice
  1137. {
  1138. get
  1139. {
  1140. return (_channelBuyPrice.Equals("") || Convert.ToDouble(_channelBuyPrice) == 0) ? "--" : _channelBuyPrice;
  1141. }
  1142. set
  1143. {
  1144. Set(() => ChannelBuyPrice, ref _channelBuyPrice, value);
  1145. }
  1146. }
  1147. public virtual string ChannelSellPrice
  1148. {
  1149. get { return (_channelSellPrice.Equals("") || Convert.ToDouble(_channelSellPrice) == 0) ? "--" : _channelSellPrice; }
  1150. set
  1151. {
  1152. Set(() => ChannelSellPrice, ref _channelSellPrice, value);
  1153. }
  1154. }
  1155. #endregion
  1156. /// <summary>
  1157. /// 是否可限价平
  1158. /// </summary>
  1159. public virtual bool IsLimitPriceEnable
  1160. {
  1161. get { return true; }
  1162. }
  1163. /// <summary>
  1164. /// 是否显示价格项
  1165. /// </summary>
  1166. public virtual bool IsExecutePriceVbs
  1167. {
  1168. //this.OpenCloseMode != OpenCloseMode.BUILDTYPE_CLOSE;
  1169. get { return PriceMode != ePriceMode.PRICEMODE_MARKET; }
  1170. }
  1171. public virtual string IsExecutePriceVbsMargin
  1172. {
  1173. get { return IsExecutePriceVbs == true ? "0,0,0,0" : "0,0,0,35"; }
  1174. }
  1175. /// <summary>
  1176. /// 先平后建是否可用
  1177. /// </summary>
  1178. public virtual bool IsOpenCloseEdit
  1179. {
  1180. //this.OpenCloseMode != OpenCloseMode.BUILDTYPE_CLOSE;
  1181. get { return true; }
  1182. }
  1183. /// <summary>
  1184. /// 是否可以选择建仓-默认可选
  1185. /// </summary>
  1186. public virtual bool IsEnableSelectOpenMode
  1187. {
  1188. get
  1189. {
  1190. return true;
  1191. }
  1192. }
  1193. /// <summary>
  1194. /// 是否可以修改数量-默认可修改
  1195. /// </summary>
  1196. public virtual bool IsEnableChangeLot
  1197. {
  1198. get
  1199. {
  1200. return true;
  1201. }
  1202. }
  1203. /// <summary>
  1204. /// 是否可按商品平仓 (不可按商品平仓)
  1205. /// </summary>
  1206. public virtual bool IsCanGoodsEdit
  1207. {
  1208. get
  1209. {
  1210. return true;
  1211. }
  1212. }
  1213. /// <summary>
  1214. /// 是否显示先平后建
  1215. /// </summary>
  1216. public virtual bool IsCloseOpenVbs
  1217. {
  1218. get
  1219. {
  1220. return true;
  1221. }
  1222. }
  1223. /// <summary>
  1224. /// 建仓是否显示
  1225. /// </summary>
  1226. public virtual bool IsOpenVbs
  1227. {
  1228. get { return true; }
  1229. }
  1230. /// <summary>
  1231. /// 检查显示内容或可编辑
  1232. /// </summary>
  1233. public virtual void CheckedVisibleEnable()
  1234. {
  1235. RaisePropertyChanged(() => IsPriceModeVisible);
  1236. RaisePropertyChanged(() => IsExecutePrice);
  1237. RaisePropertyChanged(() => IsBidAskVsb);
  1238. RaisePropertyChanged(() => IsBidQueueVsb);
  1239. RaisePropertyChanged(() => IsPriceRangeVsb);
  1240. RaisePropertyChanged(() => IsTriggerTypeVsb);
  1241. RaisePropertyChanged(() => IsExpirationVsb);
  1242. RaisePropertyChanged(() => IsStopPLVsb);
  1243. RaisePropertyChanged(() => IsAllowPipsVsb);
  1244. RaisePropertyChanged(() => WinTitle);
  1245. RaisePropertyChanged(() => IsCanOrderEdit);
  1246. RaisePropertyChanged(() => IsCloseEnable);
  1247. RaisePropertyChanged(() => IsBuyEnable);
  1248. RaisePropertyChanged(() => IsSellEnable);
  1249. RaisePropertyChanged(() => IsSellVsb);
  1250. RaisePropertyChanged(() => IsOpenCloseVisible);
  1251. RaisePropertyChanged(() => IsOpenCloseVisibleMargin);
  1252. RaisePropertyChanged(() => IsOrderOptionVisible);
  1253. RaisePropertyChanged(() => BuyTitle);
  1254. RaisePropertyChanged(() => IsCloseTypeVsb);
  1255. RaisePropertyChanged(() => IsEnableByPrePostOrder);
  1256. RaisePropertyChanged(() => IsExecutePriceVbs);
  1257. RaisePropertyChanged(() => IsExecutePriceVbsMargin);
  1258. RaisePropertyChanged(() => IsCanGoodsEdit);
  1259. RaisePropertyChanged(() => IsLimitPriceEnable);
  1260. RaisePropertyChanged(() => IsEnableSelectOpenMode);
  1261. RaisePropertyChanged(() => IsOpenCloseEdit);
  1262. RaisePropertyChanged(() => IsEnableChangeLot);
  1263. RaisePropertyChanged(() => IsCloseOpenVbs);
  1264. RaisePropertyChanged(() => IsOpenVbs);
  1265. RaisePropertyChanged(() => IsShowRaiseFall);
  1266. RaisePropertyChanged(() => IsPrePostVisible);
  1267. RaisePropertyChanged(() => IsMarketPriceVisibity);
  1268. RaisePropertyChanged(() => IsVisibility_ListingSelect);
  1269. RaisePropertyChanged(() => IsLotMaxVsb);
  1270. RaisePropertyChanged(() => IsVisibility_DelistingModel);
  1271. }
  1272. #endregion
  1273. #region 当前登录用户多资金信息列表
  1274. private List<string> _currentUserFundsList = null;
  1275. /// <summary>
  1276. /// 当前登录用户多资金信息列表
  1277. /// </summary>
  1278. public List<string> CurrentUserFundsList
  1279. {
  1280. get
  1281. {
  1282. return _currentUserFundsList;
  1283. }
  1284. set
  1285. {
  1286. Set(() => CurrentUserFundsList, ref _currentUserFundsList, value);
  1287. if (CurrentUserFundsList != null && CurrentUserFundsList.Count() > 1)
  1288. {
  1289. IsShowUserMultFundsList = Visibility.Visible;//显示多资金账号列表
  1290. _currentUserFundsList.Insert(0, "请选择资金账户");
  1291. UserManager.CurrentTradeAccount.FundsAccountId = 0;
  1292. }
  1293. else
  1294. {
  1295. _currentSelectedFunds = CurrentUserFundsList.First(); //单资金账号 默认选择第一个
  1296. if (!_currentSelectedFunds.Contains("请"))
  1297. {
  1298. UserManager.CurrentTradeAccount.FundsAccountId = ulong.Parse(_currentSelectedFunds);
  1299. }
  1300. }
  1301. SetMinMaxQtyVaule();
  1302. }
  1303. }
  1304. #endregion
  1305. #region 是否显示用户多资金信息列表
  1306. private Visibility _isShowUserMultFundsList = Visibility.Collapsed;
  1307. /// <summary>
  1308. /// 是否显示用户多资金信息列表
  1309. /// </summary>
  1310. public Visibility IsShowUserMultFundsList
  1311. {
  1312. get
  1313. {
  1314. return _isShowUserMultFundsList;
  1315. }
  1316. set
  1317. {
  1318. Set(() => IsShowUserMultFundsList, ref _isShowUserMultFundsList, value);
  1319. }
  1320. }
  1321. #endregion
  1322. #region 当前选中的资金账号
  1323. private string _currentSelectedFunds = "请选择资金账户";
  1324. /// <summary>
  1325. /// 当前选中的资金账号
  1326. /// </summary>
  1327. public string CurrentSelectedFunds
  1328. {
  1329. get
  1330. {
  1331. return _currentSelectedFunds;
  1332. }
  1333. set
  1334. {
  1335. Set(() => CurrentSelectedFunds, ref _currentSelectedFunds, value);
  1336. UserManager.CurrentTradeAccount.FundsAccountId = 0;
  1337. if (!_currentSelectedFunds.Contains("请"))
  1338. {
  1339. UserManager.CurrentTradeAccount.FundsAccountId = ulong.Parse(CurrentSelectedFunds);
  1340. }
  1341. SetMinMaxQtyVaule();
  1342. }
  1343. }
  1344. #endregion
  1345. /// <summary>
  1346. /// 是否显示-点选成交
  1347. /// </summary>
  1348. public virtual bool IsVisibility_ListingSelect
  1349. {
  1350. get
  1351. {
  1352. return false;
  1353. }
  1354. }
  1355. /// <summary>
  1356. /// 是否显示市价下单
  1357. /// </summary>
  1358. public virtual bool IsMarketPriceVisibity
  1359. {
  1360. get
  1361. {
  1362. return true;
  1363. }
  1364. }
  1365. /// <summary>
  1366. /// 是否显示涨跌停
  1367. /// </summary>
  1368. public virtual bool IsShowRaiseFall
  1369. {
  1370. get
  1371. {
  1372. return false;
  1373. }
  1374. }
  1375. /// <summary>
  1376. /// 是否显示预埋单功能
  1377. /// </summary>
  1378. public bool IsPrePostVisible
  1379. {
  1380. get
  1381. {
  1382. return ApplicationParameter.IsPrePostVisible == 1; ////
  1383. }
  1384. }
  1385. /// <summary>
  1386. ///
  1387. /// </summary>
  1388. /// <returns></returns>
  1389. protected void GetHoldDetails()
  1390. {
  1391. if (this.CurrentGoods != null)
  1392. {
  1393. //var holdingOrders = (CurrentGoods.TradeMode == eTradeMode.Full_Transfer ? CacheManager.CacheRealGoodsPositionList : CacheManager.CacheGoodsPositionList);// UserManager.GetCacheOrders<HoldingOrder>();
  1394. var holdingOrders = CacheManager.CacheGoodsPositionList;// UserManager.GetCacheOrders<HoldingOrder>();
  1395. if (holdingOrders == null || !holdingOrders.Any())
  1396. {
  1397. SetMinMaxQtyVaule();
  1398. return;
  1399. }
  1400. var direction = _direction == Direction.Ask ? Direction.Bid : Direction.Ask;
  1401. HoldDetails = CacheManager.GetGoodsPositionList(direction, (uint)CurrentGoods.GoodsParameters.GoodsId, CurrentGoods.TradeMode);//holdingOrders.Where((item) => item.GoodsId == CurrentGoods.GoodsParameters.GoodsId && item.Direction == direction).ToList();
  1402. SelectOrder = HoldDetails.FirstOrDefault();
  1403. }
  1404. }
  1405. /// <summary>
  1406. /// 提交表单
  1407. /// </summary>
  1408. /// <param name="successAction">成功回调</param>
  1409. /// <param name="errorAction">错误返回</param>
  1410. public virtual void PostOrder(Action<OrderDetail> successAction, Action<ErrorEntity> errorAction)
  1411. {
  1412. }
  1413. /// <summary>
  1414. /// 创建基本单据
  1415. /// </summary>
  1416. /// <returns></returns>
  1417. public virtual NewEntrustOrder BuildEntrustOrder()
  1418. {
  1419. var newOrder = new NewEntrustOrder()
  1420. {
  1421. BuyOrSell = Direction,
  1422. GoodsCode = this.CurrentGoods.GoodsCode,
  1423. OperaterId = UserManager.CurrentTradeAccount.LoginID,
  1424. GoodsId = (uint)this.CurrentGoods.GoodsParameters.GoodsId,
  1425. AccountType = UserManager.CurrentTradeAccount.AccountType,
  1426. BuildType = OpenCloseMode,
  1427. EntrurstTime = ApplicationParameter.ServerTimeNow,
  1428. MemberAreaId = UserManager.CurrentTradeAccount.MemberAreaId,
  1429. EntrustQuantity = Lot,
  1430. PriceMode = this.PriceMode,
  1431. ValidType = this.CurrentExpirationType,
  1432. TriggerType = (uint)this._currentTriggerType,
  1433. TriggerPrice = this.TriggerPrice,
  1434. MarketId = this.CurrentGoods.MarketID,
  1435. TradeMode = CurrentGoods.TradeMode,
  1436. LoginID = UserManager.CurrentTradeAccount.LoginID,
  1437. AccountId = UserManager.CurrentTradeAccount.FundsAccountId,
  1438. OrderFlag = (uint)this.OrderFlag,
  1439. OrderFormType = eOrderFormType.Commom,
  1440. ChannelPriceMode = this.CurrentChannelPriceMode,
  1441. CurrentGoods = this.CurrentGoods,
  1442. Ip = ApplicationParameter.PublisgNetIp,
  1443. };
  1444. ApplicationParameter.MakeSpsl(newOrder);
  1445. // if (FormType == eOrderFormType.Listting)
  1446. if (_currentGoods.TradeMode == eTradeMode.TRADEMODE_LISTING_SELECT)
  1447. {
  1448. newOrder.OrderFormType = eOrderFormType.Listting;
  1449. newOrder.ListingSelectType = ListingSelectModel;
  1450. if (ListingSelectModel != eListingSelectType.LISTINGSELECTTYPE_LISTING)
  1451. {
  1452. newOrder.DelistingType = DelistingModel;
  1453. }
  1454. if (ListingSelectModel == eListingSelectType.LISTINGSELECTTYPE_DELISTING && DelistingModel == eDelistingType.DELISTINGTYPE_SELECTED)
  1455. {
  1456. newOrder.RelationTicket = (ulong)CacheManager.OrderId_Listing;
  1457. }
  1458. }
  1459. #region 注销BY DK
  1460. //if (UserManager.CurrentTradeAccount.FundsAccounts.Any() && UserManager.CurrentTradeAccount.FundsAccounts[0] != null)
  1461. //{
  1462. // newOrder.AccountId = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  1463. // if (newOrder.AccountId == 0)
  1464. // {
  1465. // newOrder.AccountId = UserManager.CurrentTradeAccount.AccountId;
  1466. // }
  1467. //}
  1468. //else
  1469. //{
  1470. // newOrder.AccountId = UserManager.CurrentTradeAccount.AccountId;
  1471. //}
  1472. #endregion
  1473. // newOrder.EntrustPrice = ExecutePrice;// 买卖按钮变化了。所以不需要这样传值
  1474. // 点击界面上的买入卖出,会触犯买卖方向的变化。所以直接用买卖方向来判断,应该可以
  1475. if (ChannelBuyPrice.Equals("--"))
  1476. {
  1477. newOrder.EntrustPrice = 0;
  1478. }
  1479. else
  1480. {
  1481. if (newOrder.BuyOrSell == Direction.Bid) // 买入
  1482. {
  1483. newOrder.EntrustPrice = Convert.ToDecimal(ChannelBuyPrice);
  1484. }
  1485. else if (newOrder.BuyOrSell == Direction.Ask)// 卖出
  1486. {
  1487. newOrder.EntrustPrice = Convert.ToDecimal(ChannelSellPrice);
  1488. }
  1489. }
  1490. //直接获取单据价格-挂牌单据
  1491. if (ListingSelectModel == eListingSelectType.LISTINGSELECTTYPE_DELISTING && DelistingModel == eDelistingType.DELISTINGTYPE_SELECTED)
  1492. {
  1493. newOrder.EntrustPrice = CacheManager.OrderPrice_Listing;//OrderPrice_Listing;
  1494. }
  1495. // newOrder.RelationTicket = 0;
  1496. #region MTP2.0 注销
  1497. ////按单平
  1498. //if (OpenCloseMode != OpenCloseMode.BUILDTYPE_OPEN && GoodsOrderMode == GoodsOrderMode.Order)
  1499. //{
  1500. // newOrder.RelationTicket = SelectOrder == null ? 0 : SelectOrder.OrderID;
  1501. //}
  1502. #endregion
  1503. if (CurrentUserFundsList != null && CurrentUserFundsList.Count() == 1)
  1504. {
  1505. newOrder.AccountId = ulong.Parse(CurrentUserFundsList.FirstOrDefault());
  1506. }
  1507. return newOrder;
  1508. }
  1509. /// <summary>
  1510. /// 输入的价格是否有效
  1511. /// </summary>
  1512. /// <param name="price"></param>
  1513. /// <returns></returns>
  1514. protected bool CheckExecutePrice(decimal price)
  1515. {
  1516. int temp = CurrentGoods.GoodsParameters.HqExchFigures;
  1517. if (price >= 0 && price <= 1000000)
  1518. {
  1519. var pic = price % (1 / ((decimal)Math.Pow(10, temp)));
  1520. return pic == 0;
  1521. }
  1522. else
  1523. {
  1524. return false;
  1525. }
  1526. }
  1527. /// <summary>
  1528. /// 设置价格范围
  1529. /// </summary>
  1530. protected virtual void SetEntrustPriceRange() { }
  1531. /// <summary>
  1532. /// 验证数据
  1533. /// </summary>
  1534. /// <param name="msg"></param>
  1535. /// <returns></returns>
  1536. public virtual bool Validated(ref string msg)
  1537. {
  1538. #region
  1539. if (CurrentUserFundsList != null && CurrentUserFundsList.Count() > 1 && CurrentSelectedFunds.Contains("请"))
  1540. {
  1541. msg = "请选择资金账户";
  1542. return false;
  1543. }
  1544. if (Lot > 9223372036854775807)
  1545. {
  1546. msg = "超出最大委托数量";
  1547. return false;
  1548. }
  1549. //var isclose = OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE ||
  1550. // (CurrentGoods != null && CurrentGoods.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_PAY &&
  1551. // Direction == Direction.Ask);
  1552. //if (!IsOpenCloseEdit && OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSETHENOPEN && CurrentGoods.GoodsParameters.MoneyMode != eMoneyMode.MONEYMODE_PAY)
  1553. //{
  1554. // msg = Muchinfo.MTPClient.Resources.Client_Resource.OpenClose_IsNotAllow;
  1555. // return false;
  1556. //}
  1557. //if (!IsEnableSelectOpenMode && OpenCloseMode == OpenCloseMode.BUILDTYPE_OPEN && CurrentGoods.GoodsParameters.MoneyMode != eMoneyMode.MONEYMODE_PAY)
  1558. //{
  1559. // msg = Muchinfo.MTPClient.Resources.Client_Resource.Open_IsNotAllow;
  1560. // return false;
  1561. //}
  1562. //if (!IsCloseEnable && OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE && CurrentGoods.GoodsParameters.MoneyMode != eMoneyMode.MONEYMODE_PAY)
  1563. //{
  1564. // msg = Muchinfo.MTPClient.Resources.Client_Resource.Close_IsNotAllow;
  1565. // return false;
  1566. //}
  1567. //if (Lot <= 0 || Lot == decimal.Zero)
  1568. //{
  1569. // //数量不在正确范围内
  1570. // msg = Muchinfo.MTPClient.Resources.Client_Resource.Lot_Vailed_MustUpOfZero;
  1571. // return false;
  1572. //}
  1573. ////可用资金不足,最小交易数量为{0}!
  1574. ////if (OpenCloseMode != OpenCloseMode.BUILDTYPE_CLOSE && MinLot > MaxLot)
  1575. ////{
  1576. //// msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.EntrustOrderViewModel_MinLotLargeThanMaxLot, MinLot); ;
  1577. //// return false;
  1578. ////}
  1579. ////可用资金不足,最小交易数量为{0}!
  1580. ////if (!isclose && MinLot > MaxLot)
  1581. ////{
  1582. //// msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.EntrustOrderViewModel_MinLotLargeThanMaxLot, MinLot); ;
  1583. //// return false;
  1584. ////}
  1585. //if (Lot > MaxLot)
  1586. //{
  1587. // //msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Lot_Open_DownOfMaxMinOpenLot, MaxLot, MinLot);
  1588. // msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.EntrustOrderViewModel_OpenLotGreatThanMaxLot, MaxLot); ;
  1589. // return false;
  1590. //}
  1591. //if (!isclose && Lot < MinLot)
  1592. //{
  1593. // //单笔数量最小为:{0}
  1594. // msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.EntrustOrderViewModel_MinInputNum, MinLot);
  1595. // return false;
  1596. //}
  1597. //if (MinLot != 0 && (Lot % MinLot) != 0)
  1598. //{
  1599. // // 1.将商品交易规则项“单笔最小建仓数量”更名为“单笔最小交易数量”,“单笔最大建仓数量”更名为“单笔最大交易数量”;
  1600. // //2.服务端,客户端实现:平仓数量不是最小交易数量整数倍的,能且只能将剩余可用数量全部平仓,
  1601. // // 即:平仓数量!=单笔最小交易数量*int(平仓数量/单笔最小交易数量),
  1602. // //2.1若:平仓数量=剩余可平数量,平仓数量可平;
  1603. // //2.2若:平仓数量!=剩余可平数量,平仓数量不可平,服务端或者客户端提示“平仓数量不是单笔最小交易数量{显示单笔最小交易数量}整数倍,只能将剩余可用数量全部平仓”,提示方式和校验时点按照之前逻辑;
  1604. // if (!isclose)
  1605. // {
  1606. // //数量输入有误!应为{0}的倍数.
  1607. // msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.EntrustOrderViewModel_InputNumShouldBeRight, MinLot);
  1608. // return false;
  1609. // }
  1610. // else if (Lot != MaxLot)
  1611. // {
  1612. // msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.TradeClose_ErrorTips, MinLot);
  1613. // return false;
  1614. // }
  1615. //}
  1616. //if (this.PriceMode != ePriceMode.PRICEMODE_MARKET && !CheckExecutePrice(ExecutePrice))
  1617. //{
  1618. // //msg = "委托价格不在提示范围内";
  1619. // msg = Muchinfo.MTPClient.Resources.Client_Resource.ErrorEntrustPrice;
  1620. // return false;
  1621. //}
  1622. //if (this.OrderFlag == OrderMethods.PreOrder && TriggerPrice <= 0)
  1623. //{
  1624. // //msg = "触发价格需要大于0";
  1625. // msg = Muchinfo.MTPClient.Resources.Client_Resource.Error_TriggerPriceNeedGreaterThanZero;
  1626. // return false;
  1627. //}
  1628. //if (this.OrderFlag == OrderMethods.PreOrder && ApplicationParameter.MaxPrePostOrderLot > 0 && MaxPreOrderLot >= ApplicationParameter.MaxPrePostOrderLot)
  1629. //{
  1630. // //msg = "预埋单最多可保留{0}条,请撤销部分单据后进行提交";
  1631. // msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Error_MaxPrePostOrderLot, ApplicationParameter.MaxPrePostOrderLot);
  1632. // return false;
  1633. //}
  1634. return true;
  1635. #endregion
  1636. }
  1637. /// <summary>
  1638. /// 设置更新下单数量
  1639. /// </summary>
  1640. protected virtual void SetMinMaxQtyVaule()
  1641. {
  1642. }
  1643. /// <summary>
  1644. /// 是否显示摘牌类型
  1645. /// </summary>
  1646. public virtual bool IsVisibility_DelistingModel
  1647. {
  1648. get
  1649. {
  1650. return false;
  1651. }
  1652. }
  1653. /// <summary>
  1654. /// 所有权商品,买建卖平显示
  1655. /// </summary>
  1656. protected virtual void SetSellCloseBuyOpen()
  1657. {
  1658. }
  1659. #region 计算可下单数量
  1660. /// <summary>
  1661. /// 根据可用资金算出可下单的数量
  1662. /// </summary>
  1663. /// <returns></returns>
  1664. protected decimal GetEnableNum(decimal price)
  1665. {
  1666. decimal enablenum = 0;
  1667. decimal usableFunds = 0;
  1668. decimal dividernum = 0;
  1669. //可用资金[多资金账户]
  1670. usableFunds = UserManager.GetCurrentUsableFundsByAccountId(UserManager.CurrentTradeAccount.FundsAccountId);//UserManager.CurrentAccountUsableFunds();
  1671. if (usableFunds > 0)
  1672. {
  1673. #region 计算可购买
  1674. dividernum = GetDivider(price);
  1675. if (dividernum != 0)
  1676. {
  1677. var calcLot = usableFunds / dividernum;
  1678. if (calcLot <= 0)
  1679. {
  1680. enablenum = 0;
  1681. }
  1682. else if (calcLot >= int.MaxValue)
  1683. {
  1684. enablenum = int.MaxValue;
  1685. }
  1686. else
  1687. {
  1688. enablenum = calcLot; //数量
  1689. }
  1690. }
  1691. else ////不收任何费用时显示最大值
  1692. {
  1693. return int.MaxValue;
  1694. }
  1695. return enablenum > 0 ? enablenum : 0;
  1696. #endregion
  1697. }
  1698. else
  1699. {
  1700. return 0;//没有资金不可以买
  1701. }
  1702. }
  1703. /// <summary>
  1704. /// 每手下单所需资金
  1705. /// </summary>
  1706. /// <param name="price">价格</param>
  1707. /// <returns></returns>
  1708. private decimal GetDivider(decimal price)
  1709. {
  1710. decimal dividernum = 0;
  1711. decimal dividernumChange = 0;
  1712. if (Direction == Direction.Bid)
  1713. {
  1714. //【买】建仓手续费
  1715. dividernumChange = GetTradeFeeBy(eTradeFeeType.TRADEFEETYPE_TRADECHARGE, price);
  1716. }
  1717. else
  1718. {
  1719. //【卖】建仓手续费
  1720. dividernumChange = GetTradeFeeBy(eTradeFeeType.TRADEFEETYPE_TRADECHARGE, price);
  1721. }
  1722. //竞价全额
  1723. if (_currentGoods != null)// && _currentGoods.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_PAY)
  1724. {
  1725. //dividernum = _currentGoods.CurrentPrice == 0 ? _currentGoods.LastClose : _currentGoods.CurrentPrice;
  1726. dividernum = price * _currentGoods.AgreeUnit + dividernumChange;
  1727. return dividernum;
  1728. }
  1729. return GetTradeFeeBy(eTradeFeeType.TRADEFEETYPE_TRADECHARGE, price) + dividernumChange;
  1730. }
  1731. /// <summary>
  1732. /// 获取指定【交易费用类型】的费用
  1733. /// </summary>
  1734. /// <param name="tradeFeeType"></param>
  1735. /// <param name="price"></param>
  1736. /// <returns></returns>
  1737. private decimal GetTradeFeeBy(eTradeFeeType tradeFeeType, decimal price)
  1738. {
  1739. decimal dividerTradeFee = 0;
  1740. #region 类型:建仓保证金
  1741. //获取交易费用类型=建仓保证金
  1742. var eTradeFee = _goodsService.GetTradeFee(_currentGoods.TradeMode, tradeFeeType);
  1743. GoodsFeeType goodsfee = null;
  1744. GoodsFeeType accountfee = null;
  1745. #endregion
  1746. if (_currentGoods != null && CacheManager.TradeGoodsFeeRules != null && CacheManager.TradeGoodsFeeRules.ContainsKey((int)_currentGoods.GoodsId))
  1747. {
  1748. #region 类型:建仓保证金
  1749. if (CacheManager.TradeGoodsFeeRules[(int)_currentGoods.GoodsId].GoodsFees.ContainsKey((int)eTradeFee))
  1750. {
  1751. goodsfee = CacheManager.TradeGoodsFeeRules[(int)_currentGoods.GoodsId].GoodsFees[(int)eTradeFee];
  1752. }
  1753. if (CacheManager.TradeGoodsFeeRules[(int)_currentGoods.GoodsId].AccountGoodsFees.ContainsKey((int)eTradeFee))
  1754. {
  1755. accountfee = CacheManager.TradeGoodsFeeRules[(int)_currentGoods.GoodsId].AccountGoodsFees[(int)eTradeFee];
  1756. }
  1757. #endregion
  1758. }
  1759. #region 类型:建仓保证金
  1760. //商品是总额百分比模式
  1761. if (goodsfee != null && (int)eCalMode.CALMODE_FIXEDRATIO == goodsfee.FeeMode)
  1762. {
  1763. //可用资金/合约单位*价格*占用百分比 或者可用资金/合约单位固定值
  1764. if (accountfee != null)
  1765. {
  1766. switch ((int)accountfee.FeeMode)
  1767. {
  1768. case (int)eCalMode.CALMODE_FIXEDRATIO:
  1769. dividerTradeFee = (_currentGoods.GoodsParameters.AgreeUnit) * price * (accountfee.FeeValue + goodsfee.FeeValue);
  1770. break;
  1771. case (int)eCalMode.CALMODE_FIXEDNUMBER:
  1772. dividerTradeFee = (_currentGoods.GoodsParameters.AgreeUnit) * price * goodsfee.FeeValue + accountfee.FeeValue;
  1773. break;
  1774. }
  1775. }
  1776. else
  1777. {
  1778. dividerTradeFee = (_currentGoods.GoodsParameters.AgreeUnit) * price * goodsfee.FeeValue;
  1779. }
  1780. }
  1781. //商品是合约单位固定值的模式
  1782. else if (goodsfee != null && (int)eCalMode.CALMODE_FIXEDNUMBER == goodsfee.FeeMode)
  1783. {
  1784. //可用资金/合约单位*价格*占用百分比 或者可用资金/合约单位固定值
  1785. if (accountfee != null)
  1786. {
  1787. switch ((int)accountfee.FeeMode)
  1788. {
  1789. case (int)eCalMode.CALMODE_FIXEDRATIO:
  1790. dividerTradeFee = (_currentGoods.GoodsParameters.AgreeUnit) * price * accountfee.FeeValue + goodsfee.FeeValue;
  1791. break;
  1792. case (int)eCalMode.CALMODE_FIXEDNUMBER:
  1793. dividerTradeFee = accountfee.FeeValue + goodsfee.FeeValue;
  1794. break;
  1795. }
  1796. }
  1797. else
  1798. {
  1799. dividerTradeFee = goodsfee.FeeValue;
  1800. }
  1801. }
  1802. #endregion
  1803. return dividerTradeFee;
  1804. }
  1805. /// <summary>
  1806. /// 设置
  1807. /// </summary>
  1808. protected virtual void DefautEntrustPrice(bool isUpdateLimitePrice = true)
  1809. {
  1810. if (this._currentGoods == null)
  1811. {
  1812. return;
  1813. }
  1814. if (this.PriceMode == ePriceMode.PRICEMODE_LIMIT)
  1815. {
  1816. switch (this._currentGoods.TradeMode)
  1817. {
  1818. case eTradeMode.TRADEMODE_MARKETMAKE:
  1819. ExecutePrice = _direction == Direction.Ask ? _currentGoods.AskPrice : _currentGoods.BidPrice;
  1820. break;
  1821. case eTradeMode.TRADEMODE_BIDDING:
  1822. case eTradeMode.TRADEMODE_LISTING_SELECT:
  1823. // 需求 #25835 竞价市场下点击下单类型为限价时,自动将买一卖一价带入价格框,若无买一卖一,则取昨收价。
  1824. ExecutePrice = _direction == Direction.Ask ? _currentGoods.BidPrice : _currentGoods.AskPrice;
  1825. if (ExecutePrice <= 0)
  1826. {
  1827. //任务 #26769 //竞价市场-》-》限价-》默认价格 为昨收OR最新价
  1828. ExecutePrice = _currentGoods.CurrentPrice == 0 ? _currentGoods.LastClose : _currentGoods.CurrentPrice;
  1829. }
  1830. break;
  1831. case eTradeMode.TRADEMODE_ENTRUST_HEDGE:
  1832. switch (CurrentChannelPriceMode)
  1833. {
  1834. case ChannelPriceMode.MatchPrice:
  1835. ExecutePrice = Direction == Direction.Ask
  1836. ? _currentGoods.BidPrice
  1837. : _currentGoods.AskPrice;
  1838. ChannelBuyPrice = Convert.ToString(_currentGoods.AskPrice);
  1839. ChannelSellPrice = Convert.ToString(_currentGoods.BidPrice);
  1840. break;
  1841. case ChannelPriceMode.MarketPrice:
  1842. ChannelBuyPrice = "0";
  1843. ChannelSellPrice = "0";
  1844. ExecutePrice = 0;
  1845. break;
  1846. // 4、若价格选择为超价,
  1847. // 买入按钮上价格取卖价(卖一价)+配置的超价点数*行情最小变动单位*10^行情小数位,
  1848. // 卖出按钮上价格取买价(买一价)-配置的超价点数*行情最小变动单位*10^行情小数位,买卖价变动时价格需要跟着变动;
  1849. case ChannelPriceMode.SuperPrice:
  1850. double superPoint = SystemParamManager.getChannelSuperPoint;
  1851. var changeValue = superPoint * _currentGoods.QuoteMinUnit / Math.Pow(10, _currentGoods.DecimalPlaces);
  1852. ExecutePrice = Direction == Direction.Ask
  1853. ? _currentGoods.BidPrice == 0 ? 0 : (_currentGoods.BidPrice - (decimal)changeValue)
  1854. : _currentGoods.AskPrice == 0 ? 0 : (_currentGoods.AskPrice + (decimal)changeValue);
  1855. ChannelBuyPrice = Convert.ToString(_currentGoods.AskPrice == 0 ? 0 : (_currentGoods.AskPrice + (decimal)changeValue));
  1856. ChannelSellPrice = Convert.ToString(_currentGoods.BidPrice == 0 ? 0 : (_currentGoods.BidPrice - (decimal)changeValue));
  1857. break;
  1858. case ChannelPriceMode.LastestPrice:
  1859. ExecutePrice = _currentGoods.CurrentPrice;
  1860. ChannelBuyPrice = Convert.ToString(_currentGoods.CurrentPrice);
  1861. ChannelSellPrice = Convert.ToString(_currentGoods.CurrentPrice);
  1862. break;
  1863. case ChannelPriceMode.LimitPrice:
  1864. if (isUpdateLimitePrice)
  1865. {
  1866. ExecutePrice = Direction == Direction.Ask
  1867. ? _currentGoods.BidPrice
  1868. : _currentGoods.AskPrice;
  1869. }
  1870. ChannelBuyPrice = Convert.ToString(ExecutePrice);
  1871. ChannelSellPrice = Convert.ToString(ExecutePrice);
  1872. break;
  1873. default:
  1874. ExecutePrice = Direction == Direction.Ask
  1875. ? CurrentGoods.BidPrice
  1876. : CurrentGoods.AskPrice;
  1877. ChannelBuyPrice = Convert.ToString(_currentGoods.BidPrice);
  1878. ChannelSellPrice = Convert.ToString(_currentGoods.AskPrice);
  1879. break;
  1880. }
  1881. break;
  1882. default:
  1883. break;
  1884. }
  1885. }
  1886. else if (this.PriceMode == ePriceMode.PRICEMODE_MARKET)
  1887. {
  1888. switch (this._currentGoods.TradeMode)
  1889. {
  1890. case eTradeMode.TRADEMODE_MARKETMAKE:
  1891. ExecutePrice = _direction == Direction.Ask ? _currentGoods.AskPrice : _currentGoods.BidPrice;
  1892. break;
  1893. case eTradeMode.TRADEMODE_BIDDING:
  1894. case eTradeMode.TRADEMODE_BIDDINGMARKETMAKE:
  1895. case eTradeMode.TRADEMODE_ENTRUST_HEDGE:
  1896. //市价默认价格
  1897. ExecutePrice = 0;
  1898. ChannelBuyPrice = "0";
  1899. ChannelSellPrice = "0";
  1900. break;
  1901. }
  1902. }
  1903. }
  1904. /// <summary>
  1905. /// 设置默认下单数量,设置建仓平仓时使用
  1906. /// </summary>
  1907. protected void SetInitVaules()
  1908. {
  1909. // 需求 #29897客户端下单平仓的时候,默认不要全部卖出,可以默认卖出0手,需要修改后才可以进行平仓;[建仓平仓都按这个规则]
  1910. if ((OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE ||
  1911. (_currentGoods.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_PAY && Direction == Direction.Ask))) ///全部平仓
  1912. {
  1913. /*var currentAccount = UserManager.CurrentTradeAccount.FundsAccountId;// == 0 ? CacheManager.FundsAccountId : UserManager.CurrentTradeAccount.FundsAccountId;
  1914. if (currentAccount == 0) return;
  1915. TradePositionModel t = CacheManager.GetHoldingSummary(_currentGoods.GoodsId, currentAccount.ToString());
  1916. if (t == null)
  1917. {
  1918. Lot = MaxLot;
  1919. return;
  1920. }
  1921. var qty = Direction == Direction.Ask ? t.AvailableBuyHolderQty() : t.AvailableSellHolderQty();
  1922. Lot = qty;*/
  1923. Lot = MaxLot;
  1924. }
  1925. else
  1926. {
  1927. if (ApplicationParameter.DefaultOrderLot == 0)
  1928. {
  1929. Lot = MinLot;
  1930. }
  1931. else
  1932. {
  1933. Lot = ApplicationParameter.DefaultOrderLot; ////默认下单数量
  1934. }
  1935. }
  1936. }
  1937. #endregion
  1938. /// <summary>
  1939. /// 设置默认价格模式[读取数据库配置--设置]
  1940. /// </summary>
  1941. protected virtual void setDefaultPriceMode()
  1942. {
  1943. //所有商品默认为限价
  1944. PriceMode = ePriceMode.PRICEMODE_LIMIT;
  1945. }
  1946. public override void Cleanup()
  1947. {
  1948. base.Cleanup();
  1949. MessengerHelper.DefaultUnregister<TradeAccount>(this, MessengerTokens.HolderRefresh);
  1950. MessengerHelper.DefaultUnregister<string>(this, MessengerTokens.MoneyNoticeToken);
  1951. MessengerHelper.QuoteUnregister<List<QuoteGoods>>(this, MessengerTokens.ReceiveRealTimeQuote);
  1952. }
  1953. /// <summary>
  1954. /// 获取预埋单-可下最最大数量
  1955. /// </summary>
  1956. protected void GetPrePostOrderMaxQty()
  1957. {
  1958. ulong currentAccountId;
  1959. if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
  1960. {
  1961. currentAccountId = (uint)UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  1962. }
  1963. else
  1964. {
  1965. currentAccountId = UserManager.CurrentTradeAccount.AccountId;
  1966. }
  1967. _goodsService.QueryPrePostDetailQty(currentAccountId, QueryPreOrderParameterSuccess, ErrorPreOrderParameterCallBack);
  1968. }
  1969. /// <summary>
  1970. /// 委托单参数查询-成功返回
  1971. /// </summary>
  1972. /// <param name="itemList"></param>
  1973. protected void QueryPreOrderParameterSuccess(List<PreOrderParameter> itemList)
  1974. {
  1975. if (itemList != null)
  1976. {
  1977. MaxPreOrderLot = itemList.FirstOrDefault().maxPreOrderLot;
  1978. }
  1979. }
  1980. /// <summary>
  1981. /// 委托单参数查询-失败返回
  1982. /// </summary>
  1983. /// <param name="errorEntity"></param>
  1984. private void ErrorPreOrderParameterCallBack(ErrorEntity errorEntity)
  1985. {
  1986. IsBusy = false;
  1987. }
  1988. /// <summary>
  1989. /// 设置订单委托价格
  1990. /// </summary>
  1991. /// <param name="price"></param>
  1992. public void SetOrderPrice(decimal price)
  1993. {
  1994. if (PriceMode == ePriceMode.PRICEMODE_LIMIT)
  1995. {
  1996. if (price > 0)
  1997. {
  1998. ExecutePrice = price;
  1999. }
  2000. }
  2001. }
  2002. #region 通道交易相关属性及方法
  2003. /// <summary>
  2004. /// 是否通道交易模式
  2005. /// </summary>
  2006. public virtual bool IsVisibilityChannelTrade
  2007. {
  2008. get { return false; }
  2009. }
  2010. /// <summary>
  2011. /// 通道交易价格方式字典
  2012. /// </summary>
  2013. public Dictionary<ChannelPriceMode, string> ChannelPriceModeList
  2014. {
  2015. get
  2016. {
  2017. var dic1 = new Dictionary<ChannelPriceMode, string>
  2018. {
  2019. {ChannelPriceMode.LastestPrice, ChannelPriceMode.LastestPrice.Discription()},
  2020. {ChannelPriceMode.MatchPrice, ChannelPriceMode.MatchPrice.Discription()},
  2021. {ChannelPriceMode.MarketPrice, ChannelPriceMode.MarketPrice.Discription()},
  2022. {ChannelPriceMode.SuperPrice, ChannelPriceMode.SuperPrice.Discription()},
  2023. {ChannelPriceMode.LimitPrice, ChannelPriceMode.LimitPrice.Discription()},
  2024. };
  2025. var dic2 = new Dictionary<ChannelPriceMode, string> // 不支持市价
  2026. {
  2027. {ChannelPriceMode.LastestPrice, ChannelPriceMode.LastestPrice.Discription()},
  2028. {ChannelPriceMode.MatchPrice, ChannelPriceMode.MatchPrice.Discription()},
  2029. {ChannelPriceMode.SuperPrice, ChannelPriceMode.SuperPrice.Discription()},
  2030. {ChannelPriceMode.LimitPrice, ChannelPriceMode.LimitPrice.Discription()},
  2031. };
  2032. return ApplicationParameter.CanMarketPrice(CurrentGoods) ? dic1 : dic2;
  2033. }
  2034. }
  2035. private ChannelPriceMode _currentChannelPriceMode;
  2036. /// <summary>
  2037. /// 当前通道交易价格方式
  2038. /// </summary>
  2039. public ChannelPriceMode CurrentChannelPriceMode
  2040. {
  2041. get
  2042. {
  2043. return _currentChannelPriceMode;
  2044. }
  2045. set
  2046. {
  2047. Set(() => CurrentChannelPriceMode, ref _currentChannelPriceMode, value);
  2048. var priceMode = value == ChannelPriceMode.MarketPrice ? ePriceMode.PRICEMODE_MARKET : ePriceMode.PRICEMODE_LIMIT;
  2049. if ((int) priceMode == -1) return;
  2050. PriceMode = priceMode;
  2051. }
  2052. }
  2053. /// <summary>
  2054. /// 止盈止损价格类型
  2055. /// </summary>
  2056. /// <value>The channel price mode list.</value>
  2057. public Dictionary<ChannelPriceMode, string> ChannelSPSLPriceModeList
  2058. {
  2059. get
  2060. {
  2061. var dic = new Dictionary<ChannelPriceMode, string>
  2062. {
  2063. {ChannelPriceMode.LastestPrice, ChannelPriceMode.LastestPrice.Discription()},
  2064. {ChannelPriceMode.MatchPrice, ChannelPriceMode.MatchPrice.Discription()},
  2065. {ChannelPriceMode.SuperPrice, ChannelPriceMode.SuperPrice.Discription()},
  2066. {ChannelPriceMode.MarketPrice, ChannelPriceMode.MarketPrice.Discription()}
  2067. };
  2068. var dic1 = new Dictionary<ChannelPriceMode, string>
  2069. {
  2070. {ChannelPriceMode.LastestPrice, ChannelPriceMode.LastestPrice.Discription()},
  2071. {ChannelPriceMode.MatchPrice, ChannelPriceMode.MatchPrice.Discription()},
  2072. {ChannelPriceMode.SuperPrice, ChannelPriceMode.SuperPrice.Discription()}
  2073. };
  2074. return ApplicationParameter.CanMarketPrice(CurrentGoods) ? dic : dic1;
  2075. }
  2076. }
  2077. /// <summary>
  2078. /// 是否止盈止损
  2079. /// </summary>
  2080. /// <value><c>true</c> if this instance is SPSL model; otherwise, <c>false</c>.</value>
  2081. public virtual bool IsSPSLModel
  2082. {
  2083. get { return OrderModel == OrderModel.SPSL; }
  2084. }
  2085. /// <summary>
  2086. /// 是否正常下单
  2087. /// </summary>
  2088. /// <value><c>true</c> if this instance is normal model; otherwise, <c>false</c>.</value>
  2089. public virtual bool IsNormalModel
  2090. {
  2091. get { return OrderModel == OrderModel.Normal; }
  2092. }
  2093. private SPSLOrderType _currentSPSLOrderType;
  2094. /// <summary>
  2095. /// 止盈止损类型【止损单/止盈单/撤单】
  2096. /// </summary>
  2097. /// <value>The type of the current SPSL order.</value>
  2098. public SPSLOrderType CurrentSPSLOrderType
  2099. {
  2100. get
  2101. {
  2102. return _currentSPSLOrderType;
  2103. }
  2104. set
  2105. {
  2106. Set(() => CurrentSPSLOrderType, ref _currentSPSLOrderType, value);
  2107. RaisePropertyChanged(() => TriggerPriceMode);
  2108. UpdateSPSLPriceRange();
  2109. }
  2110. }
  2111. private string _holdAvgPriceDisplay;
  2112. /// <summary>
  2113. /// 持仓均价
  2114. /// </summary>
  2115. /// <value>The hold average price display.</value>
  2116. public string HoldAvgPriceDisplay
  2117. {
  2118. get
  2119. {
  2120. return _holdAvgPriceDisplay;
  2121. }
  2122. set
  2123. {
  2124. Set(() => HoldAvgPriceDisplay, ref _holdAvgPriceDisplay, value);
  2125. }
  2126. }
  2127. private string _directionDisplay;
  2128. /// <summary>
  2129. /// 止盈止损方向
  2130. /// </summary>
  2131. /// <value>The hold average price display.</value>
  2132. public string DirectionDisplay
  2133. {
  2134. get
  2135. {
  2136. return _directionDisplay;
  2137. }
  2138. set
  2139. {
  2140. Set(() => DirectionDisplay, ref _directionDisplay, value);
  2141. }
  2142. }
  2143. private string _holdTotalQtyDisplay;
  2144. /// <summary>
  2145. /// 持仓数量
  2146. /// </summary>
  2147. /// <value>The hold total qty display.</value>
  2148. public string HoldTotalQtyDisplay
  2149. {
  2150. get
  2151. {
  2152. return _holdTotalQtyDisplay;
  2153. }
  2154. set
  2155. {
  2156. Set(() => HoldTotalQtyDisplay, ref _holdTotalQtyDisplay, value);
  2157. }
  2158. }
  2159. /// <summary>
  2160. /// Gets the trigger price mode.
  2161. /// </summary>
  2162. /// <value>The trigger price mode.</value>
  2163. public string TriggerPriceMode
  2164. {
  2165. get
  2166. {
  2167. if (CurrentSPSLOrderType == SPSLOrderType.SPOrder) return "止盈价";
  2168. return "止损价";
  2169. }
  2170. }
  2171. protected decimal _spslTriggerPrice;
  2172. /// <summary>
  2173. /// 资管止盈止损触发价
  2174. /// </summary>
  2175. public virtual decimal SPSLTriggerPrice
  2176. {
  2177. get
  2178. {
  2179. return _spslTriggerPrice;
  2180. }
  2181. set
  2182. {
  2183. Set(() => SPSLTriggerPrice, ref _spslTriggerPrice, value);
  2184. }
  2185. }
  2186. protected decimal _spslTriggerMinPrice;
  2187. /// <summary>
  2188. /// 资管止盈止损触发价最小值
  2189. /// </summary>
  2190. public virtual decimal SPSLTriggerMinPrice
  2191. {
  2192. get
  2193. {
  2194. return _spslTriggerMinPrice;
  2195. }
  2196. set
  2197. {
  2198. Set(() => SPSLTriggerMinPrice, ref _spslTriggerMinPrice, value);
  2199. }
  2200. }
  2201. protected decimal _spslTriggerMaxPrice;
  2202. /// <summary>
  2203. /// 资管止盈止损触发价最小值
  2204. /// </summary>
  2205. public virtual decimal SPSLTriggerMaxPrice
  2206. {
  2207. get
  2208. {
  2209. return _spslTriggerMaxPrice;
  2210. }
  2211. set { Set(() => SPSLTriggerMaxPrice, ref _spslTriggerMaxPrice, value); }
  2212. }
  2213. /// <summary>
  2214. /// 更新止盈止损触发价范围
  2215. /// </summary>
  2216. private void UpdateSPSLPriceRange()
  2217. {
  2218. //持仓单方向为买——止盈价格需大于最新价,止损价格需要小于最新价;
  2219. if (this.Direction == Direction.Ask)
  2220. {
  2221. if (this.CurrentSPSLOrderType == SPSLOrderType.SPOrder)
  2222. {
  2223. SPSLTriggerMinPrice = CurrentGoods.CurrentPrice;
  2224. SPSLTriggerMaxPrice = decimal.MaxValue;
  2225. }else{
  2226. SPSLTriggerMinPrice = 0;
  2227. SPSLTriggerMaxPrice = CurrentGoods.CurrentPrice;
  2228. }
  2229. }
  2230. //持仓单方向为卖——止盈价格需小于最新价,止损价格需要大于最新价。
  2231. if (this.Direction == Direction.Bid)
  2232. {
  2233. if (this.CurrentSPSLOrderType == SPSLOrderType.SPOrder)
  2234. {
  2235. SPSLTriggerMinPrice = 0;
  2236. SPSLTriggerMaxPrice = CurrentGoods.CurrentPrice;
  2237. }
  2238. else
  2239. {
  2240. SPSLTriggerMinPrice = CurrentGoods.CurrentPrice;
  2241. SPSLTriggerMaxPrice = decimal.MaxValue;
  2242. }
  2243. }
  2244. SPSLTriggerPrice = CurrentGoods.CurrentPrice;
  2245. }
  2246. #endregion
  2247. #region 90705 因为止盈止损单由服务端触发,最好每次都取服务端的数据
  2248. /// <summary>
  2249. /// 下面四个是用于设置止盈价止损价的最大最小值
  2250. /// </summary>
  2251. private decimal _slMaxPrice;
  2252. private decimal _slMinPrice;
  2253. private decimal _spMaxPrice;
  2254. private decimal _spMinPrice;
  2255. /// <summary>
  2256. /// 止损的最大值
  2257. /// </summary>
  2258. public decimal SlMaxPrice
  2259. {
  2260. get { return _slMaxPrice; }
  2261. set { Set(() => SlMaxPrice, ref _slMaxPrice, value); }
  2262. }
  2263. /// <summary>
  2264. /// 止损的最小值
  2265. /// </summary>
  2266. public decimal SlMinPrice
  2267. {
  2268. get { return _slMinPrice; }
  2269. set { Set(() => SlMinPrice, ref _slMinPrice, value); }
  2270. }
  2271. /// <summary>
  2272. /// 止盈的最大值
  2273. /// </summary>
  2274. public decimal SpMaxPrice
  2275. {
  2276. get { return _spMaxPrice; }
  2277. set { Set(() => SpMaxPrice, ref _spMaxPrice, value); }
  2278. }
  2279. /// <summary>
  2280. /// 止盈的最小值
  2281. /// </summary>
  2282. public decimal SpMinPrice
  2283. {
  2284. get { return _spMinPrice; }
  2285. set { Set(() => SpMinPrice, ref _spMinPrice, value); }
  2286. }
  2287. /// <summary>
  2288. /// 根据买卖方向来锁定输入框的输入最大值最小值
  2289. /// </summary>
  2290. private void LockEditTextMaxMin()
  2291. {
  2292. //持仓单方向为买——止盈价格需大于最新价,止损价格需要小于最新价;
  2293. if (this.Direction == Direction.Ask) // 买持仓
  2294. {
  2295. SpMinPrice = /*CurrentGoods.CurrentPrice 别问我为什么不用这个了,因为没有办法做到,当设置成0的时候,控件自动设置为最小值,这样就影响到的判断*/0;
  2296. SpMaxPrice = decimal.MaxValue;
  2297. SlMinPrice = 0;
  2298. SlMaxPrice = /*CurrentGoods.CurrentPrice*/decimal.MaxValue;// 最大值也会有这样的问题,当输入数字的大于最大值,失去焦点后,这个值会恢复到空间的最大值。
  2299. }
  2300. //持仓单方向为卖——止盈价格需小于最新价,止损价格需要大于最新价。
  2301. if (this.Direction == Direction.Bid) // 卖持仓
  2302. {
  2303. SpMinPrice = 0;
  2304. SpMaxPrice = /*CurrentGoods.CurrentPrice*/decimal.MaxValue;
  2305. SlMinPrice = /*CurrentGoods.CurrentPrice*/0;
  2306. SlMaxPrice = decimal.MaxValue;
  2307. }
  2308. // 给输入框绑定默认值
  2309. SpPrice = (double)CurrentGoods.CurrentPrice;
  2310. SlPrice = (double)CurrentGoods.CurrentPrice;
  2311. }
  2312. #region 做设置止盈止损价时候,止盈止损价超出了价格范围时的提示
  2313. /// <summary>
  2314. /// 检测止盈价止损价输入是否合法
  2315. /// --此方法就有提示了,不需要再外面处理
  2316. /// </summary>
  2317. /// <returns>true 合法</returns>
  2318. public bool CheckProfitLoss()
  2319. {
  2320. if (OrderModel == OrderModel.SPSL)// 止盈止损的下单模式下,我才会处理,其他的模式都放过
  2321. {
  2322. if (!_canUseSpPrice && !_canUseSlPrice)
  2323. {
  2324. CheckTips(Client_Resource.Use_SpPrice_Or_SlPrice);
  2325. return false;
  2326. }
  2327. //买方向持仓止盈价格设置小于最新价时,提示“止盈价格必须高于该合约最新价,请重新设置”
  2328. //买方向持仓止损价格设置大于最新价时,提示“止损价格必须低于该合约最新价,请重新设置”
  2329. if (this.Direction == Direction.Ask) // 买持仓
  2330. {
  2331. if (_canUseSpPrice && SpPrice <= (double)CurrentGoods.CurrentPrice) // 买方向持仓止盈价格设置小于最新价时
  2332. {
  2333. // 提示“止盈价格必须高于该合约最新价,请重新设置”
  2334. CheckTips(Client_Resource.SpPrice_High_than_Last_Price);
  2335. return false;
  2336. }
  2337. else if (_canUseSlPrice && SlPrice >= (double)CurrentGoods.CurrentPrice) // 买方向持仓止损价格设置大于最新价时
  2338. {
  2339. // 提示“止损价格必须低于该合约最新价,请重新设置”
  2340. CheckTips(Client_Resource.SlPrice_Low_than_Last_Price);
  2341. return false;
  2342. }
  2343. }
  2344. // 卖方向持仓止盈价格设置大于最新价时,提示“止盈价格必须低于该合约最新价,请重新设置”
  2345. // 卖方向持仓止损价格设置小于最新价时,提示“止损价格必须高于该合约最新价,请重新设置”
  2346. else if (this.Direction == Direction.Bid) // 卖持仓
  2347. {
  2348. if (_canUseSpPrice && SpPrice >= (double)CurrentGoods.CurrentPrice) // 卖方向持仓止盈价格设置大于最新价时
  2349. {
  2350. // 提示“止盈价格必须低于该合约最新价,请重新设置”
  2351. CheckTips(Client_Resource.SpPrice_Low_than_Last_Price);
  2352. return false;
  2353. }
  2354. else if (_canUseSlPrice && SlPrice <= (double)CurrentGoods.CurrentPrice) // 卖方向持仓止损价格设置小于最新价时
  2355. {
  2356. //提示“止损价格必须高于该合约最新价,请重新设置”
  2357. CheckTips(Client_Resource.SlPrice_High_than_Last_Price);
  2358. return false;
  2359. }
  2360. }
  2361. }
  2362. return true;
  2363. }
  2364. /// <summary>
  2365. /// just show Question tips message
  2366. /// </summary>
  2367. /// <param name="tips"></param>
  2368. private void CheckTips(string tips)
  2369. {
  2370. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  2371. {
  2372. MessageBoxHelper.ShowQuestion(tips,
  2373. Client_Resource.DeliveryOrderView_WarningTipsTitle);
  2374. }));
  2375. }
  2376. #endregion
  2377. /// <summary>
  2378. /// 止盈价
  2379. /// </summary>
  2380. private double _spPrice;
  2381. public double SpPrice
  2382. {
  2383. get { return _spPrice; }
  2384. set { Set(() => SpPrice, ref _spPrice, value); }
  2385. }
  2386. private double _slPrice;
  2387. public double SlPrice
  2388. {
  2389. get { return _slPrice; }
  2390. set { Set(() => SlPrice, ref _slPrice, value); }
  2391. }
  2392. /// <summary>
  2393. /// 查询止盈止损单
  2394. /// </summary>
  2395. public void QuerySpslOrderByFundAccountId()
  2396. {
  2397. if (IsBusy) return;
  2398. IsBusy = true;
  2399. _commonQueryService.QuerySPSLOrder(UserManager.CurrentTradeAccount.FundsAccountId, (list =>
  2400. {
  2401. IsBusy = false;
  2402. _spslOrders = list;
  2403. CountSpslSetNum();
  2404. }), CancelErrorCallBack);
  2405. }
  2406. /// <summary>
  2407. /// 查询失败返回
  2408. /// </summary>
  2409. /// <param name="errorEntity"></param>
  2410. private void CancelErrorCallBack(ErrorEntity errorEntity)
  2411. {
  2412. IsBusy = false;
  2413. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  2414. {
  2415. ErrorManager.ShowReturnError(errorEntity, Client_Resource.UI2014_Tips, true);
  2416. }));
  2417. }
  2418. /// <summary>
  2419. /// 计算已经设置的止盈止损数量
  2420. /// </summary>
  2421. public void CountSpslSetNum()
  2422. {
  2423. decimal setNum = 0;// 已经设置的止盈止损的数量
  2424. if (_spslOrders != null)
  2425. {
  2426. Direction direction = Direction == Direction.Ask ? Direction.Bid : Direction.Ask;
  2427. _spslOrders.ForEach((model =>
  2428. {
  2429. //已经向需求确认过,如果止盈止损单中存在之前持仓未成交的单据时,得到的数量可能是大于当前的持仓数据,这个也没有关系。从数据上来说,该商品的相同方向上的待触发单据的数量确实是这么多。
  2430. if (model.GoodsId == _currentGoods.GoodsId &&
  2431. model.Status == SPSLOrderStatus.NotTrigger &&
  2432. direction == model.BuyOrSell)// 相同商品,待触发的状态,相同方向
  2433. {
  2434. setNum += model.OrderQty;
  2435. }
  2436. }));
  2437. }
  2438. HadSetEntrustNum = setNum;
  2439. }
  2440. /// <summary>
  2441. /// 已设止盈止损的数量-查询止盈止损单中现存的数量 #90705
  2442. /// 2. 增加显示已设置过多少数量(需要将已设置的止盈单、止损单、止盈止损单数量相加);
  2443. /// </summary>
  2444. private decimal _hadSetEntrustNum = 0;
  2445. public decimal HadSetEntrustNum
  2446. {
  2447. get { return _hadSetEntrustNum; }
  2448. set { Set(() => HadSetEntrustNum, ref _hadSetEntrustNum, value); }
  2449. }
  2450. /// <summary>
  2451. /// 是否启用止盈价
  2452. /// </summary>
  2453. private bool _canUseSpPrice;
  2454. /// <summary>
  2455. /// 是否启用止损价
  2456. /// </summary>
  2457. private bool _canUseSlPrice;
  2458. public bool CanUseSpPrice
  2459. {
  2460. get { return _canUseSpPrice; }
  2461. set { Set(() => CanUseSpPrice, ref _canUseSpPrice, value); }
  2462. }
  2463. public bool CanUseSlPrice
  2464. {
  2465. get { return _canUseSlPrice; }
  2466. set { Set(() => CanUseSlPrice, ref _canUseSlPrice, value); }
  2467. }
  2468. #endregion
  2469. #region 买卖按钮的颜色控制
  2470. private SolidColorBrush _buyBackGroundBrush = Brushes.Red;
  2471. public SolidColorBrush BuyBackGroundBrush
  2472. {
  2473. get { return _buyBackGroundBrush; }
  2474. set { Set(() => BuyBackGroundBrush, ref _buyBackGroundBrush, value); }
  2475. }
  2476. private SolidColorBrush _sellBackGroundBrush = Brushes.Green;
  2477. public SolidColorBrush SellBackGroundBrush
  2478. {
  2479. get { return _sellBackGroundBrush; }
  2480. set { Set(() => SellBackGroundBrush, ref _sellBackGroundBrush, value); }
  2481. }
  2482. /// <summary>
  2483. /// 在平仓时候,显示买卖方向就置灰,且不可以点击
  2484. /// </summary>
  2485. /// <param name="direction"></param>
  2486. public void ChangeBuySellBackground(Direction direction)
  2487. {
  2488. switch (direction)
  2489. {
  2490. case Direction.Ask:// 单据是卖方向的,那就将买方向的置灰,
  2491. {
  2492. SellBackGroundBrush = new SolidColorBrush(Color.FromRgb(100, 100, 100));
  2493. CanUseSell = false;
  2494. BuyBackGroundBrush = Brushes.Red;
  2495. CanUseBuy = true;
  2496. break;
  2497. }
  2498. case Direction.Bid:
  2499. {
  2500. SellBackGroundBrush = Brushes.Green;
  2501. CanUseSell = true;
  2502. BuyBackGroundBrush = new SolidColorBrush(Color.FromRgb(100, 100, 100));
  2503. CanUseBuy = false;
  2504. break;
  2505. }
  2506. default:// 买卖都可以用
  2507. {
  2508. SellBackGroundBrush = Brushes.Green;
  2509. CanUseSell = true;
  2510. BuyBackGroundBrush = Brushes.Red;
  2511. CanUseBuy = true;
  2512. break;
  2513. }
  2514. }
  2515. }
  2516. private bool _canUseBuy;
  2517. public bool CanUseBuy
  2518. {
  2519. get { return _canUseBuy; }
  2520. set { Set(() => CanUseBuy, ref _canUseBuy, value); }
  2521. }
  2522. private bool _canUseSell;
  2523. public bool CanUseSell
  2524. {
  2525. get { return _canUseSell; }
  2526. set { Set(() => CanUseSell, ref _canUseSell, value); }
  2527. }
  2528. #endregion
  2529. }
  2530. }