Skip to content

FinLab Command-Line Interface (CLI)

The current FinLab CLI is available through python -m finlab. It supports account login, credential export, session status, legacy token migration, the AI assistant, and cloud strategy deployment and scheduling.

Still in testing

This feature is currently in alpha and may be buggy or unstable. Use with care. For any issues, please file a report on Discord and we will fix it as soon as possible.

Quick Setup

Install or update FinLab:

pip install -U finlab

Log in to your FinLab account:

python -m finlab login

Check your login status:

python -m finlab status

Auth And Credentials

Login

Open a browser login flow and save credentials locally.

python -m finlab login

Logout

Clear local credentials and try to remove the server-side session.

python -m finlab logout

Status

Show the current local session, whether the API key is configured, the plan name, and active server-side sessions.

python -m finlab status

Export Credentials

Export the current login credentials for headless or cloud environments.

python -m finlab token

Output shell export commands:

python -m finlab token --env

Migrate Legacy Token

Show guidance for migrating from the legacy FINLAB_API_TOKEN flow to the current login system.

python -m finlab migrate

AI Assistant

Ask the FinLab AI assistant from the terminal: package usage, backtest errors, data definitions, accounts and plans. It shares one conversation history and the monthly quota of 200 questions (reset at 00:00 on the 1st, Taiwan time) with the website support chat. Log in first.

Ask one question and wait for the answer:

python -m finlab ai "How do I get monthly revenue?"

Send an error message or code along with the question:

python my_strategy.py 2>&1 | python -m finlab ai "How do I fix this error?"

Without a question it starts a chat. Multi-line pastes are sent as one question; type exit to leave:

python -m finlab ai

Ctrl+C only stops waiting; the question is still answered. Show the latest question and answer, waiting if it is still in progress:

python -m finlab ai --last

The assistant only answers FinLab questions. Accounts that keep sending unrelated or meaningless content after a reminder, or send malicious content, lose access to the assistant.

Cloud Strategy Updates

Use the FinLab CLI to deploy strategies to the cloud, schedule daily runs, trigger manual runs, inspect execution logs, and review monthly usage.

Before You Start

Log in to your FinLab account:

python -m finlab login

Cloud strategy code runs in an isolated container with the FinLab SDK pre-installed. Strategy IDs must start with a letter or number, contain only letters, numbers, ., _, and -, and be at most 64 characters. Schedule times use HH:MM in the Asia/Taipei timezone.

Plans, Quotas, And Tiers

Cloud strategy execution limits available tiers and strategy count by plan. Use python -m finlab cloud status to view the current account's allowed tiers and execution count for the month.

Plan Limits

Plan Strategy limit Default tier Available tiers
Free 0 None None
VIP 3 s s
AI 5 m m, l
AI MAX 10 s s, m, l, xl

When --tier is omitted, a new strategy uses the account plan's default tier. Updating an existing strategy keeps its current tier when it already has one. Free users cannot deploy cloud strategies.

Tier Specs

Tier CPU Memory Timeout Concurrency
s 1 4 GiB 300 sec 30
m 2 4 GiB 180 sec 1
l 4 16 GiB 300 sec 1
xl 8 32 GiB 600 sec 1

List Strategies

List cloud strategies for the logged-in account:

python -m finlab cloud list

List up to 500 strategies:

python -m finlab cloud list --limit 500

Inspect A Strategy

Fetch metadata for one strategy. Inline strategies include source code. Zip strategies show metadata and the entry script only, because source files are stored in cloud storage.

python -m finlab cloud get my-strategy

Print only inline strategy source code, which is useful when redirecting output to a file or piping it to another tool:

python -m finlab cloud get my-strategy --code-only

Deploy A Strategy

You can deploy a single Python file or a zip archive for multi-file strategies.

Deploy a single Python file:

python -m finlab cloud deploy my-strategy --code strategy.py

Deploy and set a daily run time:

python -m finlab cloud deploy my-strategy --code strategy.py --time 09:30 --tier s

Deploy and opt into the contest:

python -m finlab cloud deploy my-strategy --code strategy.py --time 09:30 --contest --contest-alias TeamA

Deploy a multi-file strategy:

python -m finlab cloud deploy zip-strategy --zip strategy.zip --entry-script main.py --tier m

Use exactly one of --code and --zip. Inline source code is limited to 256 KiB. Zip uploads are limited to 5 MiB compressed, 50 MiB extracted, and 100 files.

Options:

Name Description Default
--code Single Python strategy file to deploy. None
--zip Zip archive to deploy for a multi-file strategy. None
--entry-script Python entry script inside the zip, for example main.py. Required with --zip. None
--time Daily schedule time in HH:MM. Omit to keep an existing schedule unchanged. None
--tier Compute tier: s, m, l, or xl, subject to plan access. Account default
--contest Opt this strategy into the contest. Only scheduled executions count. None
--no-contest Withdraw this strategy from the contest. Rejoining after withdrawal is not supported by the backend. None
--contest-alias Public leaderboard alias, up to 64 characters. None

Contest strategies must upload a backtest report during scheduled execution, for example with sim(..., upload=True). Manual cloud run executions do not count toward contest results.

Run Manually

Trigger one execution immediately. The strategy must already be deployed. Manual triggers are rate-limited to 5 runs per strategy per hour.

python -m finlab cloud run my-strategy

Override the compute tier for this manual run only:

python -m finlab cloud run my-strategy --tier m

View Execution Logs

Show recent execution records for a strategy, including status, duration, and cost. Status values include queued, running, success, error, timeout, and quota_exceeded.

python -m finlab cloud logs my-strategy

Limit the number of records and show stored stdout, stderr, and error messages:

python -m finlab cloud logs my-strategy --limit 5 --show-output

Schedule Frequency

All schedules use Asia/Taipei without a market-holiday calendar. Missing monthly dates are skipped. With no frequency option, new schedules run daily and existing frequencies are preserved.

python -m finlab cloud schedule set my-strat 09:00 --frequency weekly --days-of-week 1,5
python -m finlab cloud schedule set my-strat 09:00 --frequency monthly --day-of-month 31
python -m finlab cloud schedule set my-strat --frequency custom --cron '0 9 * * 1-5'
python -m finlab cloud deploy my-strat --code strategy.py --time 09:00 --frequency weekly --days-of-week 1,5

Weekdays use 0 (Sunday) through 6 (Saturday). Cron accepts five numeric fields: minute, hour, day, month, weekday, with *, lists, ranges and steps. Restricted day-of-month and day-of-week fields use OR semantics.

Set a daily run time:

python -m finlab cloud schedule set my-strategy 14:30

Remove the daily schedule:

python -m finlab cloud schedule delete my-strategy

Check Monthly Quota

Show current cloud execution usage, allowed tiers, and execution counts:

python -m finlab cloud status

Query a specific month:

python -m finlab cloud status --month 2026-04

Delete A Strategy

Delete a strategy, metadata, code, and schedule. Execution history is preserved.

python -m finlab cloud delete my-strategy

Skip the deletion confirmation prompt:

python -m finlab cloud delete my-strategy -y