-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
636 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ | ||
"kraken": { | ||
"BTC-EUR": { | ||
"accounts": [ | ||
"user1", | ||
"user2" | ||
], | ||
"algorithmName": "example-trader", | ||
"repeatTime": "5s", | ||
"baseStartAmount": "0.5BTC", | ||
"quoteStartAmount": "50%EUR", | ||
"stopCriteria": [ | ||
{ | ||
"type": "duration", | ||
"value": "4h" | ||
}, | ||
{ | ||
"type": "protectLoss", | ||
"value": "-30%" | ||
}, | ||
{ | ||
"type": "secureProfit", | ||
"value": "80%" | ||
} | ||
] | ||
}, | ||
"ETH-EUR": { | ||
"accounts": [ | ||
"user1" | ||
], | ||
"algorithmName": "example-trader", | ||
"repeatTime": "3s", | ||
"baseStartAmount": "45ETH", | ||
"quoteStartAmount": "50%EUR", | ||
"stopCriteria": [ | ||
{ | ||
"type": "duration", | ||
"value": "4h" | ||
}, | ||
{ | ||
"type": "protectLoss", | ||
"value": "-30%" | ||
}, | ||
{ | ||
"type": "secureProfit", | ||
"value": "80%" | ||
} | ||
] | ||
} | ||
}, | ||
"binance": { | ||
"XRP-USDT": { | ||
"accounts": [ | ||
"user1" | ||
], | ||
"algorithmName": "example-trader", | ||
"repeatTime": "1s", | ||
"baseStartAmount": "50000.56XRP", | ||
"quoteStartAmount": "100%USDT", | ||
"stopCriteria": [] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#pragma once | ||
|
||
#include <map> | ||
|
||
#include "auto-trade-config.hpp" | ||
#include "cct_fixedcapacityvector.hpp" | ||
#include "cct_smallvector.hpp" | ||
#include "cct_vector.hpp" | ||
#include "exchange-name-enum.hpp" | ||
#include "exchange-names.hpp" | ||
#include "exchangename.hpp" | ||
|
||
namespace cct { | ||
|
||
class AutoTradeOptions { | ||
public: | ||
using AccountAutoTradeOptionsPtrVector = | ||
SmallVector<const schema::AutoTradeExchangeConfig *, kTypicalNbPrivateAccounts>; | ||
|
||
struct MarketExchanges { | ||
Market market; | ||
ExchangeNames privateExchangeNames; | ||
const schema::AutoTradeMarketConfig *pMarketAutoTradeOptions{}; | ||
}; | ||
|
||
using MarketStatusVector = vector<MarketExchanges>; | ||
|
||
struct MarketExchangeOptions { | ||
MarketStatusVector marketStatusVector; | ||
}; | ||
|
||
struct PublicExchangeMarketOptions { | ||
ExchangeName publicExchangeName; | ||
MarketExchangeOptions marketExchangeOptions; | ||
}; | ||
|
||
using PublicExchangeMarketOptionsVector = FixedCapacityVector<schema::AutoTradeExchangeConfig, kNbSupportedExchanges>; | ||
|
||
AutoTradeOptions() noexcept = default; | ||
|
||
explicit AutoTradeOptions(schema::AutoTradeConfig &&autoTradeConfig); | ||
|
||
auto begin() const { return _autoTradeConfig.begin(); } | ||
auto end() const { return _autoTradeConfig.end(); } | ||
|
||
ExchangeNames exchangeNames() const; | ||
|
||
ExchangeNameEnumVector publicExchanges() const; | ||
|
||
AccountAutoTradeOptionsPtrVector accountAutoTradeOptionsPtr(std::string_view publicExchangeName) const; | ||
|
||
const schema::AutoTradeExchangeConfig &operator[](ExchangeNameEnum exchangeNameEnum) const; | ||
|
||
private: | ||
schema::AutoTradeConfig _autoTradeConfig; | ||
}; | ||
|
||
} // namespace cct |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#pragma once | ||
|
||
#include <array> | ||
#include <compare> | ||
#include <functional> | ||
#include <unordered_map> | ||
|
||
#include "auto-trade-config.hpp" | ||
#include "cct_smallvector.hpp" | ||
#include "cct_vector.hpp" | ||
#include "exchange-names.hpp" | ||
#include "exchange.hpp" | ||
#include "market-trader-engine.hpp" | ||
#include "market.hpp" | ||
#include "timedef.hpp" | ||
|
||
namespace cct { | ||
class AutoTradeOptions; | ||
class CoincenterInfo; | ||
|
||
class AutoTradeProcessor { | ||
public: | ||
using MarketTraderEngines = std::array<std::unordered_map<Market, MarketTraderEngine>, kNbSupportedExchanges>; | ||
|
||
explicit AutoTradeProcessor(const AutoTradeOptions& autoTradeOptions); | ||
|
||
struct SelectedMarket { | ||
ExchangeNames privateExchangeNames; | ||
Market market; | ||
}; | ||
|
||
using SelectedMarketVector = SmallVector<SelectedMarket, kTypicalNbPrivateAccounts>; | ||
|
||
SelectedMarketVector computeSelectedMarkets(); | ||
|
||
MarketTraderEngines createMarketTraderEngines(const CoincenterInfo& coincenterInfo) const; | ||
|
||
private: | ||
struct MarketStatus { | ||
ExchangeNames privateExchangeNames; | ||
Market market; | ||
TimePoint lastQueryTime; | ||
const schema::AutoTradeMarketConfig* pMarketAutoTradeOptions{}; | ||
}; | ||
|
||
using MarketStatusVector = vector<MarketStatus>; | ||
|
||
struct ExchangeStatus { | ||
MarketStatusVector marketStatusVector; | ||
const schema::AutoTradeExchangeConfig* pPublicExchangeAutoTradeOptions{}; | ||
ExchangeNameEnum exchangeNameEnum; | ||
}; | ||
|
||
using ExchangeStatusVector = SmallVector<ExchangeStatus, kTypicalNbPrivateAccounts>; | ||
|
||
ExchangeStatusVector _exchangeStatusVector; | ||
TimePoint _startTs = Clock::now(); | ||
TimePoint _ts{_startTs}; | ||
}; | ||
} // namespace cct |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "auto-trade-options.hpp" | ||
|
||
#include <utility> | ||
|
||
#include "auto-trade-config.hpp" | ||
#include "cct_invalid_argument_exception.hpp" | ||
|
||
namespace cct { | ||
|
||
AutoTradeOptions::AutoTradeOptions(schema::AutoTradeConfig &&autoTradeConfig) | ||
: _autoTradeConfig(std::move(autoTradeConfig)) {} | ||
|
||
ExchangeNames AutoTradeOptions::exchangeNames() const { | ||
ExchangeNames exchangeNames; | ||
for (const auto &[exchangeNameEnum, publicExchangeAutoTradeOptions] : _autoTradeConfig) { | ||
const int posPublicExchangeName = exchangeNames.size(); | ||
for (const auto &[market, autoTradeMarketConfig] : publicExchangeAutoTradeOptions) { | ||
const int posMarket = exchangeNames.size(); | ||
for (std::string_view account : autoTradeMarketConfig.accounts) { | ||
ExchangeName exchangeName(exchangeNameEnum, account); | ||
const auto it = std::find(exchangeNames.begin() + posPublicExchangeName, exchangeNames.end(), exchangeName); | ||
if (it == exchangeNames.end()) { | ||
exchangeNames.push_back(std::move(exchangeName)); | ||
} else if (it >= exchangeNames.begin() + posMarket) { | ||
throw invalid_argument("Duplicated account {} for exchange {}", account, exchangeName.name()); | ||
} | ||
} | ||
} | ||
} | ||
return exchangeNames; | ||
} | ||
|
||
ExchangeNameEnumVector AutoTradeOptions::publicExchanges() const { | ||
ExchangeNameEnumVector exchanges; | ||
for (const auto &[publicExchangeName, _] : _autoTradeConfig) { | ||
exchanges.emplace_back(publicExchangeName); | ||
} | ||
std::ranges::sort(exchanges); | ||
return exchanges; | ||
} | ||
|
||
AutoTradeOptions::AccountAutoTradeOptionsPtrVector AutoTradeOptions::accountAutoTradeOptionsPtr( | ||
std::string_view publicExchangeName) const { | ||
AccountAutoTradeOptionsPtrVector accountAutoTradeOptionsPtr; | ||
for (const auto &[exchangeNameEnum, publicExchangeAutoTradeOptions] : _autoTradeConfig) { | ||
if (kSupportedExchanges[static_cast<int>(exchangeNameEnum)] == publicExchangeName) { | ||
accountAutoTradeOptionsPtr.emplace_back(&publicExchangeAutoTradeOptions); | ||
} | ||
} | ||
return accountAutoTradeOptionsPtr; | ||
} | ||
|
||
const schema::AutoTradeExchangeConfig &AutoTradeOptions::operator[](ExchangeNameEnum exchangeNameEnum) const { | ||
const auto it = std::ranges::find_if(_autoTradeConfig, [exchangeNameEnum](const auto &exchangeConfig) { | ||
return exchangeConfig.first == exchangeNameEnum; | ||
}); | ||
if (it == _autoTradeConfig.end()) { | ||
throw exception("No auto trade options for exchange {}", kSupportedExchanges[static_cast<int>(exchangeNameEnum)]); | ||
} | ||
return it->second; | ||
} | ||
|
||
} // namespace cct |
Oops, something went wrong.