Skip to content

Commit e81a52c

Browse files
committed
Error handling of nonexistent pairs for all existing exchanges
1 parent f9d2453 commit e81a52c

1 file changed

Lines changed: 43 additions & 28 deletions

File tree

main.cpp

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -356,51 +356,54 @@ QMap<QString, QMap<QString, QString>> get_exchange_data(QString current_sources,
356356
QJsonDocument doc = QJsonDocument::fromJson(data);
357357
QJsonArray json_array = doc.array();
358358

359+
// It checks if there are any messages. They usually appear when we ask for a pair that doesn't exist.
360+
if (data.contains("Invalid")) {
361+
qInfo() << domain << ":" << data;
362+
nonexistent_pair = true;
363+
}
364+
359365
// Checking connection errors
360-
network_status = (json_array.empty()) ? 1 : 0;
361-
if (network_status == 1) {
366+
if (network_status == 1 || nonexistent_pair == true) {
362367

363368
for (int i = 0; i < symbol_list.size(); ++i) {
364369
output.insert(symbol_list[i], return_null_map());
365370
}
366371

367-
return output;
368-
}
369-
370-
for (int i = 0; i < symbol_list.size(); ++i) {
372+
} else {
373+
for (int i = 0; i < symbol_list.size(); ++i) {
371374

372-
QJsonValue values = json_array[i];
373-
QJsonObject obj = values.toObject();
375+
QJsonValue values = json_array[i];
376+
QJsonObject obj = values.toObject();
374377

375-
QString current_symbol = obj["symbol"].toString();
378+
QString current_symbol = obj["symbol"].toString();
376379

377-
QMap<QString, QString> inner_map;
378-
inner_map.insert("symbol", current_symbol);
379-
inner_map.insert("price", digit_format(obj["lastPrice"]));
380-
inner_map.insert("price_24h", digit_format(obj["highPrice"]));
381-
inner_map.insert("price_24l", digit_format(obj["lowPrice"]));
382-
inner_map.insert("price_percent_change", digit_format(obj["priceChangePercent"], 2));
380+
QMap<QString, QString> inner_map;
381+
inner_map.insert("symbol", current_symbol);
382+
inner_map.insert("price", digit_format(obj["lastPrice"]));
383+
inner_map.insert("price_24h", digit_format(obj["highPrice"]));
384+
inner_map.insert("price_24l", digit_format(obj["lowPrice"]));
385+
inner_map.insert("price_percent_change", digit_format(obj["priceChangePercent"], 2));
383386

384-
// Set High/Low 24h price difference
385-
double d_H24 = obj["highPrice"].toString().toDouble();
386-
double d_L24 = obj["lowPrice"].toString().toDouble();
387-
inner_map.insert("price_difference", digit_format((d_H24-d_L24)/(d_L24/100), 2));
387+
// Set High/Low 24h price difference
388+
double d_H24 = obj["highPrice"].toString().toDouble();
389+
double d_L24 = obj["lowPrice"].toString().toDouble();
390+
inner_map.insert("price_difference", digit_format((d_H24-d_L24)/(d_L24/100), 2));
388391

389-
for (QString symbol : symbol_list) {
390-
QString raw = symbol;
391-
raw.replace("-", "");
392+
for (QString symbol : symbol_list) {
393+
QString raw = symbol;
394+
raw.replace("-", "");
392395

393-
if (raw == current_symbol) {
396+
if (raw == current_symbol) {
394397

395-
QStringList parts = symbol.split("-");
396-
inner_map.insert("coin", parts[0]);
398+
QStringList parts = symbol.split("-");
399+
inner_map.insert("coin", parts[0]);
397400

398-
output.insert(symbol, inner_map);break;
401+
output.insert(symbol, inner_map);break;
402+
}
399403
}
400-
}
401404

405+
}
402406
}
403-
404407
}
405408
else if (current_sources == "poloniex_com") { // poloniex.com
406409

@@ -432,6 +435,18 @@ QMap<QString, QMap<QString, QString>> get_exchange_data(QString current_sources,
432435
QString current_symbol = symbol;
433436

434437
QJsonValue jv_symbol_value = json_obj.value(symbol);
438+
439+
// It checks if there are any messages. They usually appear when we ask for a pair that doesn't exist.
440+
if (jv_symbol_value.isUndefined()) {
441+
442+
QStringList pairs = symbol_list[i].split("-");
443+
output.insert(symbol_list[i], return_null_map("ERROR", pairs.at(0)));
444+
qInfo() << "Pair that doesn't exist" << " : " << symbol_list[i];
445+
446+
nonexistent_pair = true;
447+
continue;
448+
}
449+
435450
QJsonObject jo_symbol_value = jv_symbol_value.toObject();
436451

437452
QMap<QString, QString> inner_map;

0 commit comments

Comments
 (0)