Skip to content

Commit

Permalink
[Code cleaning] - Create PublicTradeVector and MarketOrderBookVector
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanel committed Mar 17, 2024
1 parent 33493ab commit abea1f9
Show file tree
Hide file tree
Showing 54 changed files with 297 additions and 262 deletions.
34 changes: 16 additions & 18 deletions CONFIG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Configuration
=============
# Configuration

At this step, `coincenter` is built. To execute properly, it needs read/write access to a special directory `data` which contains a tree of files as follows:

Expand All @@ -14,9 +13,9 @@ This directory is set according to these rules, by decreasing priority:
- or from `CCT_DATA_DIR` environment variable if it is set at runtime
- or defaults to the default data directory chosen at build time from `CCT_DATA_DIR` environment variable

# Important files
## Important files

## secret/secret.json
### secret/secret.json

Fill this file with your private keys for each of your account(s) in the exchanges.
Of course, no need to say that this file should be kept secret, and not transit in the internet, or any other *Docker* image/layer or *git* commit.
Expand All @@ -26,13 +25,13 @@ For additional security, always bind your keys to your IP (some exchanges will f

[data/secret/secret_test.json](data/secret/secret_test.json) shows the syntax.

### Additional information
#### Additional information

#### Kucoin
##### Kucoin

In addition of the `key` and `private` values, you will need to provide your `passphrase` as well. It's provided as a string field along with your key in the `secret.json` file.

#### Bithumb
##### Bithumb

Bithumb **withdrawals** have an extra personal information check: they need to know the **English** and **Korean** name of the owner of the destination account.
Thus it's also an information that you need to provide in the keys of your targeted accounts for a Bithumb withdrawal.
Expand All @@ -41,13 +40,13 @@ Korean name should be provided with the `accountOwner.koName` field in the key o

Refer to the [data/secret/secret_test.json](data/secret/secret_test.json) example file in case of doubt.

## static/generalconfig.json
### static/generalconfig.json

Contains options that are not exchange specific.

Configures the logging, tracking activity of relevant commands, and console output type.

### Options description
#### General options description

| Name | Value | Description |
| ---------------------------------------------- | ---------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
Expand All @@ -61,10 +60,10 @@ Configures the logging, tracking activity of relevant commands, and console outp
| **log.maxNbFiles** | Integer | Number of maximum rotating files for log in files |
| **requests.concurrency.nbMaxParallelRequests** | Integer | Size of the thread pool that makes exchange requests. |


## static/exchangeconfig.json
### static/exchangeconfig.json

This json file should follow this specific format:

```yaml
- top_level_option:
- default:
Expand All @@ -79,6 +78,7 @@ This json file should follow this specific format:
```
Currently, options are set from two ways:
- **Comma separated values** are aggregated for each exchange with the 'default' values (if present)
- **Single values** are retrieved in a 'bottom first' priority model, meaning that if a value is specified for an exchange name, it is chosen. Otherwise, it checks at the default value for this option, and if again not present, uses a hardcoded default one (cf in the code).
Expand Down Expand Up @@ -122,7 +122,7 @@ The chosen values will be:

Refer to the hardcoded default json example as a model in case of doubt.

### Options description
#### Exchanges options description

| Module | Name | Value | Description |
| ----------- | ---------------------------------- | -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
Expand Down Expand Up @@ -156,10 +156,8 @@ Refer to the hardcoded default json example as a model in case of doubt.
| *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.
- 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`.


##### 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.
- 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`.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Main features:
- Last trades
- Withdraw fees

## Private requests
## Account requests

- Balance
- Trade (buy & sell in several flavors)
Expand Down Expand Up @@ -55,7 +55,7 @@ Main features:

- [coincenter](#coincenter)
- [Market Data](#market-data)
- [Private requests](#private-requests)
- [Account requests](#account-requests)
- [Supported exchanges](#supported-exchanges)
- [About](#about)
- [Installation](#installation)
Expand All @@ -76,7 +76,7 @@ Main features:
- [Currencies](#currencies)
- [Examples](#examples)
- [Markets](#markets)
- [Examples](#examples-1)
- [Examples of markets queries](#examples-of-markets-queries)
- [Ticker information](#ticker-information)
- [Order books](#order-books)
- [Last 24h traded volume](#last-24h-traded-volume)
Expand All @@ -90,7 +90,7 @@ Main features:
- [Withdraw fees](#withdraw-fees)
- [Example 1: query all withdraw fees](#example-1-query-all-withdraw-fees)
- [Example 2: query ETH withdraw fees on Kraken and Kucoin](#example-2-query-eth-withdraw-fees-on-kraken-and-kucoin)
- [Private requests](#private-requests-1)
- [Private requests](#private-requests)
- [Selecting private keys on exchanges](#selecting-private-keys-on-exchanges)
- [Balance](#balance)
- [Trade](#trade)
Expand All @@ -114,9 +114,9 @@ Main features:
- [Examples with explanation](#examples-with-explanation-1)
- [Deposit information](#deposit-information)
- [Recent deposits](#recent-deposits)
- [Examples](#examples-2)
- [Examples](#examples-1)
- [Recent withdraws](#recent-withdraws)
- [Examples](#examples-3)
- [Examples](#examples-2)
- [Closed orders](#closed-orders)
- [Opened orders](#opened-orders)
- [Cancel opened orders](#cancel-opened-orders)
Expand Down Expand Up @@ -251,7 +251,7 @@ This allows to flush correctly the latest data (caches, logs, etc) to files at t

By default, it logs in the console with the 'info' level, and in 'debug' in rotating files.

For this, you can configure statically the default level for each in the [config file](CONFIG.md#options-description).
For this, you can configure statically the default level for each in the [config file](CONFIG.md#general-options-description).
It can be overridden on the command line, with options `--log <log-level>` and `--log-file <log-level>`.

##### Activity history
Expand All @@ -268,7 +268,7 @@ By default, it stores all types of trades and withdraws results, but the list is
### Parallel requests

You may want to query several exchanges for a command at the same time. In this case, it's possible to ask `coincenter` to launch requests in parallel when it's possible.
By default, the number of requests in parallel is `1`. To increase it, change the value of the field `nbMaxParallelRequests` in `generalconfig.json` file (more information [here](CONFIG.md#options-description)).
By default, the number of requests in parallel is `1`. To increase it, change the value of the field `nbMaxParallelRequests` in `generalconfig.json` file (more information [here](CONFIG.md#general-options-description)).

You will have a nice boost of speed when you query the same thing from multiple exchanges / or accounts. However, the logs may not be ordered anymore.

Expand Down Expand Up @@ -310,7 +310,7 @@ Also, result can be narrowed to list of exchanges given after the optional curre

**Note**: Markets are returned with the currency pair presented in original order from the exchange, as it could give additional information for services relying on this option (even though it's not needed for `trade` option of `coincenter`)

##### Examples
##### Examples of markets queries

Lists all markets for all exchanges

Expand Down Expand Up @@ -793,7 +793,7 @@ If you want to trade coin *AAA* into *CCC* but exchange does not have a *AAA-CCC

In order to activate multi trades, there are two ways:

- Default behavior is controlled by [multiTradeAllowedByDefault option](CONFIG.md#options-description) in the `exchangeconfig.json` file. If `true`, multi trade is allowed for the given exchange (or all exchanges if under `default` level).
- Default behavior is controlled by [multiTradeAllowedByDefault option](CONFIG.md#exchanges-options-description) in the `exchangeconfig.json` file. If `true`, multi trade is allowed for the given exchange (or all exchanges if under `default` level).
- It can be forced by adding command line flag `--multi-trade`.

In the case it's activated in the config file, `--no-multi-trade` can force deactivation of the multi trade.
Expand All @@ -804,13 +804,13 @@ Some exchanges (**Kraken** and **Binance** for instance) allow to actually query

#### Buy / Sell

Trade family of commands require that you specify the *start amount* (with the start currency) and the *target currency*. You can use `buy` and `sell` commands when you have a start amount (for *sell*) or a target amount (for *buy*) only. It's more easy to use, but `coincenter` needs to know which are the [preferred currencies](CONFIG.md#options-description) to which it can *sell* the start amount to, or use as start amount for a *buy*.
Trade family of commands require that you specify the *start amount* (with the start currency) and the *target currency*. You can use `buy` and `sell` commands when you have a start amount (for *sell*) or a target amount (for *buy*) only. It's more easy to use, but `coincenter` needs to know which are the [preferred currencies](CONFIG.md#exchanges-options-description) to which it can *sell* the start amount to, or use as start amount for a *buy*.

Sell option also supports percentage as start amount. In this case, the desired percentage of total available amount of given currency on matching exchanges (the ones specified after the `,` or all if none given as usual) will be sold. To complement this, `sell-all` option with a start currency instead of an amount is supported as well, which is syntactic sugar of a sell of `100%` of available amount.

Buy a percentage is not available yet, simply because I am not sure about what should be the behavior of this option. If you have ideas about it, do not hesitate to propose them.

The list of preferred currencies should be filled prior to **buy / sell** command and is statically loaded at start of coincenter. It is an array of currencies ordered by decreasing priority, and they represent the currencies that can be used as target currency for a *sell*, and base currency for a *buy*. See [config](CONFIG.md#options-description) file to see how to set the preferred currencies.
The list of preferred currencies should be filled prior to **buy / sell** command and is statically loaded at start of coincenter. It is an array of currencies ordered by decreasing priority, and they represent the currencies that can be used as target currency for a *sell*, and base currency for a *buy*. See [config](CONFIG.md#exchanges-options-description) file to see how to set the preferred currencies.

##### Syntax

Expand Down
5 changes: 3 additions & 2 deletions src/api-objects/include/apikey.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <string_view>
#include <type_traits>

#include "accountowner.hpp"
#include "cct_string.hpp"
Expand Down Expand Up @@ -57,8 +58,8 @@ class APIKey {
std::string_view passphrase() const { return _passphrase; }
const AccountOwner &accountOwner() const { return _accountOwner; }

using trivially_relocatable = std::integral_constant<bool, is_trivially_relocatable_v<string> &&
is_trivially_relocatable_v<AccountOwner>>::type;
using trivially_relocatable =
std::bool_constant<is_trivially_relocatable_v<string> && is_trivially_relocatable_v<AccountOwner>>::type;

private:
string _platform;
Expand Down
12 changes: 7 additions & 5 deletions src/api-objects/include/exchangepublicapitypes.hpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
#pragma once

#include <functional>
#include <unordered_map>

#include "cct_allocator.hpp"
#include "cct_flatset.hpp"
#include "cct_smallvector.hpp"
#include "cct_vector.hpp"
#include "currencycode.hpp"
#include "market-vector.hpp"
#include "market.hpp"
#include "marketorderbook.hpp"
#include "monetaryamount.hpp"
#include "publictrade.hpp"

namespace cct {
using MarketSet = FlatSet<Market>;

using MarketSet = FlatSet<Market, std::less<Market>, allocator<Market>, MarketVector>;
using MarketOrderBookMap = std::unordered_map<Market, MarketOrderBook>;
using MarketPriceMap = std::unordered_map<Market, MonetaryAmount>;
using MarketsPath = SmallVector<Market, 3>;
using TradesVector = vector<PublicTrade>;
} // namespace cct

} // namespace cct
2 changes: 1 addition & 1 deletion src/api-objects/include/recentdeposit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RecentDeposit {

private:
MonetaryAmount _amount;
TimePoint _timePoint{};
TimePoint _timePoint;
};

class ClosestRecentDepositPicker {
Expand Down
9 changes: 4 additions & 5 deletions src/api-objects/include/withdrawinfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ class InitiatedWithdrawInfo {
MonetaryAmount grossEmittedAmount() const { return _grossEmittedAmount; }

using trivially_relocatable =
std::integral_constant<bool, is_trivially_relocatable_v<Wallet> && is_trivially_relocatable_v<string>>::type;
std::bool_constant<is_trivially_relocatable_v<Wallet> && is_trivially_relocatable_v<string>>::type;

private:
Wallet _receivingWallet;
string _withdrawIdOrMsgIfNotInitiated;
MonetaryAmount _grossEmittedAmount;
TimePoint _initiatedTime{}; // The time at which withdraw has been ordered from the source exchange
TimePoint _initiatedTime; // The time at which withdraw has been ordered from the source exchange
};

class SentWithdrawInfo {
Expand Down Expand Up @@ -84,12 +84,11 @@ class DeliveredWithdrawInfo {

std::string_view withdrawId() const;

using trivially_relocatable =
std::integral_constant<bool, is_trivially_relocatable_v<Wallet> && is_trivially_relocatable_v<string>>::type;
using trivially_relocatable = is_trivially_relocatable<api::InitiatedWithdrawInfo>::type;

private:
api::InitiatedWithdrawInfo _initiatedWithdrawInfo;
TimePoint _receivedTime{}; // time at which destination provides received funds as available for trade
TimePoint _receivedTime; // time at which destination provides received funds as available for trade
MonetaryAmount _receivedAmount; // fee deduced amount that destination will receive
};

Expand Down
3 changes: 2 additions & 1 deletion src/api/common/include/exchangepublicapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "monetaryamount.hpp"
#include "monetaryamountbycurrencyset.hpp"
#include "priceoptions.hpp"
#include "public-trade-vector.hpp"

namespace cct {

Expand Down Expand Up @@ -104,7 +105,7 @@ class ExchangePublic : public ExchangeBase {
virtual MonetaryAmount queryLast24hVolume(Market mk) = 0;

/// Retrieve an ordered vector of recent last trades
virtual TradesVector queryLastTrades(Market mk, int nbTrades = kNbLastTradesDefault) = 0;
virtual PublicTradeVector queryLastTrades(Market mk, int nbTrades = kNbLastTradesDefault) = 0;

/// Retrieve the last price of given market.
virtual MonetaryAmount queryLastPrice(Market mk) = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/api/common/include/exchangepublicapi_mock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "exchangepublicapitypes.hpp"
#include "fiatconverter.hpp"
#include "monetaryamount.hpp"
#include "public-trade-vector.hpp"

namespace cct::api {
class MockExchangePublic : public ExchangePublic {
Expand All @@ -28,7 +29,7 @@ class MockExchangePublic : public ExchangePublic {
MOCK_METHOD(MarketOrderBookMap, queryAllApproximatedOrderBooks, (int depth), (override));
MOCK_METHOD(MarketOrderBook, queryOrderBook, (Market mk, int depth), (override));
MOCK_METHOD(MonetaryAmount, queryLast24hVolume, (Market mk), (override));
MOCK_METHOD(TradesVector, queryLastTrades, (Market mk, int nbTrades), (override));
MOCK_METHOD(PublicTradeVector, queryLastTrades, (Market mk, int nbTrades), (override));
MOCK_METHOD(MonetaryAmount, queryLastPrice, (Market mk), (override));
};
} // namespace cct::api
Loading

0 comments on commit abea1f9

Please sign in to comment.