OpenPine C++ API
C++ wrapper for the OpenPine Pine Script VM
Loading...
Searching...
No Matches
OpenPine C API

C ABI and C++ wrappers for the OpenPine Pine Script VM. Use this to run Pine scripts from C or C++ and read chart outputs (plots, labels, lines, etc.) without depending on Rust directly.

Requirements

  • C++17 (for the C++ wrapper; the raw C ABI is C-compatible)
  • CMake 3.11+ (for building)
  • Rust (stable) with Cargo — the library is built from the openpine-capi crate via Corrosion

Building

From the repository root (not from crates/capi):

mkdir build && cd build
cmake ..
cmake --build .

This builds the static library (openpine_capi) and the C++ example. The example target is helloworld (see examples/cpp/).

Using the headers

  • Include path: add crates/capi/cpp/include to your include path.
  • Single include: #include <openpine.hpp> — this pulls in the C++ wrapper API (Instance, Chart, visuals, error handling).
  • Link: link your executable with openpine_capi.

Example CMake snippet:

include_directories(path/to/openpine/crates/capi/cpp/include)
target_link_libraries(your_target openpine_capi)
set_property(TARGET your_target PROPERTY CXX_STANDARD 17)

If you build from the repo root with the top-level CMakeLists.txt, openpine_capi is already defined via Corrosion.

Quick example

#include <openpine.hpp>
int main() {
indicator("SMA")
plot(ta.sma(close, 5))
)", "1D");
// Implement DataProvider (push bars in candlesticksOpen)
MyProvider provider(bars);
opts.setDataProvider(&provider);
auto instance = openpine::Instance::create(opts);
// Run asynchronously; callback fires on the execution thread
std::promise<void> done;
instance.run("NASDAQ:AAPL", "1D", 0, [&done](const openpine::Result&) {
done.set_value();
});
done.get_future().wait();
auto chart = instance.chart();
// Filter by type so the iterator yields only Plot; no manual type check.
auto iter = chart.seriesGraphIterator(openpine::SeriesGraphType::Plot);
while (iter.next()) {
const auto plot = iter.seriesGraph().asPlot().value();
// read plot.title(), plot.value(i), etc.
}
}
Options for creating an Instance.
Definition instance.hpp:184
static Instance create(const CreateInstanceOptions &options)
Creates a new Instance.
Definition instance.hpp:338
Single include for the OpenPine C++ wrapper API.

Catch openpine::Error for creation and execution failures.

Main types

Type Description
openpine::CreateInstanceOptions Script source, timeframe, optional path and options.
openpine::Instance VM instance; create(), run(symbol, tf, from, callback), chart(), scriptInfo().
openpine::DataProvider Abstract base; implement symbolInfo() + candlesticksOpen().
openpine::CandlestickStream RAII push stream; create in candlesticksOpen, push from any thread.
openpine::Chart Chart data; seriesLength(), seriesGraphIterator(), graphIterator(), asBarColors().
openpine::SeriesGraphIterator Iterates series graphs (plot, background colors, fill, etc.). Optional SeriesGraphType filter.
openpine::GraphIterator Iterates non-series graphs (hline, label, line, box, etc.). Optional GraphType filter.
openpine::SeriesGraph / openpine::Graph Tagged unions; use type() and asPlot(), asLabel(), etc.
openpine::Error Thrown on failure; errorMessage(), errorSpan().

Layout

  • cpp/include/ — C++ headers. openpine.hpp is the main entry; ffi.hpp is the raw C ABI (generated by cbindgen).
  • src/ — Rust implementation and FFI exports that back the C ABI.

The C++ API is a thin wrapper over the C API with RAII, std::optional, and exceptions for errors.