How to connect

SQL API

ClickHousearrow-up-right 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

Please Contact Koinjuenvelope to get the database url and your credentials, the following examples show how to authenticate yourself with them.

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,
    username="<username>",
    password="<password>",
    database="public_data",
)
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.

circle-info

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-typesarrow-up-right

Rust

Install clickhouse-rsarrow-up-right 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 : arrow-up-righthttps://clickhouse.com/docs/integrations/rust#data-typesarrow-up-right

Golang

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

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/decimalarrow-up-right) 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-conversionsarrow-up-right

Other methods

Using ClickHouse CLI Client doc : https://clickhouse.com/docs/integrations/sql-clients/cliarrow-up-right Using BI and visualization tools doc : https://clickhouse.com/docs/integrations/data-visualizationarrow-up-right Using programming language clients and various third-party services doc : https://clickhouse.com/docs/integrationsarrow-up-right 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-formatsarrow-up-right

REST API

Authentication

Contact Koinjuenvelope to get your api keys then use http basic auth to authenticate your requests.

Part of the documentation are generated from OPEN API which spec file is avaialble herearrow-up-right.

curl

python

Last updated