For the complete documentation index, see llms.txt. This page is also available as Markdown.

How to connect

SQL API

ClickHouse is an open-source column-oriented DBMS for online analytical processing (OLAP) that allows users to generate analytical reports using SQL queries in real-time.

The database can be interacted with either via its CLI client or connector available for all the mainstream languages.

Authentication

Sign up at koinju.io/pricing — or Contact Koinju — to get the database url and your credentials, the following examples show how to authenticate yourself with them.

Upgraded your plan? Your tier's limits and data-history window are bound to a SQL connection when it opens. After upgrading, reconnect — close and reopen the connection, or restart your BI tool / connection pool — so the new tier takes effect. An already-open session does not pick up the change and may return Not enough privileges until it reconnects. (REST API requests pick up your new tier automatically — no action needed.)

Python

Install clickhouse-connect

pip install clickhouse-connect

Because the connector allows to query directly into a pandas DataFrame, if this feature is desired pandas should be installed as well.

Get the last 20 trades for any instrument starting with BTC

import clickhouse_connect

conn = clickhouse_connect.get_client(
    host="<provided_database_url>",
    port=8443,
    secure=True,
    username="<username>",
    password="<password>",
    database="api",
)
df = conn.query_df(
    "select * from trade where  market like 'BTC%' and timestamp > toStartOfDay(now()) order by timestamp desc limit 20"
)
print(df.columns)
print(df[["exchange", "market", "timestamp", "price", "quantity", "side"]].head())

Outputs

The query includes an additional filter by timestamp to optimize speed. The trade table, over 40TB, contains all public trades across several exchanges. While the entire dataset is searchable, limiting the time frame ensures results return in milliseconds instead of seconds, especially if queries do not match existing indexes. More details on query optimization are provided for each endpoint and in a general overview.

All datetimes returned by koinju timezone aware and set to UTC. By default the connector will convert them to the user's timezone. So care should be applied if for some reasons the timezone awareness need to be dropped ( as for example when storing results in a excel spreadsheet).

Type equivalence between clickhouse and python : https://clickhouse.com/docs/integrations/python#read-format-options-python-types

Rust

Install clickhouse-rs and other dependecies

Then execute the following

Ouputs

The conversion of the Decimal type into String in the query allows to decode the strings directly into Decimal type from rust_decimal crate.

Type equivalence between clickhouse and rust : https://clickhouse.com/docs/integrations/rust#data-types

Golang

Install [clickhouse-go](https://github.com/ClickHouse/clickhouse-go)

By default all the decimal numbers in our tables are represented in [Decimal256 with a scale of 20](https://clickhouse.com/docs/sql-reference/data-types/decimal) as to not lose any precision from data recieved from the exchages.

If user value correctness the users can stick to decimal by installing and using this [decimal library](https://github.com/shopspring/decimal ) ) or if speed is a priority simply using float. The connector will accept both values for field structs represented as decimals in the database.

Outputs

Type equivalence between clickhouse and go: https://clickhouse.com/docs/integrations/go#type-conversions

Other methods

Using ClickHouse CLI Client doc : https://clickhouse.com/docs/integrations/sql-clients/cli Using BI and visualization tools doc : https://clickhouse.com/docs/integrations/data-visualization Using programming language clients and various third-party services doc : https://clickhouse.com/docs/integrations Data formats : Along with getting the SQL result directly, ClickHouse also supports exporting data in various formats, like CSV, parquet etc. doc : https://clickhouse.com/docs/integrations/data-formats

REST API

The REST API uses a two-tier access model:

Endpoints
Authentication
Free
Developer
Professional
Business
Enterprise

/market/*

None (public)

10 req/s

10 req/s

10 req/s

10 req/s

Custom

/ohlcv, /trade

API key (x-api-key header)

100 req/day, 100 items

100 req/day, 1K items

1K req/day, 1K items

10K req/day, 1K items

Custom

See Pricing for full tier details.

Public Endpoints

Market listing endpoints are open — no authentication required.

curl

python

Private Endpoints

The /ohlcv and /trade endpoints require an API key passed in the x-api-key header.

Sign up at koinju.io/pricing — or Contact Koinju — to get your API key.

curl

python

Part of the documentation is generated from OpenAPI, the spec file is available here.

Last updated

Was this helpful?