Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Code refactoring] - Migrate exchange config to glaze json #614

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ As an example, consider this file:
}
}
},
"tradefees": {
"tradeFees": {
"default": {
"maker": "0.1",
},
Expand All @@ -116,7 +116,7 @@ As an example, consider this file:

The chosen values will be:

| Exchange | `asset/withdrawExclude` | `tradefees/maker` |
| Exchange | `asset/withdrawExclude` | `tradeFees/maker` |
| -------- | ----------------------- | ----------------- |
| Binance | `BTC,BQX` | `0.1` |
| Kraken | `BTC,EUR,KFEE` | `0.1` |
Expand Down Expand Up @@ -146,8 +146,8 @@ Refer to the hardcoded default json example as a model in case of doubt.
| *query* | **updateFrequency.currencies** | Duration string (ex: `4h`) | Minimum duration between two consecutive requests of currencies |
| *query* | **updateFrequency.markets** | Duration string (ex: `4h`) | Minimum duration between two consecutive requests of markets |
| *query* | **updateFrequency.withdrawalFees** | Duration string (ex: `12h`) | Minimum duration between two consecutive requests of withdrawal fees |
| *query* | **updateFrequency.allOrderbooks** | Duration string (ex: `2s`) | Minimum duration between two consecutive requests of all order books (or ticker) |
| *query* | **updateFrequency.orderbook** | Duration string (ex: `1s`) | Minimum duration between two consecutive requests of a single orderbook |
| *query* | **updateFrequency.allOrderBooks** | Duration string (ex: `2s`) | Minimum duration between two consecutive requests of all order books (or ticker) |
| *query* | **updateFrequency.orderBook** | Duration string (ex: `1s`) | Minimum duration between two consecutive requests of a single orderbook |
| *query* | **updateFrequency.tradedVolume** | Duration string (ex: `4h`) | Minimum duration between two consecutive requests of last traded volume |
| *query* | **updateFrequency.lastPrice** | Duration string (ex: `1s500ms`) | Minimum duration between two consecutive requests of price |
| *query* | **updateFrequency.depositWallet** | Duration string (ex: `1min`) | Minimum duration between two consecutive requests of deposit information (including wallet) |
Expand All @@ -156,12 +156,12 @@ Refer to the hardcoded default json example as a model in case of doubt.
| *query* | **marketDataSerialization** | Boolean (`true` or `false`) | If `true` and `coincenter` is compiled with **protobuf** support, some market data will automatically be exported in the `data/serialization` directory (`orderbook` and `last-trades`) for a long term storage |
| *query* | **multiTradeAllowedByDefault** | Boolean (`true` or `false`) | If `true`, [multi-trade](README.md#multi-trade) will be allowed by default for `trade`, `buy` and `sell`. It can be overridden at command line level with `--no-multi-trade` and `--multi-trade`. |
| *query* | **validateApiKey** | Boolean (`true` or `false`) | If `true`, each loaded private key will be tested at start of the program. In case of a failure, it will be removed from the list of private accounts loaded by `coincenter`, so that later queries do not consider it instead of raising a runtime exception. The downside is that it will make an additional check that will make startup slower. | |
| *tradefees* | **maker** | String as decimal number representing a percentage (for instance, "0.15") | Trade fees occurring when a maker order is matched |
| *tradefees* | **taker** | String as decimal number representing a percentage (for instance, "0.15") | Trade fees occurring when a taker order is matched |
| *tradeFees* | **maker** | String as decimal number representing a percentage (for instance, "0.15") | Trade fees occurring when a maker order is matched |
| *tradeFees* | **taker** | String as decimal number representing a percentage (for instance, "0.15") | Trade fees occurring when a taker order is matched |
| *withdraw* | **validateDepositAddressesInFile** | Boolean (`true` or `false`) | If `true`, each withdraw will perform an additional validation check from a trusted list of "whitelisted" addresses in `depositaddresses.json` file. Withdraw will not be processed if destination wallet is not present in the file. |

##### Notes

- `updateFrequency` is itself a json document containing all duration values as query frequencies.
See [ExchangeConfig default file](src/objects/src/exchangeconfigdefault.hpp) as an example for the syntax.
- `updateFrequency` is itself a json document containing all duration values as query frequencies.
See [ExchangeConfig default file](src/schema/src/exchange-config-default.hpp) as an example for the syntax.
- Unused and not explicitly set values (so, when loaded from default values) from your personal `exchangeconfig.json` file will be logged for information about what will actually be used by `coincenter`.
4 changes: 2 additions & 2 deletions src/api-objects/include/apikeysprovider.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <map>
#include <array>
#include <string_view>

#include "apikey.hpp"
Expand Down Expand Up @@ -42,4 +42,4 @@ class APIKeysProvider {

APIKeysPerExchange _apiKeysPerExchange;
};
} // namespace cct::api
} // namespace cct::api
5 changes: 3 additions & 2 deletions src/api-objects/include/tradeoptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
#include <string_view>

#include "cct_string.hpp"
#include "exchange-query-config.hpp"
#include "monetaryamount.hpp"
#include "priceoptions.hpp"
#include "timedef.hpp"
#include "tradedefinitions.hpp"

namespace cct {
class ExchangeConfig;

class TradeOptions {
public:
static constexpr Duration kDefaultMinTimeBetweenPriceUpdates = seconds(5);
Expand All @@ -28,7 +29,7 @@ class TradeOptions {
TradeSyncPolicy tradeSyncPolicy = TradeSyncPolicy::kSynchronous);

/// Constructs a new TradeOptions based on 'rhs' with unspecified options overriden from exchange config values
TradeOptions(const TradeOptions &rhs, const ExchangeConfig &exchangeConfig);
TradeOptions(const TradeOptions &rhs, const schema::ExchangeQueryTradeConfig &exchangeTradeConfig);

constexpr Duration maxTradeTime() const { return _maxTradeTime; }

Expand Down
13 changes: 6 additions & 7 deletions src/api-objects/src/tradeoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "cct_string.hpp"
#include "durationstring.hpp"
#include "exchangeconfig.hpp"
#include "exchange-query-config.hpp"
#include "priceoptions.hpp"
#include "timedef.hpp"
#include "tradedefinitions.hpp"
Expand All @@ -23,15 +23,14 @@ TradeOptions::TradeOptions(const PriceOptions &priceOptions, TradeTimeoutAction
_tradeTypePolicy(tradeTypePolicy),
_tradeSyncPolicy(tradeSyncPolicy) {}

TradeOptions::TradeOptions(const TradeOptions &rhs, const ExchangeConfig &exchangeConfig)
: _maxTradeTime(rhs._maxTradeTime == kUndefinedDuration ? exchangeConfig.tradeConfig().timeout()
: rhs._maxTradeTime),
TradeOptions::TradeOptions(const TradeOptions &rhs, const schema::ExchangeQueryTradeConfig &exchangeTradeConfig)
: _maxTradeTime(rhs._maxTradeTime == kUndefinedDuration ? exchangeTradeConfig.timeout.duration : rhs._maxTradeTime),
_minTimeBetweenPriceUpdates(rhs._minTimeBetweenPriceUpdates == kUndefinedDuration
? exchangeConfig.tradeConfig().minPriceUpdateDuration()
? exchangeTradeConfig.minPriceUpdateDuration.duration
: rhs._minTimeBetweenPriceUpdates),
_priceOptions(rhs._priceOptions.isDefault() ? PriceOptions(exchangeConfig.tradeConfig()) : rhs._priceOptions),
_priceOptions(rhs._priceOptions.isDefault() ? PriceOptions(exchangeTradeConfig) : rhs._priceOptions),
_timeoutAction(rhs._timeoutAction == TradeTimeoutAction::kDefault
? exchangeConfig.tradeConfig().tradeTimeoutAction()
? (exchangeTradeConfig.timeoutMatch ? TradeTimeoutAction::kMatch : TradeTimeoutAction::kCancel)
: rhs._timeoutAction),
_tradeMode(rhs._tradeMode),
_tradeTypePolicy(rhs._tradeTypePolicy),
Expand Down
7 changes: 3 additions & 4 deletions src/api/common/include/exchange-permanent-curl-options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@

#include <cstdint>

#include "exchange-query-config.hpp"
#include "permanentcurloptions.hpp"

namespace cct {

class ExchangeConfig;

namespace api {

class ExchangePermanentCurlOptions {
public:
explicit ExchangePermanentCurlOptions(const ExchangeConfig &exchangeConfig);
explicit ExchangePermanentCurlOptions(const schema::ExchangeQueryConfig &queryConfig);

enum class Api : int8_t { Public, Private };

PermanentCurlOptions::Builder builderBase(Api api) const;

private:
const ExchangeConfig &_exchangeConfig;
const schema::ExchangeQueryConfig &_queryConfig;
};

} // namespace api
Expand Down
1 change: 0 additions & 1 deletion src/api/common/include/exchangeprivateapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "currencycode.hpp"
#include "currencyexchangeflatset.hpp"
#include "depositsconstraints.hpp"
#include "exchangeconfig.hpp"
#include "exchangeprivateapitypes.hpp"
#include "exchangepublicapi.hpp"
#include "exchangepublicapitypes.hpp"
Expand Down
9 changes: 6 additions & 3 deletions src/api/common/include/exchangepublicapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ namespace cct {
class AbstractMarketDataDeserializer;
class AbstractMarketDataSerializer;
class CoincenterInfo;
class ExchangeConfig;
class FiatConverter;

namespace schema {
struct ExchangeConfig;
}

namespace api {

class ExchangePublic : public CacheFileUpdatorInterface {
Expand Down Expand Up @@ -179,7 +182,7 @@ class ExchangePublic : public CacheFileUpdatorInterface {

const CoincenterInfo &coincenterInfo() const { return _coincenterInfo; }

const ExchangeConfig &exchangeConfig() const { return _exchangeConfig; }
const schema::ExchangeConfig &exchangeConfig() const { return _exchangeConfig; }

CommonAPI &commonAPI() { return _commonApi; }

Expand Down Expand Up @@ -215,7 +218,7 @@ class ExchangePublic : public CacheFileUpdatorInterface {
FiatConverter &_fiatConverter;
CommonAPI &_commonApi;
const CoincenterInfo &_coincenterInfo;
const ExchangeConfig &_exchangeConfig;
const schema::ExchangeConfig &_exchangeConfig;
std::unique_ptr<AbstractMarketDataDeserializer> _marketDataDeserializerPtr;
std::unique_ptr<AbstractMarketDataSerializer> _marketDataSerializerPtr;
std::recursive_mutex _publicRequestsMutex;
Expand Down
18 changes: 9 additions & 9 deletions src/api/common/src/exchange-permanent-curl-options.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
#include "exchange-permanent-curl-options.hpp"

#include "exchangeconfig.hpp"
#include "exchange-query-config.hpp"
#include "permanentcurloptions.hpp"

namespace cct::api {

ExchangePermanentCurlOptions::ExchangePermanentCurlOptions(const ExchangeConfig &exchangeConfig)
: _exchangeConfig(exchangeConfig) {}
ExchangePermanentCurlOptions::ExchangePermanentCurlOptions(const schema::ExchangeQueryConfig &queryConfig)
: _queryConfig(queryConfig) {}

PermanentCurlOptions::Builder ExchangePermanentCurlOptions::builderBase(Api api) const {
PermanentCurlOptions::Builder builder;

builder.setAcceptedEncoding(_exchangeConfig.acceptEncoding())
.setRequestCallLogLevel(_exchangeConfig.requestsCallLogLevel())
.setRequestAnswerLogLevel(_exchangeConfig.requestsAnswerLogLevel())
.setTimeout(_exchangeConfig.httpConfig().timeout());
builder.setAcceptedEncoding(_queryConfig.acceptEncoding)
.setRequestCallLogLevel(_queryConfig.logLevels.requestsCall)
.setRequestAnswerLogLevel(_queryConfig.logLevels.requestsAnswer)
.setTimeout(_queryConfig.http.timeout.duration);

switch (api) {
case Api::Private:
builder.setMinDurationBetweenQueries(_exchangeConfig.privateAPIRate());
builder.setMinDurationBetweenQueries(_queryConfig.privateAPIRate.duration);
break;
case Api::Public:
builder.setMinDurationBetweenQueries(_exchangeConfig.publicAPIRate())
builder.setMinDurationBetweenQueries(_queryConfig.publicAPIRate.duration)
.setTooManyErrorsPolicy(PermanentCurlOptions::TooManyErrorsPolicy::kReturnEmptyResponse);
break;
default:
Expand Down
Loading
Loading