Skip to content

Instantly share code, notes, and snippets.

View miohtama's full-sized avatar
🏠
https://tradingstrategy.ai

Mikko Ohtamaa miohtama

🏠
https://tradingstrategy.ai
View GitHub Profile
curl -X POST -H "Content-Type: application/json" \
--data '{
"jsonrpc": "2.0",
"method": "eth_call",
"params": [
{
"to": "0xcA11bde05977b3631167028862bE2a173976CA11",
"data": "399542e9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000005a0000000000000000000000000000000000000000000000000000000000000062000000000000000000000000000000000000000000000000000000000000006a0000000000000000000000000000000000000000000000000000000000000074000000000000000000000000000000000000000000000000000000000000007e0000000000000000000000000000000000000000000000000000000000000086000000000000000000000000000000000000000000000000000000000000008e000000000000000000000000000000000000000000000000000000000000009800000000000000000000000
@miohtama
miohtama / nan_json_encoder.py
Created January 15, 2026 19:43
Nan-Aware Python JSON encoder
import json
import math
from datetime import datetime, timedelta
from decimal import Decimal
from enum import Enum
from typing import Collection, Mapping
from uuid import UUID
import pandas as pd
from dataclasses_json.core import Json
@miohtama
miohtama / gist:fb3a942d84d658d92a50ccc67cfcf1d9
Created September 16, 2025 11:55
GMX Python API example
# github.com/tradingstrategy-ai/web3-ethereum-defi
from eth_defi.gmx.create_increase_order import IncreaseOrder
from eth_defi.gmx.trading import GMXTrading
from eth_defi.provider.multi_provider import create_multi_provider_web3
from eth_defi.gmx.config import GMXConfig
from eth_defi.hotwallet import HotWallet
from eth_account import Account
import os
You can append data to a Parquet dataset in PyArrow by using the `pyarrow.parquet.write_to_dataset()` function and setting the `existing_data_behavior` parameter to `'overwrite_or_append'`.
This function writes new Parquet files to the dataset directory. If the data belongs to a new partition, a new partition directory is created. If it belongs to an existing partition, a new file is added to that partition's directory.
-----
### \#\# How It Works
The key is the `existing_data_behavior` argument, which tells PyArrow how to handle the new data in relation to any data already at the destination.
@miohtama
miohtama / python-redis-json-dataclass-example.py
Created May 18, 2021 09:48
Python simple persistent database with dataclass, JSON and Redis.
"""A simple trade execution report database by using Python dataclass, Redis and JSON.
- A very simple database for arbitrage trade execution reports.
- Dataclasses are serialised and deserialised to JSON that is stored in the Redis.
- There is type validation for members and class-types.
- Class-types like Decimal are converted back to their original format upon deserialisation.
- Optional members are supported and the member presence is validated.
- Past trades can be iterated in either order by creation.
- A simple CSV exported is provided.
@miohtama
miohtama / webserver.py
Created September 17, 2015 01:54
Using Waitress web server to run functional py.test test suite for a WSGI app in Python
"""py.test fixtures for spinning up a WSGI server for functional test run."""
import threading
import time
from pyramid.router import Router
from waitress import serve
from urllib.parse import urlparse
import pytest
@miohtama
miohtama / foundry-local-dev.sh
Last active July 28, 2025 13:20
Foundry local development with master
#!/bin/bash
#
# Set up a founry for local development, using faster dev profile for compilation
#
PROFILE=dev
# You need to delete the existing forge etc. commands, because even
# if the cargo install says "replacing" they did not really seem to replace and
# some old version was left around.
@miohtama
miohtama / purge_logs.sh
Created January 27, 2017 10:04
Remove old logs from Quassel SQLite database
#!/bin/sh
BAK_PATH="${HOME}/.config/quassel-irc.org/quassel-storage.sqlite.bak"
CURRENT_PATH="${HOME}/.config/quassel-irc.org/quassel-storage.sqlite"
# first day of data that will be maintained
# -15 day means that *every* chatline stored before 16 days ago and so on are going to be eliminated.
# only the last 15 days are keeped.
DATE_TO_PRUNE='-15 day'
die() {
@miohtama
miohtama / grvt-ccxt-api.py
Last active May 7, 2025 11:53
Compare GRVT CCXT-compatibility API with a known similiar decentralised perp exchange
"""Compare GRVT CCXT-compatibility API with a known similiar decentralised perp exchange.
- Run the same CCXT API functions against know decentralised perp exchange and GRVT
and compare the results
"""
import logging
import os
from pprint import pprint
import ccxt
@miohtama
miohtama / gist:5216738
Created March 21, 2013 21:05
Enabling SSLCACertificateFile and SSLVerifyClient for one page only in Apache 2.2+
# Apache configuration for running local browser against a locally running xxxx for manual smartcard testing
# Listen 4433
<VirtualHost 127.0.0.1:4433>
# Real men use mod_proxy
DocumentRoot "/nowhere"
ServerName local-apache
ServerAdmin you@example.com