-
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
27 changed files
with
438 additions
and
27 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
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,53 @@ | ||
{ | ||
"kraken": { | ||
"BTC-EUR": { | ||
"algorithmName": "example-trader", | ||
"repeatTime": "3s", | ||
"baseStartAmount": "0.5BTC", | ||
"quoteStartAmount": "50%EUR", | ||
"stopCriteria": [ | ||
{ | ||
"type": "duration", | ||
"value": "4h" | ||
}, | ||
{ | ||
"type": "protectLoss", | ||
"value": "-30%" | ||
}, | ||
{ | ||
"type": "secureProfit", | ||
"value": "80%" | ||
} | ||
] | ||
}, | ||
"ETH-EUR": { | ||
"algorithmName": "example-trader", | ||
"repeatTime": "3s", | ||
"baseStartAmount": "45ETH", | ||
"quoteStartAmount": "50%EUR", | ||
"stopCriteria": [ | ||
{ | ||
"type": "duration", | ||
"value": "4h" | ||
}, | ||
{ | ||
"type": "protectLoss", | ||
"value": "-30%" | ||
}, | ||
{ | ||
"type": "secureProfit", | ||
"value": "80%" | ||
} | ||
] | ||
} | ||
}, | ||
"binance_user1": { | ||
"XRP-USDT": { | ||
"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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
#include <map> | ||
|
||
#include "market-auto-trade-options.hpp" | ||
#include "market.hpp" | ||
|
||
namespace cct { | ||
|
||
using AccountAutoTradeOptions = std::map<Market, MarketAutoTradeOptions>; | ||
|
||
} |
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,31 @@ | ||
#pragma once | ||
|
||
#include <map> | ||
|
||
#include "account-auto-trade-options.hpp" | ||
#include "cct_json.hpp" | ||
#include "cct_smallvector.hpp" | ||
#include "exchange-names.hpp" | ||
#include "exchangename.hpp" | ||
|
||
namespace cct { | ||
|
||
class AutoTradeOptions { | ||
public: | ||
using AccountAutoTradeOptionsPtrVector = SmallVector<const AccountAutoTradeOptions *, kTypicalNbPrivateAccounts>; | ||
|
||
AutoTradeOptions() noexcept = default; | ||
|
||
explicit AutoTradeOptions(const json &data); | ||
|
||
auto size() const noexcept { return _options.size(); } | ||
|
||
PublicExchangeNameVector getExchanges() const; | ||
|
||
AccountAutoTradeOptionsPtrVector getAccountAutoTradeOptionsPtr(std::string_view publicExchangeName) const; | ||
|
||
private: | ||
std::map<ExchangeName, AccountAutoTradeOptions> _options; | ||
}; | ||
|
||
} // 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,18 @@ | ||
#pragma once | ||
|
||
#include "threadpool.hpp" | ||
|
||
namespace cct { | ||
class AutoTradeOptions; | ||
|
||
class AutoTradeProcessor { | ||
public: | ||
explicit AutoTradeProcessor(const AutoTradeOptions& autoTradeOptions); | ||
|
||
void start(); | ||
|
||
private: | ||
const AutoTradeOptions& _autoTradeOptions; | ||
ThreadPool _threadPool; | ||
}; | ||
} // 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,37 @@ | ||
#pragma once | ||
|
||
#include <span> | ||
#include <string_view> | ||
|
||
#include "auto-trade-stop-criterion.hpp" | ||
#include "cct_json.hpp" | ||
#include "cct_string.hpp" | ||
#include "cct_vector.hpp" | ||
#include "monetaryamount.hpp" | ||
#include "timedef.hpp" | ||
|
||
namespace cct { | ||
|
||
class MarketAutoTradeOptions { | ||
public: | ||
explicit MarketAutoTradeOptions(const json &data); | ||
|
||
std::string_view algorithmName() const { return _algorithmName; } | ||
|
||
Duration repeatTime() const { return _repeatTime; } | ||
|
||
MonetaryAmount baseStartAmount() const { return _baseStartAmount; } | ||
|
||
MonetaryAmount quoteStartAmount() const { return _quoteStartAmount; } | ||
|
||
std::span<const AutoTradeStopCriterion> stopCriterion() const { return _stopCriteria; } | ||
|
||
private: | ||
string _algorithmName; | ||
Duration _repeatTime; | ||
MonetaryAmount _baseStartAmount; | ||
MonetaryAmount _quoteStartAmount; | ||
vector<AutoTradeStopCriterion> _stopCriteria; | ||
}; | ||
|
||
} // 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,40 @@ | ||
#include "auto-trade-options.hpp" | ||
|
||
namespace cct { | ||
|
||
AutoTradeOptions::AutoTradeOptions(const json &data) { | ||
for (const auto &[exchangeName, marketAutoTradeOptions] : data.items()) { | ||
AccountAutoTradeOptions accountAutoTradeOptions; | ||
for (const auto &marketJson : marketAutoTradeOptions.items()) { | ||
accountAutoTradeOptions.emplace(marketJson.key(), MarketAutoTradeOptions(marketJson.value())); | ||
} | ||
_options.emplace(exchangeName, std::move(accountAutoTradeOptions)); | ||
} | ||
} | ||
|
||
PublicExchangeNameVector AutoTradeOptions::getExchanges() const { | ||
PublicExchangeNameVector exchanges; | ||
for (const auto &[exchangeStr, _] : _options) { | ||
ExchangeName exchangeName(exchangeStr); | ||
std::string_view exchangeNameStr = exchangeName.name(); | ||
// It's possible because std::map keys are lexicographically ordered | ||
if (exchanges.empty() || exchanges.back().name() != exchangeNameStr) { | ||
exchanges.emplace_back(exchangeNameStr); | ||
} | ||
} | ||
return exchanges; | ||
} | ||
|
||
AutoTradeOptions::AccountAutoTradeOptionsPtrVector AutoTradeOptions::getAccountAutoTradeOptionsPtr( | ||
std::string_view publicExchangeName) const { | ||
AccountAutoTradeOptionsPtrVector accountAutoTradeOptionsPtr; | ||
for (const auto &[exchangeStr, accountAutoTradeOptions] : _options) { | ||
ExchangeName exchangeName(exchangeStr); | ||
if (exchangeStr.name() == publicExchangeName) { | ||
accountAutoTradeOptionsPtr.emplace_back(&accountAutoTradeOptions); | ||
} | ||
} | ||
return accountAutoTradeOptionsPtr; | ||
} | ||
|
||
} // 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,12 @@ | ||
#include "auto-trade-processor.hpp" | ||
|
||
#include "auto-trade-options.hpp" | ||
|
||
namespace cct { | ||
|
||
AutoTradeProcessor::AutoTradeProcessor(const AutoTradeOptions& autoTradeOptions) | ||
: _autoTradeOptions(autoTradeOptions), _threadPool(autoTradeOptions.size()) {} | ||
|
||
void AutoTradeProcessor::start() {} | ||
|
||
} // namespace cct |
Oops, something went wrong.