| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453 |
- using GalaSoft.MvvmLight;
- 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.Infrastructure.Utilities;
- using Muchinfo.MTPClient.IService;
- using Muchinfo.MTPClient.Resources;
- using System;
- using System.Collections.Generic;
- using System.IO;
- //----------------------------------------------------------------
- //Module Name: $safeprojectname$
- //Purpose:
- //CopyRight: Muchinfo
- //History:
- //----------------------------------------------------------------
- //DateTime 2016/1/16 10:06:39
- //Author
- //Description Create
- //----------------------------------------------------------------
- using System.Windows;
- using System.Windows.Media.Imaging;
- namespace Muchinfo.MTPClient.Trade.ViewModels
- {
- public class TradeOrderBase : ViewModelBase
- {
- private QuoteGoods _currentGoods; ////当前商品
- private bool _isBidDirection = true;
- private ExpirationType _currentExpirationType = ExpirationType.Today;
- private OrderType _currentOrderType; ////订单类型
- private decimal _pips = 5; //// 成交点差
- protected IOrderService _orderService;
- /// LimitOrderVisibility
- /// </summary>
- private Visibility _limitOrderGridVisibility;
- private decimal _lot;
- /// <summary>
- /// MarketOrderVisibility
- /// </summary>
- private Visibility _marketOrderGridVisibility;
- public TradeOrderBase(QuoteGoods currentGoods, OrderType orderType)
- {
- _currentGoods = currentGoods;
- CurrentOrderType = orderType;
- _orderService = SimpleIoc.Default.GetInstance<IOrderService>();
- IsBidDirection = true;
- }
- /// <summary>
- /// 价格格式化
- /// </summary>
- public string PriceFormat
- {
- get
- {
- if (this._currentGoods != null)
- {
- return _currentGoods.FormatPrice;
- }
- else
- {
- return "F0";
- }
- }
- }
- /// <summary>
- /// 表单买卖方向
- /// </summary>
- public bool IsBidDirection
- {
- get
- {
- return _isBidDirection;
- }
- set
- {
- Set(() => IsBidDirection, ref _isBidDirection, value);
- SetQuotePrice();
- }
- }
- /// <summary>
- /// 当前商品
- /// </summary>
- public QuoteGoods CurrentGoods
- {
- get
- {
- return _currentGoods;
- }
- }
- /// <summary>
- /// Sets and gets the CurrentOrderType property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public OrderType CurrentOrderType
- {
- get
- {
- return _currentOrderType;
- }
- set
- {
- Set(() => CurrentOrderType, ref _currentOrderType, value);
- if (value == OrderType.MarketOpenOrder || value == OrderType.BidMarketOpen)
- {
- MarketOrderGridVisibility = Visibility.Visible;
- LimitOrderGridVisibility = Visibility.Collapsed;
- }
- else if (value == OrderType.LimitOpenOrder || value == OrderType.BidLimitOpen)
- {
- MarketOrderGridVisibility = Visibility.Collapsed;
- LimitOrderGridVisibility = Visibility.Visible;
- }
- }
- }
- /// <summary>
- /// Sets and gets the LimitOrderVisibility property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public Visibility LimitOrderGridVisibility
- {
- get
- {
- return _limitOrderGridVisibility;
- }
- set
- {
- Set(() => LimitOrderGridVisibility, ref _limitOrderGridVisibility, value);
- }
- }
- /// <summary>
- /// Sets and gets the Lot property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public decimal Lot
- {
- get
- {
- return _lot;
- }
- set
- {
- Set(() => Lot, ref _lot, value);
- // RaisePropertyChanged(() => LotVailedString);
- }
- }
- /// <summary>
- /// Sets and gets the MarketOrderVisibility property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public Visibility MarketOrderGridVisibility
- {
- get
- {
- return _marketOrderGridVisibility;
- }
- set
- {
- //if (_marketOrderGridVisibility == Visibility.Visible)
- //{
- // WindowHeight = 580;
- //}
- //else
- //{
- // WindowHeight = 580;
- //}
- Set(() => MarketOrderGridVisibility, ref _marketOrderGridVisibility, value);
- }
- }
- /// <summary>
- /// 商品图片资源
- /// </summary>
- public BitmapImage ImageSource
- {
- get
- {
- if (File.Exists(UserManager.SysConfigFolderPath + "\\GoodsImages\\" + _currentGoods.GoodsCode + "." + ApplicationParameter.ImageExtension))
- {
- return new BitmapImage(new Uri(UserManager.SysConfigFolderPath + "\\GoodsImages\\" + _currentGoods.GoodsCode + "." + ApplicationParameter.ImageExtension));
- }
- else
- {
- return null;
- }
- }
- }
- /// <summary>
- /// 图片可见性
- /// </summary>
- public Visibility ImageVisibility
- {
- get
- {
- if (File.Exists(UserManager.SysConfigFolderPath + "\\GoodsImages\\" + _currentGoods.GoodsCode + "." + ApplicationParameter.ImageExtension))
- {
- return Visibility.Visible;
- }
- else
- {
- return Visibility.Collapsed;
- }
- }
- }
- /// <summary>
- /// Sets and gets the Pips property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public decimal Pips
- {
- get
- {
- return _pips;
- }
- set
- {
- Set(() => Pips, ref _pips, value);
- }
- }
- /// <summary>
- /// 是否允许点差
- /// </summary>
- private bool _isAllowPips;
- /// <summary>
- /// 是否允许点差
- /// </summary>
- public bool IsAllowPips
- {
- get
- {
- return _isAllowPips;
- }
- set
- {
- Set(() => IsAllowPips, ref _isAllowPips, value);
- }
- }
- private bool _isBidMarket;
- /// <summary>
- /// 是否是竞价商品
- /// </summary>
- public bool IsBidMarket
- {
- get { return _isBidMarket; }
- set { Set(() => IsBidMarket, ref _isBidMarket, value); }
- }
- /// <summary>
- /// 获取和设置the expiration types
- /// </summary>
- public Dictionary<ExpirationType, string> ExpirationTypes
- {
- get
- {
- var types = new Dictionary<ExpirationType, string>();
- ExpirationType expirationType;
- try
- {
- string[] expirationData = ApplicationParameter.ExpirationType.Split(',');
- for (int i = 0; i < expirationData.Length; i++)
- {
- expirationType = (ExpirationType)System.Enum.Parse(typeof(ExpirationType), expirationData[i], true);
- types.Add(expirationType, expirationType.Discription());
- }
- }
- catch (Exception e)
- {
- }
- //types.Add(ExpirationType.SomeTime, "指定时间有效");
- //types.Add(ExpirationType.Weekday, ExpirationType.Weekday.Discription());
- return types;
- }
- }
- /// <summary>
- /// Sets and gets the CurrentExpirationType property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public ExpirationType CurrentExpirationType
- {
- get
- {
- return _currentExpirationType;
- }
- set
- {
- Set(() => CurrentExpirationType, ref _currentExpirationType, value);
- }
- }
- private decimal _executePrice;
- /// <summary>
- /// 限价建仓单-执行价格
- /// </summary>
- public decimal ExecutePrice
- {
- get
- {
- return _executePrice;
- }
- set
- {
- Set(() => ExecutePrice, ref _executePrice, value);
- }
- }
-
- private decimal _quotePrice; //当前行情价
- /// <summary>
- /// 当前行情价
- /// </summary>
- public decimal QuotePrice
- {
- get
- {
- return _quotePrice;
- }
- set
- {
- Set(() => QuotePrice, ref _quotePrice, value);
- }
- }
- #region 虚函数属性
- /// <summary>
- /// 验证信息
- /// </summary>
- /// <returns></returns>
- public virtual bool Validated()
- {
- return true;
- }
- /// <summary>
- /// 获取和设置the order types
- /// </summary>
- public virtual Dictionary<OrderType, string> OrderTypes
- {
- get
- {
- var types = new Dictionary<OrderType, string>
- {
- {OrderType.MarketOpenOrder, Muchinfo_Resource.OrderType_Enum_MarketOpen},
- {OrderType.LimitOpenOrder, Muchinfo_Resource.OrderType_Enum_LimitOpen}
- };
- return types;
- }
- }
- /// <summary>
- /// 创建下单委托对象
- /// </summary>
- /// <returns>下单委托对象</returns>
- public virtual NewEntrustOrder BuildEntrustOrder()
- {
- var entrustOrder = new NewEntrustOrder()
- {
-
- GoodsCode = this.CurrentGoods.GoodsCode,
- MarketId = (uint)this.CurrentGoods.GoodsParameters.MarketId,
- GoodId = (uint)this.CurrentGoods.GoodsParameters.GoodsId,
- AccountType = UserManager.CurrentTradeAccount.AccountType,
- BuyOrSell = IsBidDirection ? Direction.Bid : Direction.Ask,
- EntrustQuantity = Lot,
- AccountId = UserManager.CurrentTradeAccount.AccountId,
- OpenType = OpenClose.Open,
- EntrurstTime = ApplicationParameter.ServerTimeNow,
- MemberId = (uint)UserManager.CurrentTradeAccount.MemberAreaId,
- };
- entrustOrder.OrderMode = OrderMode.InValid;
- // entrustOrder.TradeCloseMode = TradeCloseMode.IsVailed;
- entrustOrder.ValidType = CurrentExpirationType;
- return entrustOrder;
- }
- /// <summary>
- /// 提交表单
- /// </summary>
- /// <param name="successAction">成功回调</param>
- /// <param name="errorAction">错误返回</param>
- public virtual void PostOrder(Action<OrderDetail> successAction, Action<ErrorEntity> errorAction)
- {
- }
- /// <summary>
- /// 设置当前下单价格
- /// </summary>
- protected virtual void SetQuotePrice()
- {
- //todo:暂时设置默认值
- if (CurrentGoods != null)
- {
- ExecutePrice = IsBidDirection ? CurrentGoods.BidPrice : CurrentGoods.AskPrice;
- QuotePrice = ExecutePrice;
- }
- }
- #endregion
- /// <summary>
- /// Cleanups this instance.
- /// </summary>
- public override void Cleanup()
- {
- ////取消注册消息
- base.Cleanup();
- ApplicationParameter.QuotationMessenger.Unregister(this);
- }
- }
- }
|