Skip to main content

An all-in-one tool to assess the latency of crypto exchange APIs.

Project description

ticktracer

ticktracer is a simple Python application that allows you to trace your latency to crypto exchanges, and was developed to run on Alibaba Cloud ECS and analyze the shortest latency for exchanges hosted on Alibaba Cloud. However, any cloud provider can be used.

When the machine running ticktracer and the target exchange use the same NTP service, we can safely assume that the any clock skew between the two instances is negligible. If your instance has chronyc installed, you can verify the time synchronization status of the machine through the command chronyc sources.

Currently only websocket data feed latency can be extracted. It works by establishing a websocket connection to a crypto exchange API endpoint, decrypting the session with Wireshark, and comparing the arrival timestamp of packets with the payload timestamps provided by the exchange itself. Packet timestamps are received by libpcap from the kernel and are not generated by ticktracer itself, unlike other projects. See here for more information.

Architecture overview

Supported Exchanges

  • Binance
  • Bybit
  • OKX

Requirements

Ticktracer has been tested on the following operating systems:

  • macOS >= 14.0
  • Debian >= 12.0
  • Ubuntu >= 22.0

In addition, the following external dependencies are required:

  • wireshark or tshark >= 4.0.7
  • libssl-dev for Debian-based systems or openssl for MacOS

Installation

MacOS

Install dependencies

brew install wireshark openssl

Install ticktracer with pipx (recommended)

brew install pipx
pipx ensurepath
pipx install ticktracer

Install ticktracer with pip

Install ticktracer with pip:

python3 -m pip install ticktracer

Linux (Debian)

Install dependencies

sudo apt update && sudo apt install -y tshark libssl-dev

Install ticktracer with pipx (recommended)

sudo apt install pipx
pipx ensurepath
pipx install ticktracer

Install ticktracer with pip

python3 -m pip install ticktracer

Root permissions

Note that Wireshark requires the user to either have root privileges or to be part of the wireshark group in order to trace packets. To enable non-root access to wireshark, run the following command and select yes:

sudo dpkg-reconfigure wireshark-common

To add your user to the wireshark group, run the following command:

sudo adduser <YOUR-USER> wireshark

Create a new session in your terminal, and verify that you are part of the wireshark group with the following command:

groups

Automated environments

For automated environments, like a userdata script, use the following commands to install wireshark:

export DEBIAN_FRONTEND=noninteractive
apt update && apt install -y libssl-dev tshark

Usage

usage: ticktracer [-h] -e EXCHANGE -p PAIR -d DURATION [-i INTERFACE]

options:
  -h, --help            show this help message and exit
  -e, --exchange_id {okx,binance,bybit}
                        The exchange to connect with.
  -p, --pair PAIR       The trading pair to monitor. Look up the specific format on the exchange's API documentation.
  -d, --duration DURATION
                        Duration in seconds to monitor.
  -i, --interface INTERFACE
                        The network interface to listen on. Default is eth0 for Linux or en0 for macOS.

Example: ticktracer -e okx -p BTC/USDT -d 60

After the monitoring duration has elapsed, the script will output the latency in milliseconds across different percentiles:

Total samples taken: 11567
Latency report:
+------------+-------------------------+
| Percentile | Latency in milliseconds |
+------------+-------------------------+
|    MIN     |          3.104          |
|    25%     |          9.151          |
|    50%     |          10.401         |
|    75%     |          11.762         |
|    90%     |          13.08          |
|    95%     |          14.102         |
|    99%     |          19.474         |
|   99.9%    |          32.975         |
|    MAX     |          48.023         |
+------------+-------------------------+

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ticktracer-0.0.4.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ticktracer-0.0.4-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file ticktracer-0.0.4.tar.gz.

File metadata

  • Download URL: ticktracer-0.0.4.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for ticktracer-0.0.4.tar.gz
Algorithm Hash digest
SHA256 eec93cbdbd2c7127fedbe97487d7799978031466bcb42cc10b8b098a6738ab50
MD5 631d0646c6c9eec5529abf1e20ca89c0
BLAKE2b-256 3a66405941d503a3c3a02c13e157fae3be6d78f511f7b0690e6797604845d4a1

See more details on using hashes here.

File details

Details for the file ticktracer-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: ticktracer-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for ticktracer-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 700d3ce7531cbebe40d2c07e569ec00ce6a75f35c57f41d4c85d8f05de1a74c5
MD5 cc263a2af9ff43c5e57d99d1879ae1fa
BLAKE2b-256 085e32ab1b97e2f796b94f57618e76323090ac8790bc7bbf7741e15435bf355c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page