TPF Labs
Run a strategyAll pages

Run a strategy

A live strategy is your own program. It runs on your machine, talks to your deployment over the client API and trades in its own book, under its own limits.

  1. 1. Backtest

    On stored history, in the web desk

  2. 2. Write

    The same logic on the client API

  3. 3. Paper

    Run it against a made-up market

  4. 4. Live

    Small limits, its own key and book

Ways to automate

Runs onTrades real accounts
Algo orderYour deploymentYes
Program on the client APIYour machineYes
BacktestYour deploymentNo, history only
C++ strategy in the open frameworkYour machineNo, simulated exchange

1. Backtest the idea

Write it in Python under Automation → Backtest. Backtesting lists what the simulation counts and what it leaves out. Backtest code does not trade, so the live version is a separate program.

2. Write the program

The Python SDK needs Python 3.10 or newer and installs from the repository: pip install ./sdk/python. This is the shape of a strategy. The C++ SDK has the same calls.

my_strategy.py
from raikiri import Book, Client

with Client() as client:  # reads RAIKIRI_API_* variables
    btc = client.market.find("BTC/USDT", account="binance")
    try:
        with client.stream(book=btc, levels=1, hz=5) as stream:
            for event in stream:
                if isinstance(event, Book) and event.bids and event.asks:
                    ...  # decide, then client.orders.limit(...)
    finally:
        client.orders.cancel_all(instrument=btc)

Prices and sizes are exact decimals, and a float raises an error. A sent order means queued: a risk refusal arrives afterwards as status denied.

3. Run it on paper

The paper market is the real API in front of a random walk. No exchange, account or money is involved. It needs the open framework's build tools. Use it to test your code, not to judge profit or execution.

Shell 1: the paper market
git clone https://github.com/TeachPenguinsFly/raikiri && cd raikiri
# build the tools once: see the open framework's quickstart
cmake --build build/dev-asan --target apid
(cd sdk/python && uv sync)
uv run --project sdk/python python examples/paper/paper.py
Shell 2: an example strategy
# paste the three export lines that paper.py printed, then
uv run --project sdk/python python examples/python/market_maker.py

Eight examples come with the SDKs, each in Python and C++:

ExampleShows
place_and_cancelPlace a limit order, look at it, cancel it
stream_quotesPrint quotes as they arrive
stream_fillsWatch your fills and position
twapStart a TWAP, watch, pause and resume it
sor_slippageSmart-route an order and read its slippage
option_chainOne expiry with each strike's greeks
market_makerRequote on each book update, with a position limit
stale_price_guardPull your orders when quotes stop

They are in the repository. They show the mechanics and are not strategies to run with money. They refuse any address but your own machine unless you set RAIKIRI_EXAMPLES_LIVE=yes.

4. Go live

  1. Ask us for an API key for this strategy. The key's client trades in a book called client:<client id>.
  2. Set small limits on that book before the first order.
  3. Point the program at your deployment and start it.
Shell
export RAIKIRI_API_URL=https://api.example.com   # the address we send you
export RAIKIRI_API_KEY=YOUR_KEY_ID
export RAIKIRI_API_SECRET=YOUR_SECRET
python my_strategy.py

Watch it and stop it

Orders and fills appear on the desk. To stop one strategy, press Kill on its book under Automation → Risk: new orders are refused and the open ones are cancelled. Positions stay open.