Support

Calculate TICK and TRIN indicators

Overview

In this example we will use the Live client to calculate two technical indicators: market tick (TICK) and the traders index (TRIN).

Trades schema

These indicators are updated on every execution for all symbols on the venue. To get this, we will use the trades schema, which provides records for every trade execution.

Example

We can pass in symbols="ALL_SYMBOLS" to request all symbols of a dataset at once.

import itertools import databento as db import numpy as np # First, create a live client and connect live_client = db.Live(key="$YOUR_API_KEY") # Next, we will subscribe to trades for all symbols live_client.subscribe( dataset="GLBX.MDP3", schema="trades", symbols="ALL_SYMBOLS", ) # Then, we setup our initial values for TICK/TRIN uptick = downtick = upvol = downvol = 0 # We will consume 20 records and then close for this example for record in itertools.islice(live_client, 20): if isinstance(record, db.TradeMsg): side = record.side if side == "A": downtick += 1 downvol += record.size elif side == "B": uptick += 1 upvol += record.size tick = uptick / downtick if downtick != 0 else np.nan trin_base = upvol / downvol if downvol != 0 else np.nan trin = tick / trin_base if trin_base != 0 else np.nan print(f"{tick:.4f}", f"{trin:.4f}") 

Result

1.0000 1.0000 0.5000 1.0000 0.3333 1.0000 0.2500 1.0000 0.2000 2.2000 0.1667 2.0000 0.1429 1.8571 0.1250 1.8750 0.1111 2.1111 0.2222 2.1111 0.3333 1.5833 0.4444 1.0556 0.4000 1.0000 0.5000 1.0000 0.6000 1.0909 0.5455 1.1405 0.5000 1.0909 0.4615 1.0909 0.4286 1.0909