OpenPine C++ API
C++ wrapper for the OpenPine Pine Script VM
Loading...
Searching...
No Matches
openpine::CandlestickStream Class Reference

RAII wrapper around a ffi::CandlestickStream. More...

#include <instance.hpp>

Public Member Functions

 CandlestickStream (std::string_view symbol, std::string_view timeframe, int64_t from_time)
 Creates a new stream.
 ~CandlestickStream ()
 CandlestickStream (const CandlestickStream &)=delete
CandlestickStreamoperator= (const CandlestickStream &)=delete
void push (const CandlestickItem &item)
 Pushes one bar into the stream (thread-safe).
void finish ()
 Signals end-of-stream (thread-safe). Idempotent.
ffi::CandlestickStream * release ()
 Returns the underlying raw handle and releases ownership.
ffi::CandlestickStream * handle () const
 Returns the raw handle without releasing ownership.

Detailed Description

RAII wrapper around a ffi::CandlestickStream.

Create one inside DataProvider::candlesticksOpen, push bars via push(), and call finish() (or let the destructor do it) when all data has been queued. The stream may be pushed from any thread.

ffi::CandlestickStream* candlesticksOpen(
std::string_view symbol, std::string_view timeframe, int64_t from_time)
override {
auto stream = std::make_unique<CandlestickStream>(symbol, timeframe,
from_time);
// Optionally spawn a thread to push data asynchronously:
std::thread([s = std::move(stream), bars = load(symbol, timeframe)]() {
for (auto& b : bars) s->push(b);
s->finish();
}).detach();
// Return the raw handle — the VM takes ownership.
return stream.release()->handle();
}

Definition at line 57 of file instance.hpp.

Constructor & Destructor Documentation

◆ CandlestickStream() [1/2]

openpine::CandlestickStream::CandlestickStream ( std::string_view symbol,
std::string_view timeframe,
int64_t from_time )
inline

Creates a new stream.

Pass the same arguments received from DataProvider::candlesticksOpen.

Definition at line 64 of file instance.hpp.

Referenced by CandlestickStream(), and operator=().

◆ ~CandlestickStream()

openpine::CandlestickStream::~CandlestickStream ( )
inline

Definition at line 71 of file instance.hpp.

References finish().

◆ CandlestickStream() [2/2]

openpine::CandlestickStream::CandlestickStream ( const CandlestickStream & )
delete

References CandlestickStream().

Member Function Documentation

◆ finish()

void openpine::CandlestickStream::finish ( )
inline

Signals end-of-stream (thread-safe). Idempotent.

Definition at line 88 of file instance.hpp.

Referenced by ~CandlestickStream().

◆ handle()

ffi::CandlestickStream * openpine::CandlestickStream::handle ( ) const
inline

Returns the raw handle without releasing ownership.

Definition at line 112 of file instance.hpp.

◆ operator=()

CandlestickStream & openpine::CandlestickStream::operator= ( const CandlestickStream & )
delete

References CandlestickStream().

◆ push()

void openpine::CandlestickStream::push ( const CandlestickItem & item)
inline

Pushes one bar into the stream (thread-safe).

Definition at line 79 of file instance.hpp.

◆ release()

ffi::CandlestickStream * openpine::CandlestickStream::release ( )
inline

Returns the underlying raw handle and releases ownership.

Call this to hand the stream over to the VM (i.e. as the return value of candlesticksOpen). After this call the CandlestickStream object must not be used for pushing — but it is still safe to call finish() via the raw pointer through candlestickStreamFinish.

Definition at line 105 of file instance.hpp.


The documentation for this class was generated from the following file: