Skip to content

Instantly share code, notes, and snippets.

@t4n1o
t4n1o / archives_mirror.py
Created January 2, 2022 14:33
python part
"""This module downloads csv data files for bitmex's historical `trades` data."""
# TODO consider using s = requests.Session()
# r = s.get(url, headers=headers, stream=True)
# requests: session with keepalive and better error handling
# urllib: connection close is hard-coded (no keep-alive), worse error-handling, but standard library (no pip requirements)
# TODO Check if any tests are relevant
# TODO error handling -review
import gzip
import logging
//! Load csv.gz files from the bitmex archives and process them into csv files per day.
//!
//! We read files, then decompress them into text strings, then run a regex parser on it,
//! there is no limit to how much memory this program uses.
//!
//! Functionality:
//! - has config option for checking for duplicates (execution time becomes longer)
//! - finds the last index before continuing
//! - writes first to a temp file then renames
use chrono::{Duration, NaiveDate};
@t4n1o
t4n1o / test_data_formats.py
Created September 22, 2021 13:41
Test tradeoffs between hdf and parquet (gzip, brotli, snappy)
# Copyright 2021 t4n1o
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@t4n1o
t4n1o / datetime_cheatsheet.py
Last active August 2, 2021 17:22
Python datetime timezone cheatsheet
import datetime
import pytz
sample_datetime = datetime.datetime(2019, 2, 3, 6, 30, 15, tzinfo=datetime.timezone.utc)
# Drop the timezone (tzinfo attribute) from a datetime object.
sample_datetime.replace(tzinfo=None)
@t4n1o
t4n1o / gist:87a8949589e1aefd6542f1887fd654d3
Last active March 7, 2021 19:23
pyverse automation into docs/uml folder
#!/usr/bin/python3
"""A script to make UML diagrams out of python source code and saves it to the docs directory.
For this to work you need to first install:
-pylint
`python3 -m pip install pylint`
-graphviz
`sudo apt-get install graphviz`
"""
import shutil