Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Change Log

## [0.7.7] - 2025-01-03 - Live Streaming Support

### Added

- **PineTS.stream() Method**: Event-driven wrapper of `PineTS.run()` to simplify handling live data and real-time updates
- Documentation updates for streaming functionality

### Fixed

- **Critical Fix**: Live data processing was producing wrong values in `ta.*` functions due to incorrect handling of current vs committed candles

## [0.7.6] - 2025-12-30 - Additional Plot Functions

### Added
Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,33 @@ npm install pinets

## Usage Examples

### Streaming Data

PineTS provides a convenient event-based interface for streaming live data:

```javascript
import { PineTS, Provider } from 'pinets';

const pineTS = new PineTS(Provider.Binance, 'BTCUSDT', '1m');

// Start streaming with 1 second interval
const evt = pineTS.stream(
indicator,
//assuming that indicator is a pine source code or pineTS function
{
pageSize: 10,
live: true,
interval: 1000,
}
);

evt.on('data', (ctx) => {
console.log('Update:', ctx.result.close);
});

// See documentation for full details
```

### Option 1: Run Native Pine Script Directly _(Experimental)_

Starting with v0.7.0, you can run original Pine Script code directly:
Expand Down
46 changes: 26 additions & 20 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,44 +127,50 @@ const { result } = await pineTS.run((context) => {
});
```

## Using Pagination for Large Datasets
## Streaming Data and Pagination

For processing large datasets efficiently or streaming live market data, use pagination:
For processing large datasets efficiently or handling live data streams, use the `stream()` method:

```javascript
import { PineTS, Provider } from 'pinets';

// Initialize with a provider for live streaming capability
const pineTS = new PineTS(Provider.Binance, 'BTCUSDT', '1h');
// Initialize with a provider
const pineTS = new PineTS(Provider.Binance, 'BTCUSDT', '1m', 100);

// Process 200 candles in pages of 50
const iterator = pineTS.run(
// Start streaming
const evt = pineTS.stream(
(context) => {
const ta = context.ta;
const { close } = context.data;

const sma = ta.sma(close, 20);
return { sma };
const sma = context.ta.sma(close, 14);
return { close, sma };
},
200,
50
{
pageSize: 50, // Process in chunks of 50
live: true, // Continue with live data
interval: 2000, // Poll every 2 seconds
}
);

// Process each page as it becomes available
for await (const page of iterator) {
console.log(`Received ${page.result.sma.length} results`);
// With a provider and no end date, automatically continues with live data
}
// Listen for updates
evt.on('data', (ctx) => {
const { close, sma } = ctx.result;
console.log(`Update: Close=${close[close.length - 1]}, SMA=${sma[sma.length - 1]}`);
});

evt.on('error', (err) => console.error(err));

// To stop streaming later
// evt.stop();
```

**Benefits:**

- Memory efficient for large datasets
- Shows progress during processing
- Automatically streams live market data when using a provider
- Event-based interface is easier to integrate
- Automatically streams live market data
- Perfect for real-time trading bots and dashboards

📖 **For complete pagination documentation and advanced examples, see [Pagination & Live Streaming](../pagination/).**
📖 **For complete pagination and streaming documentation, see [Pagination & Live Streaming](../pagination/).**

## Key Differences: PineTS Syntax vs Native Pine Script

Expand Down
47 changes: 36 additions & 11 deletions docs/indicators.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,48 @@ permalink: /indicators/
has_children: false
---

# Demo Indicators
## Basic Demo

These demo indicators showcase the capabilities of PineTS for creating interactive trading indicators.
A simple introduction to QFChart with basic candlestick charting and essential features.

## Simple Cross Signal (uses native PineScript)
[View Demo](https://quantforge.org/demos/basic-01.html){: .btn .btn-primary }

This example shows how to load and run a native PineScript code using PineTS and QFChart
[View Demo](indicators/cross-signal/index.html){: .btn .btn-primary }
## Full Featured Demo

## WillVixFix Indicator (uses PineTS syntax)
Comprehensive demo showcasing all QFChart features including multiple indicators, tools, and advanced charting capabilities.

WillVixFix is a volatility-based indicator that helps identify potential reversal points in the market.
[View Demo](https://quantforge.org/demos/full.html){: .btn .btn-primary }

[View Demo](indicators/willvixfix/index.html){: .btn .btn-primary }
## PineScript Demo

## Squeeze Momentum Indicator (uses PineTS syntax)
Execute native Pine Script code using PineTS runtime and visualize the results with QFChart. Demonstrates runtime transpilation.

The Squeeze Momentum indicator identifies when the market is "squeezing" (low volatility) and about to break out with increased momentum.
[View Demo](https://quantforge.org/demos/pinescript.html){: .btn .btn-primary }

[View Demo](indicators/sqzmom/index.html){: .btn .btn-primary }
## Live Charts

These demos showcase real-time streaming with PineTS, featuring live data updates and countdown timers.

### Live MACD (1min)

Real-time MACD indicator on 1-minute timeframe. Demonstrates live indicator calculations and updates.

[View Demo](https://quantforge.org/demos/live-macd-1min.html){: .btn .btn-primary }

### Live Squeeze Momentum (1min)

Live Squeeze Momentum indicator on 1-minute timeframe. Shows advanced indicator visualization.

[View Demo](https://quantforge.org/demos/live-sqzmom-1min.html){: .btn .btn-primary }

### Live Institutional Bias (1min)

Real-time Institutional Bias indicator on 1-minute timeframe. Demonstrates complex indicator calculations.

[View Demo](https://quantforge.org/demos/live-institbias-1min.html){: .btn .btn-primary }

## Williams VIX Fix (Daily)

Williams VIX Fix indicator on daily timeframe. Shows volatility-based indicator visualization.

[View Demo](https://quantforge.org/demos/williams-vixfix-daily.html){: .btn .btn-primary }
51 changes: 51 additions & 0 deletions docs/initialization-and-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This guide explains how to initialize PineTS and run indicators or strategies wi
- [PineTS Constructor](#pinets-constructor)
- [Initialization Options](#initialization-options)
- [The run() Method](#the-run-method)
- [The stream() Method](#the-stream-method)
- [Context Object](#context-object)
- [Return Values](#return-values)
- [Complete Examples](#complete-examples)
Expand Down Expand Up @@ -281,6 +282,56 @@ Returns a `Promise<Context>` object containing:

---

## The stream() Method

The `stream()` method provides an event-based interface for handling live data streams, making it easy to integrate with real-time applications.

### Syntax

```typescript
const evt = pineTS.stream(
pineTSCode: Function | String,
options?: {
pageSize?: number,
live?: boolean,
interval?: number
}
);
```

### Options

| Option | Type | Default | Description |
| ---------- | --------- | ----------------- | ---------------------------------------------------------------------------------------------- |
| `pageSize` | `number` | `undefined` (all) | Number of bars per chunk. If not specified, processes all available historical data in one go. |
| `live` | `boolean` | `true` | Whether to continue fetching live data after processing historical data. |
| `interval` | `number` | `1000` | Polling interval in milliseconds for live data. |

### Usage

The method returns an object with `on()` and `stop()` methods:

```typescript
// Start streaming
const evt = pineTS.stream(indicator, { pageSize: 1, live: true, interval: 2000 });

// Handle data updates
evt.on('data', (context) => {
// Process new data
console.log('New data:', context.result);
});

// Handle errors
evt.on('error', (error) => {
console.error('Stream error:', error);
});

// Stop streaming
// evt.stop();
```

---

## Context Object

The context object is passed to your indicator function and contains all the data and utilities needed for calculations.
Expand Down
Loading