Skip to content

Commit

Permalink
Improve returned trade result information
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanel committed Nov 1, 2023
1 parent 715d209 commit a5ee4c5
Show file tree
Hide file tree
Showing 44 changed files with 1,957 additions and 1,176 deletions.
238 changes: 208 additions & 30 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/api-objects/include/tradeoptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class TradeOptions {

string str(bool placeRealOrderInSimulationMode) const;

bool operator==(const TradeOptions &) const = default;
bool operator==(const TradeOptions &) const noexcept = default;

private:
Duration _maxTradeTime = kDefaultTradeDuration;
Expand Down
2 changes: 2 additions & 0 deletions src/api-objects/include/withdrawoptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class WithdrawOptions {

std::string_view withdrawSyncPolicyStr() const;

bool operator==(const WithdrawOptions &) const noexcept = default;

private:
/// The waiting time between each query of withdraw info to check withdraw status from an exchange.
/// A very small value is not relevant as withdraw time order of magnitude are minutes or hours
Expand Down
2 changes: 2 additions & 0 deletions src/api-objects/include/withdrawsordepositsconstraints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class WithdrawsOrDepositsConstraints {
}
bool isIdOnlyDependent() const { return _currencyIdTimeConstraintsBmp.isDepositIdOnlyDependent(); }

bool operator==(const WithdrawsOrDepositsConstraints &) const noexcept = default;

using trivially_relocatable = is_trivially_relocatable<IdSet>::type;

private:
Expand Down
7 changes: 7 additions & 0 deletions src/api/interface/include/exchange.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ class Exchange {
std::string_view name() const { return _exchangePublic.name(); }
std::string_view keyName() const { return apiPrivate().keyName(); }

ExchangeName createExchangeName() const {
if (hasPrivateAPI()) {
return {name(), keyName()};
}
return ExchangeName(name());
}

api::ExchangePublic &apiPublic() { return _exchangePublic; }
const api::ExchangePublic &apiPublic() const { return _exchangePublic; }

Expand Down
14 changes: 14 additions & 0 deletions src/engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ target_link_libraries(coincenter_engine PUBLIC coincenter_api-interface)
target_link_libraries(coincenter_engine PUBLIC coincenter_objects)
target_include_directories(coincenter_engine PUBLIC include)

add_unit_test(
coincentercommandfactory_test
test/coincentercommandfactory_test.cpp
LIBRARIES
coincenter_engine
)

add_unit_test(
commandlineoptionsparser_test
test/commandlineoptionsparser_test.cpp
Expand Down Expand Up @@ -57,4 +64,11 @@ add_unit_test(
test/stringoptionparser_test.cpp
LIBRARIES
coincenter_engine
)

add_unit_test(
transferablecommandresult_test
test/transferablecommandresult_test.cpp
LIBRARIES
coincenter_engine
)
1 change: 0 additions & 1 deletion src/engine/include/balanceperexchangeportfolio.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include "cct_const.hpp"
#include "cct_json.hpp"
#include "queryresulttypes.hpp"
#include "simpletable.hpp"
Expand Down
8 changes: 3 additions & 5 deletions src/engine/include/coincenter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@

#include <optional>
#include <span>
#include <string_view>

#include "apikeysprovider.hpp"
#include "coincenterinfo.hpp"
#include "commonapi.hpp"
#include "exchange.hpp"
#include "exchangename.hpp"
#include "exchangepool.hpp"
#include "exchangesorchestrator.hpp"
#include "fiatconverter.hpp"
#include "metricsexporter.hpp"
#include "monitoringinfo.hpp"
#include "ordersconstraints.hpp"
#include "queryresultprinter.hpp"
#include "queryresulttypes.hpp"
#include "tradedamounts.hpp"
#include "transferablecommandresult.hpp"

namespace cct {

Expand Down Expand Up @@ -132,7 +129,8 @@ class Coincenter {
const FiatConverter &fiatConverter() const { return _fiatConverter; }

private:
void processCommand(const CoincenterCommand &cmd);
TransferableCommandResultVector processCommand(
const CoincenterCommand &cmd, std::span<const TransferableCommandResult> previousTransferableResults);

const CoincenterInfo &_coincenterInfo;
api::CommonAPI _commonAPI;
Expand Down
2 changes: 2 additions & 0 deletions src/engine/include/coincentercommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class CoincenterCommand {
bool isPercentageAmount() const { return _isPercentageAmount; }
bool withBalanceInUse() const { return _withBalanceInUse; }

bool operator==(const CoincenterCommand&) const noexcept = default;

using trivially_relocatable = std::integral_constant<bool, is_trivially_relocatable_v<ExchangeNames> &&
is_trivially_relocatable_v<OrdersConstraints>>::type;

Expand Down
29 changes: 29 additions & 0 deletions src/engine/include/coincentercommandfactory.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include "coincentercommand.hpp"
#include "coincentercommandtype.hpp"
#include "coincenteroptions.hpp"

namespace cct {
class StringOptionParser;

class CoincenterCommandFactory {
public:
CoincenterCommandFactory(const CoincenterCmdLineOptions &cmdLineOptions, const CoincenterCommand *pPreviousCommand)
: _cmdLineOptions(cmdLineOptions), _pPreviousCommand(pPreviousCommand) {}

static CoincenterCommand CreateMarketCommand(StringOptionParser &optionParser);

CoincenterCommand createOrderCommand(CoincenterCommandType type, StringOptionParser &optionParser);

CoincenterCommand createTradeCommand(CoincenterCommandType type, StringOptionParser &optionParser);

CoincenterCommand createWithdrawApplyCommand(StringOptionParser &optionParser);

CoincenterCommand createWithdrawApplyAllCommand(StringOptionParser &optionParser);

private:
const CoincenterCmdLineOptions &_cmdLineOptions;
const CoincenterCommand *_pPreviousCommand;
};
} // namespace cct
9 changes: 1 addition & 8 deletions src/engine/include/coincentercommands.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#pragma once

#include <span>
#include <string_view>

#include "cct_vector.hpp"
#include "coincentercommand.hpp"
#include "coincenteroptions.hpp"
#include "monitoringinfo.hpp"
#include "timedef.hpp"

namespace cct {
Expand All @@ -16,18 +14,13 @@ class CoincenterCommands {
// Builds a CoincenterCommands without any commands.
CoincenterCommands() noexcept = default;

// Builds a CoincenterCommands and add commands from given command line options.
explicit CoincenterCommands(const CoincenterCmdLineOptions &cmdLineOptions)
: CoincenterCommands(std::span<const CoincenterCmdLineOptions>{&cmdLineOptions, 1U}) {}

// Builds a CoincenterCommands and add commands from given command line options span.
explicit CoincenterCommands(std::span<const CoincenterCmdLineOptions> cmdLineOptionsSpan);

static vector<CoincenterCmdLineOptions> ParseOptions(int argc, const char *argv[]);

/// @brief Set this CoincenterCommands from given command line options.
/// @return false if only help or version is asked, true otherwise
bool addOption(const CoincenterCmdLineOptions &cmdLineOptions);
void addOption(const CoincenterCmdLineOptions &cmdLineOptions, const CoincenterCommand *pPreviousCommand);

std::span<const CoincenterCommand> commands() const { return _commands; }

Expand Down
Loading

0 comments on commit a5ee4c5

Please sign in to comment.