Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Bittrex::GetMyOpenOrdersReplyFinished()
- {
- QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
- if(reply->error())
- {
- reply->deleteLater();
- return;
- }
- QString strReply = (QString)reply->readAll();
- QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8());
- QJsonObject jsonObject = jsonResponse.object();
- bool suc = jsonObject["success"].toBool();
- if(suc != true)
- return;
- QJsonArray data = jsonObject["result"].toArray();
- int coinIndex = 0;
- qint64 checkTime = QDateTime::currentMSecsSinceEpoch();
- foreach (const QJsonValue & value, data)
- {
- QJsonObject obj = value.toObject();
- QString orderId = obj["OrderUuid"].toString();
- QString currency = obj["Exchange"].toString();
- CoinInfo *coin = FindCoinByName(currency, coinIndex);
- if(coin == 0)
- continue;
- bool match = false;
- foreach (OpenTradeData *openTrade, coin->m_OpenTradeList)
- {
- if(openTrade->OrderId == orderId)
- {
- openTrade->Checked = checkTime;
- match = true;
- break;
- }
- }
- if(match)
- continue;
- QString orderType = obj["OrderType"].toString();
- qreal quantity = obj["Quantity"].toDouble();
- qreal atPrice = obj["Limit"].toDouble();
- QString time = obj["Opened"].toString();
- QDateTime timeStamp = QDateTime::fromString(time, Qt::ISODate).addSecs(7200);
- QString timeStr = timeStamp.toString("M/d/yyyy h:m:s");
- OpenTradeData *openTradeData = 0;
- if(orderType == "LIMIT_SELL")
- {
- openTradeData = new OpenTradeData(coin, orderId, "Bittrex", coin->GetCoinName(), timeStr,
- "SELL", QString::number(quantity, 'f', 8), "",
- coin->GetLastTradePriceStr(), "0.0", QString::number(atPrice, 'f', 8));
- }
- else if(orderType == "LIMIT_BUY")
- {
- openTradeData = new OpenTradeData(coin, orderId, "Bittrex", coin->GetCoinName(), timeStr,
- "BUY", QString::number(quantity, 'f', 8), QString::number(atPrice, 'f', 8),
- coin->GetLastTradePriceStr(), "0.0f", "0.0f");
- }
- // GetMyOrdersHistory(currency, coinIndex);
- coin->m_OpenTradeList.append(openTradeData);
- emit NewOpenOrderToTable(openTradeData);
- }
- // this loop will remove trades that does not match the one from web
- foreach (OpenTradeData *openTrade, coin->m_OpenTradeList)
- {
- if(openTrade->Checked != checkTime)
- {
- // remove
- // emit updateguiremove...
- }
- }
- reply->deleteLater();
- }
- CoinInfo *Bittrex::FindCoinByName(QString coinName)
- {
- for(int i = 0; i < m_CoinList.size(); i++)
- {
- if(m_CoinList[i]->GetCoinName() == coinName)
- {
- return m_CoinList[i];
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement