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
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
# If only OPENAI_API_KEY is set, OpenAI is selected automatically.
# If both keys are set, Anthropic stays the default until you choose a provider in Settings.
# Provider and model choices are saved in Settings; environment keys take precedence over saved keys.
# Route Anthropic or OpenAI requests through a gateway or proxy (defaults: the public APIs).
# ANTHROPIC_BASE_URL=
# OPENAI_BASE_URL=
# Local or third-party OpenAI-compatible servers (Ollama, LM Studio, OpenRouter...) are set up in Settings.

# Optional market data: no provider is configured or enabled by this template.
# Choose a connection or upload candle CSVs in Settings > Market data.
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ All notable changes to this project are documented here. The format follows [Kee
- Prop firm tracker: evaluation and reset costs, refunds, payout requests, receipts, cash ROI, renewals, attachments, CSV import and export
- Calendar insights, rolling performance trends, and a trade explorer scatter in Reports
- Light mode, a collapsible sidebar, and friendlier AI setup and error notices
- OpenAI-compatible AI provider for local or third-party models (Ollama, LM Studio, OpenRouter and others), and documented `ANTHROPIC_BASE_URL` / `OPENAI_BASE_URL` gateway support (proposed by @fiandev in [#19](https://github.com/LuxAlgo/trade-journal/pull/19))

### Changed

Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,22 @@ docker compose up -d

### Configuration (all optional)

| Env var | Effect |
| ------------------- | -------------------------------------------------------------------------------------------------------- |
| `JOURNAL_PASSWORD` | Require a password; recommended when accessible beyond localhost |
| `JOURNAL_SECRET` | Encryption key source for credentials at rest (default: generated key file in the data dir) |
| `JOURNAL_DATA_DIR` | Database, attachments, and local encryption key directory (default `./data` relative to the app process) |
| `ANTHROPIC_API_KEY` | Anthropic AI key via env instead of the Settings page |
| `OPENAI_API_KEY` | OpenAI AI key via env instead of the Settings page |
| Env var | Effect |
| -------------------- | -------------------------------------------------------------------------------------------------------- |
| `JOURNAL_PASSWORD` | Require a password; recommended when accessible beyond localhost |
| `JOURNAL_SECRET` | Encryption key source for credentials at rest (default: generated key file in the data dir) |
| `JOURNAL_DATA_DIR` | Database, attachments, and local encryption key directory (default `./data` relative to the app process) |
| `ANTHROPIC_API_KEY` | Anthropic AI key via env instead of the Settings page |
| `OPENAI_API_KEY` | OpenAI AI key via env instead of the Settings page |
| `ANTHROPIC_BASE_URL` | Send Anthropic requests through a gateway or proxy (default `https://api.anthropic.com/v1`) |
| `OPENAI_BASE_URL` | Send OpenAI requests through a gateway or proxy (default `https://api.openai.com/v1`) |

Set these in the process environment or in `apps/web/.env.local` for local Next.js runs; the root [`.env.example`](.env.example) documents the optional values. For Docker, configure the service environment in [`docker-compose.yml`](docker-compose.yml).

For AI, open **Settings → AI**, select **Anthropic** or **OpenAI**, enter your API key, and choose **Save AI settings**. OpenAI defaults to `gpt-4.1-mini`; you can enter another text model ID available to your account. Each provider keeps its own encrypted key and model choice. Existing Anthropic settings continue to work. An OpenAI-only environment setup selects OpenAI automatically; with both keys present, Anthropic remains the default until you save a provider choice. Environment keys override saved keys and must be changed on the server. Saving settings does not make a model request or verify account access.

To use a local or third-party model, select **OpenAI-compatible** and enter the server's API URL, a model ID, and an API key only if the server requires one: for example `http://localhost:11434/v1` for Ollama or `https://openrouter.ai/api/v1` for OpenRouter. The journal server sends Chat Completions requests to that URL, so it must be reachable from there. In Docker, `localhost` is the container itself; use `http://host.docker.internal:11434/v1` instead (on Linux, also add `extra_hosts: ["host.docker.internal:host-gateway"]` to the service and make sure the model server listens beyond `127.0.0.1`). A saved key is only sent to the URL it was saved with, so saving a different URL removes it. AI statement parsing on the Import page stays on Anthropic and OpenAI, which accept PDFs and strict structured output.

Deploy anywhere a Node process and a persistent disk exist: Docker, Railway, Fly.io, a small VPS. Serverless platforms without a disk need an external database, which this release does not support. SQLite on disk is the point.

Optional historical market data powers estimated MAE/MFE and candle replay on closed trades, with Vela™ rendering the charts. Configure a connection or upload candle CSVs in **Settings → Market data**. No provider is enabled or selected by default. See [Market data and replay](#market-data-and-replay) below and the [market data guide](docs/market-data.md) for setup, calculation definitions, and coverage limits.
Expand Down Expand Up @@ -136,7 +140,7 @@ flowchart LR
| **Trade pages** | Charted on [Vela](https://www.npmjs.com/package/@luxalgo/vela) with entry/exit markers and P&L labels: fill paths from recorded executions, optional user-selected market candles, and trade replay. Estimated MAE/MFE, running P&L, executions, ratings, stops/targets, tags, mistakes. |
| **Daily journal** | Day stats, intraday P&L curve, autosaving Markdown notes with templates and attachments (images, PDFs). Type them or **dictate** them with browser speech recognition (no journal API key required; browser support and speech processing vary). |
| **Notebook & playbooks** | Folders, search, tags, trade links; named setups with rule checklists scored per trade, with adherence and followed-vs-broken performance in Reports. |
| **AI reflection** | Bring your own Anthropic or OpenAI API key: session recaps, per-trade critiques, "ask your journal" over your own aggregates. Key encrypted at rest; requests go from your server to the model, nowhere else. |
| **AI reflection** | Bring your own Anthropic or OpenAI API key, or use any OpenAI-compatible server such as Ollama: session recaps, per-trade critiques, "ask your journal" over your own aggregates. Key encrypted at rest; requests go from your server to the model, nowhere else. |
| **Routines & misses** | Pre-, during- and post-session routines with weekday schedules and a 13-week history; a missed-opportunity log kept out of your trading metrics. |
| **Journal defaults** | Configure breakeven tolerance, plus fee and stop/target rules per account and symbol; set timezone and contract multipliers for consistent calculations. |
| **Prop firms** | Evaluation and reset expenses, refunds, payout requests, partial receipts, reversals, cash ROI, account phases, renewal reminders, attachments, and generic cash CSV import/export. Separate from trade P&L. |
Expand Down
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"@ai-sdk/anthropic": "^4.0.41",
"@ai-sdk/openai": "^4.0.64",
"@ai-sdk/openai-compatible": "3.0.46",
"@dnd-kit/core": "6.3.1",
"@dnd-kit/sortable": "10.0.0",
"@luxalgo/broker-sdk": "0.5.1",
Expand Down
22 changes: 21 additions & 1 deletion apps/web/src/app/api/settings/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
aiModelSetting,
getAiProvider,
getAiSettings,
normalizeAiBaseUrl,
setAiKey,
setCompatibleBaseUrl,
setSetting,
} from "@/server/settings";
import { AI_PROVIDERS, AI_PROVIDER_NAMES, isAiProvider, type AiProvider } from "@/lib/ai-settings";
Expand All @@ -34,6 +36,9 @@ interface SettingsBody {
/** Set to a key string to store (encrypted), or null to clear. Absent = unchanged. */
anthropicKey?: string | null;
openaiKey?: string | null;
compatibleKey?: string | null;
/** OpenAI-compatible API root. A different URL clears the saved key unless one is sent. */
compatibleBaseUrl?: string;
aiProvider?: AiProvider;
aiModel?: string;
currencyConversion?: CurrencyConversion;
Expand Down Expand Up @@ -68,8 +73,21 @@ export const PATCH = handler(async (request: Request) => {
}
}
if (body.aiProvider !== undefined)
requireValue(isAiProvider(body.aiProvider), "Choose Anthropic or OpenAI.");
requireValue(
isAiProvider(body.aiProvider),
"Choose Anthropic, OpenAI or an OpenAI-compatible server.",
);
const provider = body.aiProvider ?? getAiProvider();
const compatibleBaseUrl =
body.compatibleBaseUrl === undefined
? undefined
: typeof body.compatibleBaseUrl === "string"
? normalizeAiBaseUrl(body.compatibleBaseUrl)
: null;
requireValue(
compatibleBaseUrl !== null,
"Enter a valid server URL, such as http://localhost:11434/v1.",
);
if (body.aiModel !== undefined)
requireValue(
typeof body.aiModel === "string" &&
Expand Down Expand Up @@ -125,6 +143,8 @@ export const PATCH = handler(async (request: Request) => {
const key = body[`${id}Key`];
if (key !== undefined) setAiKey(id, key);
}
if (compatibleBaseUrl)
setCompatibleBaseUrl(compatibleBaseUrl, body.compatibleKey !== undefined);
if (body.aiProvider !== undefined) setSetting("aiProvider", body.aiProvider);
if (body.aiModel !== undefined) setSetting(aiModelSetting(provider), body.aiModel.trim());
});
Expand Down
13 changes: 6 additions & 7 deletions apps/web/src/components/ai-import-options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import { HelpHint } from "./ui/tooltip";
import { Input } from "./ui/input";
import { Label } from "./ui/label";
import { OptionSelect } from "./ui/option-select";
import { AI_DEFAULT_MODELS, AI_PROVIDER_NAMES, type AiSettingsPayload } from "@/lib/ai-settings";
import {
AI_DEFAULT_MODELS,
AI_PROVIDER_NAMES,
type AiSettingsPayload,
type AiProvider,
} from "@/lib/ai-settings";
import { AI_IMPORT_HELP, type AiImportOptions as Options } from "@/lib/ai-import";
AI_IMPORT_HELP,
type AiImportOptions as Options,
type AiImportProvider,
} from "@/lib/ai-import";

export function AiImportOptions({
enabled,
Expand Down Expand Up @@ -90,7 +89,7 @@ export function AiImportOptions({
value={value.provider}
disabled={disabled}
onValueChange={(provider) => {
const next = provider as AiProvider;
const next = provider as AiImportProvider;
onChange({
provider: next,
model: settings?.aiConnections[next].model ?? AI_DEFAULT_MODELS[next],
Expand Down
Loading
Loading