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

Represents a compiled, executable Pine Script instance. More...

#include <instance.hpp>

Public Types

using RunCallback = std::function<void(const Result&)>
 Callback invoked when run() completes.
using EventCallback = std::function<void(const ffi::CEvent&)>
 Callback invoked for each event during run().

Public Member Functions

Chart chart () const
 Returns the chart produced by the last completed run().
ScriptInfo scriptInfo () const
 Returns the script metadata.
void run (std::string_view symbol, std::string_view timeframe, int64_t from_time, RunCallback callback, EventCallback event_callback=nullptr)
 Starts asynchronous execution and returns immediately.
 Instance (Instance &&)=default
Instanceoperator= (Instance &&)=default

Static Public Member Functions

static Instance create (const CreateInstanceOptions &options)
 Creates a new Instance.

Detailed Description

Represents a compiled, executable Pine Script instance.

Definition at line 235 of file instance.hpp.

Member Typedef Documentation

◆ EventCallback

using openpine::Instance::EventCallback = std::function<void(const ffi::CEvent&)>

Callback invoked for each event during run().

The CEvent pointer is valid only for the duration of the callback.

Definition at line 251 of file instance.hpp.

◆ RunCallback

using openpine::Instance::RunCallback = std::function<void(const Result&)>

Callback invoked when run() completes.

Called on the OS thread that drives the VM execution (not the caller's thread). result is valid only for the duration of the callback. Copy any error message you need before returning.

Definition at line 244 of file instance.hpp.

Constructor & Destructor Documentation

◆ Instance()

openpine::Instance::Instance ( Instance && )
default

References Instance().

Referenced by create(), Instance(), and operator=().

Member Function Documentation

◆ chart()

Chart openpine::Instance::chart ( ) const
inline

Returns the chart produced by the last completed run().

Definition at line 260 of file instance.hpp.

◆ create()

Instance openpine::Instance::create ( const CreateInstanceOptions & options)
inlinestatic

Creates a new Instance.

Exceptions
Errorif compilation fails.

Definition at line 338 of file instance.hpp.

References Instance().

◆ operator=()

Instance & openpine::Instance::operator= ( Instance && )
default

References Instance().

◆ run()

void openpine::Instance::run ( std::string_view symbol,
std::string_view timeframe,
int64_t from_time,
RunCallback callback,
EventCallback event_callback = nullptr )
inline

Starts asynchronous execution and returns immediately.

The VM pulls candlestick data from the DataProvider injected via CreateInstanceOptions::setDataProvider(). When execution completes (or fails), callback is invoked on a separate OS thread.

The Instance must remain valid until callback fires.

Parameters
symbolMain chart symbol (e.g. "NASDAQ:AAPL").
timeframeMain chart timeframe (e.g. "1D").
from_timeStart time in epoch milliseconds (0 = beginning).
callbackInvoked with the result on the execution thread.
event_callbackOptional per-event callback. Pass nullptr to skip.
Exceptions
Errorif the run cannot be started (e.g. bad symbol/timeframe).

Definition at line 396 of file instance.hpp.

References run().

Referenced by run().

◆ scriptInfo()

ScriptInfo openpine::Instance::scriptInfo ( ) const
inline

Returns the script metadata.

Definition at line 263 of file instance.hpp.


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