Skip to content

Commit

Permalink
[Upbit & Bithumb] - No order book logs for order book query
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanel committed May 5, 2024
1 parent 6b6ad92 commit 8783fc2
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 53 deletions.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ if(NOT spdlog_FOUND)
list(APPEND fetchContentPackagesToMakeAvailable spdlog)
endif()

# JWT library
FetchContent_Declare(
jwt-cpp
URL https://github.com/Thalhammer/jwt-cpp/archive/refs/tags/v0.7.0.tar.gz
URL_HASH SHA256=b9eb270e3ba8221e4b2bc38723c9a1cb4fa6c241a42908b9a334daff31137406
)

set(JWT_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)

list(APPEND fetchContentPackagesToMakeAvailable jwt-cpp)

# Make fetch content available
if(fetchContentPackagesToMakeAvailable)
message(STATUS "Configuring packages ${fetchContentPackagesToMakeAvailable}")
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ARG BUILD_WITH_PROMETHEUS=1
# Install base & build dependencies, needed certificates for curl to work with https
RUN apt update && \
apt upgrade -y && \
apt install build-essential ninja-build libssl-dev zlib1g-dev libcurl4-openssl-dev cmake git ca-certificates -y --no-install-recommends
apt install build-essential ninja-build libssl-dev zlib1g-dev libcurl4-openssl-dev cmake ca-certificates -y --no-install-recommends

# Copy source files
WORKDIR /app/src
Expand Down
2 changes: 1 addition & 1 deletion alpine.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ARG BUILD_ASAN=0
ARG BUILD_WITH_PROMETHEUS=1

# Install base & build dependencies, needed certificates for curl to work with https
RUN apk add --update --upgrade --no-cache g++ libc-dev openssl-dev zlib-dev curl-dev cmake ninja git ca-certificates
RUN apk add --update --upgrade --no-cache g++ libc-dev openssl-dev zlib-dev curl-dev cmake ninja ca-certificates

# Copy source files
WORKDIR /app/src
Expand Down
11 changes: 0 additions & 11 deletions src/api/exchanges/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@

include(FetchContent)

FetchContent_Declare(
jwt-cpp
GIT_REPOSITORY https://github.com/Thalhammer/jwt-cpp
GIT_TAG v0.7.0
GIT_SHALLOW true
)

set(JWT_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)

FetchContent_MakeAvailable(jwt-cpp)

aux_source_directory(src API_EXCHANGES_SRC)

