Skip to main content

Chart your own CSV of daily bars

This plugin, written in Python, serves a CSV file of daily bars as a Taji data source, so a chart pinned to it draws your bars instead of a vendor's.

You need a checkout of the repo with Taji's Python (bash engine/crates/taji/scripts/python.sh .python) and a headless kernel booted with TAJI_PLUGINS, as Build a process plugin does. A plugin is a directory holding its manifest and its program; TAJI_PLUGINS names a directory of such directories, so the two files below go in $TAJI_PLUGINS/csv-source/.

The program, csv-source/csv_source.py:

csv_source.py
import calendar
import csv
import datetime
import os

import taji

p = taji.plugin()


@p.read("bars")
def bars(ask):
path = os.path.join(os.environ["HOME"], ask["asked"] + ".csv")
if not os.path.exists(path):
raise taji.Refused(404, "not_listed", f"no {ask['asked']}.csv")
lo, hi = ask["from"], ask["to"]
rows = []
with open(path, newline="") as f:
for r in csv.DictReader(f):
ts = calendar.timegm(datetime.date.fromisoformat(r["date"]).timetuple())
if (lo is None or ts >= lo) and (hi is None or ts < hi):
rows.append({"ts_utc": ts, **{k: r[k] for k in ("open", "high", "low", "close", "volume")}})
return rows


p.run()

Its manifest, csv-source/taji-plugin.toml (the manifest reference):

taji-plugin.toml
id = "csv-source"
name = "CSV source"
version = "0.1.0"
taji = ">=0.7, <0.8"

[process]
run = ["csv_source.py"]
python = {}

[[sources]]
id = "csv-source"
reads = [{ class = "equity", product = "bars", span = "history" }]
bars = { timeframes = ["D"] }

The CSV, put where the plugin reads it. These rows are nine made-up daily bars for SPY, 2026-11-19 to 2026-12-02, one per session:

setup.sh
mkdir -p "$STATE/plugins/csv-source/data"
cat > "$STATE/plugins/csv-source/data/SPY.csv" <<'CSV'
date,open,high,low,close,volume
2026-11-19,99.95,100.6,99.77,100.46,4100000
2026-11-20,100.41,100.88,100.35,100.72,3700000
2026-11-23,100.8,101.77,100.41,101.05,2400000
2026-11-24,101.1,102.87,100.88,102.32,3500000
2026-11-25,102.38,102.7,102.07,102.44,2500000
2026-11-27,102.57,103.3,102.29,103.15,2150000
2026-11-30,103.02,103.21,102.42,102.51,2200000
2026-12-01,102.59,104.25,102.39,103.89,4300000
2026-12-02,103.72,104.25,103.07,104.03,2900000
CSV

Then pin the chart to the plugin and read its bars over the wire:

calls.json
[
{"name": "pin", "method": "POST", "route": "/verb/desk/{desk}/chart/1/set_provider", "body": {"provider": "csv-source"}},
{"name": "bars", "method": "GET", "route": "/get/bars?symbols=equity:SPY&timeframe=D&from=2026-11-01&to=2026-12-02&provider=csv-source", "until": "length == 9", "shot": true}
]

A daily SPY chart pinned to CSV source, drawing the CSV&#39;s bars and nothing before them: the last eight candles, 2026-11-20 to 2026-12-02, climbing from a 100.35 low to a 104.03 close, the first under the drawing toolbar with only its volume showing

  1. @p.read("bars") registers the handler for the one product the manifest's [[sources]] declares. Taji calls it with a ReadAsk (the protocol): asked is the item's key (SPY for equity:SPY), and from and to bound the span in UTC seconds, null where open.
  2. os.environ["HOME"] is the plugin's own data directory, <state dir>/plugins/csv-source/data, the one place its sandbox lets it write besides its temp directory. The plugin reads <symbol>.csv there, so a second file, AAPL.csv, serves equity:AAPL with no change to the code. A symbol with no file is 404 not_listed.
  3. calendar.timegm turns each date into the bar's ts_utc: a daily bar's is its trading day's 00:00 UTC. The prices and volume go through as the CSV spells them, since a bar's figures are decimal strings.
  4. rows keeps the bars inside [from, to), oldest first, as a bars read must answer.
  5. [process] runs csv_source.py on Taji's own Python; python = {} gives it the standard library and the SDK, all this program imports.
  6. [[sources]] declares one source, csv-source, reading bars of class equity at history, and bars = { timeframes = ["D"] } says it answers daily bars alone.
  7. setup.sh writes SPY.csv into the plugin's data directory. $STATE is the kernel's state dir; for your own Taji it is the path configuration names.
  8. set_provider pins chart 1, the Desk's chart pane, to csv-source, so its bars come from your file and no other source. null returns it to the hub's ranking.
  9. /get/bars reads the same bars with provider=csv-source. A YYYY-MM-DD in from or to is a New York session date, taken whole.

The pin's answer names the view node it changed. The chip atop the chart in the picture reads CSV source, the manifest's name, beside a pin:

{
"node": "desk/01a24245-bfbd-7762-89fb-4e70e956511d/chart/view",
"seq": 1796408196819587
}

The bars, decoded from Arrow to JSON:

