Skip to main content

Build Status Codecov GitHub

CMCLogger - Coin Market Cap Cryptocurreny Data Logger

A python API and script for requesting, parsing and storing the latest cryptocurrency data availalbe using the Coin Market Cap Free API. Data entries are stored in a SQLite3 database, with CLI features for querying data and logger status.

TLDR - Just Get Some Data

# Install the module and script
pip install CMCLogger

# Initialise the required configuration, supplying your API key. (Made above)
CMCLogger -a 'your-api-key' -g

# Start the logger. Use 'nohup CMCLogger' to start detached, 'CMCLogger &' to start in background.
CMCLogger 

# Query the latest stored price information for ticker 'BTC'
CMCLogger -q BTC
'BTC: $11676.55 (3.53%)'

# Same as above, but more detailed.
CMCLogger -dq BTC
'BTC: $11676.55 1H: -0.22% 1D: 3.53% 7D: 4.77% 24h Volume: 66.65 Billion'

# Get the logger status. Health is the moving average success rate of the last 30 calls.
CMCLogger -s
'Last successful call 1 minutes ago, health 100.0%.'

# Stop the logger
CMCLogger -k

# Copy the SQLite database to an excel file
CMCLogger -x

Stored Data

When the logger is initialised, it creates a directory structure inside $XDG_CONFIG_HOME. This could be ~/.local/share/CMCLogger or ~/.config/CMCLogger, use echo $XDG_CONFIG_HOME to find the location on your system.

The directory structure is as follows:

CMCLogger
├── config.ini
└── data
    ├── cryptoData.db
    ├── log
    └── status.ini

config.ini

Contains configuration parameters used. Change any of these settings and restart the logger to apply them. Values shown are the default.

[CMC_API]
api_private_key = your-private-key-here
conversion_currency = AUD
curreny_symbol = $
rank_start_index = 1
rank_end_index = 200
request_interval = 5

[General]
status_file_format = ini

cryptoData.db

A SQLite3 database containing all data retreived by the logger. The database contains a separate table, named afeter the cryptocurrency symbol for each individual currecy collected. SQLitebrower, is a good tool for browsing databases, or use CMCLogger -x to convert the database to an Excel file for viewing.

status.ini

Contains information on the status of the logger. This information is queried and returned when using CMCLogger -s or CMCLogger -ds

[Last Successful Call]
timestamp = 2020-04-23 23:10:55.275000+03:00
error_code = 0
error_message = None
elapsed = 17
credit_count = 1

[Last Failed Call]
timestamp = 2020-04-23 22:39:26.646297+03:00
error_code = 255
error_message = No network connections available.
elapsed = 0
credit_count = 0

[Current Session]
health = 100.0
successful_calls = 35644
failed_calls = 587
success_rate = 98.38

[All Time]
successful_calls = 35746
failed_calls = 589
success_rate = 98.38

log

Runtime logs stored by the Python logging module.

Polybar / I3WM Integration

I3WM

Add to .i3/config to start the logger on login.

exec --no-startup-id CMCLogger

Polybar

Add a polybar module for the target bar:

[module/crypto]
type = custom/script
exec = ~/bin/crypto
tail = true
interval = 300

The target script simply cycles through a set of symbols, a blank string is returned if the last entry was more than 10 minutes ago.

#!/bin/bash

queryArray=("BTC" "LTC" "ETH")
TEMPFILE="/tmp/tmp.CMCLOGGER"
source $TEMPFILE 2> /dev/null

function getNextSymbol {
	position=0
	for symbol in ${queryArray[@]}; do
		((position++))
		if [[ "$symbol" == "$LAST_SYMBOL" ]]; then
			size=${#queryArray[@]}
			position=$((position%size))
			CURRENT_SYMBOL=${queryArray[$position]}
			break
		fi
		CURRENT_SYMBOL=${queryArray[0]}
	done
	echo "LAST_SYMBOL=$CURRENT_SYMBOL" > $TEMPFILE
}

function checkStatus {
	jsonStatus=$(CMCLogger -js 2> /dev/null)
	lastCall=$(echo "$jsonStatus" | jq -r '.last_call')

	if (( $lastCall > 10 )); then
		echo ''
		exit
	fi
}

getNextSymbol
checkStatus
CMCLogger -q $CURRENT_SYMBOL

Metadata

Release files for CMCLogger 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for CMCLogger 0.0.1
File Size Uploaded
CMCLogger-0.0.1.tar.gz 20.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for CMCLogger 0.0.1
File Interpreter ABI Platform
CMCLogger-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 44.4 kB

Release files / CMCLogger-0.0.1.tar.gz

Download URL CMCLogger-0.0.1.tar.gz
Size 20.1 kB
Tags Source
SHA-256 checksum
How to use checksums
561bc3a0053baa7079c64b45b9c1d3b71a4d2c1da2301d81520d0c6bc0f5650e
BLAKE2b-256 checksum
How to use checksums
61e0a49b7e54ceb94ca3e347ccb709041ba927bac9946fc2059a7df6ec02dd95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release files / CMCLogger-0.0.1-py3-none-any.whl

Download URL CMCLogger-0.0.1-py3-none-any.whl
Size 24.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
948bf564f5389cbc83fa94d738f2385184dc9cf5fa84f28f35e00a5dd356a6a2
BLAKE2b-256 checksum
How to use checksums
8fac6f3a46ed5236af2c73ea5d91a87503ff31f23d1f48bcccfe6f34cc035f9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page