add_library(coincenter_api-exchange STATIC ${API_EXCHANGES_SRC})
Expand Down
4 changes: 3 additions & 1 deletion src/api/exchanges/src/bithumbpublicapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ MarketOrderBookMap GetOrderBooks(CurlHandle& curlHandle, const CoincenterInfo& c
}
}
}
log::info("Retrieved {} markets (+ order books) from Bithumb", ret.size());
if (ret.size() > 1) {
log::info("Retrieved {} markets (+ order books) from Bithumb", ret.size());
}
return ret;
}
} // namespace
Expand Down
5 changes: 3 additions & 2 deletions src/api/exchanges/src/upbitpublicapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ std::optional<MonetaryAmount> UpbitPublic::queryWithdrawalFee(CurrencyCode curre
CurrencyExchangeFlatSet UpbitPublic::TradableCurrenciesFunc::operator()() {
const MarketSet& markets = _marketsCache.get();
CurrencyExchangeFlatSet currencies;
currencies.reserve(markets.size() / 2);
for (Market mk : markets) {
currencies.emplace(mk.base(), mk.base(), mk.base());
currencies.emplace(mk.quote(), mk.quote(), mk.quote());
Expand Down Expand Up @@ -219,7 +218,9 @@ MarketOrderBookMap ParseOrderBooks(const json& result, int depth) {
}
ret.insert_or_assign(market, MarketOrderBook(time, market, orderBookLines));
}
log::info("Retrieved {} order books from Upbit", ret.size());
if (ret.size() > 1) {
log::info("Retrieved {} order books from Upbit", ret.size());
}
return ret;
}
} // namespace
Expand Down
57 changes: 22 additions & 35 deletions src/engine/src/coincenteroptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,41 +43,28 @@ std::ostream& CoincenterCmdLineOptions::PrintVersion(std::string_view programNam
void CoincenterCmdLineOptions::mergeGlobalWith(const CoincenterCmdLineOptions& rhs) {
static constexpr CoincenterCmdLineOptions kDefaultOpts;

if (rhs.dataDir != kDefaultOpts.dataDir) {
dataDir = rhs.dataDir;
}
if (rhs.logConsole != kDefaultOpts.logConsole) {
logConsole = rhs.logConsole;
}
if (rhs.logFile != kDefaultOpts.logFile) {
logFile = rhs.logFile;
}
if (rhs.noSecrets != kDefaultOpts.noSecrets) {
noSecrets = rhs.noSecrets;
}
if (rhs.repeatTime != kDefaultOpts.repeatTime) {
repeatTime = rhs.repeatTime;
}
if (rhs.monitoringAddress != kDefaultOpts.monitoringAddress) {
monitoringAddress = rhs.monitoringAddress;
}
if (rhs.monitoringUsername != kDefaultOpts.monitoringUsername) {
monitoringUsername = rhs.monitoringUsername;
}
if (rhs.monitoringPassword != kDefaultOpts.monitoringPassword) {
monitoringPassword = rhs.monitoringPassword;
}

if (rhs.repeats != kDefaultOpts.repeats) {
repeats = rhs.repeats;
}

if (rhs.monitoringPort != kDefaultOpts.monitoringPort) {
monitoringPort = rhs.monitoringPort;
}
if (rhs.useMonitoring != kDefaultOpts.useMonitoring) {
useMonitoring = rhs.useMonitoring;
}
// Yes, an ugly macro ! I find it appropriate here, to minimize risk of copy-pasting mistakes.
// It's also more readable.
#define CCT_OPTIONS_MERGE_GLOBAL_WITH(field) \
do { \
if (rhs.field != kDefaultOpts.field) { \
(field) = rhs.field; \
} \
} while (0)

CCT_OPTIONS_MERGE_GLOBAL_WITH(dataDir);
CCT_OPTIONS_MERGE_GLOBAL_WITH(logConsole);
CCT_OPTIONS_MERGE_GLOBAL_WITH(logFile);
CCT_OPTIONS_MERGE_GLOBAL_WITH(noSecrets);
CCT_OPTIONS_MERGE_GLOBAL_WITH(repeatTime);
CCT_OPTIONS_MERGE_GLOBAL_WITH(monitoringAddress);
CCT_OPTIONS_MERGE_GLOBAL_WITH(monitoringUsername);
CCT_OPTIONS_MERGE_GLOBAL_WITH(monitoringPassword);
CCT_OPTIONS_MERGE_GLOBAL_WITH(repeats);
CCT_OPTIONS_MERGE_GLOBAL_WITH(monitoringPort);
CCT_OPTIONS_MERGE_GLOBAL_WITH(useMonitoring);

#undef CCT_OPTIONS_MERGE_GLOBAL_WITH
}

TradeOptions CoincenterCmdLineOptions::computeTradeOptions() const {
Expand Down
4 changes: 2 additions & 2 deletions src/http-request/src/curlhandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ std::string_view CurlHandle::query(std::string_view endpoint, const CurlOptions
if (nowTime < _lastQueryTime + _minDurationBetweenQueries) {
// We should sleep a bit before performing query
const Duration sleepingTime = _minDurationBetweenQueries - (nowTime - _lastQueryTime);
log::debug("Wait {} before performing query", DurationToString(sleepingTime));
log::trace("Wait {} before performing query", DurationToString(sleepingTime));
std::this_thread::sleep_for(sleepingTime);
_lastQueryTime = nowTime + sleepingTime;
} else {
Expand All @@ -251,7 +251,7 @@ std::string_view CurlHandle::query(std::string_view endpoint, const CurlOptions
log::log(_requestCallLogLevel, "{} {}{}{}", ToString(opts.requestType()), modifiedURL, optsStr.empty() ? "" : "?",
optsStr);

// Actually make the query, with a fast retry mechanism
// Actually make the query, with a fast retry mechanism (to avoid random technical errors)
Duration sleepingTime = milliseconds(100);
int retryPos = 0;
CURLcode res;
Expand Down

0 comments on commit 8783fc2

Please sign in to comment.