[
{
"symbol": "SPY",
"provider": "csv-source",
"start_dt": "2026-11-19T00:00:00+00:00",
"knowable": "2026-11-19T21:00:00+00:00",
"open": 99.95,
"high": 100.6,
"low": 99.77,
"close": 100.46,
"volume": 4100000,
"vwap": null,
"trade_count": null,
"up_volume": null,
"down_volume": null
},
{
"symbol": "SPY",
"provider": "csv-source",
"start_dt": "2026-11-20T00:00:00+00:00",
"knowable": "2026-11-20T21:00:00+00:00",
"open": 100.41,
"high": 100.88,
"low": 100.35,
"close": 100.72,
"volume": 3700000,
"vwap": null,
"trade_count": null,
"up_volume": null,
"down_volume": null
},
{
"symbol": "SPY",
"provider": "csv-source",
"start_dt": "2026-11-23T00:00:00+00:00",
"knowable": "2026-11-23T21:00:00+00:00",
"open": 100.8,
"high": 101.77,
"low": 100.41,
"close": 101.05,
"volume": 2400000,
"vwap": null,
"trade_count": null,
"up_volume": null,
"down_volume": null
},
{
"symbol": "SPY",
"provider": "csv-source",
"start_dt": "2026-11-24T00:00:00+00:00",
"knowable": "2026-11-24T21:00:00+00:00",
"open": 101.1,
"high": 102.87,
"low": 100.88,
"close": 102.32,
"volume": 3500000,
"vwap": null,
"trade_count": null,
"up_volume": null,
"down_volume": null
},
{
"symbol": "SPY",
"provider": "csv-source",
"start_dt": "2026-11-25T00:00:00+00:00",
"knowable": "2026-11-25T21:00:00+00:00",
"open": 102.38,
"high": 102.7,
"low": 102.07,
"close": 102.44,
"volume": 2500000,
"vwap": null,
"trade_count": null,
"up_volume": null,
"down_volume": null
},
{
"symbol": "SPY",
"provider": "csv-source",
"start_dt": "2026-11-27T00:00:00+00:00",
"knowable": "2026-11-27T18:00:00+00:00",
"open": 102.57,
"high": 103.3,
"low": 102.29,
"close": 103.15,
"volume": 2150000,
"vwap": null,
"trade_count": null,
"up_volume": null,
"down_volume": null
},
{
"symbol": "SPY",
"provider": "csv-source",
"start_dt": "2026-11-30T00:00:00+00:00",
"knowable": "2026-11-30T21:00:00+00:00",
"open": 103.02,
"high": 103.21,
"low": 102.42,
"close": 102.51,
"volume": 2200000,
"vwap": null,
"trade_count": null,
"up_volume": null,
"down_volume": null
},
{
"symbol": "SPY",
"provider": "csv-source",
"start_dt": "2026-12-01T00:00:00+00:00",
"knowable": "2026-12-01T21:00:00+00:00",
"open": 102.59,
"high": 104.25,
"low": 102.39,
"close": 103.89,
"volume": 4300000,
"vwap": null,
"trade_count": null,
"up_volume": null,
"down_volume": null
},
{
"symbol": "SPY",
"provider": "csv-source",
"start_dt": "2026-12-02T00:00:00+00:00",
"knowable": "2026-12-02T21:00:00+00:00",
"open": 103.72,
"high": 104.25,
"low": 103.07,
"close": 104.03,
"volume": 2900000,
"vwap": null,
"trade_count": null,
"up_volume": null,
"down_volume": null
}
]

Captured 2026-12-04 on a headless kernel with csv-source under TAJI_PLUGINS; the CSV's figures are made up.

  • Nine rows, one per CSV line, oldest first, each with provider csv-source: provider=csv-source kept every other source out.
  • open, high, low, close and volume are the CSV's figures, decoded from the wire's decimals: 2026-11-20 closes at 100.72 on 3,700,000 shares.
  • start_dt is the ts_utc the plugin sent. knowable is the kernel's, from the exchange calendar: 21:00 UTC on a full day, 18:00 UTC on 2026-11-27, the half day after Thanksgiving. The CSV has no row for 2026-11-26, when the market was shut.
  • vwap, trade_count, up_volume and down_volume are null: the plugin states none.

Change it​

Read a CSV whose headers are capitalised, Date,Open,High,Low,Close,Volume:

for r in csv.DictReader(f):
+ r = {k.lower(): v for k, v in r.items()}
ts = calendar.timegm(datetime.date.fromisoformat(r["date"]).timetuple())

Read a CSV with no volume column. A bar's volume may be null, which Taji holds as 0:

- rows.append({"ts_utc": ts, **{k: r[k] for k in ("open", "high", "low", "close", "volume")}})
+ rows.append({"ts_utc": ts, **{k: r[k] for k in ("open", "high", "low", "close")}, "volume": None})

Unpin the chart, so it draws the bars the hub ranks first again (Yahoo's, on a keyless kernel):

- {"name": "pin", "method": "POST", "route": "/verb/desk/{desk}/chart/1/set_provider", "body": {"provider": "csv-source"}},
+ {"name": "pin", "method": "POST", "route": "/verb/desk/{desk}/chart/1/set_provider", "body": {"provider": null}},

Next​