TPF Labs
Client APIAll pages

Client API

Signed REST and one WebSocket, for your own strategies, reporting and back office. Orders from it pass the same risk checks as orders from the desk.

Start

We issue a key with your address, key id and secret. The Python and C++ SDKs are in the public repository and read these variables:

Shell
export RAIKIRI_API_URL=https://api.example.com
export RAIKIRI_API_KEY=YOUR_KEY_ID
export RAIKIRI_API_SECRET=YOUR_SECRET
Python
from raikiri import Client

client = Client()
print(client.whoami())

btc = client.market.find("BTC/USDT", account="binance")
order = client.orders.limit(btc, "buy", "0.001", "60000", post_only=True)
print(client.orders.get(order.id).status)
client.orders.cancel(order.id)

Try the code on the open framework's paper market first. It runs the same API with no money involved. Every route and field is in the OpenAPI file, client-api.yaml.

What a key allows

SettingMeaning
Permissionsread, trade for orders, algo for parent orders
AccountsWhich exchange accounts. A key narrowed to some accounts cannot start algos, because the router uses all of them.
SymbolsFor example BTC/*
AddressesThe IP addresses it may be used from
RatesRequests and order changes per second, and open streams

GET /api/v1/whoami returns the permissions, scope and rates. A client has one book and sees only its own orders, fills and positions. Balances belong to the exchange account, so clients that share an account see the same ones.

Signing

The SDKs sign for you. Otherwise send three headers on every call except /time and /health. The signature is the lowercase hex HMAC-SHA256 of five fields joined by newlines: timestamp in milliseconds, method, path, query without the question mark, and body.

curl
TS=$(($(date +%s) * 1000))
SIG=$(printf '%s\n%s\n%s\n%s\n%s' "$TS" GET /api/v1/whoami "" "" \
  | openssl dgst -sha256 -hmac "$RAIKIRI_API_SECRET" | awk '{print $NF}')

curl -s "$RAIKIRI_API_URL/api/v1/whoami" \
  -H "X-Raikiri-Key: $RAIKIRI_API_KEY" \
  -H "X-Raikiri-Timestamp: $TS" \
  -H "X-Raikiri-Signature: $SIG"

The clock may be 5 seconds off by default. A signature is accepted once, so the same request needs a new timestamp. This example has one-second steps: wait a second between calls. Sign on your server and never in a browser.

Orders

HTTP, signing headers left out
POST /api/v1/orders
Idempotency-Key: 5b0c1f0e-rebalance-17

{"instrument_id": "1001", "side": "buy", "order_type": "limit",
 "price": "60000", "qty": "0.001", "post_only": true, "external_ref": "rebalance-17"}
  • 202 means queued. Risk checks run after the answer. A refused order reads denied over REST with the reason in refusal. The stream does not carry a denial, so read the order back.
  • Every POST and DELETE needs an Idempotency-Key of 8 to 128 characters. Reuse it when you retry the same intent, and the order is not placed twice.
  • An amend is a cancel and a new order. It has a new id and loses its place in the queue. If the cancel is not confirmed within 2 seconds, nothing new is placed.
  • Numbers are decimal strings and timestamps are Unix nanoseconds as strings. The Python SDK refuses a float.
  • POST /api/v1/orders/cancel-all cancels this client's open orders. It leaves algo children to their algos.

Algos

Python
algo = client.algos.twap("BTC/USDT", "buy", qty="2", horizon_s=600, slices=20)
for state in algo.watch():
    print(state.status, state.progress, state.avg_price)

The API starts smart-routed, TWAP, VWAP and POV orders, and pauses, resumes and cancels them. The other order types are not in the client API. If an algo answers algo-lost, its children are still ordinary orders. Check them before you start another.

Stream

Connect to wss://api.example.com/api/v1/stream. The upgrade is a signed GET with an empty query and body.

Messages to send
{"op":"subscribe","id":"p","channels":["orders","fills","positions","balances","algos"]}
{"op":"subscribe","id":"q","quotes":["1001"],"hz":5}

Your own events are numbered. After a reconnect, subscribe with resume_from and epoch to receive what you missed. A gap message means that some events are gone, so read the state again over REST. Market channels (quotes, book, greeks, funding, ticker) send current values, and a slow reader gets fewer. Reconnect after three missed heartbeats. The SDKs do all of this.

Routes

Under /api/v1Use
/whoami, /time, /healthThe key, the server's clock, whether the API is up
/accounts, /balances, /positions, /fillsYour state, and the data for reporting
/instruments, /marketsWhat can be traded, with price and size steps
/ordersPlace, list, read, amend and cancel, with each order's events
/algosParent orders
/options/underlyings, /chain, /surfaceOptions data, where your deployment has it

Lists are paged by cursor. Take it from next_cursor and stop when there is none. A page can be empty and still have a next one.

Errors

Errors are application/problem+json. Program against code, not the text, and quote request_id when you write to us.

CodeWhat to do
auth-failedWrong key or signature. Check the five fields, and the path and query exactly as sent.
timestamp-skewCompare your clock with /api/v1/time.
ip-not-allowedSend us the new address.
rate-limitedWait for Retry-After. RateLimit-Remaining is on every signed answer.
out-of-scopeThe key does not cover that account or symbol.
risk-refusedOn a denied order. See why orders are refused.
venue-unavailableThe exchange connection is not taking orders. Check the desk before you retry.