/// <summary> /// Reset current depth /// </summary> /// <param name="tde">Trade depth entity</param> private void ResetCurrentDepth(TradeDepthEntity tde) { if (tde == null) { return; } AskGrid.SelectionMode = DataGridViewSelectionMode.CellSelect; AskGrid.ReadOnly = true; BidGrid.SelectionMode = DataGridViewSelectionMode.CellSelect; BidGrid.ReadOnly = true; AskGrid.DataSource = tde.AsksList; AskGrid.AutoResizeColumns(); BidGrid.DataSource = tde.BidsList; BidGrid.AutoResizeColumns(); }
/// <summary> /// Get trade Depth /// </summary> /// <returns></returns> public TradeDepthEntity GetTradeDepth(int symbolId) { try { var buyResult = DragonExPublicApis.Instance.GetMarketBuy(symbolId); var sellResult = DragonExPublicApis.Instance.GetMarketSell(symbolId); TradeDepthEntity tde = new TradeDepthEntity(); tde.TradeName = Constants.TRADE_NAME_DRAGON_EX; tde.AsksList = new List <AskBidEntity>(); tde.BidsList = new List <AskBidEntity>(); var bidsNodes = buyResult.Elements("data"); var asksNodes = sellResult.Elements("data"); AskBidEntity tempItem; int getRow = Constants.DEPTH_DISPLAY_ROW - 1; if (asksNodes.Count() < Constants.DEPTH_DISPLAY_ROW) { getRow = asksNodes.Count() - 1; } for (int i = getRow; i >= 0; i--) { var asksItem = asksNodes.ElementAt(i); tempItem = new AskBidEntity(); tempItem.No = i + 1; tempItem.Price = decimal.Parse(CommonUtils.GetAskBidElementValue(asksItem.FirstNode)); tempItem.Amount = decimal.Parse(CommonUtils.GetAskBidElementValue(asksItem.LastNode)); tde.AsksList.Add(tempItem); } tde.MinAsk = tde.AsksList[getRow]; tde.MinSecAsk = tde.AsksList[getRow - 1]; tde.MinThdAsk = tde.AsksList[getRow - 2]; getRow = Constants.DEPTH_DISPLAY_ROW - 1; if (bidsNodes.Count() < Constants.DEPTH_DISPLAY_ROW) { getRow = bidsNodes.Count() - 1; } for (int i = 0; i <= getRow; i++) { var bidsItem = bidsNodes.ElementAt(i); tempItem = new AskBidEntity(); tempItem.No = i + 1; tempItem.Price = decimal.Parse(CommonUtils.GetAskBidElementValue(bidsItem.FirstNode)); tempItem.Amount = decimal.Parse(CommonUtils.GetAskBidElementValue(bidsItem.LastNode)); tde.BidsList.Add(tempItem); } tde.MaxBid = tde.BidsList[0]; tde.MaxSecBid = tde.BidsList[1]; tde.MaxThdBid = tde.BidsList[2]; return(tde); } catch (Exception ex) { // If any error happened when Trading, out error log var logMsg = "Exception happened when getting market info in dragonex.Exception:" + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine; LogTool.LogTradeInfo(logMsg, LogLevels.ERROR); } return(null); }
/// <summary> /// Update trade depth /// </summary> /// <param name="symbolId"></param> public void UpdateTradeDepth(int symbolId) { this.Tde = GetTradeDepth(symbolId); }