Skip to content

Commit 84cc35b

Browse files
committed
Clean-up
1 parent 39c77d9 commit 84cc35b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+117
-143
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ coincenter --price sol-btc
430430

431431
### Conversion path
432432

433-
Option `--conversion-path` is used by `--multitrade` option (see [Multi trade](#multi-trade)) but may be used as stand-alone for information.
433+
Option `--conversion` is used by `--multitrade` option (see [Multi trade](#multi-trade)) but may be used as stand-alone for information.
434434
From a starting currency to a destination currency, `coincenter` examines the shortest conversion path (in terms of number of conversion) possible to reach the destination currency, on optional list of exchanges.
435435

436436
It will print the result as an ordered list of markets for each exchange.

monitoring/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ The first time you launch grafana, you should access it with admin/admin credent
6161
- process_cpu_seconds_total
6262
- foobar_build_info
6363

64-
## Labels
64+
## Labels
6565
Use labels to differentiate the characteristics of the thing that is being measured:
6666
currency="EOS" or "USD"...

src/api/common/include/cryptowatchapi.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@
77

88
#include "cachedresult.hpp"
99
#include "cct_flatset.hpp"
10-
#include "cct_run_modes.hpp"
1110
#include "curlhandle.hpp"
1211
#include "exchangebase.hpp"
1312
#include "market.hpp"
13+
#include "runmodes.hpp"
14+
#include "timehelpers.hpp"
1415

1516
namespace cct {
1617
class CoincenterInfo;
1718
namespace api {
1819
/// Public API connected to different exchanges, providing fast methods to retrieve huge amount of data.
1920
class CryptowatchAPI : public ExchangeBase {
2021
public:
21-
using Clock = std::chrono::high_resolution_clock;
22-
using TimePoint = std::chrono::time_point<Clock>;
23-
2422
explicit CryptowatchAPI(const CoincenterInfo &config, settings::RunMode runMode = settings::RunMode::kProd,
2523
Clock::duration fiatsUpdateFrequency = std::chrono::hours(96),
2624
bool loadFromFileCacheAtInit = true);

src/api/common/include/tradeoptions.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
#include <string_view>
55

66
#include "cct_string.hpp"
7+
#include "timehelpers.hpp"
78
#include "tradedefinitions.hpp"
89

910
namespace cct {
1011
class TradeOptions {
1112
public:
12-
using Clock = std::chrono::high_resolution_clock;
13-
using TimePoint = std::chrono::time_point<Clock>;
14-
1513
static constexpr Clock::duration kDefaultTradeDuration = std::chrono::seconds(30);
1614
static constexpr Clock::duration kDefaultMinTimeBetweenPriceUpdates = std::chrono::seconds(5);
1715

src/api/common/src/cryptowatchapi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#include "cct_file.hpp"
77
#include "cct_json.hpp"
88
#include "cct_log.hpp"
9-
#include "cct_toupperlower.hpp"
109
#include "coincenterinfo.hpp"
10+
#include "toupperlower.hpp"
1111

1212
namespace cct {
1313
namespace api {

src/api/common/src/exchangeprivateapi.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <chrono>
44
#include <thread>
55

6-
#include "cct_time_helpers.hpp"
6+
#include "timehelpers.hpp"
77

88
namespace cct {
99
namespace api {
@@ -27,8 +27,7 @@ void ExchangePrivate::addBalance(BalancePortfolio &balancePortfolio, MonetaryAmo
2727
if (optConvertedAmountEquiCurrency) {
2828
equivalentInMainCurrency = *optConvertedAmountEquiCurrency;
2929
} else {
30-
log::warn("Cannot convert {} into {} on {}", amount.currencyCode().str(), equiCurrency.str(),
31-
_exchangePublic.name());
30+
log::warn("Cannot convert {} into {} on {}", amount.currencyStr(), equiCurrency.str(), _exchangePublic.name());
3231
equivalentInMainCurrency = MonetaryAmount(0, equiCurrency);
3332
}
3433
log::debug("{} Balance {} (eq. {})", _exchangePublic.name(), amount.str(), equivalentInMainCurrency.str());
@@ -55,7 +54,7 @@ MonetaryAmount ExchangePrivate::multiTrade(MonetaryAmount &from, CurrencyCode to
5554
_exchangePublic.findFastestConversionPath(from.currencyCode(), toCurrency);
5655
if (conversionPath.empty()) {
5756
log::error("Cannot trade {} into {} on {}", initialAmount.str(), toCurrency.str(), _exchangePublic.name());
58-
return MonetaryAmount(0, toCurrency, 0);
57+
return MonetaryAmount(0, toCurrency);
5958
}
6059
const int nbTrades = conversionPath.size();
6160
MonetaryAmount avAmount = from;

src/api/exchanges/include/binancepublicapi.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
#include "cachedresult.hpp"
77
#include "cct_json.hpp"
8-
#include "cct_time_helpers.hpp"
98
#include "curlhandle.hpp"
109
#include "currencycode.hpp"
1110
#include "exchangepublicapi.hpp"
11+
#include "timehelpers.hpp"
1212
#include "volumeandpricenbdecimals.hpp"
1313

1414
namespace cct {

src/api/exchanges/include/bithumbprivateapi.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#include <unordered_map>
44

55
#include "cachedresult.hpp"
6-
#include "cct_time_helpers.hpp"
76
#include "curlhandle.hpp"
87
#include "exchangeprivateapi.hpp"
8+
#include "timehelpers.hpp"
99
#include "tradeinfo.hpp"
1010

1111
namespace cct {

src/api/exchanges/include/bithumbpublicapi.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#pragma once
22

33
#include "cachedresult.hpp"
4-
#include "cct_time_helpers.hpp"
54
#include "curlhandle.hpp"
65
#include "exchangepublicapi.hpp"
6+
#include "timehelpers.hpp"
77

88
namespace cct {
99

src/api/exchanges/include/krakenpublicapi.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#include "cachedresult.hpp"
44
#include "cct_string.hpp"
5-
#include "cct_time_helpers.hpp"
65
#include "curlhandle.hpp"
76
#include "exchangepublicapi.hpp"
7+
#include "timehelpers.hpp"
88
#include "volumeandpricenbdecimals.hpp"
99
namespace cct {
1010

src/api/exchanges/src/binanceprivateapi.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ json PrivateQuery(CurlHandle& curlHandle, const APIKey& apiKey, CurlOptions::Req
4444
if (binanceError(dataJson)) {
4545
int statusCode = dataJson["code"]; // "1100" for instance
4646
int nbRetries = 0;
47-
CurlHandle::Clock::duration sleepingTime = curlHandle.minDurationBetweenQueries();
47+
Clock::duration sleepingTime = curlHandle.minDurationBetweenQueries();
4848
while (++nbRetries < kNbOrderRequestsRetries && (statusCode == -2013 || statusCode == -2011)) {
4949
// Order does not exist : this may be possible when we query an order info too fast
5050
log::warn("Binance cannot find order yet");
@@ -161,7 +161,7 @@ PlaceOrderInfo BinancePrivate::placeOrder(MonetaryAmount from, MonetaryAmount vo
161161
kBinanceCoinCur.str());
162162
json result = PrivateQuery(_curlHandle, _apiKey, CurlOptions::RequestType::kPost,
163163
binancePublic._commonInfo.getBestBaseURL(), "/sapi/v1/asset/dust",
164-
{{"asset", from.currencyCode().str()}});
164+
{{"asset", from.currencyStr()}});
165165
if (!result.contains("transferResult") || result["transferResult"].empty()) {
166166
throw exception("Unexpected dust transfer result");
167167
}
@@ -277,8 +277,7 @@ TradedAmounts BinancePrivate::parseTrades(Market m, CurrencyCode fromCurrencyCod
277277
} else if (fee.currencyCode() == detailTradedInfo.tradedTo.currencyCode()) {
278278
detailTradedInfo.tradedTo -= fee;
279279
} else {
280-
log::warn("Fee is deduced from {} which is outside {}, do not count it in this trade", fee.currencyCode().str(),
281-
m.str());
280+
log::warn("Fee is deduced from {} which is outside {}, do not count it in this trade", fee.currencyStr(), m.str());
282281
}
283282
return detailTradedInfo;
284283
}

src/api/exchanges/src/binancepublicapi.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ json PublicQuery(CurlHandle& curlHandle, std::string_view baseURL, std::string_v
4747
return dataJson;
4848
}
4949

50-
CurlHandle::Clock::duration Ping(CurlHandle& curlHandle, std::string_view baseURL) {
51-
CurlHandle::TimePoint t1 = CurlHandle::Clock::now();
50+
Clock::duration Ping(CurlHandle& curlHandle, std::string_view baseURL) {
51+
TimePoint t1 = Clock::now();
5252
json sysTime = PublicQuery(curlHandle, baseURL, "time");
53-
CurlHandle::TimePoint t2 = CurlHandle::Clock::now();
54-
CurlHandle::Clock::duration ping = t2 - t1;
53+
TimePoint t2 = Clock::now();
54+
Clock::duration ping = t2 - t1;
5555
if (!sysTime.contains("serverTime")) {
5656
throw exception("Binance reply should contain system time information");
5757
}
58-
CurlHandle::TimePoint binanceSysTimePoint(std::chrono::milliseconds(sysTime["serverTime"].get<uint64_t>()));
58+
TimePoint binanceSysTimePoint(std::chrono::milliseconds(sysTime["serverTime"].get<uint64_t>()));
5959
if (t1 < binanceSysTimePoint && binanceSysTimePoint < t2) {
6060
log::debug("Your system clock is synchronized with Binance one");
6161
} else {
@@ -120,7 +120,7 @@ BinancePublic::CommonInfo::CommonInfo(const CoincenterInfo& coincenterInfo, cons
120120
_baseURLUpdater(CachedResultOptions(std::chrono::hours(96))) {}
121121

122122
std::string_view BinancePublic::CommonInfo::BaseURLUpdater::operator()() {
123-
CurlHandle::Clock::duration pingDurations[kNbBaseURLs];
123+
Clock::duration pingDurations[kNbBaseURLs];
124124
std::transform(std::execution::par, std::begin(_curlHandles), std::end(_curlHandles),
125125
std::begin(BinancePublic::kURLBases), std::begin(pingDurations), Ping);
126126
int minPingDurationPos = static_cast<int>(std::min_element(std::begin(pingDurations), std::end(pingDurations)) -

src/api/exchanges/src/bithumbprivateapi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ PlaceOrderInfo BithumbPrivate::placeOrder(MonetaryAmount /*from*/, MonetaryAmoun
250250
MaxNbDecimalsUnitMap::const_iterator maxUnitNbDecimalsIt = _maxNbDecimalsUnitMap.find(m.base());
251251
int8_t nbMaxDecimalsUnits = std::numeric_limits<MonetaryAmount::AmountType>::digits10;
252252
if (maxUnitNbDecimalsIt != _maxNbDecimalsUnitMap.end() &&
253-
maxUnitNbDecimalsIt->second.lastUpdatedTime + _nbDecimalsRefreshTime > TradeOptions::Clock::now()) {
253+
maxUnitNbDecimalsIt->second.lastUpdatedTime + _nbDecimalsRefreshTime > Clock::now()) {
254254
nbMaxDecimalsUnits = maxUnitNbDecimalsIt->second.nbDecimals;
255255
volume.truncate(nbMaxDecimalsUnits);
256256
}

src/api/exchanges/src/huobiprivateapi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
#include "apikey.hpp"
77
#include "cct_codec.hpp"
88
#include "cct_nonce.hpp"
9-
#include "cct_toupperlower.hpp"
109
#include "huobipublicapi.hpp"
1110
#include "ssl_sha.hpp"
1211
#include "stringhelpers.hpp"
12+
#include "toupperlower.hpp"
1313

1414
namespace cct {
1515
namespace api {

src/api/exchanges/src/huobipublicapi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
#include "cct_exception.hpp"
1010
#include "cct_log.hpp"
11-
#include "cct_toupperlower.hpp"
1211
#include "coincenterinfo.hpp"
1312
#include "cryptowatchapi.hpp"
1413
#include "fiatconverter.hpp"
1514
#include "monetaryamount.hpp"
15+
#include "toupperlower.hpp"
1616

1717
namespace cct {
1818
namespace api {

src/api/exchanges/src/krakenprivateapi.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
#include "cct_json.hpp"
1010
#include "cct_log.hpp"
1111
#include "cct_nonce.hpp"
12-
#include "cct_time_helpers.hpp"
1312
#include "coincenterinfo.hpp"
1413
#include "krakenpublicapi.hpp"
1514
#include "ssl_sha.hpp"
1615
#include "stringhelpers.hpp"
16+
#include "timehelpers.hpp"
1717

1818
namespace cct {
1919
namespace api {
@@ -55,7 +55,7 @@ json PrivateQuery(CurlHandle& curlHandle, const APIKey& apiKey, std::string_view
5555

5656
string ret = curlHandle.query(method_url, opts);
5757
json jsonData = json::parse(std::move(ret));
58-
CurlHandle::Clock::duration sleepingTime = curlHandle.minDurationBetweenQueries();
58+
Clock::duration sleepingTime = curlHandle.minDurationBetweenQueries();
5959
while (jsonData.contains("error") && !jsonData["error"].empty() &&
6060
jsonData["error"].front().get<std::string_view>() == "EAPI:Rate limit exceeded") {
6161
log::error("Kraken private API rate limit exceeded");

src/api/exchanges/src/kucoinprivateapi.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
#include "apikey.hpp"
66
#include "cct_codec.hpp"
77
#include "cct_nonce.hpp"
8-
#include "cct_toupperlower.hpp"
98
#include "kucoinpublicapi.hpp"
109
#include "ssl_sha.hpp"
10+
#include "toupperlower.hpp"
1111

1212
namespace cct {
1313
namespace api {
@@ -16,9 +16,6 @@ namespace {
1616

1717
json PrivateQuery(CurlHandle& curlHandle, const APIKey& apiKey, CurlOptions::RequestType requestType,
1818
std::string_view method, CurlPostData&& postdata = CurlPostData()) {
19-
const bool endpointWithParameters =
20-
requestType == CurlOptions::RequestType::kGet || requestType == CurlOptions::RequestType::kDelete;
21-
2219
CurlOptions opts(requestType, std::move(postdata));
2320

2421
Nonce nonce = Nonce_TimeSinceEpoch();
@@ -27,7 +24,7 @@ json PrivateQuery(CurlHandle& curlHandle, const APIKey& apiKey, CurlOptions::Req
2724
strToSign.append(method);
2825

2926
if (!opts.postdata.empty()) {
30-
if (endpointWithParameters) {
27+
if (requestType == CurlOptions::RequestType::kGet || requestType == CurlOptions::RequestType::kDelete) {
3128
strToSign.push_back('?');
3229
strToSign.append(opts.postdata.str());
3330
} else {
@@ -76,7 +73,7 @@ void InnerTransfer(CurlHandle& curlHandle, const APIKey& apiKey, MonetaryAmount
7673
log::info("Perform inner transfer of {} to {} account", amount.str(), toStr);
7774
PrivateQuery(curlHandle, apiKey, CurlOptions::RequestType::kPost, "/api/v2/accounts/inner-transfer",
7875
{{"clientOid", Nonce_TimeSinceEpoch()}, // Not really needed, but it's mandatory apparently
79-
{"currency", amount.currencyCode().str()},
76+
{"currency", amount.currencyStr()},
8077
{"amount", amount.amountStr()},
8178
{"from", fromStr},
8279
{"to", toStr}});

src/api/exchanges/src/kucoinpublicapi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
#include "cct_exception.hpp"
1010
#include "cct_log.hpp"
11-
#include "cct_toupperlower.hpp"
1211
#include "coincenterinfo.hpp"
1312
#include "cryptowatchapi.hpp"
1413
#include "fiatconverter.hpp"
1514
#include "monetaryamount.hpp"
1615
#include "stringhelpers.hpp"
16+
#include "toupperlower.hpp"
1717

1818
namespace cct {
1919
namespace api {

src/api/exchanges/src/upbitprivateapi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
#include "cct_json.hpp"
1515
#include "cct_log.hpp"
1616
#include "cct_nonce.hpp"
17-
#include "cct_toupperlower.hpp"
1817
#include "coincenterinfo.hpp"
1918
#include "monetaryamount.hpp"
2019
#include "ssl_sha.hpp"
20+
#include "toupperlower.hpp"
2121
#include "upbitpublicapi.hpp"
2222

2323
namespace cct {

src/engine/include/coincenteroptions.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@
77

88
#include "cct_const.hpp"
99
#include "cct_string.hpp"
10-
#include "cct_time_helpers.hpp"
1110
#include "commandlineoptionsparser.hpp"
1211
#include "currencycode.hpp"
1312
#include "stringhelpers.hpp"
13+
#include "timehelpers.hpp"
1414
#include "tradeoptions.hpp"
1515
#include "wallet.hpp"
1616

1717
namespace cct {
1818

1919
struct CoincenterCmdLineOptions {
20-
using Duration = Clock::duration;
21-
2220
static constexpr std::string_view kDefaultMonitoringIPAddress = "0.0.0.0"; // in Docker, localhost does not work
2321
static constexpr int kDefaultMonitoringPort = 9091; // Prometheus default push port
2422
static constexpr Duration kDefaultRepeatTime = std::chrono::seconds(1);
@@ -119,8 +117,8 @@ CommandLineOptionsParser<OptValueType> CreateCoincenterCommandLineOptionsParser(
119117
{{{"Public queries", 2}, "--ticker", "[exch1,...]", "Print ticker information for all markets for all exchanges,"
120118
"or only for specified ones"},
121119
&OptValueType::ticker},
122-
{{{"Public queries", 2}, "--conversion-path", 'c', "<cur1-cur2[,exch1,...]>", "Print fastest conversion path of 'cur1' to 'cur2' "
123-
"for given exchanges if possible"},
120+
{{{"Public queries", 2}, "--conversion", 'c', "<cur1-cur2[,exch1,...]>", "Print fastest conversion path of 'cur1' to 'cur2' "
121+
"for given exchanges if possible"},
124122
&OptValueType::conversion_path},
125123
{{{"Public queries", 2}, "--volume-day", "<cur1-cur2[,exch1,...]>", "Print last 24h traded volume for market 'cur1'-'cur2' "
126124
"for all exchanges (or specified one)"},

src/engine/include/coincenterparsedoptions.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
#include "cct_const.hpp"
77
#include "cct_string.hpp"
8-
#include "cct_time_helpers.hpp"
98
#include "commandlineoptionsparser.hpp"
109
#include "currencycode.hpp"
1110
#include "exchangename.hpp"
1211
#include "market.hpp"
1312
#include "monetaryamount.hpp"
13+
#include "timehelpers.hpp"
1414
#include "tradeoptions.hpp"
1515

1616
namespace cct {

src/engine/src/coincenter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
#include "cct_exception.hpp"
1212
#include "cct_fixedcapacityvector.hpp"
1313
#include "cct_smallvector.hpp"
14-
#include "cct_time_helpers.hpp"
1514
#include "coincenteroptions.hpp"
1615
#include "coincenterparsedoptions.hpp"
1716
#include "simpletable.hpp"
1817
#include "stringoptionparser.hpp"
18+
#include "timehelpers.hpp"
1919

2020
namespace cct {
2121

@@ -274,7 +274,7 @@ void Coincenter::exportBalanceMetrics(const BalancePerExchange &balancePerExchan
274274
key.set("total", "no");
275275
MonetaryAmount totalEquiAmount(0, equiCurrency);
276276
for (BalancePortfolio::MonetaryAmountWithEquivalent amountWithEqui : balancePortfolio) {
277-
key.set("currency", amountWithEqui.amount.currencyCode().str());
277+
key.set("currency", amountWithEqui.amount.currencyStr());
278278
metricGateway.add(MetricType::kGauge, MetricOperation::kSet, key, amountWithEqui.amount.toDouble());
279279
if (!equiCurrency.isNeutral()) {
280280
totalEquiAmount += amountWithEqui.equi;

src/monitoring/include/prometheusmetricgateway.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <utility>
1111

1212
#include "abstractmetricgateway.hpp"
13-
#include "cct_time_helpers.hpp"
13+
#include "timehelpers.hpp"
1414

1515
/// Registry to collect stats
1616
namespace cct {

0 commit comments

Comments
 (0)