Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ta4j/ta4j/llms.txt

Use this file to discover all available pages before exploring further.

All data sources in ta4j share a single interface: BarSeriesDataSource. Every implementation loads data the same way — you pass a ticker, an interval, and a date range, and get back a BarSeries. This makes it straightforward to swap sources without touching your strategy code.

The BarSeriesDataSource interface

public interface BarSeriesDataSource {
    BarSeries loadSeries(String ticker, Duration interval, Instant start, Instant end);
}
All built-in sources from ta4j-examples implement this interface. You can write strategies against any source and switch between them at any point.

Built-in sources

YahooFinanceHttpBarSeriesDataSource fetches OHLCV data from Yahoo Finance’s public API. No API key required.
import ta4jexamples.datasources.YahooFinanceHttpBarSeriesDataSource;
import java.time.Duration;
import java.time.Instant;

// Enable response caching to avoid hitting API limits during development
YahooFinanceHttpBarSeriesDataSource dataSource =
        new YahooFinanceHttpBarSeriesDataSource(true);

// Unified interface: works with any BarSeriesDataSource
BarSeries series = dataSource.loadSeries(
        "AAPL",
        Duration.ofDays(1),
        Instant.parse("2023-01-01T00:00:00Z"),
        Instant.parse("2023-12-31T23:59:59Z"));
Convenience methods for common patterns:
// Load by bar count (730 daily bars = ~2 years)
BarSeries daily = dataSource.loadSeriesInstance(
        "AAPL",
        YahooFinanceHttpBarSeriesDataSource.YahooFinanceInterval.DAY_1,
        730);

// Static convenience: 1 year of daily data
BarSeries aapl = YahooFinanceHttpBarSeriesDataSource.loadSeries("AAPL", 365);

// Static convenience: 500 hourly bars
BarSeries btc = YahooFinanceHttpBarSeriesDataSource.loadSeries(
        "BTC-USD",
        YahooFinanceHttpBarSeriesDataSource.YahooFinanceInterval.HOUR_1,
        500);
Supported assets:
  • Stocks: "AAPL", "MSFT", "GOOGL", "TSLA", etc.
  • ETFs: "SPY", "QQQ", "VTI", etc.
  • Cryptocurrencies: "BTC-USD", "ETH-USD", "SOL-USD", etc.
Supported intervals:
Enum constantDuration
MINUTE_11 minute
MINUTE_55 minutes
MINUTE_1515 minutes
MINUTE_3030 minutes
HOUR_11 hour
HOUR_44 hours
DAY_11 day
WEEK_11 week
MONTH_11 month
Pagination: When the requested range exceeds conservative API limits (for example, 30 days for intraday intervals, 1 year for daily), the implementation splits the request into multiple chunks automatically and merges results.
Enable caching with new YahooFinanceHttpBarSeriesDataSource(true). Responses are saved to temp/responses/ and reused. Historical data (end date in the past) is cached indefinitely; recent data respects the bar interval.
Yahoo Finance is an unofficial API. It may impose rate limits (~2000 requests/hour per IP) and availability can vary. For production systems, consider an official data provider.

File-based sources

Loads OHLCV bar data from CSV files. The implementation uses intelligent filename pattern matching to locate the right file based on the ticker symbol.
import ta4jexamples.datasources.CsvFileBarSeriesDataSource;

BarSeriesDataSource csv = new CsvFileBarSeriesDataSource();
BarSeries eth = csv.loadSeries(
        "ETH-USD",
        Duration.ofDays(1),
        start,
        end);
CSV files must contain OHLCV columns. The filename should include the ticker so the data source can match it.
Parses JSON data in Coinbase or Binance export format. Supports flexible date filtering to load a subset of the file.
import ta4jexamples.datasources.JsonFileBarSeriesDataSource;

BarSeriesDataSource json = new JsonFileBarSeriesDataSource();
BarSeries btc = json.loadSeries(
        "BTC-USD",
        Duration.ofHours(1),
        start,
        end);
Aggregates Bitstamp trade-level CSV data into OHLCV bars on the fly. This is the data source used in the ta4j quickstart example.
import ta4jexamples.datasources.BitStampCsvTradesFileBarSeriesDataSource;

// Loads the bundled Bitstamp BTC trade history and aggregates into bars
BarSeries series = BitStampCsvTradesFileBarSeriesDataSource.loadBitstampSeries();
This source is best for offline development and examples. It reads raw tick data and computes OHLCV candles from trade price and volume.

Using the unified interface

Because all sources implement BarSeriesDataSource, you can write code that works with any source:
BarSeriesDataSource yahoo   = new YahooFinanceHttpBarSeriesDataSource(true);
BarSeriesDataSource coinbase = new CoinbaseHttpBarSeriesDataSource(true);
BarSeriesDataSource csv      = new CsvFileBarSeriesDataSource();

// Same call, different implementation
BarSeries aapl = yahoo.loadSeries("AAPL",    Duration.ofDays(1), start, end);
BarSeries btc  = coinbase.loadSeries("BTC-USD", Duration.ofDays(1), start, end);
BarSeries eth  = csv.loadSeries("ETH-USD",   Duration.ofDays(1), start, end);

Implementing a custom data source

Implement BarSeriesDataSource to load data from any origin — a broker API, a database, or a WebSocket stream:
import org.ta4j.core.BarSeries;
import org.ta4j.core.BaseBarSeriesBuilder;
import ta4jexamples.datasources.BarSeriesDataSource;

import java.time.Duration;
import java.time.Instant;

public class MyBrokerDataSource implements BarSeriesDataSource {

    @Override
    public BarSeries loadSeries(String ticker, Duration interval,
                                Instant start, Instant end) {
        // Fetch data from your broker or exchange API
        List<MyOhlcv> ohlcvList = myBrokerApi.getCandles(ticker, interval, start, end);

        BarSeries series = new BaseBarSeriesBuilder().withName(ticker).build();
        for (MyOhlcv bar : ohlcvList) {
            series.barBuilder()
                    .timePeriod(interval)
                    .endTime(bar.getEndTime())
                    .openPrice(bar.getOpen())
                    .highPrice(bar.getHigh())
                    .lowPrice(bar.getLow())
                    .closePrice(bar.getClose())
                    .volume(bar.getVolume())
                    .amount(0)
                    .add();
        }
        return series;
    }
}
ta4j requires only OHLCV (Open, High, Low, Close, Volume) data. The amount field is optional and can be set to 0 when not available.

Live trading

Aggregate raw trades into bars using ConcurrentBarSeries.

Performance metrics

Evaluate strategies once your series is loaded.