| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726 |
- using System.Collections.ObjectModel;
- using System.Windows.Controls;
- using System.Windows.Input;
- using GalaSoft.MvvmLight;
- using GalaSoft.MvvmLight.Command;
- using GalaSoft.MvvmLight.Ioc;
- using Muchinfo.MTPClient.Analysis.Views.PriceCard;
- using Muchinfo.MTPClient.Data;
- using Muchinfo.MTPClient.Data.Enums;
- using Muchinfo.MTPClient.Data.Model;
- using Muchinfo.MTPClient.Data.Model.Analysis;
- using Muchinfo.MTPClient.Data.Quote;
- using Muchinfo.MTPClient.Infrastructure.Cache;
- using Muchinfo.MTPClient.Infrastructure.Helpers;
- using Muchinfo.MTPClient.Infrastructure.Utilities;
- using Muchinfo.MTPClient.IService;
- using Muchinfo.PC.Common.Extensions;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- //----------------------------------------------------------------
- //Module Name: $safeprojectname$
- //Purpose:
- //CopyRight: Muchinfo
- //History:
- //----------------------------------------------------------------
- //DateTime 2015/12/12 14:10:10
- //Author
- //Description Create
- //----------------------------------------------------------------
- using System.Threading.Tasks;
- using System.Windows;
- namespace Muchinfo.MTPClient.Analysis.ViewModels
- {
- public class QuotePriceViewModel : ViewModelBase, IDisposable
- {
- public IQuoteDataService _iQuoteDataService;
- // private List<SubPenData> _allSource = new List<SubPenData>();
-
- private QuoteGoods _currentGoods; //当前显示的商品
- private short _tickCount = 100;
- private FrameworkElement _goodsCategory;
- private static object _lockObject = new object();
-
-
- /// <summary>
- /// 商品分类显示盘面
- /// </summary>
- public FrameworkElement GoodsCategory
- {
- get
- {
- return _goodsCategory;
- }
- set { Set(() => GoodsCategory, ref _goodsCategory, value); }
- }
- /// <summary>
- /// 报价牌中的商品
- /// </summary>
- public QuoteGoods Goods
- {
- get
- {
- return _currentGoods;
- }
- set
- {
- bool isupdate = _currentGoods == null || !_currentGoods.Equals(value);
- Set(() => Goods, ref _currentGoods, value);
- if (value != null)
- {
- UiInitQuotePriceView( );
- }
- if (isupdate)
- {
- UpdateCommissions(_currentGoods);
- InitData();
- }
- RaisePropertyChanged(()=> IsQuoteQueueVbs);
- }
- }
- /// <summary>
- /// 是否显示大力士
- /// </summary>
- public bool IsQuoteQueueVbs
- {
- get
- {
- if (_currentGoods == null)
- return false;
- switch (_currentGoods.TradeMode)
- {
- case eTradeMode.TRADEMODE_MARKETMAKE:
- return false; ////做市不显示
- case eTradeMode.TRADEMODE_BIDDING:
- var showType = (QueueShowType) ApplicationParameter.QuoteQueueInfo;
- return showType == QueueShowType.Bid || showType == QueueShowType.All;
-
- case eTradeMode.TRADEMODE_BIDDINGMARKETMAKE:
- var showType1 = (QueueShowType) ApplicationParameter.QuoteQueueInfo;
- return showType1 == QueueShowType.BidMake || showType1 == QueueShowType.All;
- default:
- return false;
- }
- }
- }
- #region 是否显示买卖更多=》点选市场才显示
-
- /// <summary>
- /// 是否显示买卖更多=》点选市场才显示
- /// </summary>
- public Visibility IsVisibility_More
- {
- get
- {
- if (Goods.TradeMode == eTradeMode.TRADEMODE_LISTING_SELECT)
- {
- return Visibility.Visible;
- }
- else
- {
- return Visibility.Collapsed;
- }
- }
-
- }
- #endregion
- #region 是否显示间隔线-分割买卖五档
- /// <summary>
- /// 是否显示间隔线-分割买卖五档
- /// </summary>
- public Visibility IsVisibility_Line
- {
- get
- {
- if (Goods.TradeMode != eTradeMode.TRADEMODE_LISTING_SELECT)
- {
- return Visibility.Visible;
- }
- else
- {
- return Visibility.Collapsed;
- }
- }
- }
- #endregion
- private RelayCommand<string> _getAskCommissionCommand;
- /// <summary>
- /// 卖五档 更多
- /// </summary>
- public RelayCommand<string> GetAskCommissionCommand
- {
- get
- {
- return _getAskCommissionCommand
- ?? (_getAskCommissionCommand = new RelayCommand<string>(
- p =>
- {
- var SearchParameters = new SearchCommissionsParameter();
- SearchParameters.BuyOrSell = Direction.Ask;
- SearchParameters.CurrentContenModel = TabContetMode.HistoryCommissions;
- SearchParameters.GoodsId = Goods.GoodsId;
- // MessengerHelper.DefaultSend<TabContetMode>(TabContetMode.HistoryCommissions, MessengerTokens.HistoryCommissionsTab);
- //MessengerHelper.DefaultSend<bool>(false, MessengerTokens.IsShowSellCommondBtn);
- MessengerHelper.DefaultSend<SearchCommissionsParameter>(SearchParameters, MessengerTokens.HistoryCommissionsTab);
-
- }));
- }
- }
- private RelayCommand<string> _getBidCommissionCommand;
- /// <summary>
- /// 买五档 更多
- /// </summary>
- public RelayCommand<string> GetBidCommissionCommand
- {
- get
- {
- return _getBidCommissionCommand
- ?? (_getBidCommissionCommand = new RelayCommand<string>(
- p =>
- {
- var SearchParameters = new SearchCommissionsParameter();
- SearchParameters.BuyOrSell = Direction.Bid;
- SearchParameters.CurrentContenModel = TabContetMode.HistoryCommissions;
- SearchParameters.GoodsId = Goods.GoodsId;
- // MessengerHelper.DefaultSend<TabContetMode>(TabContetMode.HistoryCommissions, MessengerTokens.HistoryCommissionsTab);
- // MessengerHelper.DefaultSend<bool>(false, MessengerTokens.IsShowBuyCommondBtn);
- MessengerHelper.DefaultSend<SearchCommissionsParameter>(SearchParameters, MessengerTokens.HistoryCommissionsTab);
-
- }));
- }
- }
- private bool _isBidGoods;
- /// <summary>
- /// 竞价商品显示内容
- /// </summary>
- public bool IsBidGoods
- {
- get { return _isBidGoods; }
- set
- {
- Set(() => IsBidGoods, ref _isBidGoods, value);
- }
- }
- private double _showCount;
- /// <summary>
- /// 显示数量
- /// </summary>
- public double ShowCount
- {
- get { return _showCount; }
- set { _showCount = value; }
- }
-
- private bool _isBusy;
- /// <summary>
- /// 显示忙等待
- /// </summary>
- public bool IsBusy
- {
- get { return _isBusy; }
- set { Set(() => IsBusy, ref _isBusy, value); }
- }
- private List<SubPenData> _listSubSource=new List<SubPenData>();
- private ObservableCollection<SubPenData> _dataSource=new ObservableCollection<SubPenData>();
- /// <summary>
- /// 分笔数据
- /// </summary>
- public ObservableCollection<SubPenData> DataSource
- {
- get { return _dataSource; }
- set { Set(() => DataSource, ref _dataSource, value); }
- }
-
- public QuotePriceViewModel()
- {
-
- _iQuoteDataService = SimpleIoc.Default.GetInstance<IQuoteDataService>();
-
- if (ApplicationParameter.QuoteTickCount > 0)
- {
- _tickCount = ApplicationParameter.QuoteTickCount;
- }
- }
- public void TaskInitQuotePriceView(QuoteTradePlan tradePlan,QuoteGoods goods)
- {
- //#if DEBUG
- // DataSource = new ObservableCollection<SubPenData>();
- // int count = 60;
- // Random random=new Random(ApplicationParameter.ServerTimeNow.Millisecond);
-
- // for (int i = 0; i < count; i++)
- // {
- // var penData = new SubPenData(Goods.GoodsParameters.HqExchFigures);
- // penData.Time = ApplicationParameter.ServerTimeNow.AddMinutes(-count + i);
- // penData.Price = random.Next(4000, 4500);
- // penData.CompleteQte = random.Next(20, 100);
- // DataSource.Add(penData);
- // }
- // ////累计实时行情
- // RegReadTimeQuote();
- //#else
- Goods = goods;
- if (tradePlan != null &&tradePlan.OpenCloseDates!=null&& tradePlan.OpenCloseDates.Any())
- {
-
- DateTime openDate = ApplicationParameter.ServerTimeNow.Date,
- closeDate = ApplicationParameter.ServerTimeNow.Date.AddHours(24);
-
- openDate = tradePlan.OpenCloseDates[0].OpenDate;
- closeDate = tradePlan.OpenCloseDates[tradePlan.OpenCloseDates.Count - 1].CloseDate;
-
- //IsBusy = true; //暂时将加载状态条去掉,后续开启
- _iQuoteDataService.GetHistoryCycleData(Goods, CycleType.Tik, openDate, closeDate, _tickCount, QueryTikSuccess, QueryTikError);
- }
- //#endif
- }
- /// <summary>
- /// 查询历史Tik数据
- /// </summary>
- /// <param name="historyCycle">历史Tik数据</param>
- public void QueryTikSuccess(GoodsHistoryCycle historyCycle)
- {
- IsBusy = false;
- if (historyCycle != null && historyCycle.Symbol.ToLower() == _currentGoods.Symbol.ToLower()) ///当前商品是否一致
- {
- if (historyCycle.SubDataPoints != null && historyCycle.SubDataPoints.Any())
- {
- // 任务 #90594
- _listSubSource = historyCycle.SubDataPoints.ToList().Where(z=>z.CompleteQte > 0).ToList();
- //todo:滚动到最后一条数据
- MessengerHelper.DefaultSend<QuotePriceViewModel>(this, MessengerTokens.UpdateTik);
- }
- }
- ////累计实时行情
- RegReadTimeQuote();
- }
- #region 大力士
- private Commission _currentCommission;
- /// <summary>
- /// 当前选择的五档
- /// </summary>
- public Commission CurrentCommission
- {
- get { return _currentCommission; }
- set
- {
- Set(() => CurrentCommission, ref _currentCommission, value);
- AnalysisPackage(_currentCommission);
- }
- }
- private List<EntructInfo> _entructInfos;
- /// <summary>
- /// 显示委托信息列表
- /// </summary>
- public List<EntructInfo> EntructInfos
- {
- get { return _entructInfos; }
- set { Set(() => EntructInfos, ref _entructInfos, value); }
- }
- /// <summary>
- /// 委托信息显示解析(大利市)
- /// </summary>
- private void AnalysisPackage(Commission commission)
- {
- var entructInfos = new List<EntructInfo>();
- if (_currentGoods != null && commission != null)
- {
- var askBidQueue = commission.Direction == Direction.Ask
- ? _currentGoods.AskQueueInfo
- : _currentGoods.BidQueueInfo;
- if (!string.IsNullOrWhiteSpace(askBidQueue))
- {
- string[] queueStrings = askBidQueue.Split(';');
- if (queueStrings.Length >= (commission.Index - 1)) ////分解5档
- {
- var accountsOrder = queueStrings[commission.Index - 1];
- if (!string.IsNullOrWhiteSpace(accountsOrder))
- {
- string[] dataVals = accountsOrder.Split(',');
- for (int i = 0; i < dataVals.Length; i += 2)
- {
- var entruct = new EntructInfo();
- entruct.AccountCode = dataVals[i];
- if (i + 1 < dataVals.Length)
- {
- entruct.Qty = dataVals[i + 1];
- }
- entructInfos.Add(entruct);
- }
- }
- }
- }
- }
- EntructInfos = entructInfos;
- }
-
- #endregion
- public void QueryTikError(ErrorEntity error)
- {
- IsBusy = false;
- ////累计实时行情
- RegReadTimeQuote();
- LogInfoHelper.WriteInfo(string.Format("请求分笔数据:{0}({1})", error.ReturnCode, error.ReturnDesc));
- }
- /// <summary>
- /// 更新商品
- /// </summary>
- /// <param name="goods">商品信息</param>
- public void UpdateGoods(QuoteGoods goods)
- {
- Goods = goods;
- _listSubSource.Clear();
- DataSource.Clear();
- }
- public void UiInitQuotePriceView()
- {
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- switch (_currentGoods.TradeMode)
- {
- case eTradeMode.TRADEMODE_MARKETMAKE:
- GoodsCategory = new PriceCardDiskAskBid(this);
- IsBidGoods = false;
- break;
- case eTradeMode.TRADEMODE_BIDDINGMARKETMAKE:
- case eTradeMode.TRADEMODE_BIDDING:
- case eTradeMode.TRADEMODE_LISTING_SELECT:
- case eTradeMode.TRADEMODE_ENTRUST_HEDGE:
- GoodsCategory = new PriceCardDiskMakeMatch2(this);
- IsBidGoods = true;
- break;
- default:
- GoodsCategory = new PriceCardDiskAskBid(this);
- break;
- }
- }));
- }
-
- private void RegReadTimeQuote()
- {
- MessengerHelper.QuoteUnregister<List<QuoteGoods>>(this, MessengerTokens.ReceiveRealTikQuote);
- MessengerHelper.QuoteRegister<List<QuoteGoods>>(this, MessengerTokens.ReceiveRealTikQuote, (quoteList) =>
- {
- if (quoteList == null || !quoteList.Any()) return;
- lock (_lockObject)
- {
- foreach (var item in quoteList)
- {
- if (item == null) continue;
- if (Goods.Symbol.ToLower() == item.Symbol.ToLower())
- {
- UpdateCommissions(item); ////更新五档
- if ((item.CurrentPrice==0||item.Date==DateTime.MinValue))
- {
- continue; ////竞价不是成交的行情不显示分笔
- }
- var penData = new SubPenData(Goods.GoodsParameters.HqExchFigures)
- {
- Time = item.Date,
- Price =(double) item.CurrentPrice,
- CompleteQte =(double) item.CurrentVolume,
- IsChangedByTotalVolume = item.IsChangedByTotalVolume,
- };
- // 任务 #90594
- if (penData.CompleteQte <= 0 || !penData.IsChangedByTotalVolume) continue;
- if (null != _listSubSource)
- {
- if (_listSubSource.Count >= _tickCount)
- {
- var removeNum = _listSubSource.Count - (_tickCount - 1); //移除数量
- for (int i = 0; i < removeNum; i++)
- {
- _listSubSource.RemoveAt(0);
- }
- }
- _listSubSource.Add(penData);
- MessengerHelper.DefaultSend<QuotePriceViewModel>(this, MessengerTokens.UpdateTik);
- }
- else
- {
- _listSubSource = new List<SubPenData>();
- _listSubSource.Add(penData);
- MessengerHelper.DefaultSend<QuotePriceViewModel>(this, MessengerTokens.UpdateTik);
- }
- break;
- }
- }
- }
- });
- }
-
- public void Dispose()
- {
-
- this.Cleanup();
- //if (this._allSource != null)
- //{
- // foreach (var subPenData in _allSource)
- // {
- // subPenData.Dispose();
- // }
- // this._allSource.Clear();
- //}
- //this._allSource = null;
-
- }
- /// <summary>
- /// 更新数据
- /// </summary>
- public void UpdateDataSource(int showCount)
- {
- if (_listSubSource.Any())
- {
- var index = _listSubSource.Count - showCount < 0 ? 0 : _listSubSource.Count - showCount;
- DataSource =new ObservableCollection<SubPenData>(_listSubSource.GetRange(index, _listSubSource.Count - index));
- }
- }
- public void SendQuoteTick()
- {
- if (_currentGoods!=null)
- {
- MessengerHelper.DefaultSend<QuoteGoods>(_currentGoods, MessengerTokens.ShowTikDetail);
- }
- }
- #region 切换商品
- /// <summary>
- /// 下一商品
- /// </summary>
- public RelayCommand NextCommand
- {
- get
- {
- return new RelayCommand(() =>
- {
- MessengerHelper.DefaultSend<bool>(true, MessengerTokens.ChartGoodsChange);
- }, IsCanNext);
- }
- }
- /// <summary>
- /// 前一个商品
- /// </summary>
- public RelayCommand ForwordCommand
- {
- get
- {
- return new RelayCommand(() =>
- {
- MessengerHelper.DefaultSend<bool>(false, MessengerTokens.ChartGoodsChange);
- }, IsCanForword);
- }
- }
- /// <summary>
- /// 是否可前一个
- /// </summary>
- /// <returns></returns>
- private bool IsCanForword()
- {
- if (_currentGoods == null)
- {
- return false;
- }
- var goodsList = CacheManager.CacheGoodsBaseInfos.Where((item) => item.TradeMode != eTradeMode.TRADEMODE_SALE).ToList();
- if (!goodsList.Any())
- {
- return false;
- }
- var index = goodsList.FindIndex((item) => _currentGoods.Symbol == item.Symbol);
- return index != -1 && index != 0; ///当前是否为第一个
- }
- /// <summary>
- /// 是否可下一个商品
- /// </summary>
- /// <returns></returns>
- private bool IsCanNext()
- {
- if (_currentGoods == null)
- {
- return false;
- }
- var goodsList = CacheManager.CacheGoodsBaseInfos.Where((item) => item.TradeMode != eTradeMode.TRADEMODE_SALE).ToList();
- if (!goodsList.Any())
- {
- return false;
- }
- var index = goodsList.FindIndex((item) => _currentGoods.Symbol == item.Symbol);
- return index != -1 && index != goodsList.Count - 1; ///当前是否为第一个
- }
- #endregion
- #region 五档
- private List<Commission> _commissions;
- /// <summary>
- /// 卖五档
- /// </summary>
- public List<Commission> Commissions
- {
- get { return _commissions; }
- set { Set(() => Commissions, ref _commissions, value); }
- }
- private List<Commission> _bidcommissions;
- /// <summary>
- /// 买五档
- /// </summary>
- public List<Commission> BidCommissions
- {
- get { return _bidcommissions; }
- set { Set(() => BidCommissions, ref _bidcommissions, value); }
- }
- /// <summary>
- /// 设置买卖档
- /// </summary>
- /// <param name="bid">if set to <c>true</c> [bid].</param>
- /// <param name="commissions">The commissions.</param>
- /// <returns>List{Commission}.</returns>
- private List<Commission> SortCommissions(bool bid, Commission[] commissions, string formatStr)
- {
- var commissionLsit = new List<Commission>();
- int index = 1;
- foreach (var commission in commissions)
- {
- commission.Index = index;
- commission.FormatString = formatStr;
- commissionLsit.Add(commission);
- index++;
- }
- if (!bid)
- {
- commissionLsit = commissionLsit.OrderByDescending((item) => item.Index).ToList();
- }
- return commissionLsit;
- }
- /// <summary>
- /// 更新五档行情
- /// </summary>
- /// <param name="goods"></param>
- private void UpdateCommissions(QuoteGoods goods)
- {
- if (goods != null)
- {
- //var askCommissions = SortCommissions(false, goods.AskList, Goods.FormatPrice);
- //var bidCommissions = SortCommissions(true, goods.BidList, Goods.FormatPrice);
- //askCommissions.AddRange(bidCommissions);
- //Commissions = askCommissions;
- Commissions = SortCommissions(false, goods.AskList, Goods.FormatPrice);
- BidCommissions = SortCommissions(true, goods.BidList, Goods.FormatPrice);
- }
- }
- #endregion
-
- #region 是否显示换手率
- private void InitData()
- {
- HiddenDataByMarket();
- }
- /// <summary>
- /// 隐藏数据逻辑
- /// </summary>
- private void HiddenDataByMarket()
- {
- if (_currentGoods != null && _currentGoods.GoodsParameters != null)
- switch (_currentGoods.GoodsParameters.TradeMode)
- {
- case eTradeMode.TRADEMODE_MARKETMAKE:
- case eTradeMode.TRADEMODE_BIDDING:
- IsVisibilityTurnoverRate = Visibility.Visible;
- break;
- case eTradeMode.TRADEMODE_BIDDINGMARKETMAKE:
- //换手率混合市场应隐藏
- IsVisibilityTurnoverRate = Visibility.Collapsed;
- break;
- default:
- IsVisibilityTurnoverRate = Visibility.Visible;
- break;
- }
- }
- private Visibility _isVisibilityTurnoverRate = Visibility.Visible;
- /// <summary>
- /// 是否显示换手率-
- /// </summary>
- public Visibility IsVisibilityTurnoverRate
- {
- get
- {
- return _isVisibilityTurnoverRate;
- }
- set
- {
- Set(() => IsVisibilityTurnoverRate, ref _isVisibilityTurnoverRate, value);
- }
- }
- #endregion
- }
- }
|