Skip to content

Instantly share code, notes, and snippets.

View mwlang's full-sized avatar

Michael Lang mwlang

View GitHub Profile
require "http"
class Listener
getter symbol : String
def initialize(@symbol : String)
@channel = Channel(String).new
@open = false
@url = "wss://stream.binance.com:9443/ws/#{@symbol.downcase}@depth"
require "./query_param_helper"
require "http"
require "json"
class OrderBookEntry
getter last_update_id : Int32
getter price : Float64
getter quantity : Float64
def initialize(uid : Int32, price : Float64, quantity : Float64)
CRYSTAL = crystal
UNAME = "$(shell uname -ms)"
LIBRARY_PATH = $(shell brew --prefix crystal-lang)/embedded/lib
TARGET = cr_math.bundle
$(TARGET): cr_math.o
$(CC) -bundle -L$(LIBRARY_PATH) -o $@ $^
cr_math.o: cr_math.cr
{"interval":"1M","timestamp":1556308620,"high_price":22.8058,"low_price":22.7881,"open_price":22.8058,"close_price":22.7881,"target_volume":14706.032755,"base_volume":644.92}
{"interval":"1M","timestamp":1556308680,"high_price":22.7885,"low_price":22.7109,"open_price":22.7885,"close_price":22.744,"target_volume":41692.869956,"base_volume":1833.33}
{"interval":"1M","timestamp":1556308740,"high_price":22.7867,"low_price":22.7213,"open_price":22.7265,"close_price":22.763,"target_volume":57258.608166,"base_volume":2516.55}
{"interval":"1M","timestamp":1556308800,"high_price":22.7869,"low_price":22.7208,"open_price":22.7584,"close_price":22.7863,"target_volume":29642.196593,"base_volume":1302.67}
{"interval":"1M","timestamp":1556308860,"high_price":22.7983,"low_price":22.7861,"open_price":22.7978,"close_price":22.7861,"target_volume":2494.932451,"base_volume":109.44}
@mwlang
mwlang / city.rake
Created April 17, 2019 14:26
Code to turn an irregular phone number into a regular one so we can grab area code reliably and then look up the city it belongs to.
namespace :city do
STATE_NAMES = {
"Alabama" => "AL",
"Alaska" => "AK",
"American" => "AS",
"Arizona" => "AZ",
"Arkansas" => "AR",
"California" => "CA",
"Colorado" => "CO",
========================================
Iteration = 91175 (replaying)
ST: 24 MT: 38 LT: 52
Funds: 988.9258339463607
RPC: 0.436%
----------------------------------------
BNBBTC BUY_PREP T:14 P:1.0222287 V:0.0014118 ST:0.0014107:UP MT:0.0014108:DOWN LT:0.0014108:DOWN S:0.173% RPC:2.153% CTPC:0.000% RSI:60.14:47.52:UP RSI:56.04:46.73:DOWN RSI:57.17:44.07:UP H/L:58.702/37.192
BNBUSDT BUY_PREP T:19 P:987.9036 V:4.8262 ST:4.8242:UP MT:4.8247:DOWN LT:4.8246:UP S:0.277% RPC:-1.281% CTPC:0.000% RSI:48.37:53.25:DOWN RSI:52.57:53.04:UP RSI:51.55:51.23:UP H/L:65.991/36.807
========================================
Iteration = 91174 (replaying)
@mwlang
mwlang / _summary.txt
Last active August 2, 2018 07:09
A comparison of rebalancing your cryptocurrency portfolio on daily basis vs. doing nothing at all after initial investments over same time period. Starting with November 1, 2017
================================================================================
initial usd: 10000
initial btc: 1.440971
btc per coin: 0.1440970983887783
start date: 2017-11-01
end date: 2017-11-01
================================================================================
The DO NOTHING performance
1.44097100 6.17230188
10000.00 47167.30
@mwlang
mwlang / _error.out
Created May 28, 2018 16:06
Bitshares Witness Node keeps dying. Why?
2756441ms th_a witness.cpp:87 plugin_initialize ] witness plugin: plugin_initialize() begin
2756441ms th_a witness.cpp:97 plugin_initialize ] Public Key: BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
2756442ms th_a witness.cpp:115 plugin_initialize ] witness plugin: plugin_initialize() end
2756443ms th_a object_database.cpp:106 open ] Opening object database from /mnt/data/bitshares-core/programs/witness_node/witness_node_data_dir/blockchain ...
2834465ms th_a object_database.cpp:111 open ] Done opening object database.
2834495ms th_a db_management.cpp:59 reindex ] reindexing blockchain
2834496ms th_a db_management.cpp:65 reindex ] Replaying blocks, starting at 24076699...
2835816ms th_a db_management.cpp:78 reindex ] Writing database to disk at block 24076779
2957431ms th_a db_manageme
@mwlang
mwlang / squawk.rb
Created December 26, 2017 17:57
API KEYS and Slack webhook keys redacted.
require 'twitter'
require 'slack-notifier'
client = Twitter::REST::Client.new do |config|
config.consumer_key = "..."
config.consumer_secret = "..."
end
notifier = Slack::Notifier.new "https://hooks.slack.com/services/.../.../...", username: "officialmcafee"
@mwlang
mwlang / _results.txt
Created August 30, 2017 03:45
Bitcoin analysis of average change by weekday and month for YTD 2017 ending through August
Sun Mon Tue Wed Thu Fri Sat
Jan 0.8 0.16 2.74 -1.3 -1.2 -1.97 0.77
Feb -0.24 1.6 1.9 0.29 1.1 0.73 -0
Mar 2.4 2.76 1.09 -1.85 -0.33 -3.56 -0.57
Apr 1.32 1.44 1.18 0.17 1.98 0.43 0.29
May 1.16 3.8 2.18 3.82 0.1 -3.63 1.44
Jun 0.05 -1.56 5.58 -5.27 2.01 1.13 0.71
Jul -0.67 3.35 -0.76 0.29 7.54 -2.99 -1.28
Aug 0.45 2.87 -0.26 0.93 1.8 1.51 5.26