Advertisement
upd

c++ qt horror

upd
Oct 17th, 2014
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.14 KB | None | 0 0
  1. void Bittrex::GetMyOpenOrdersReplyFinished()
  2. {
  3.     QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
  4.  
  5.     if(reply->error())
  6.     {
  7.         reply->deleteLater();
  8.         return;
  9.     }
  10.     QString strReply = (QString)reply->readAll();
  11.  
  12.     QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8());
  13.  
  14.     QJsonObject jsonObject = jsonResponse.object();
  15.  
  16.     bool suc = jsonObject["success"].toBool();
  17.  
  18.     if(suc != true)
  19.         return;
  20.  
  21.     QJsonArray data = jsonObject["result"].toArray();
  22.  
  23.     int coinIndex = 0;
  24.     qint64 checkTime = QDateTime::currentMSecsSinceEpoch();
  25.  
  26.     foreach (const QJsonValue & value, data)
  27.     {
  28.         QJsonObject obj = value.toObject();
  29.         QString orderId = obj["OrderUuid"].toString();
  30.         QString currency = obj["Exchange"].toString();
  31.  
  32.         CoinInfo *coin = FindCoinByName(currency, coinIndex);
  33.         if(coin == 0)
  34.             continue;
  35.  
  36.         bool match = false;
  37.         foreach (OpenTradeData *openTrade, coin->m_OpenTradeList)
  38.         {
  39.             if(openTrade->OrderId == orderId)
  40.             {
  41.                 openTrade->Checked = checkTime;
  42.                 match = true;
  43.                 break;
  44.             }
  45.         }
  46.  
  47.         if(match)
  48.             continue;
  49.  
  50.         QString orderType = obj["OrderType"].toString();
  51.  
  52.         qreal quantity = obj["Quantity"].toDouble();
  53.         qreal atPrice = obj["Limit"].toDouble();
  54.  
  55.         QString time = obj["Opened"].toString();
  56.         QDateTime timeStamp = QDateTime::fromString(time, Qt::ISODate).addSecs(7200);
  57.  
  58.         QString timeStr = timeStamp.toString("M/d/yyyy h:m:s");
  59.  
  60.         OpenTradeData *openTradeData = 0;
  61.  
  62.         if(orderType == "LIMIT_SELL")
  63.         {
  64.             openTradeData = new OpenTradeData(coin, orderId, "Bittrex", coin->GetCoinName(), timeStr,
  65.                                               "SELL", QString::number(quantity, 'f', 8), "",
  66.                                               coin->GetLastTradePriceStr(), "0.0", QString::number(atPrice, 'f', 8));
  67.         }
  68.         else if(orderType == "LIMIT_BUY")
  69.         {
  70.             openTradeData = new OpenTradeData(coin, orderId, "Bittrex", coin->GetCoinName(), timeStr,
  71.                                               "BUY", QString::number(quantity, 'f', 8), QString::number(atPrice, 'f', 8),
  72.                                               coin->GetLastTradePriceStr(), "0.0f", "0.0f");
  73.         }
  74. //        GetMyOrdersHistory(currency, coinIndex);
  75.  
  76.         coin->m_OpenTradeList.append(openTradeData);
  77.  
  78.         emit NewOpenOrderToTable(openTradeData);
  79.     }
  80.    
  81.     // this loop will remove trades that does not match the one from web
  82.     foreach (OpenTradeData *openTrade, coin->m_OpenTradeList)
  83.     {
  84.         if(openTrade->Checked != checkTime)
  85.         {
  86.             // remove
  87.             // emit updateguiremove...
  88.         }
  89.     }
  90.    
  91.     reply->deleteLater();
  92. }
  93.  
  94. CoinInfo *Bittrex::FindCoinByName(QString coinName)
  95. {
  96.     for(int i = 0; i < m_CoinList.size(); i++)
  97.     {
  98.         if(m_CoinList[i]->GetCoinName() == coinName)
  99.         {
  100.             return m_CoinList[i];
  101.         }
  102.     }
  103.     return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement