| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- //----------------------------------------------------------------
- //Module Name: $safeprojectname$
- //Purpose:
- //CopyRight: Muchinfo
- //History:
- //----------------------------------------------------------------
- //DateTime 2016/7/22 16:04:40
- //Author
- //Description Create
- //----------------------------------------------------------------
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input.StylusPlugIns;
- using System.Windows.Media;
- using GalaSoft.MvvmLight;
- using GalaSoft.MvvmLight.Command;
- using GalaSoft.MvvmLight.Ioc;
- using Muchinfo.MTPClient.Data;
- using Muchinfo.MTPClient.Data.Enums;
- using Muchinfo.MTPClient.Data.Helper;
- using Muchinfo.MTPClient.Data.Model;
- using Muchinfo.MTPClient.Data.Model.Account;
- using Muchinfo.MTPClient.Data.Model.GoodRules;
- using Muchinfo.MTPClient.Infrastructure.Cache;
- using Muchinfo.MTPClient.Infrastructure.Utilities;
- using Muchinfo.MTPClient.IService;
- using Muchinfo.MTPClient.Infrastructure.Helpers;
- using Muchinfo.MTPClient.Infrastructure.MessageBox;
- using Muchinfo.MTPClient.Resources;
- namespace Muchinfo.MTPClient.Trade.ViewModels
- {
- public class TradeBaseViewModel : ViewModelBase
- {
- protected const int defaut_minLot = 1;
- protected const int defaut_maxLot = 88;
- protected IOrderService _orderService;
- protected IGoodsService _goodsService;
- private bool _isfristInit; //是否第一次初始化
- protected QuoteGoods _currentGoods; //当前下单的商品
- private Direction _direction; ////买卖方向
- private OpenCloseMode _openCloseMode = OpenCloseMode.BUILDTYPE_OPEN; ////建仓平方式
- private eListingSelectType _listingSelectModel = eListingSelectType.LISTINGSELECTTYPE_LISTING; ////挂牌点选类型
- private eDelistingType _delistingModel = eDelistingType.DELISTINGTYPE_PRICE;//摘牌类型
- protected GoodsOrderMode _goodsOrderMode = GoodsOrderMode.Goods; ///平仓时按单还是商品
- private bool _isBusy;
- private ExpirationType _currentExpirationType = ExpirationType.Today; //有效期
- private OrderMethods _orderFlag; ////下单方式【正常单、预埋单】
- private OrderModel _orderModel = OrderModel.Normal;
- private string _channelBuyPrice = "";
- private string _channelSellPrice = "";
- private ICommonQueryService _commonQueryService;
- private List<SPSLOrderModel> _spslOrders;
- public virtual bool ShowOpenCloseOrder
- {
- get { return ApplicationParameter.ShowOpenCloseOrder; }
- }
- private void Init()
- {
- if (_commonQueryService == null)
- {
- _commonQueryService = SimpleIoc.Default.GetInstance<ICommonQueryService>();
- }
- }
- public TradeBaseViewModel(QuoteGoods goods, Direction direction)
- {
- _currentGoods = goods;
- _direction = direction;
- LockEditTextMaxMin();
- _orderService = SimpleIoc.Default.GetInstance<IOrderService>();
- _goodsService = SimpleIoc.Default.GetInstance<IGoodsService>();
- TriggerListingOrder();
- GetHoldDetails();
- SetInitVaules();
- Init();
- OpenCloseMode = (OpenCloseMode)ApplicationParameter.DefaultOpenMode;
- //所有商品默认为限价
- //PriceMode = ePriceMode.PRICEMODE_LIMIT;
- setDefaultPriceMode();
- //初始化多资金账号信息
- CurrentUserFundsList = CacheManager.CacheTAAcountList.Select(x => x.FundsAccounts.AccountId.ToString()).ToList();
- //UserManager.CurrentTradeAccount.FundsAccountId = 0;
- //单据成交时需重新计算委托数据
- MessengerHelper.DefaultRegister<TradeAccount>(this, MessengerTokens.HolderRefresh, (e) =>
- {
- GetHoldDetails();
- SetMinMaxQtyVaule();
- });
- ////资金变化计算数量
- MessengerHelper.DefaultRegister<string>(this, MessengerTokens.MoneyNoticeToken, (e) =>
- {
- GetHoldDetails();
- SetMinMaxQtyVaule();
- });
- MessengerHelper.DefaultRegister<string>(this, MessengerTokens.OrderChangeToRefeshTrade, (e) =>
- {
- OpenCloseMode = (OpenCloseMode) ApplicationParameter.DefaultOpenMode;
- });
- }
- /// <summary>
- /// 平仓ty
- /// </summary>
- /// <param name="goods"></param>
- /// <param name="orderBase"></param>
- public TradeBaseViewModel(QuoteGoods goods, OrderBase orderBase)
- : this(goods, orderBase.Direction == Direction.Ask ? Direction.Bid : Direction.Ask)
- {
- //初始化多资金账号信息
- CurrentUserFundsList = CacheManager.CacheTAAcountList.Select(x => x.FundsAccounts.AccountId.ToString()).ToList();
- RaisePropertyChanged(() => Direction);
- Init();
- //TriggerListingOrder();
- }
- /// <summary>
- /// 触发挂牌下单属性
- /// </summary>
- private void TriggerListingOrder()
- {
- //挂牌下单
- if (CacheManager.FromType == eOrderFormType.Listting)
- {
- FormType = eOrderFormType.Listting;
- }
- else
- {
- FormType = eOrderFormType.Commom;
- }
- }
- #region 是否忙
- /// <summary>
- /// 是否忙
- /// </summary>
- public bool IsBusy
- {
- get { return _isBusy; }
- set { Set(() => IsBusy, ref _isBusy, value); }
- }
- #endregion
- #region 是否是复杂下单
- private bool _isComplex;
- /// <summary>
- /// 是否是复杂下单
- /// </summary>
- public bool IsComplex
- {
- get { return _isComplex; }
- set { Set(() => IsComplex, ref _isComplex, value); }
- }
- #endregion
- #region 冻结头寸数量
- /// <summary>
- /// 冻结头寸数量
- /// </summary>
- private decimal _positionFzQty;
- /// <summary>
- /// 冻结头寸数量
- /// </summary>
- public decimal PositionFzQty
- {
- get { return _positionFzQty; }
- set { _positionFzQty = value; }
- }
- #endregion
- #region 持仓汇总
- /// <summary>
- /// 持仓汇总
- /// </summary>
- private decimal _totalHoldDetails;
- /// <summary>
- /// 持仓汇总
- /// </summary>
- /// <value>The total hold details.</value>
- public decimal TotalHoldDetails
- {
- get
- {
- return _totalHoldDetails;
- }
- set
- {
- Set(() => TotalHoldDetails, ref _totalHoldDetails, value);
- }
- }
- #endregion
- #region 可用持仓数量
- private decimal _availHoldQty = decimal.Zero;
- /// <summary>
- /// 可用持仓数量
- /// </summary>
- public decimal AvailHoldQty
- {
- get
- {
- return _availHoldQty;
- }
- set
- {
- Set(() => AvailHoldQty, ref _availHoldQty, value);
- }
- }
- #endregion
- #region 【10倍/20倍/30倍】保证金比例
- private MarginRate _marginRate = MarginRate.Margin10;
- /// <summary>
- /// 保证金比例
- /// </summary>
- public MarginRate MarginRate
- {
- get { return _marginRate; }
- set { Set(() => MarginRate, ref _marginRate, value); }
- }
- #endregion
- #region 【大于/小于/大于或等于/小于或等于】触发类型绑定
- private Dictionary<eTriggerType, string> _dicTriggerType;
- /// <summary>
- /// 触发类型绑定
- /// </summary>
- public Dictionary<eTriggerType, string> DicTriggerType
- {
- get
- {
- _dicTriggerType = new Dictionary<eTriggerType, string>();
- _dicTriggerType.Add(eTriggerType.TRIGGERTYPE_GREATER_OR_EQUAL, TriggerPriceType.GreaterThanOrEqual.Discription());
- _dicTriggerType.Add(eTriggerType.TRIGGERTYPE_LESS_OR_EQUAL, TriggerPriceType.LessThanOrEqual.Discription());
- _dicTriggerType.Add(eTriggerType.TRIGGERTYPE_LESS, TriggerPriceType.LessThan.Discription());
- _dicTriggerType.Add(eTriggerType.TRIGGERTYPE_GREATER, TriggerPriceType.GreaterThan.Discription());
- return _dicTriggerType;
- }
- }
- #endregion
- #region 【买人/卖出】买卖方向
- /// <summary>
- /// 买卖方向
- /// </summary>
- public Direction Direction
- {
- get
- {
- return _direction;
- }
- set
- {
- if (value == Direction.unSet)
- {
- return;
- }
- Set(() => Direction, ref _direction, value);
- CheckedVisibleEnable();
- SetMinMaxQtyVaule(); //设置数量
- GetHoldDetails();
- DefautEntrustPrice(this.CurrentChannelPriceMode != ChannelPriceMode.LimitPrice);//设置默认值
- SetSellCloseBuyOpen();
- }
- }
- #endregion
- #region 是否支持预埋单选项
- //private bool _isEnableByPrePostOrder = false;
- ///// <summary>
- ///// Sets and gets the IsEnableByPrePostOrder property.
- ///// Changes to that property's value raise the PropertyChanged event.
- ///// </summary>
- //public bool IsEnableByPrePostOrder
- //{
- // get
- // {
- // return _isEnableByPrePostOrder;
- // }
- // set
- // {
- // Set(() => IsEnableByPrePostOrder, ref _isEnableByPrePostOrder, value);
- // }
- //}
- public virtual bool IsEnableByPrePostOrder
- {
- get { return true; }
- }
- #endregion
- #region 【正常单/预埋单】下单方式
- /// <summary>
- /// 下单方式
- /// </summary>
- public OrderMethods OrderFlag
- {
- get
- {
- return _orderFlag;
- }
- set
- {
- if (value == OrderMethods.unSelect)
- {
- return;
- }
- Set(() => OrderFlag, ref _orderFlag, value);
- }
- }
- #endregion
- #region 正常下\SPSL下单
- /// <summary>
- /// Gets or sets the order model.
- /// </summary>
- /// <value>The order model.</value>
- public OrderModel OrderModel
- {
- get
- {
- return _orderModel;
- }
- set
- {
- Set(() => OrderModel, ref _orderModel, value);
- RaisePropertyChanged(() => IsSPSLModel);
- RaisePropertyChanged(() => IsNormalModel);
- }
- }
- #endregion
- //===============挂牌下单属性↓=======================
- #region 挂牌点选类型
- /// <summary>
- /// 挂牌点选类型
- /// </summary>
- public eListingSelectType ListingSelectModel
- {
- get
- {
- return _listingSelectModel;
- }
- set
- {
- Set(() => ListingSelectModel, ref _listingSelectModel, value);
- RaisePropertyChanged(() => IsVisibility_DelistingModel);
- RaisePropertyChanged(() => IsExecutePriceVbs);
- RaisePropertyChanged(() => IsVisibility_ListingInfo);
- RaisePropertyChanged(() => IsExecutePrice);
- //RaisePropertyChanged(() => Lot);
- RaisePropertyChanged(() => IsEnableChangeLot);
- RaisePropertyChanged(() => IsVisibility_ListingSelect);
- ResetDelistingModel();
- }
- }
- #endregion
- /// <summary>
- /// 重置摘牌类型
- /// </summary>
- public void ResetDelistingModel()
- {
- if (ListingSelectModel != eListingSelectType.LISTINGSELECTTYPE_LISTING)
- {
- DelistingModel = eDelistingType.DELISTINGTYPE_PRICE;
- RaisePropertyChanged(() => DelistingModel);
- }
- }
- #region 摘牌类型
- /// <summary>
- /// 摘牌类型
- /// </summary>
- public eDelistingType DelistingModel
- {
- get
- {
- if (_delistingModel != eDelistingType.DELISTINGTYPE_SELECTED)
- {
- _delistingModel = eDelistingType.DELISTINGTYPE_PRICE;
- }
- return _delistingModel;
- }
- set
- {
- Set(() => DelistingModel, ref _delistingModel, value);
- RaisePropertyChanged(() => IsExecutePriceVbs);
- RaisePropertyChanged(() => IsVisibility_ListingInfo);
- RaisePropertyChanged(() => IsExecutePrice);
- RaisePropertyChanged(() => IsEnableChangeLot);
- // RaisePropertyChanged(() => Lot);
- }
- }
- #endregion
- #region 下单类型。普通下单/摘牌下单
- private eOrderFormType _formType = eOrderFormType.Commom;
- /// <summary>
- /// 下单类型。普通下单/摘牌下单
- /// </summary>
- public eOrderFormType FormType
- {
- get
- {
- return _formType;
- }
- set
- {
- Set(() => FormType, ref _formType, value);
- IsVisibility_Listing = Visibility.Collapsed;
- if (CurrentGoods.TradeMode == eTradeMode.TRADEMODE_LISTING_SELECT)
- {
- IsVisibility_Listing = Visibility.Visible;
- }
- else
- {
- IsVisibility_Listing = Visibility.Collapsed;
- }
- }
- }
- #endregion
- #region 摘牌下单是否可见
- private Visibility _isVisibility_Listing = Visibility.Collapsed;
- /// <summary>
- /// 摘牌下单是否可见
- /// </summary>
- public Visibility IsVisibility_Listing
- {
- get
- {
- return _isVisibility_Listing;
- }
- set
- {
- Set(() => IsVisibility_Listing, ref _isVisibility_Listing, value);
- }
- }
- #endregion
- #region 摘牌委托单号=》来自点选数据
- private string _orderIdListing = CacheManager.OrderId_Listing.ToString();
- /// <summary>
- /// 摘牌委托单号=》来自点选数据
- /// </summary>
- public string OrderId_Listing
- {
- get
- {
- return _orderIdListing;
- }
- set
- {
- Set(() => OrderId_Listing, ref _orderIdListing, value);
- }
- }
- #endregion
- #region 摘牌委托价格=》来自点选数据
- private string _orderPrice_Listing = CacheManager.OrderPrice_Listing.ToString();
- /// <summary>
- /// 摘牌委托价格=》来自点选数据
- /// </summary>
- public string OrderPrice_Listing
- {
- get
- {
- return _orderPrice_Listing;
- }
- set
- {
- Set(() => OrderPrice_Listing, ref _orderPrice_Listing, value);
- }
- }
- #endregion
- #region 是否显示摘牌单据信息
- private Visibility _isVisibility_ListingInfo = Visibility.Collapsed;
- /// <summary>
- /// 是否显示摘牌单据信息
- /// </summary>
- public Visibility IsVisibility_ListingInfo
- {
- get
- {
- if (CacheManager.FromType == eOrderFormType.Listting && CacheManager.OrderId_Listing != 0
- && ListingSelectModel == eListingSelectType.LISTINGSELECTTYPE_DELISTING && DelistingModel == eDelistingType.DELISTINGTYPE_SELECTED)
- {
- return Visibility.Visible;
- }
- return _isVisibility_ListingInfo;
- }
- set
- {
- Set(() => IsVisibility_ListingInfo, ref _isVisibility_ListingInfo, value);
- }
- }
- #endregion
- //===============挂牌下单属性↑=======================
- #region 【建仓/平仓/先平后建/取消订单】建平仓方式
- /// <summary>
- /// 建平仓方式
- /// </summary>
- public OpenCloseMode OpenCloseMode
- {
- get
- {
- if (_openCloseMode != OpenCloseMode.BUILDTYPE_CLOSE && _openCloseMode != OpenCloseMode.BUILDTYPE_OPEN && _openCloseMode != OpenCloseMode.BUILDTYPE_CLOSETHENOPEN)// 完全不考虑拓展的吗?我现在加了一个BUILDTYPE_CLOSETHENOPEN,怎么办?
- {
- _openCloseMode = OpenCloseMode.BUILDTYPE_OPEN;
- }
- return _openCloseMode;
- }
- set
- {
- var needInit = value != _openCloseMode && (_openCloseMode == OpenCloseMode.BUILDTYPE_CLOSE || value == OpenCloseMode.BUILDTYPE_CLOSE);
- Set(() => OpenCloseMode, ref _openCloseMode, value);
- /* // 90663需求
- if (_openCloseMode == OpenCloseMode.BUILDTYPE_CLOSETHENOPEN) // 如果现在选择的自动开平,那就存一个标志位
- {
- ApplicationParameter.DefaultOpenMode = (int) OpenCloseMode.BUILDTYPE_CLOSETHENOPEN;
- }
- else
- {
- ApplicationParameter.DefaultOpenMode = (int)OpenCloseMode.BUILDTYPE_OPEN;
- }
- */
- CheckedVisibleEnable();
- SetMinMaxQtyVaule(); //设置数量
- SetEntrustPriceRange();
- if (needInit)
- {
- SetInitVaules();
- }
- ChangeBuySellBackground(Direction.unSet);
- }
- }
- /// <summary>
- /// 点击openCloseradio Button按钮触发的事件,和枚举绑定不同的事件,必须是由手动点击触发的事件
- /// </summary>
- public RelayCommand<Int16> SelectOpenCloseCommand
- {
- get
- {
- return new RelayCommand<Int16>(i =>
- {
- if (i == 3)
- {
- ApplicationParameter.DefaultOpenMode = (int) OpenCloseMode.BUILDTYPE_CLOSETHENOPEN;
- }
- else
- {
- ApplicationParameter.DefaultOpenMode = (int)OpenCloseMode.BUILDTYPE_OPEN;
- }
- });
- }
- }
- #endregion
- #region 【市价/限价】取价方式
- protected ePriceMode _priceMode;
- /// <summary>
- /// 取价方式
- /// </summary>
- public virtual ePriceMode PriceMode
- {
- get
- {
- return _priceMode;
- }
- set
- {
- if ((int)value == -1) return;
- Set(() => PriceMode, ref _priceMode, value);
- DefautEntrustPrice();
- CheckedVisibleEnable();
- SetMinMaxQtyVaule(); //设置数量
- }
- }
- #endregion
- #region 【按商品/按单】平仓方式
- /// <summary>
- /// 平仓方式
- /// </summary>
- public virtual GoodsOrderMode GoodsOrderMode
- {
- get { return _goodsOrderMode; }
- set
- {
- if (value == GoodsOrderMode.unSet)
- {
- return;
- }
- var needInit = value != _goodsOrderMode;
- Set(() => GoodsOrderMode, ref _goodsOrderMode, value);
- SetMinMaxQtyVaule(); //设置数量
- if (needInit)
- {
- SetInitVaules();
- }
- }
- }
- #endregion
- #region 委托价格
- protected decimal _executePrice;
- /// <summary>
- /// 委托价格
- /// </summary>
- public virtual decimal ExecutePrice
- {
- get
- {
- return _executePrice;
- }
- set
- {
- Set(() => ExecutePrice, ref _executePrice, value);
- if(OrderModel == OrderModel.Normal) SetMinMaxQtyVaule();
- ChannelBuyPrice = Convert.ToString(value);
- ChannelSellPrice = Convert.ToString(value);
- }
- }
- #endregion
- #region 当前选择触发价格类型
- private eTriggerType _currentTriggerType = eTriggerType.TRIGGERTYPE_GREATER_OR_EQUAL;
- /// <summary>
- /// Sets and gets the 当前选择触发价格类型 property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public eTriggerType CurrentTirrgerType
- {
- get
- {
- return _currentTriggerType;
- }
- set
- {
- Set(() => CurrentTirrgerType, ref _currentTriggerType, value);
- }
- }
- #endregion
- #region 合约单位名称枚举
- /// <summary>
- /// 合约单位名称枚举
- /// </summary>
- public string AgreeUnitType
- {
- get
- {
- if (_currentGoods == null)
- {
- return string.Empty;
- }
- var goodsUnit = CacheManager.TradeGoodsUnit.FirstOrDefault((x) => x.UNITID == _currentGoods.GoodsParameters.AgreeUnitType);
- if (goodsUnit != null)
- {
- return goodsUnit.GOODSUNITNAME;
- }
- return string.Empty;
- }
- }
- #endregion
- #region 触发价格
- private decimal _triggerPrice = 0;
- /// <summary>
- /// Sets and gets the 触发价格 property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public decimal TriggerPrice
- {
- get
- {
- return _triggerPrice;
- }
- set
- {
- Set(() => TriggerPrice, ref _triggerPrice, value);
- }
- }
- #endregion
- #region 【置灰】设置按键不可用
- private bool _oKButtonEnabled = true;
- /// <summary>
- ///设置按键不可用IsBidAskVsb
- /// </summary>
- public bool OKButtonEnabled
- {
- get
- {
- return _oKButtonEnabled;
- }
- set
- {
- Set(() => OKButtonEnabled, ref _oKButtonEnabled, value);
- }
- }
- #endregion
- #region 【置灰】是否可平仓
-
- /// <summary>
- /// 是否可平仓
- /// </summary>
- public virtual bool IsCloseEnable
- {
- get
- {
- var buyOrSell = Direction == Direction.Ask ? Direction.Bid : Direction.Ask;
- //查询是否有反方向持仓
- var hasHoldSummary = UserManager.HasGoodsHoldSummary(UserManager.CurrentTradeAccount.AccountId, buyOrSell,
- _currentGoods.GoodsId);
-
- //var holdersNum = CacheManager.GetGoodsPositionAvailableQty(dirction, _currentGoods.GoodsId, CurrentGoods.TradeProperty);
- //if (holdersNum > 0)
- //{
- // _isCloseEnable = true;
- //}
- return hasHoldSummary && ApplicationParameter.ShowCloseOrder;
- //return true;
- }
- }
- #endregion
- #region 【当日有效/本周有效】过期类型
- /// <summary>
- /// Sets and gets the 过期类型 property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public ExpirationType CurrentExpirationType
- {
- get
- {
- return _currentExpirationType;
- }
- set
- {
- Set(() => CurrentExpirationType, ref _currentExpirationType, value);
- }
- }
- #endregion
- #region 最大数量
- private decimal _maxLot;
- /// <summary>
- /// 最大数量
- /// </summary>
- public decimal MaxLot
- {
- get { return _maxLot; }
- set { Set(() => MaxLot, ref _maxLot, value); }
- }
- #endregion
- #region 最小数量
- private decimal _minLot;
- /// <summary>
- /// 最小数量
- /// </summary>
- public decimal MinLot
- {
- get { return _minLot; }
- set { Set(() => MinLot, ref _minLot, value); }
- }
- #endregion
- #region 最大限制数量
- private decimal _limitMaxLot = Int32.MaxValue;
- /// <summary>
- /// 最大限制数量
- /// </summary>
- public decimal LimitMaxLot
- {
- get { return _limitMaxLot; }
- set { Set(() => LimitMaxLot, ref _limitMaxLot, value); }
- }
- #endregion
- #region 最大预埋单数量
- private decimal _maxPreOrderLot = decimal.Zero;
- /// <summary>
- /// 最大预埋单数量
- /// </summary>
- public decimal MaxPreOrderLot
- {
- get { return _maxPreOrderLot; }
- set { Set(() => MaxPreOrderLot, ref _maxPreOrderLot, value); }
- }
- #endregion
- #region 最大买持仓量
- private decimal _maxHolderBuyLot;
- /// <summary>
- /// 最大买持仓量
- /// </summary>
- public decimal MaxHolderBuyLot
- {
- get { return _maxHolderBuyLot; }
- set { Set(() => MaxHolderBuyLot, ref _maxHolderBuyLot, value); }
- }
- #endregion
- #region 最大卖持仓量
- private decimal _maxHolderSellLot;
- /// <summary>
- /// 最大卖持仓量
- /// </summary>
- public decimal MaxHolderSellLot
- {
- get { return _maxHolderSellLot; }
- set { Set(() => MaxHolderSellLot, ref _maxHolderSellLot, value); }
- }
- #endregion
- #region 最大持仓量
- private decimal _maxHolderLot;
- /// <summary>
- /// 最大卖仓量
- /// </summary>
- public decimal MaxHolderLot
- {
- get { return _maxHolderLot; }
- set { Set(() => MaxHolderLot, ref _maxHolderLot, value); }
- }
- #endregion
- #region 数量
- private decimal _lot = decimal.Zero;
- /// <summary>
- /// 数量
- /// </summary>
- public decimal Lot
- {
- get
- {
- //#region 挂牌下单属性赋值=》数量
- //if (CacheManager.FromType == eOrderFormType.Listting && CacheManager.OrderId_Listing != 0)
- //{
- // if (ListingSelectModel == eListingSelectType.LISTINGSELECTTYPE_DELISTING && DelistingModel == eDelistingType.DELISTINGTYPE_SELECTED)
- // {
- // return CacheManager.OrderLot_Listing;
- // }
- //}
- //#endregion
- return _lot;
- }
- set
- {
- Set(() => Lot, ref _lot, value);
- RaisePropertyChanged(() => RelationNum);
- }
- }
- /// <summary>
- /// 单位
- /// </summary>
- public string RelationNum
- {
- get
- {
- if (_currentGoods != null)
- {
- return (_currentGoods.GoodsParameters.AgreeUnit * _lot).ToString();
- }
- else
- {
- return "-";
- }
- }
- }
- #endregion
- #region 价格格式化
- /// <summary>
- /// 价格格式化
- /// </summary>
- public string PriceFormat
- {
- get
- {
- if (this._currentGoods != null)
- {
- return _currentGoods.FormatPrice;
- }
- else
- {
- return "F0";
- }
- }
- }
- #endregion
- #region MyRegion小数位数据
- /// <summary>
- ///
- /// </summary>
- public int DecimalCount
- {
- get { return _currentGoods.GoodsParameters.HqExchFigures; }
- }
- #endregion
- #region 可输入小数位数
- /// <summary>
- /// 可输入小数位数
- /// </summary>
- public decimal PriceMinUnit
- {
- get
- {
- int temp = 0;
- uint quoteMinUnit = 1;
- if (this._currentGoods != null && this._currentGoods.GoodsParameters != null)
- {
- //temp = _currentGoods.GoodsParameters.HqExchFigures;
- temp = _currentGoods.DecimalPlaces;
- quoteMinUnit = _currentGoods.QuoteMinUnit;
- }
- //return Convert.ToDecimal(1 / Math.Pow(10, temp));
- return Convert.ToDecimal(quoteMinUnit / Math.Pow(10, temp));
- }
- }
- #endregion
- #region 当前商品的持仓单
- private List<HoldingOrder> _holdDetails;
- /// <summary>
- /// 当前商品的持仓单
- /// </summary>
- public List<HoldingOrder> HoldDetails
- {
- get { return _holdDetails; }
- set
- {
- Set(() => HoldDetails, ref _holdDetails, value);
- CheckedVisibleEnable();
- }
- }
- #endregion
- #region 当前持仓明细表
- private HoldingOrder _selectOrder;
- /// <summary>
- /// 当前持仓明细表商品
- /// </summary>
- public HoldingOrder SelectOrder
- {
- get { return _selectOrder; }
- set
- {
- Set(() => SelectOrder, ref _selectOrder, value);
- SetMinMaxQtyVaule();
- CheckedVisibleEnable();
- // SetInitVaules();
- }
- }
- #endregion
- #region 最小偏移
- private decimal _minUsedMargin;
- /// <summary>
- /// 最小偏移
- /// </summary>
- public decimal MinUsedMargin
- {
- get { return _minUsedMargin; }
- set { Set(() => MinUsedMargin, ref _minUsedMargin, value); }
- }
- #endregion
- #region 标题
- public virtual string SellTitle
- {
- get
- {
- return Muchinfo.MTPClient.Resources.Client_Resource.Order_OTC_Sell;
- }
- }
- public virtual string BuyTitle
- {
- get
- {
- return Muchinfo.MTPClient.Resources.Client_Resource.Order_OTC_Buy;
- }
- }
- private string _winTitle;
- /// <summary>
- /// 标题
- /// </summary>
- public string WinTitle
- {
- get
- {
- if (OrderModel == OrderModel.SPSL) return "止盈止损";
- return Muchinfo.MTPClient.Resources.Client_Resource.Order_Entruct_Titile + (Direction == Direction.Ask ? SellTitle : BuyTitle);
- }
- }
- #endregion
- #region 当前选择商品/所属市场【[混合]竞价/即期/竞价全额】
- /// <summary>
- /// 当前选择商品
- /// </summary>
- public QuoteGoods CurrentGoods
- {
- get { return _currentGoods; }
- }
- #endregion
- #region 界面项目是否显示控制 默认根据类型,如需修改刚重写
- /// <summary>
- /// 是否显示价格类型可见 默认显示
- /// </summary>
- public virtual bool IsPriceModeVisible
- {
- get { return true; }
- }
- /// <summary>
- /// 是否可显示允许点差 默认不显示
- /// </summary>
- public virtual bool IsAllowPipsVsb
- {
- get { return false; }
- }
- private bool _isStopPLVsb;
- /// <summary>
- /// 是否显示止盈止损可见 默认不显示
- /// </summary>
- public virtual bool IsStopPLVsb
- {
- get { return false; }
- }
- /// <summary>
- /// 是否有效期可见 默认不显示
- /// </summary>
- public virtual bool IsExpirationVsb
- {
- get { return false; }
- }
- /// <summary>
- /// 触发类型是否可显示 默认不显示
- /// </summary>
- public virtual bool IsTriggerTypeVsb
- {
- get { return false; }
- }
- /// <summary>
- /// 是否可显示人价格范围 默认不显示
- /// </summary>
- public virtual bool IsPriceRangeVsb
- {
- get { return false; }
- }
- /// <summary>
- /// 是否显示买卖五档
- /// </summary>
- public virtual bool IsBidQueueVsb
- {
- get { return false; }
- }
- /// <summary>
- /// 是否显示买卖价
- /// </summary>
- public virtual bool IsBidAskVsb
- {
- get { return false; }
- }
- /// <summary>
- /// 是否可按单平 (不可按单平)
- /// </summary>
- public virtual bool IsCanOrderEdit
- {
- get
- {
- return true;// OpenCloseMode != OpenCloseMode.BUILDTYPE_CLOSETHENOPEN;
- }
- }
- /// <summary>
- /// 平仓是否可见
- /// </summary>
- public virtual bool IsCloseTypeVsb
- {
- get
- {
- return OpenCloseMode != OpenCloseMode.BUILDTYPE_OPEN;
- }
- }
- /// <summary>
- /// 是否卖选项可见
- /// </summary>
- public virtual bool IsSellVsb
- {
- get
- {
- return true;
- }
- }
- /// <summary>
- /// 是否可卖出
- /// </summary>
- public virtual bool IsSellEnable
- {
- get
- {
- return true;
- }
- }
- /// <summary>
- /// 是否可买入
- /// </summary>
- public virtual bool IsBuyEnable
- {
- get
- {
- return true;
- }
- }
- /// <summary>
- /// 是否最大可下单数量
- /// </summary>
- public virtual bool IsLotMaxVsb
- {
- get
- {
- if (OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE)
- {
- return true;
- }
- return false;
- }
- }
- /// <summary>
- /// 是否显示-建仓,平仓,先平后建
- /// </summary>
- public virtual bool IsOpenCloseVisible
- {
- get
- {
- return true;//_currentGoods!=null&&_currentGoods.GoodsParameters.MoneyMode==eMoneyMode.MONEYMODE_MARGIN;
- }
- }
- public virtual string IsOpenCloseVisibleMargin
- {
- get
- {
- return IsOpenCloseVisible == true ? "0,0,0,0" : "0,25,0,0";
- }
- }
- /// <summary>
- /// 多资金与单资金布局变化
- /// </summary>
- public string ShowMultUserFundsMargin
- {
- get
- {
- return IsShowUserMultFundsList == Visibility.Visible ? "25,0,0,0" : "0,0,0,0";
- }
- }
- /// <summary>
- /// 是否显示高级下单
- /// </summary>
- public virtual bool IsOrderOptionVisible
- {
- get
- {
- return _currentGoods != null && _currentGoods.TradeMode != eTradeMode.TRADEMODE_SALE;
- }
- }
- #region 价格是否可编辑
- /// <summary>
- /// 价格是否可编辑
- /// </summary>
- public virtual bool IsExecutePrice
- {
- get { return this.PriceMode == ePriceMode.PRICEMODE_LIMIT && this.CurrentChannelPriceMode == ChannelPriceMode.LimitPrice; }
- }
- #endregion
- #region 渠道交易时候买入、卖出的价格
- public virtual string ChannelBuyPrice
- {
- get
- {
- return (_channelBuyPrice.Equals("") || Convert.ToDouble(_channelBuyPrice) == 0) ? "--" : _channelBuyPrice;
- }
- set
- {
- Set(() => ChannelBuyPrice, ref _channelBuyPrice, value);
- }
- }
- public virtual string ChannelSellPrice
- {
- get { return (_channelSellPrice.Equals("") || Convert.ToDouble(_channelSellPrice) == 0) ? "--" : _channelSellPrice; }
- set
- {
- Set(() => ChannelSellPrice, ref _channelSellPrice, value);
- }
- }
- #endregion
- /// <summary>
- /// 是否可限价平
- /// </summary>
- public virtual bool IsLimitPriceEnable
- {
- get { return true; }
- }
- /// <summary>
- /// 是否显示价格项
- /// </summary>
- public virtual bool IsExecutePriceVbs
- {
- //this.OpenCloseMode != OpenCloseMode.BUILDTYPE_CLOSE;
- get { return PriceMode != ePriceMode.PRICEMODE_MARKET; }
- }
- public virtual string IsExecutePriceVbsMargin
- {
- get { return IsExecutePriceVbs == true ? "0,0,0,0" : "0,0,0,35"; }
- }
- /// <summary>
- /// 先平后建是否可用
- /// </summary>
- public virtual bool IsOpenCloseEdit
- {
- //this.OpenCloseMode != OpenCloseMode.BUILDTYPE_CLOSE;
- get { return true; }
- }
- /// <summary>
- /// 是否可以选择建仓-默认可选
- /// </summary>
- public virtual bool IsEnableSelectOpenMode
- {
- get
- {
- return true;
- }
- }
- /// <summary>
- /// 是否可以修改数量-默认可修改
- /// </summary>
- public virtual bool IsEnableChangeLot
- {
- get
- {
- return true;
- }
- }
- /// <summary>
- /// 是否可按商品平仓 (不可按商品平仓)
- /// </summary>
- public virtual bool IsCanGoodsEdit
- {
- get
- {
- return true;
- }
- }
- /// <summary>
- /// 是否显示先平后建
- /// </summary>
- public virtual bool IsCloseOpenVbs
- {
- get
- {
- return true;
- }
- }
- /// <summary>
- /// 建仓是否显示
- /// </summary>
- public virtual bool IsOpenVbs
- {
- get { return true; }
- }
- /// <summary>
- /// 检查显示内容或可编辑
- /// </summary>
- public virtual void CheckedVisibleEnable()
- {
- RaisePropertyChanged(() => IsPriceModeVisible);
- RaisePropertyChanged(() => IsExecutePrice);
- RaisePropertyChanged(() => IsBidAskVsb);
- RaisePropertyChanged(() => IsBidQueueVsb);
- RaisePropertyChanged(() => IsPriceRangeVsb);
- RaisePropertyChanged(() => IsTriggerTypeVsb);
- RaisePropertyChanged(() => IsExpirationVsb);
- RaisePropertyChanged(() => IsStopPLVsb);
- RaisePropertyChanged(() => IsAllowPipsVsb);
- RaisePropertyChanged(() => WinTitle);
- RaisePropertyChanged(() => IsCanOrderEdit);
- RaisePropertyChanged(() => IsCloseEnable);
- RaisePropertyChanged(() => IsBuyEnable);
- RaisePropertyChanged(() => IsSellEnable);
- RaisePropertyChanged(() => IsSellVsb);
- RaisePropertyChanged(() => IsOpenCloseVisible);
- RaisePropertyChanged(() => IsOpenCloseVisibleMargin);
- RaisePropertyChanged(() => IsOrderOptionVisible);
- RaisePropertyChanged(() => BuyTitle);
- RaisePropertyChanged(() => IsCloseTypeVsb);
- RaisePropertyChanged(() => IsEnableByPrePostOrder);
- RaisePropertyChanged(() => IsExecutePriceVbs);
- RaisePropertyChanged(() => IsExecutePriceVbsMargin);
- RaisePropertyChanged(() => IsCanGoodsEdit);
- RaisePropertyChanged(() => IsLimitPriceEnable);
- RaisePropertyChanged(() => IsEnableSelectOpenMode);
- RaisePropertyChanged(() => IsOpenCloseEdit);
- RaisePropertyChanged(() => IsEnableChangeLot);
- RaisePropertyChanged(() => IsCloseOpenVbs);
- RaisePropertyChanged(() => IsOpenVbs);
- RaisePropertyChanged(() => IsShowRaiseFall);
- RaisePropertyChanged(() => IsPrePostVisible);
- RaisePropertyChanged(() => IsMarketPriceVisibity);
- RaisePropertyChanged(() => IsVisibility_ListingSelect);
- RaisePropertyChanged(() => IsLotMaxVsb);
- RaisePropertyChanged(() => IsVisibility_DelistingModel);
- }
- #endregion
- #region 当前登录用户多资金信息列表
- private List<string> _currentUserFundsList = null;
- /// <summary>
- /// 当前登录用户多资金信息列表
- /// </summary>
- public List<string> CurrentUserFundsList
- {
- get
- {
- return _currentUserFundsList;
- }
- set
- {
- Set(() => CurrentUserFundsList, ref _currentUserFundsList, value);
- if (CurrentUserFundsList != null && CurrentUserFundsList.Count() > 1)
- {
- IsShowUserMultFundsList = Visibility.Visible;//显示多资金账号列表
- _currentUserFundsList.Insert(0, "请选择资金账户");
- UserManager.CurrentTradeAccount.FundsAccountId = 0;
- }
- else
- {
- _currentSelectedFunds = CurrentUserFundsList.First(); //单资金账号 默认选择第一个
- if (!_currentSelectedFunds.Contains("请"))
- {
- UserManager.CurrentTradeAccount.FundsAccountId = ulong.Parse(_currentSelectedFunds);
- }
- }
- SetMinMaxQtyVaule();
- }
- }
- #endregion
- #region 是否显示用户多资金信息列表
- private Visibility _isShowUserMultFundsList = Visibility.Collapsed;
- /// <summary>
- /// 是否显示用户多资金信息列表
- /// </summary>
- public Visibility IsShowUserMultFundsList
- {
- get
- {
- return _isShowUserMultFundsList;
- }
- set
- {
- Set(() => IsShowUserMultFundsList, ref _isShowUserMultFundsList, value);
- }
- }
- #endregion
- #region 当前选中的资金账号
- private string _currentSelectedFunds = "请选择资金账户";
- /// <summary>
- /// 当前选中的资金账号
- /// </summary>
- public string CurrentSelectedFunds
- {
- get
- {
- return _currentSelectedFunds;
- }
- set
- {
- Set(() => CurrentSelectedFunds, ref _currentSelectedFunds, value);
- UserManager.CurrentTradeAccount.FundsAccountId = 0;
- if (!_currentSelectedFunds.Contains("请"))
- {
- UserManager.CurrentTradeAccount.FundsAccountId = ulong.Parse(CurrentSelectedFunds);
- }
- SetMinMaxQtyVaule();
- }
- }
- #endregion
- /// <summary>
- /// 是否显示-点选成交
- /// </summary>
- public virtual bool IsVisibility_ListingSelect
- {
- get
- {
- return false;
- }
- }
- /// <summary>
- /// 是否显示市价下单
- /// </summary>
- public virtual bool IsMarketPriceVisibity
- {
- get
- {
- return true;
- }
- }
- /// <summary>
- /// 是否显示涨跌停
- /// </summary>
- public virtual bool IsShowRaiseFall
- {
- get
- {
- return false;
- }
- }
- /// <summary>
- /// 是否显示预埋单功能
- /// </summary>
- public bool IsPrePostVisible
- {
- get
- {
- return ApplicationParameter.IsPrePostVisible == 1; ////
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- protected void GetHoldDetails()
- {
- if (this.CurrentGoods != null)
- {
- //var holdingOrders = (CurrentGoods.TradeMode == eTradeMode.Full_Transfer ? CacheManager.CacheRealGoodsPositionList : CacheManager.CacheGoodsPositionList);// UserManager.GetCacheOrders<HoldingOrder>();
- var holdingOrders = CacheManager.CacheGoodsPositionList;// UserManager.GetCacheOrders<HoldingOrder>();
- if (holdingOrders == null || !holdingOrders.Any())
- {
- SetMinMaxQtyVaule();
- return;
- }
- var direction = _direction == Direction.Ask ? Direction.Bid : Direction.Ask;
- HoldDetails = CacheManager.GetGoodsPositionList(direction, (uint)CurrentGoods.GoodsParameters.GoodsId, CurrentGoods.TradeMode);//holdingOrders.Where((item) => item.GoodsId == CurrentGoods.GoodsParameters.GoodsId && item.Direction == direction).ToList();
- SelectOrder = HoldDetails.FirstOrDefault();
- }
- }
- /// <summary>
- /// 提交表单
- /// </summary>
- /// <param name="successAction">成功回调</param>
- /// <param name="errorAction">错误返回</param>
- public virtual void PostOrder(Action<OrderDetail> successAction, Action<ErrorEntity> errorAction)
- {
- }
- /// <summary>
- /// 创建基本单据
- /// </summary>
- /// <returns></returns>
- public virtual NewEntrustOrder BuildEntrustOrder()
- {
- var newOrder = new NewEntrustOrder()
- {
- BuyOrSell = Direction,
- GoodsCode = this.CurrentGoods.GoodsCode,
- OperaterId = UserManager.CurrentTradeAccount.LoginID,
- GoodsId = (uint)this.CurrentGoods.GoodsParameters.GoodsId,
- AccountType = UserManager.CurrentTradeAccount.AccountType,
- BuildType = OpenCloseMode,
- EntrurstTime = ApplicationParameter.ServerTimeNow,
- MemberAreaId = UserManager.CurrentTradeAccount.MemberAreaId,
- EntrustQuantity = Lot,
- PriceMode = this.PriceMode,
- ValidType = this.CurrentExpirationType,
- TriggerType = (uint)this._currentTriggerType,
- TriggerPrice = this.TriggerPrice,
- MarketId = this.CurrentGoods.MarketID,
- TradeMode = CurrentGoods.TradeMode,
- LoginID = UserManager.CurrentTradeAccount.LoginID,
- AccountId = UserManager.CurrentTradeAccount.FundsAccountId,
- OrderFlag = (uint)this.OrderFlag,
- OrderFormType = eOrderFormType.Commom,
- ChannelPriceMode = this.CurrentChannelPriceMode,
- CurrentGoods = this.CurrentGoods,
- Ip = ApplicationParameter.PublisgNetIp,
- };
- ApplicationParameter.MakeSpsl(newOrder);
- // if (FormType == eOrderFormType.Listting)
- if (_currentGoods.TradeMode == eTradeMode.TRADEMODE_LISTING_SELECT)
- {
- newOrder.OrderFormType = eOrderFormType.Listting;
- newOrder.ListingSelectType = ListingSelectModel;
- if (ListingSelectModel != eListingSelectType.LISTINGSELECTTYPE_LISTING)
- {
- newOrder.DelistingType = DelistingModel;
- }
- if (ListingSelectModel == eListingSelectType.LISTINGSELECTTYPE_DELISTING && DelistingModel == eDelistingType.DELISTINGTYPE_SELECTED)
- {
- newOrder.RelationTicket = (ulong)CacheManager.OrderId_Listing;
- }
- }
- #region 注销BY DK
- //if (UserManager.CurrentTradeAccount.FundsAccounts.Any() && UserManager.CurrentTradeAccount.FundsAccounts[0] != null)
- //{
- // newOrder.AccountId = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
- // if (newOrder.AccountId == 0)
- // {
- // newOrder.AccountId = UserManager.CurrentTradeAccount.AccountId;
- // }
- //}
- //else
- //{
- // newOrder.AccountId = UserManager.CurrentTradeAccount.AccountId;
- //}
- #endregion
- // newOrder.EntrustPrice = ExecutePrice;// 买卖按钮变化了。所以不需要这样传值
- // 点击界面上的买入卖出,会触犯买卖方向的变化。所以直接用买卖方向来判断,应该可以
- if (ChannelBuyPrice.Equals("--"))
- {
- newOrder.EntrustPrice = 0;
- }
- else
- {
- if (newOrder.BuyOrSell == Direction.Bid) // 买入
- {
- newOrder.EntrustPrice = Convert.ToDecimal(ChannelBuyPrice);
- }
- else if (newOrder.BuyOrSell == Direction.Ask)// 卖出
- {
- newOrder.EntrustPrice = Convert.ToDecimal(ChannelSellPrice);
- }
- }
-
- //直接获取单据价格-挂牌单据
- if (ListingSelectModel == eListingSelectType.LISTINGSELECTTYPE_DELISTING && DelistingModel == eDelistingType.DELISTINGTYPE_SELECTED)
- {
- newOrder.EntrustPrice = CacheManager.OrderPrice_Listing;//OrderPrice_Listing;
- }
- // newOrder.RelationTicket = 0;
- #region MTP2.0 注销
- ////按单平
- //if (OpenCloseMode != OpenCloseMode.BUILDTYPE_OPEN && GoodsOrderMode == GoodsOrderMode.Order)
- //{
- // newOrder.RelationTicket = SelectOrder == null ? 0 : SelectOrder.OrderID;
- //}
- #endregion
- if (CurrentUserFundsList != null && CurrentUserFundsList.Count() == 1)
- {
- newOrder.AccountId = ulong.Parse(CurrentUserFundsList.FirstOrDefault());
- }
- return newOrder;
- }
- /// <summary>
- /// 输入的价格是否有效
- /// </summary>
- /// <param name="price"></param>
- /// <returns></returns>
- protected bool CheckExecutePrice(decimal price)
- {
- int temp = CurrentGoods.GoodsParameters.HqExchFigures;
- if (price >= 0 && price <= 1000000)
- {
- var pic = price % (1 / ((decimal)Math.Pow(10, temp)));
- return pic == 0;
- }
- else
- {
- return false;
- }
- }
- /// <summary>
- /// 设置价格范围
- /// </summary>
- protected virtual void SetEntrustPriceRange() { }
- /// <summary>
- /// 验证数据
- /// </summary>
- /// <param name="msg"></param>
- /// <returns></returns>
- public virtual bool Validated(ref string msg)
- {
- #region
- if (CurrentUserFundsList != null && CurrentUserFundsList.Count() > 1 && CurrentSelectedFunds.Contains("请"))
- {
- msg = "请选择资金账户";
- return false;
- }
- if (Lot > 9223372036854775807)
- {
- msg = "超出最大委托数量";
- return false;
- }
- //var isclose = OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE ||
- // (CurrentGoods != null && CurrentGoods.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_PAY &&
- // Direction == Direction.Ask);
- //if (!IsOpenCloseEdit && OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSETHENOPEN && CurrentGoods.GoodsParameters.MoneyMode != eMoneyMode.MONEYMODE_PAY)
- //{
- // msg = Muchinfo.MTPClient.Resources.Client_Resource.OpenClose_IsNotAllow;
- // return false;
- //}
- //if (!IsEnableSelectOpenMode && OpenCloseMode == OpenCloseMode.BUILDTYPE_OPEN && CurrentGoods.GoodsParameters.MoneyMode != eMoneyMode.MONEYMODE_PAY)
- //{
- // msg = Muchinfo.MTPClient.Resources.Client_Resource.Open_IsNotAllow;
- // return false;
- //}
- //if (!IsCloseEnable && OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE && CurrentGoods.GoodsParameters.MoneyMode != eMoneyMode.MONEYMODE_PAY)
- //{
- // msg = Muchinfo.MTPClient.Resources.Client_Resource.Close_IsNotAllow;
- // return false;
- //}
- //if (Lot <= 0 || Lot == decimal.Zero)
- //{
- // //数量不在正确范围内
- // msg = Muchinfo.MTPClient.Resources.Client_Resource.Lot_Vailed_MustUpOfZero;
- // return false;
- //}
- ////可用资金不足,最小交易数量为{0}!
- ////if (OpenCloseMode != OpenCloseMode.BUILDTYPE_CLOSE && MinLot > MaxLot)
- ////{
- //// msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.EntrustOrderViewModel_MinLotLargeThanMaxLot, MinLot); ;
- //// return false;
- ////}
- ////可用资金不足,最小交易数量为{0}!
- ////if (!isclose && MinLot > MaxLot)
- ////{
- //// msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.EntrustOrderViewModel_MinLotLargeThanMaxLot, MinLot); ;
- //// return false;
- ////}
- //if (Lot > MaxLot)
- //{
- // //msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Lot_Open_DownOfMaxMinOpenLot, MaxLot, MinLot);
- // msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.EntrustOrderViewModel_OpenLotGreatThanMaxLot, MaxLot); ;
- // return false;
- //}
- //if (!isclose && Lot < MinLot)
- //{
- // //单笔数量最小为:{0}
- // msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.EntrustOrderViewModel_MinInputNum, MinLot);
- // return false;
- //}
- //if (MinLot != 0 && (Lot % MinLot) != 0)
- //{
- // // 1.将商品交易规则项“单笔最小建仓数量”更名为“单笔最小交易数量”,“单笔最大建仓数量”更名为“单笔最大交易数量”;
- // //2.服务端,客户端实现:平仓数量不是最小交易数量整数倍的,能且只能将剩余可用数量全部平仓,
- // // 即:平仓数量!=单笔最小交易数量*int(平仓数量/单笔最小交易数量),
- // //2.1若:平仓数量=剩余可平数量,平仓数量可平;
- // //2.2若:平仓数量!=剩余可平数量,平仓数量不可平,服务端或者客户端提示“平仓数量不是单笔最小交易数量{显示单笔最小交易数量}整数倍,只能将剩余可用数量全部平仓”,提示方式和校验时点按照之前逻辑;
- // if (!isclose)
- // {
- // //数量输入有误!应为{0}的倍数.
- // msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.EntrustOrderViewModel_InputNumShouldBeRight, MinLot);
- // return false;
- // }
- // else if (Lot != MaxLot)
- // {
- // msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.TradeClose_ErrorTips, MinLot);
- // return false;
- // }
- //}
- //if (this.PriceMode != ePriceMode.PRICEMODE_MARKET && !CheckExecutePrice(ExecutePrice))
- //{
- // //msg = "委托价格不在提示范围内";
- // msg = Muchinfo.MTPClient.Resources.Client_Resource.ErrorEntrustPrice;
- // return false;
- //}
- //if (this.OrderFlag == OrderMethods.PreOrder && TriggerPrice <= 0)
- //{
- // //msg = "触发价格需要大于0";
- // msg = Muchinfo.MTPClient.Resources.Client_Resource.Error_TriggerPriceNeedGreaterThanZero;
- // return false;
- //}
- //if (this.OrderFlag == OrderMethods.PreOrder && ApplicationParameter.MaxPrePostOrderLot > 0 && MaxPreOrderLot >= ApplicationParameter.MaxPrePostOrderLot)
- //{
- // //msg = "预埋单最多可保留{0}条,请撤销部分单据后进行提交";
- // msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Error_MaxPrePostOrderLot, ApplicationParameter.MaxPrePostOrderLot);
- // return false;
- //}
- return true;
- #endregion
- }
- /// <summary>
- /// 设置更新下单数量
- /// </summary>
- protected virtual void SetMinMaxQtyVaule()
- {
- }
- /// <summary>
- /// 是否显示摘牌类型
- /// </summary>
- public virtual bool IsVisibility_DelistingModel
- {
- get
- {
- return false;
- }
- }
- /// <summary>
- /// 所有权商品,买建卖平显示
- /// </summary>
- protected virtual void SetSellCloseBuyOpen()
- {
- }
- #region 计算可下单数量
- /// <summary>
- /// 根据可用资金算出可下单的数量
- /// </summary>
- /// <returns></returns>
- protected decimal GetEnableNum(decimal price)
- {
- decimal enablenum = 0;
- decimal usableFunds = 0;
- decimal dividernum = 0;
- //可用资金[多资金账户]
- usableFunds = UserManager.GetCurrentUsableFundsByAccountId(UserManager.CurrentTradeAccount.FundsAccountId);//UserManager.CurrentAccountUsableFunds();
- if (usableFunds > 0)
- {
- #region 计算可购买
- dividernum = GetDivider(price);
- if (dividernum != 0)
- {
- var calcLot = usableFunds / dividernum;
- if (calcLot <= 0)
- {
- enablenum = 0;
- }
- else if (calcLot >= int.MaxValue)
- {
- enablenum = int.MaxValue;
- }
- else
- {
- enablenum = calcLot; //数量
- }
- }
- else ////不收任何费用时显示最大值
- {
- return int.MaxValue;
- }
- return enablenum > 0 ? enablenum : 0;
- #endregion
- }
- else
- {
- return 0;//没有资金不可以买
- }
- }
- /// <summary>
- /// 每手下单所需资金
- /// </summary>
- /// <param name="price">价格</param>
- /// <returns></returns>
- private decimal GetDivider(decimal price)
- {
- decimal dividernum = 0;
- decimal dividernumChange = 0;
- if (Direction == Direction.Bid)
- {
- //【买】建仓手续费
- dividernumChange = GetTradeFeeBy(eTradeFeeType.TRADEFEETYPE_TRADECHARGE, price);
- }
- else
- {
- //【卖】建仓手续费
- dividernumChange = GetTradeFeeBy(eTradeFeeType.TRADEFEETYPE_TRADECHARGE, price);
- }
- //竞价全额
- if (_currentGoods != null)// && _currentGoods.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_PAY)
- {
- //dividernum = _currentGoods.CurrentPrice == 0 ? _currentGoods.LastClose : _currentGoods.CurrentPrice;
- dividernum = price * _currentGoods.AgreeUnit + dividernumChange;
- return dividernum;
- }
- return GetTradeFeeBy(eTradeFeeType.TRADEFEETYPE_TRADECHARGE, price) + dividernumChange;
- }
- /// <summary>
- /// 获取指定【交易费用类型】的费用
- /// </summary>
- /// <param name="tradeFeeType"></param>
- /// <param name="price"></param>
- /// <returns></returns>
- private decimal GetTradeFeeBy(eTradeFeeType tradeFeeType, decimal price)
- {
- decimal dividerTradeFee = 0;
- #region 类型:建仓保证金
- //获取交易费用类型=建仓保证金
- var eTradeFee = _goodsService.GetTradeFee(_currentGoods.TradeMode, tradeFeeType);
- GoodsFeeType goodsfee = null;
- GoodsFeeType accountfee = null;
- #endregion
- if (_currentGoods != null && CacheManager.TradeGoodsFeeRules != null && CacheManager.TradeGoodsFeeRules.ContainsKey((int)_currentGoods.GoodsId))
- {
- #region 类型:建仓保证金
- if (CacheManager.TradeGoodsFeeRules[(int)_currentGoods.GoodsId].GoodsFees.ContainsKey((int)eTradeFee))
- {
- goodsfee = CacheManager.TradeGoodsFeeRules[(int)_currentGoods.GoodsId].GoodsFees[(int)eTradeFee];
- }
- if (CacheManager.TradeGoodsFeeRules[(int)_currentGoods.GoodsId].AccountGoodsFees.ContainsKey((int)eTradeFee))
- {
- accountfee = CacheManager.TradeGoodsFeeRules[(int)_currentGoods.GoodsId].AccountGoodsFees[(int)eTradeFee];
- }
- #endregion
- }
- #region 类型:建仓保证金
- //商品是总额百分比模式
- if (goodsfee != null && (int)eCalMode.CALMODE_FIXEDRATIO == goodsfee.FeeMode)
- {
- //可用资金/合约单位*价格*占用百分比 或者可用资金/合约单位固定值
- if (accountfee != null)
- {
- switch ((int)accountfee.FeeMode)
- {
- case (int)eCalMode.CALMODE_FIXEDRATIO:
- dividerTradeFee = (_currentGoods.GoodsParameters.AgreeUnit) * price * (accountfee.FeeValue + goodsfee.FeeValue);
- break;
- case (int)eCalMode.CALMODE_FIXEDNUMBER:
- dividerTradeFee = (_currentGoods.GoodsParameters.AgreeUnit) * price * goodsfee.FeeValue + accountfee.FeeValue;
- break;
- }
- }
- else
- {
- dividerTradeFee = (_currentGoods.GoodsParameters.AgreeUnit) * price * goodsfee.FeeValue;
- }
- }
- //商品是合约单位固定值的模式
- else if (goodsfee != null && (int)eCalMode.CALMODE_FIXEDNUMBER == goodsfee.FeeMode)
- {
- //可用资金/合约单位*价格*占用百分比 或者可用资金/合约单位固定值
- if (accountfee != null)
- {
- switch ((int)accountfee.FeeMode)
- {
- case (int)eCalMode.CALMODE_FIXEDRATIO:
- dividerTradeFee = (_currentGoods.GoodsParameters.AgreeUnit) * price * accountfee.FeeValue + goodsfee.FeeValue;
- break;
- case (int)eCalMode.CALMODE_FIXEDNUMBER:
- dividerTradeFee = accountfee.FeeValue + goodsfee.FeeValue;
- break;
- }
- }
- else
- {
- dividerTradeFee = goodsfee.FeeValue;
- }
- }
- #endregion
- return dividerTradeFee;
- }
- /// <summary>
- /// 设置
- /// </summary>
- protected virtual void DefautEntrustPrice(bool isUpdateLimitePrice = true)
- {
- if (this._currentGoods == null)
- {
- return;
- }
- if (this.PriceMode == ePriceMode.PRICEMODE_LIMIT)
- {
- switch (this._currentGoods.TradeMode)
- {
- case eTradeMode.TRADEMODE_MARKETMAKE:
- ExecutePrice = _direction == Direction.Ask ? _currentGoods.AskPrice : _currentGoods.BidPrice;
- break;
- case eTradeMode.TRADEMODE_BIDDING:
- case eTradeMode.TRADEMODE_LISTING_SELECT:
- // 需求 #25835 竞价市场下点击下单类型为限价时,自动将买一卖一价带入价格框,若无买一卖一,则取昨收价。
- ExecutePrice = _direction == Direction.Ask ? _currentGoods.BidPrice : _currentGoods.AskPrice;
- if (ExecutePrice <= 0)
- {
- //任务 #26769 //竞价市场-》-》限价-》默认价格 为昨收OR最新价
- ExecutePrice = _currentGoods.CurrentPrice == 0 ? _currentGoods.LastClose : _currentGoods.CurrentPrice;
- }
- break;
- case eTradeMode.TRADEMODE_ENTRUST_HEDGE:
- switch (CurrentChannelPriceMode)
- {
- case ChannelPriceMode.MatchPrice:
- ExecutePrice = Direction == Direction.Ask
- ? _currentGoods.BidPrice
- : _currentGoods.AskPrice;
- ChannelBuyPrice = Convert.ToString(_currentGoods.AskPrice);
- ChannelSellPrice = Convert.ToString(_currentGoods.BidPrice);
- break;
- case ChannelPriceMode.MarketPrice:
- ChannelBuyPrice = "0";
- ChannelSellPrice = "0";
- ExecutePrice = 0;
- break;
- // 4、若价格选择为超价,
- // 买入按钮上价格取卖价(卖一价)+配置的超价点数*行情最小变动单位*10^行情小数位,
- // 卖出按钮上价格取买价(买一价)-配置的超价点数*行情最小变动单位*10^行情小数位,买卖价变动时价格需要跟着变动;
- case ChannelPriceMode.SuperPrice:
- double superPoint = SystemParamManager.getChannelSuperPoint;
- var changeValue = superPoint * _currentGoods.QuoteMinUnit / Math.Pow(10, _currentGoods.DecimalPlaces);
- ExecutePrice = Direction == Direction.Ask
- ? _currentGoods.BidPrice == 0 ? 0 : (_currentGoods.BidPrice - (decimal)changeValue)
- : _currentGoods.AskPrice == 0 ? 0 : (_currentGoods.AskPrice + (decimal)changeValue);
- ChannelBuyPrice = Convert.ToString(_currentGoods.AskPrice == 0 ? 0 : (_currentGoods.AskPrice + (decimal)changeValue));
- ChannelSellPrice = Convert.ToString(_currentGoods.BidPrice == 0 ? 0 : (_currentGoods.BidPrice - (decimal)changeValue));
- break;
- case ChannelPriceMode.LastestPrice:
- ExecutePrice = _currentGoods.CurrentPrice;
- ChannelBuyPrice = Convert.ToString(_currentGoods.CurrentPrice);
- ChannelSellPrice = Convert.ToString(_currentGoods.CurrentPrice);
- break;
- case ChannelPriceMode.LimitPrice:
- if (isUpdateLimitePrice)
- {
- ExecutePrice = Direction == Direction.Ask
- ? _currentGoods.BidPrice
- : _currentGoods.AskPrice;
- }
- ChannelBuyPrice = Convert.ToString(ExecutePrice);
- ChannelSellPrice = Convert.ToString(ExecutePrice);
- break;
- default:
- ExecutePrice = Direction == Direction.Ask
- ? CurrentGoods.BidPrice
- : CurrentGoods.AskPrice;
-
- ChannelBuyPrice = Convert.ToString(_currentGoods.BidPrice);
- ChannelSellPrice = Convert.ToString(_currentGoods.AskPrice);
- break;
- }
- break;
- default:
- break;
- }
- }
- else if (this.PriceMode == ePriceMode.PRICEMODE_MARKET)
- {
- switch (this._currentGoods.TradeMode)
- {
- case eTradeMode.TRADEMODE_MARKETMAKE:
- ExecutePrice = _direction == Direction.Ask ? _currentGoods.AskPrice : _currentGoods.BidPrice;
- break;
- case eTradeMode.TRADEMODE_BIDDING:
- case eTradeMode.TRADEMODE_BIDDINGMARKETMAKE:
- case eTradeMode.TRADEMODE_ENTRUST_HEDGE:
- //市价默认价格
- ExecutePrice = 0;
- ChannelBuyPrice = "0";
- ChannelSellPrice = "0";
- break;
- }
- }
- }
- /// <summary>
- /// 设置默认下单数量,设置建仓平仓时使用
- /// </summary>
- protected void SetInitVaules()
- {
- // 需求 #29897客户端下单平仓的时候,默认不要全部卖出,可以默认卖出0手,需要修改后才可以进行平仓;[建仓平仓都按这个规则]
- if ((OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE ||
- (_currentGoods.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_PAY && Direction == Direction.Ask))) ///全部平仓
- {
- /*var currentAccount = UserManager.CurrentTradeAccount.FundsAccountId;// == 0 ? CacheManager.FundsAccountId : UserManager.CurrentTradeAccount.FundsAccountId;
- if (currentAccount == 0) return;
- TradePositionModel t = CacheManager.GetHoldingSummary(_currentGoods.GoodsId, currentAccount.ToString());
- if (t == null)
- {
- Lot = MaxLot;
- return;
- }
- var qty = Direction == Direction.Ask ? t.AvailableBuyHolderQty() : t.AvailableSellHolderQty();
- Lot = qty;*/
- Lot = MaxLot;
- }
- else
- {
- if (ApplicationParameter.DefaultOrderLot == 0)
- {
- Lot = MinLot;
- }
- else
- {
- Lot = ApplicationParameter.DefaultOrderLot; ////默认下单数量
- }
- }
- }
- #endregion
- /// <summary>
- /// 设置默认价格模式[读取数据库配置--设置]
- /// </summary>
- protected virtual void setDefaultPriceMode()
- {
- //所有商品默认为限价
- PriceMode = ePriceMode.PRICEMODE_LIMIT;
- }
- public override void Cleanup()
- {
- base.Cleanup();
- MessengerHelper.DefaultUnregister<TradeAccount>(this, MessengerTokens.HolderRefresh);
- MessengerHelper.DefaultUnregister<string>(this, MessengerTokens.MoneyNoticeToken);
- MessengerHelper.QuoteUnregister<List<QuoteGoods>>(this, MessengerTokens.ReceiveRealTimeQuote);
- }
- /// <summary>
- /// 获取预埋单-可下最最大数量
- /// </summary>
- protected void GetPrePostOrderMaxQty()
- {
- ulong currentAccountId;
- if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
- {
- currentAccountId = (uint)UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
- }
- else
- {
- currentAccountId = UserManager.CurrentTradeAccount.AccountId;
- }
- _goodsService.QueryPrePostDetailQty(currentAccountId, QueryPreOrderParameterSuccess, ErrorPreOrderParameterCallBack);
- }
- /// <summary>
- /// 委托单参数查询-成功返回
- /// </summary>
- /// <param name="itemList"></param>
- protected void QueryPreOrderParameterSuccess(List<PreOrderParameter> itemList)
- {
- if (itemList != null)
- {
- MaxPreOrderLot = itemList.FirstOrDefault().maxPreOrderLot;
- }
- }
- /// <summary>
- /// 委托单参数查询-失败返回
- /// </summary>
- /// <param name="errorEntity"></param>
- private void ErrorPreOrderParameterCallBack(ErrorEntity errorEntity)
- {
- IsBusy = false;
- }
- /// <summary>
- /// 设置订单委托价格
- /// </summary>
- /// <param name="price"></param>
- public void SetOrderPrice(decimal price)
- {
- if (PriceMode == ePriceMode.PRICEMODE_LIMIT)
- {
- if (price > 0)
- {
- ExecutePrice = price;
- }
- }
- }
- #region 通道交易相关属性及方法
- /// <summary>
- /// 是否通道交易模式
- /// </summary>
- public virtual bool IsVisibilityChannelTrade
- {
- get { return false; }
- }
- /// <summary>
- /// 通道交易价格方式字典
- /// </summary>
- public Dictionary<ChannelPriceMode, string> ChannelPriceModeList
- {
- get
- {
- var dic1 = new Dictionary<ChannelPriceMode, string>
- {
- {ChannelPriceMode.LastestPrice, ChannelPriceMode.LastestPrice.Discription()},
- {ChannelPriceMode.MatchPrice, ChannelPriceMode.MatchPrice.Discription()},
- {ChannelPriceMode.MarketPrice, ChannelPriceMode.MarketPrice.Discription()},
- {ChannelPriceMode.SuperPrice, ChannelPriceMode.SuperPrice.Discription()},
- {ChannelPriceMode.LimitPrice, ChannelPriceMode.LimitPrice.Discription()},
- };
- var dic2 = new Dictionary<ChannelPriceMode, string> // 不支持市价
- {
- //{ChannelPriceMode.LastestPrice, ChannelPriceMode.LastestPrice.Discription()},
- {ChannelPriceMode.MatchPrice, ChannelPriceMode.MatchPrice.Discription()},
- //{ChannelPriceMode.SuperPrice, ChannelPriceMode.SuperPrice.Discription()},
- {ChannelPriceMode.LimitPrice, ChannelPriceMode.LimitPrice.Discription()},
- };
- return ApplicationParameter.CanMarketPrice(CurrentGoods) ? dic1 : dic2;
- }
- }
- private ChannelPriceMode _currentChannelPriceMode;
- /// <summary>
- /// 当前通道交易价格方式
- /// </summary>
- public ChannelPriceMode CurrentChannelPriceMode
- {
- get
- {
- return _currentChannelPriceMode;
- }
- set
- {
- Set(() => CurrentChannelPriceMode, ref _currentChannelPriceMode, value);
- var priceMode = value == ChannelPriceMode.MarketPrice ? ePriceMode.PRICEMODE_MARKET : ePriceMode.PRICEMODE_LIMIT;
- if ((int) priceMode == -1) return;
- PriceMode = priceMode;
- }
- }
- /// <summary>
- /// 止盈止损价格类型
- /// </summary>
- /// <value>The channel price mode list.</value>
- public Dictionary<ChannelPriceMode, string> ChannelSPSLPriceModeList
- {
- get
- {
- var dic = new Dictionary<ChannelPriceMode, string>
- {
- {ChannelPriceMode.LastestPrice, ChannelPriceMode.LastestPrice.Discription()},
- {ChannelPriceMode.MatchPrice, ChannelPriceMode.MatchPrice.Discription()},
- {ChannelPriceMode.SuperPrice, ChannelPriceMode.SuperPrice.Discription()},
- {ChannelPriceMode.MarketPrice, ChannelPriceMode.MarketPrice.Discription()}
- };
- var dic1 = new Dictionary<ChannelPriceMode, string>
- {
- {ChannelPriceMode.LastestPrice, ChannelPriceMode.LastestPrice.Discription()},
- {ChannelPriceMode.MatchPrice, ChannelPriceMode.MatchPrice.Discription()},
- {ChannelPriceMode.SuperPrice, ChannelPriceMode.SuperPrice.Discription()}
- };
- return ApplicationParameter.CanMarketPrice(CurrentGoods) ? dic : dic1;
- }
- }
- /// <summary>
- /// 是否止盈止损
- /// </summary>
- /// <value><c>true</c> if this instance is SPSL model; otherwise, <c>false</c>.</value>
- public virtual bool IsSPSLModel
- {
- get { return OrderModel == OrderModel.SPSL; }
- }
- /// <summary>
- /// 是否正常下单
- /// </summary>
- /// <value><c>true</c> if this instance is normal model; otherwise, <c>false</c>.</value>
- public virtual bool IsNormalModel
- {
- get { return OrderModel == OrderModel.Normal; }
- }
- private SPSLOrderType _currentSPSLOrderType;
- /// <summary>
- /// 止盈止损类型【止损单/止盈单/撤单】
- /// </summary>
- /// <value>The type of the current SPSL order.</value>
- public SPSLOrderType CurrentSPSLOrderType
- {
- get
- {
- return _currentSPSLOrderType;
- }
- set
- {
- Set(() => CurrentSPSLOrderType, ref _currentSPSLOrderType, value);
- RaisePropertyChanged(() => TriggerPriceMode);
- UpdateSPSLPriceRange();
- }
- }
- private string _holdAvgPriceDisplay;
- /// <summary>
- /// 持仓均价
- /// </summary>
- /// <value>The hold average price display.</value>
- public string HoldAvgPriceDisplay
- {
- get
- {
- return _holdAvgPriceDisplay;
- }
- set
- {
- Set(() => HoldAvgPriceDisplay, ref _holdAvgPriceDisplay, value);
- }
- }
- private string _directionDisplay;
- /// <summary>
- /// 止盈止损方向
- /// </summary>
- /// <value>The hold average price display.</value>
- public string DirectionDisplay
- {
- get
- {
- return _directionDisplay;
- }
- set
- {
- Set(() => DirectionDisplay, ref _directionDisplay, value);
- }
- }
- private string _holdTotalQtyDisplay;
- /// <summary>
- /// 持仓数量
- /// </summary>
- /// <value>The hold total qty display.</value>
- public string HoldTotalQtyDisplay
- {
- get
- {
- return _holdTotalQtyDisplay;
- }
- set
- {
- Set(() => HoldTotalQtyDisplay, ref _holdTotalQtyDisplay, value);
- }
- }
- /// <summary>
- /// Gets the trigger price mode.
- /// </summary>
- /// <value>The trigger price mode.</value>
- public string TriggerPriceMode
- {
- get
- {
- if (CurrentSPSLOrderType == SPSLOrderType.SPOrder) return "止盈价";
- return "止损价";
- }
- }
- protected decimal _spslTriggerPrice;
- /// <summary>
- /// 资管止盈止损触发价
- /// </summary>
- public virtual decimal SPSLTriggerPrice
- {
- get
- {
- return _spslTriggerPrice;
- }
- set
- {
- Set(() => SPSLTriggerPrice, ref _spslTriggerPrice, value);
- }
- }
- protected decimal _spslTriggerMinPrice;
- /// <summary>
- /// 资管止盈止损触发价最小值
- /// </summary>
- public virtual decimal SPSLTriggerMinPrice
- {
- get
- {
- return _spslTriggerMinPrice;
- }
- set
- {
- Set(() => SPSLTriggerMinPrice, ref _spslTriggerMinPrice, value);
- }
- }
- protected decimal _spslTriggerMaxPrice;
- /// <summary>
- /// 资管止盈止损触发价最小值
- /// </summary>
- public virtual decimal SPSLTriggerMaxPrice
- {
- get
- {
- return _spslTriggerMaxPrice;
- }
- set { Set(() => SPSLTriggerMaxPrice, ref _spslTriggerMaxPrice, value); }
- }
- /// <summary>
- /// 更新止盈止损触发价范围
- /// </summary>
- private void UpdateSPSLPriceRange()
- {
- //持仓单方向为买——止盈价格需大于最新价,止损价格需要小于最新价;
- if (this.Direction == Direction.Ask)
- {
- if (this.CurrentSPSLOrderType == SPSLOrderType.SPOrder)
- {
- SPSLTriggerMinPrice = CurrentGoods.CurrentPrice;
- SPSLTriggerMaxPrice = decimal.MaxValue;
- }else{
- SPSLTriggerMinPrice = 0;
- SPSLTriggerMaxPrice = CurrentGoods.CurrentPrice;
- }
- }
- //持仓单方向为卖——止盈价格需小于最新价,止损价格需要大于最新价。
- if (this.Direction == Direction.Bid)
- {
- if (this.CurrentSPSLOrderType == SPSLOrderType.SPOrder)
- {
- SPSLTriggerMinPrice = 0;
- SPSLTriggerMaxPrice = CurrentGoods.CurrentPrice;
- }
- else
- {
- SPSLTriggerMinPrice = CurrentGoods.CurrentPrice;
- SPSLTriggerMaxPrice = decimal.MaxValue;
- }
- }
- SPSLTriggerPrice = CurrentGoods.CurrentPrice;
- }
- #endregion
- #region 90705 因为止盈止损单由服务端触发,最好每次都取服务端的数据
- /// <summary>
- /// 下面四个是用于设置止盈价止损价的最大最小值
- /// </summary>
- private decimal _slMaxPrice;
- private decimal _slMinPrice;
- private decimal _spMaxPrice;
- private decimal _spMinPrice;
- /// <summary>
- /// 止损的最大值
- /// </summary>
- public decimal SlMaxPrice
- {
- get { return _slMaxPrice; }
- set { Set(() => SlMaxPrice, ref _slMaxPrice, value); }
- }
- /// <summary>
- /// 止损的最小值
- /// </summary>
- public decimal SlMinPrice
- {
- get { return _slMinPrice; }
- set { Set(() => SlMinPrice, ref _slMinPrice, value); }
- }
- /// <summary>
- /// 止盈的最大值
- /// </summary>
- public decimal SpMaxPrice
- {
- get { return _spMaxPrice; }
- set { Set(() => SpMaxPrice, ref _spMaxPrice, value); }
- }
- /// <summary>
- /// 止盈的最小值
- /// </summary>
- public decimal SpMinPrice
- {
- get { return _spMinPrice; }
- set { Set(() => SpMinPrice, ref _spMinPrice, value); }
- }
- /// <summary>
- /// 根据买卖方向来锁定输入框的输入最大值最小值
- /// </summary>
- private void LockEditTextMaxMin()
- {
- //持仓单方向为买——止盈价格需大于最新价,止损价格需要小于最新价;
- if (this.Direction == Direction.Ask) // 买持仓
- {
- SpMinPrice = /*CurrentGoods.CurrentPrice 别问我为什么不用这个了,因为没有办法做到,当设置成0的时候,控件自动设置为最小值,这样就影响到的判断*/0;
- SpMaxPrice = decimal.MaxValue;
-
- SlMinPrice = 0;
- SlMaxPrice = /*CurrentGoods.CurrentPrice*/decimal.MaxValue;// 最大值也会有这样的问题,当输入数字的大于最大值,失去焦点后,这个值会恢复到空间的最大值。
- }
- //持仓单方向为卖——止盈价格需小于最新价,止损价格需要大于最新价。
- if (this.Direction == Direction.Bid) // 卖持仓
- {
- SpMinPrice = 0;
- SpMaxPrice = /*CurrentGoods.CurrentPrice*/decimal.MaxValue;
- SlMinPrice = /*CurrentGoods.CurrentPrice*/0;
- SlMaxPrice = decimal.MaxValue;
- }
- // 给输入框绑定默认值
- SpPrice = (double)CurrentGoods.CurrentPrice;
- SlPrice = (double)CurrentGoods.CurrentPrice;
- }
- #region 做设置止盈止损价时候,止盈止损价超出了价格范围时的提示
- /// <summary>
- /// 检测止盈价止损价输入是否合法
- /// --此方法就有提示了,不需要再外面处理
- /// </summary>
- /// <returns>true 合法</returns>
- public bool CheckProfitLoss()
- {
- if (OrderModel == OrderModel.SPSL)// 止盈止损的下单模式下,我才会处理,其他的模式都放过
- {
- if (!_canUseSpPrice && !_canUseSlPrice)
- {
- CheckTips(Client_Resource.Use_SpPrice_Or_SlPrice);
- return false;
- }
- //买方向持仓止盈价格设置小于最新价时,提示“止盈价格必须高于该合约最新价,请重新设置”
- //买方向持仓止损价格设置大于最新价时,提示“止损价格必须低于该合约最新价,请重新设置”
- if (this.Direction == Direction.Ask) // 买持仓
- {
- if (_canUseSpPrice && SpPrice <= (double)CurrentGoods.CurrentPrice) // 买方向持仓止盈价格设置小于最新价时
- {
- // 提示“止盈价格必须高于该合约最新价,请重新设置”
- CheckTips(Client_Resource.SpPrice_High_than_Last_Price);
- return false;
- }
- else if (_canUseSlPrice && SlPrice >= (double)CurrentGoods.CurrentPrice) // 买方向持仓止损价格设置大于最新价时
- {
- // 提示“止损价格必须低于该合约最新价,请重新设置”
- CheckTips(Client_Resource.SlPrice_Low_than_Last_Price);
- return false;
- }
- }
- // 卖方向持仓止盈价格设置大于最新价时,提示“止盈价格必须低于该合约最新价,请重新设置”
- // 卖方向持仓止损价格设置小于最新价时,提示“止损价格必须高于该合约最新价,请重新设置”
- else if (this.Direction == Direction.Bid) // 卖持仓
- {
- if (_canUseSpPrice && SpPrice >= (double)CurrentGoods.CurrentPrice) // 卖方向持仓止盈价格设置大于最新价时
- {
- // 提示“止盈价格必须低于该合约最新价,请重新设置”
- CheckTips(Client_Resource.SpPrice_Low_than_Last_Price);
- return false;
- }
- else if (_canUseSlPrice && SlPrice <= (double)CurrentGoods.CurrentPrice) // 卖方向持仓止损价格设置小于最新价时
- {
- //提示“止损价格必须高于该合约最新价,请重新设置”
- CheckTips(Client_Resource.SlPrice_High_than_Last_Price);
- return false;
- }
- }
- }
- return true;
- }
- /// <summary>
- /// just show Question tips message
- /// </summary>
- /// <param name="tips"></param>
- private void CheckTips(string tips)
- {
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- MessageBoxHelper.ShowQuestion(tips,
- Client_Resource.DeliveryOrderView_WarningTipsTitle);
- }));
- }
- #endregion
- /// <summary>
- /// 止盈价
- /// </summary>
- private double _spPrice;
- public double SpPrice
- {
- get { return _spPrice; }
- set { Set(() => SpPrice, ref _spPrice, value); }
- }
- private double _slPrice;
- public double SlPrice
- {
- get { return _slPrice; }
- set { Set(() => SlPrice, ref _slPrice, value); }
- }
- /// <summary>
- /// 查询止盈止损单
- /// </summary>
- public void QuerySpslOrderByFundAccountId()
- {
- if (IsBusy) return;
- IsBusy = true;
- _commonQueryService.QuerySPSLOrder(UserManager.CurrentTradeAccount.FundsAccountId, (list =>
- {
- IsBusy = false;
- _spslOrders = list;
- CountSpslSetNum();
- }), CancelErrorCallBack);
- }
- /// <summary>
- /// 查询失败返回
- /// </summary>
- /// <param name="errorEntity"></param>
- private void CancelErrorCallBack(ErrorEntity errorEntity)
- {
- IsBusy = false;
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- ErrorManager.ShowReturnError(errorEntity, Client_Resource.UI2014_Tips, true);
- }));
- }
- /// <summary>
- /// 计算已经设置的止盈止损数量
- /// </summary>
- public void CountSpslSetNum()
- {
- decimal setNum = 0;// 已经设置的止盈止损的数量
- if (_spslOrders != null)
- {
- Direction direction = Direction == Direction.Ask ? Direction.Bid : Direction.Ask;
- _spslOrders.ForEach((model =>
- {
- //已经向需求确认过,如果止盈止损单中存在之前持仓未成交的单据时,得到的数量可能是大于当前的持仓数据,这个也没有关系。从数据上来说,该商品的相同方向上的待触发单据的数量确实是这么多。
- if (model.GoodsId == _currentGoods.GoodsId &&
- model.Status == SPSLOrderStatus.NotTrigger &&
- direction == model.BuyOrSell)// 相同商品,待触发的状态,相同方向
- {
- setNum += model.OrderQty;
- }
- }));
- }
- HadSetEntrustNum = setNum;
- }
- /// <summary>
- /// 已设止盈止损的数量-查询止盈止损单中现存的数量 #90705
- /// 2. 增加显示已设置过多少数量(需要将已设置的止盈单、止损单、止盈止损单数量相加);
- /// </summary>
- private decimal _hadSetEntrustNum = 0;
- public decimal HadSetEntrustNum
- {
- get { return _hadSetEntrustNum; }
- set { Set(() => HadSetEntrustNum, ref _hadSetEntrustNum, value); }
- }
- /// <summary>
- /// 是否启用止盈价
- /// </summary>
- private bool _canUseSpPrice;
- /// <summary>
- /// 是否启用止损价
- /// </summary>
- private bool _canUseSlPrice;
- public bool CanUseSpPrice
- {
- get { return _canUseSpPrice; }
- set { Set(() => CanUseSpPrice, ref _canUseSpPrice, value); }
- }
- public bool CanUseSlPrice
- {
- get { return _canUseSlPrice; }
- set { Set(() => CanUseSlPrice, ref _canUseSlPrice, value); }
- }
- #endregion
- #region 买卖按钮的颜色控制
- private SolidColorBrush _buyBackGroundBrush = Brushes.Red;
- public SolidColorBrush BuyBackGroundBrush
- {
- get { return _buyBackGroundBrush; }
- set { Set(() => BuyBackGroundBrush, ref _buyBackGroundBrush, value); }
- }
- private SolidColorBrush _sellBackGroundBrush = Brushes.Green;
- public SolidColorBrush SellBackGroundBrush
- {
- get { return _sellBackGroundBrush; }
- set { Set(() => SellBackGroundBrush, ref _sellBackGroundBrush, value); }
- }
- /// <summary>
- /// 在平仓时候,显示买卖方向就置灰,且不可以点击
- /// </summary>
- /// <param name="direction"></param>
- public void ChangeBuySellBackground(Direction direction)
- {
- switch (direction)
- {
- case Direction.Ask:// 单据是卖方向的,那就将买方向的置灰,
- {
- SellBackGroundBrush = new SolidColorBrush(Color.FromRgb(100, 100, 100));
- CanUseSell = false;
- BuyBackGroundBrush = Brushes.Red;
- CanUseBuy = true;
- break;
- }
- case Direction.Bid:
- {
- SellBackGroundBrush = Brushes.Green;
- CanUseSell = true;
- BuyBackGroundBrush = new SolidColorBrush(Color.FromRgb(100, 100, 100));
- CanUseBuy = false;
- break;
- }
- default:// 买卖都可以用
- {
- SellBackGroundBrush = Brushes.Green;
- CanUseSell = true;
- BuyBackGroundBrush = Brushes.Red;
- CanUseBuy = true;
- break;
- }
- }
- }
- private bool _canUseBuy;
- public bool CanUseBuy
- {
- get { return _canUseBuy; }
- set { Set(() => CanUseBuy, ref _canUseBuy, value); }
- }
- private bool _canUseSell;
- public bool CanUseSell
- {
- get { return _canUseSell; }
- set { Set(() => CanUseSell, ref _canUseSell, value); }
- }
- #endregion
- }
- }
|