From 8ea6d363df77de2dca288397da8d4f9c3d3a5c4d Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 18 十月 2024 18:41:57 +0800 Subject: [PATCH] '项目完善' --- CBTrade/TickChart.cpp | 145 ++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 132 insertions(+), 13 deletions(-) diff --git a/CBTrade/TickChart.cpp b/CBTrade/TickChart.cpp index 62d98bb..6431cbe 100644 --- a/CBTrade/TickChart.cpp +++ b/CBTrade/TickChart.cpp @@ -300,8 +300,6 @@ void TickChart::drawBuyPoint(wxDC& dc, wxPoint point) { - dc.SetPen(wxColor(232, 62, 37)); - dc.SetBrush(wxColor(232, 62, 37)); dc.DrawCircle(point, POINT_REDIUS); } @@ -327,7 +325,7 @@ // 计算位置 wxString text = wxString("成交时间:").Append(tickData.time).Append("\n"); text.Append("涨幅:").Append(StringUtil::to_string(tickData.rate)).Append("%").Append("\n"); - text.Append("成交价:").Append(tickData.price).Append("元\n"); + text.Append("成交价:").Append(StringUtil::to_string( stod( tickData.price.ToStdString().c_str()),3)).Append("元\n"); text.Append("成交量:").Append(to_string(tickData.volume)).Append("\n"); text.Append("成交额:").Append(tickData.money).Append("元"); drawInfo(paint, wxPoint(point.x + POINT_REDIUS, point.y + POINT_REDIUS), text, {}); @@ -341,7 +339,7 @@ if (abs(mousePoint.x - point.x) < POINT_REDIUS * 2 && abs(mousePoint.y - point.y) < POINT_REDIUS * 2) { wxString text = wxString("成交时间:").Append(tickData.time).Append("\n"); text.Append("涨幅:").Append(StringUtil::to_string(tickData.rate)).Append("%").Append("\n"); - text.Append("成交价:").Append(tickData.price).Append("元\n"); + text.Append("成交价:").Append(StringUtil::to_string(stod(tickData.price.ToStdString().c_str()), 3)).Append("元\n"); text.Append("成交量:").Append(to_string(tickData.volume)).Append("\n"); text.Append("成交额:").Append(tickData.money).Append("元"); drawInfo(paint, wxPoint(point.x + POINT_REDIUS, point.y + POINT_REDIUS), text, {}); @@ -389,6 +387,9 @@ void TickChart::drawUnderlyingLatestRate(wxDC& paint, wxRect area) { + if (1 > 0) { + return; + } if (underlyingTickDatas.size() > 0) { // 绘制Tick线最新的点 TickData lastTickData = underlyingTickDatas.back(); @@ -415,6 +416,89 @@ paint.DrawText(rateText, wxPoint(x,y)); } +} + +void TickChart::drawUnderlyingQuotes(wxDC& paint, wxRect area) +{ + if (underlyingTickDatas.size() <= 0) { + return; + } + TickData tick = underlyingTickDatas.back(); + if (tick.quotes.size() <= 0) { + return; + } + wxSize size = paint.GetTextExtent("万"); + int lineHeight = (int)(size.GetHeight() * 1.1); + int contentHeight = size.GetHeight(); + int contentWidth = contentHeight * 3; + int height = lineHeight*10; + int width = contentWidth * 2; + + + + // 绘制买卖档口 + wxPoint middlePoint = wxPoint(area.GetLeft()+ GRID_MARGIN.left, area.GetBottom() - GRID_MARGIN.bottom - height/2); + if (stoi(TimeUtil::format(TimeUtil::getNowTimeStamp(), "%H%M%S").c_str())<120000) { + middlePoint.x = area.GetRight() - GRID_MARGIN.right - width; + } + + + wxColour textColor = wxColor(100, 100, 100); + + paint.SetBrush(wxColor(255,255,255,128)); + paint.SetPen(*wxTRANSPARENT_PEN); + paint.SetTextForeground(textColor); + //paint.DrawRoundedRectangle(wxRect(wxPoint(middlePoint.x, middlePoint.y - height/2), wxSize(width, height)),5); + + int index = 0; + for (std::list<Quote>::iterator e = tick.quotes.begin(); e != tick.quotes.end(); ++e) { + Quote qu = *e; + // 绘制买 + wxString price; + wxString money; + + if (qu.bid_volume > 0) { + // 有买1 + price = wxString(StringUtil::to_string(qu.bid_price).c_str()); + money = StringUtil::to_string( qu.bid_price * qu.bid_volume/10000,1); + money.Append("万"); + } + else { + price = "-"; + money = "-"; + } + + + paint.DrawLabel(price, wxRect(wxPoint(middlePoint.x, middlePoint.y + lineHeight * index), wxSize(contentWidth, contentHeight)), wxALIGN_LEFT); + paint.DrawLabel(money, wxRect(wxPoint(middlePoint.x + contentWidth, middlePoint.y + lineHeight * index), wxSize(contentWidth, contentHeight)), wxALIGN_RIGHT); + + // 绘制卖 + if (qu.ask_price > 0) { + // 有买1 + price = wxString(StringUtil::to_string(qu.ask_price).c_str()); + money = StringUtil::to_string(qu.ask_price * qu.ask_volume / 10000, 1); + money.Append("万"); + } + else { + price = "-"; + money = "-"; + } + + paint.DrawLabel(price, wxRect(wxPoint(middlePoint.x, middlePoint.y - lineHeight * (index+1)), wxSize(contentWidth, contentHeight)), wxALIGN_LEFT); + paint.DrawLabel(money, wxRect(wxPoint(middlePoint.x + contentWidth, middlePoint.y - lineHeight * (index+1)), wxSize(contentWidth, contentHeight)), wxALIGN_RIGHT); + + if (index == 0) { + paint.SetBrush(textColor); + paint.SetPen(textColor); + paint.DrawLine(wxPoint(middlePoint.x, middlePoint.y - (lineHeight-contentHeight)/2), wxPoint(middlePoint.x + width, middlePoint.y- (lineHeight - contentHeight) /2)); + } + index += 1; + } + + + + + } TickChart::TickChart(wxWindow* parent, wxWindowID id, int timeSpace, TIME_SPACE_TYPE timeSpaceType, wxString xStartTime, wxString xEndTime, const wxPoint& pos, const wxSize& size) : wxControl(parent, id, pos, size, wxBORDER_NONE), timeSpace(timeSpace), timeSpaceType(timeSpaceType), xStartTime(xStartTime), xEndTime(xEndTime), maxYRate(20), limitUpRate(20), preClosePrice(10.00) @@ -491,7 +575,24 @@ if (TickDataUtil::tradTimeSub((*e).time, xEndTime) > 0) { continue; } + TickTradeData info = *e; wxPoint point = convertTickDataToPoint(*e, rect); + wxColour color; + switch (info.colorType) + { + + case 1: + color = wxColor(232, 62, 37); + break; + case 3: + color = wxColor(106, 254, 193); + break; + default: + color = wxColor(232, 62, 37); + break; + } + dc.SetPen(color); + dc.SetBrush(color); drawBuyPoint(dc, point); } @@ -510,6 +611,8 @@ drawBuyAndSellPointInfo(dc, rect, mousePos); drawUnderlyingLatestRate(dc, rect); + + drawUnderlyingQuotes(dc, rect); //pdc.Clear(); // 采用双缓存绘制 @@ -682,7 +785,7 @@ } wxString time_str = TimeUtil::format((long)datas.bob, "%H:%M:%S"); float price = datas.open; - AddUnderlyingTickData(time_str, 100 * (price - underlyingCodeInfo.preClosePrice) / underlyingCodeInfo.preClosePrice, FALSE); + AddUnderlyingTickData(time_str, 100 * (price - underlyingCodeInfo.preClosePrice) / underlyingCodeInfo.preClosePrice,std::list<Quote>(), FALSE); if (i == tempUDatas->count() - 1) { // 加载Bar线无法覆盖的时间段数据 @@ -698,10 +801,23 @@ if (datas.price < 0.0001) { continue; } - AddUnderlyingTickData(TimeUtil::format((long)datas.created_at, "%H:%M:%S"), 100 * (datas.price - underlyingCodeInfo.preClosePrice) / underlyingCodeInfo.preClosePrice, FALSE); + + std::list<Quote> quotes; + for (int n = 0; n < 5; n++) { + quotes.push_back(datas.quotes[n]); + } + AddUnderlyingTickData(TimeUtil::format((long)datas.created_at, "%H:%M:%S"), 100 * (datas.price - underlyingCodeInfo.preClosePrice) / underlyingCodeInfo.preClosePrice, quotes, FALSE); } } + + } + Tick tick = JueJinDataUtil::currentTick(JueJinDataUtil::getSymbol(underlyingCodeInfo.code.ToStdString())); + std::list<Quote> quotes; + for (int n = 0; n < 5; n++) { + quotes.push_back(tick.quotes[n]); + } + AddUnderlyingTickData(TimeUtil::format((long)tick.created_at, "%H:%M:%S"), 100 * (tick.price - underlyingCodeInfo.preClosePrice) / underlyingCodeInfo.preClosePrice, quotes, FALSE); } if (cbCodeInfo.code.Length() > 0) { @@ -763,7 +879,7 @@ if (datas.price < 0.0001) { continue; } - AddUnderlyingTickData(TimeUtil::format((long)datas.created_at, "%H:%M:%S"), 100 * (datas.price - underlyingCodeInfo.preClosePrice) / underlyingCodeInfo.preClosePrice, FALSE); + AddUnderlyingTickData(TimeUtil::format((long)datas.created_at, "%H:%M:%S"), 100 * (datas.price - underlyingCodeInfo.preClosePrice) / underlyingCodeInfo.preClosePrice, std::list<Quote>(), FALSE); } } @@ -818,9 +934,9 @@ } } -void TickChart::AddUnderlyingTickData(wxString time, float rate, bool refresh) +void TickChart::AddUnderlyingTickData(wxString time, float rate, list<Quote> quotes, bool refresh) { - if (TickDataUtil::tradTimeSub(time, xEndTime) > 0) { + if (TickDataUtil::tradTimeSub(time, xEndTime) > 120) { return; } @@ -832,12 +948,13 @@ return; } if (seconds / this->timeSpace != last.time / this->timeSpace) { - underlyingTickDatas.push_back(TickData({ seconds , rate, "" })); + underlyingTickDatas.push_back(TickData({ seconds , rate, "", quotes })); } else { underlyingTickDatas.back().price = ""; underlyingTickDatas.back().time = seconds; underlyingTickDatas.back().rate = rate; + underlyingTickDatas.back().quotes = quotes; cout << "最后一条数据:" << underlyingTickDatas.back().time << "-" << underlyingTickDatas.back().price << endl; } @@ -847,7 +964,7 @@ } } else { - underlyingTickDatas.push_back(TickData({ seconds , rate, "" })); + underlyingTickDatas.push_back(TickData({ seconds , rate, "", quotes })); } // 正股不浮动 float newMaxYRate = abs(rate); @@ -861,9 +978,11 @@ } -void TickChart::AddBuyPoint(wxString time, float rate, wxString price, int volume, wxString money) +void TickChart::AddBuyPoint(wxString time, float rate, wxString price, int volume, wxString money, int type) { - AddBuyPoint(TickTradeData({ time , rate, price,volume, money })); + + + AddBuyPoint(TickTradeData({ time , rate, price,volume, money, type })); } void TickChart::AddBuyPoint(TickTradeData data) -- Gitblit v1.8.0