C++ API Reference
The C++ API provides RAII wrappers with modern C++ conveniences.
Header
#include <techkit/techkit.hpp>
Classes
Indicator Base
namespace techkit {
class Indicator {
public:
// Disable copy, enable move
Indicator(const Indicator&) = delete;
Indicator& operator=(const Indicator&) = delete;
Indicator(Indicator&& other) noexcept;
Indicator& operator=(Indicator&& other) noexcept;
~Indicator(); // Automatic cleanup
// Update methods
tk_result update(double value);
tk_result update(const tk_ohlcv& bar);
// Batch calculation
std::vector<tk_result> calculate(const double* data, size_t len);
// State management
void reset();
bool isReady() const;
int lookback() const;
std::string name() const;
// Access raw C handle
tk_indicator raw() const;
};
} // namespace techkit
Concrete Indicators
namespace techkit {
// Moving Averages
class SMA : public Indicator {
public:
explicit SMA(int period);
};
class EMA : public Indicator {
public:
explicit EMA(int period);
};
// Momentum
class RSI : public Indicator {
public:
explicit RSI(int period = 14);
};
class MACD : public Indicator {
public:
MACD(int fast = 12, int slow = 26, int signal = 9);
tk_macd_result update_macd(double value);
};
// Volatility
class BollingerBands : public Indicator {
public:
BollingerBands(int period = 20, double std_dev = 2.0);
tk_bbands_result update_bbands(double value);
};
class ATR : public Indicator {
public:
explicit ATR(int period = 14);
};
// ... all other indicators
} // namespace techkit
Indicator Chaining
#include <techkit/chain.hpp>
namespace techkit {
class Chain {
public:
Chain& then(std::unique_ptr<Indicator> ind);
tk_result update(double value);
void reset();
bool isReady() const;
};
// Factory for fluent API
template<typename T, typename... Args>
Chain chain(Args&&... args);
} // namespace techkit
Usage
// RSI smoothed by EMA
auto chain = techkit::Chain();
chain.then(std::make_unique<techkit::RSI>(14))
.then(std::make_unique<techkit::EMA>(9));
for (double price : prices) {
auto result = chain.update(price);
if (result.valid) {
std::cout << "Smoothed RSI: " << result.value << std::endl;
}
}
Example
#include <techkit/techkit.hpp>
#include <iostream>
#include <vector>
int main() {
// RAII - automatic cleanup
techkit::SMA sma(20);
techkit::RSI rsi(14);
techkit::MACD macd(12, 26, 9);
std::vector<double> prices = {100.0, 101.5, 102.3, /* ... */};
for (double price : prices) {
auto sma_r = sma.update(price);
auto rsi_r = rsi.update(price);
auto macd_r = macd.update_macd(price);
if (sma_r.valid) {
std::cout << "SMA: " << sma_r.value
<< ", RSI: " << rsi_r.value
<< ", MACD: " << macd_r.macd << std::endl;
}
}
// Automatic cleanup when variables go out of scope
return 0;
}