| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836 |
- 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
- }
- }
|