Skip to content

Instantly share code, notes, and snippets.

@tristanstraub
tristanstraub / promise-async.clj
Created January 21, 2017 21:06
In clojure, call a function returning a promise and convert it to a channel
(defn- <promise
"Call a function that returns a promise and convert it into a channel"
[f & args]
(let [out (a/chan)
done (fn [& _] (a/close! out))]
(.then (apply f args) done done)
out))
@tristanstraub
tristanstraub / cb.clj
Created January 21, 2017 21:04
In clojure, call continuation passing style function and return a channel with result.
(defn- <cb
"Call an callback style function and return a channel containing the result of calling the callback"
[f & args]
(let [out (a/chan)]
(apply f (conj (into [] args) (fn [& args]
(a/put! out args)
(a/close! out))))
out))
(a/<!! (<cb (fn [cb] (cb-style-f 1 2 3 cb))))
@tristanstraub
tristanstraub / gist:55f96bea4eea1a6027610bac7f148e47
Created January 20, 2017 02:06
One line pull/clone and update.
(cd .deploy && git pull) || git clone git@github.com:repository/path.git .deploy
@tristanstraub
tristanstraub / async-apply.cljs
Created December 29, 2016 20:51
Javascript async interop between callbacks/promises and channels
(ns service.async
(:require-macros [cljs.core.async.macros :as a])
(:require [cljs.core.async :as a]))
(defn <cb [f & args]
(let [out (a/chan)]
(apply f (conj (into [] args) #(a/close! out)))
out))
(defn <promise [f & args]
@tristanstraub
tristanstraub / stack.org
Last active October 3, 2016 03:35
Capture region to separate org buffer.
(defun append-text-to-buffer (buffer text)
  "Append to specified buffer the text of the region.
It is inserted into that buffer before its point.

When calling from a program, give three arguments:
BUFFER (or buffer name), START and END.
START and END specify the portion of the current buffer to be copied."
  (interactive
   (list (read-buffer "Append to buffer: " (other-buffer (current-buffer) t))
# INRES="1366x768" # input resolution
# OUTRES="1366x768" # output resolution
INRES="2560x1440" # input resolution
OUTRES="2560x1440" # output resolution
FPS="15" # target FPS
GOP="30" # i-frame interval, should be double of FPS,
GOPMIN="15" # min i-frame interval, should be equal to fps,
THREADS="2" # max 6
CBR="500k" # constant bitrate (should be between 1000k - 3000k)
QUALITY="veryfast" # one of the many FFMPEG preset
@tristanstraub
tristanstraub / Evidence
Last active January 3, 2016 03:01
Stockfighter level 6
Number of trades per account around price changes.
(2 2 2 2 2 ...) is suspicious.
(["MAC11396996" (2)]
["WMG74660049" (2)]
["KIB82586665" (2)]
["JAL12920359" (2)]
["KLB21545517" (2)]
["HRH56719296" (2)]
Assumptions:
1. Bots like to trade at the same quantities each time.
Profitable trades can be identified from the ticker when correlated with this unique quantity.
2. Order id and timestamps are monotonically increasing.
Orders made at regular intervals provide a correspondence between timestamp ranges
and order id ranges.
3. The most profitable trader is the inside trader.
Givens:
Ticker showed long runs at the same last trading price. The volume of these trades is also consistent,
but is probably just the behaviour of the honest bot.
Strategy:
1. Identify long runs of same last price in ticker.
2. Identify who is trading at the these long runs. (open orders and traders against open orders)
3. Which direction are they trading?
4. Identify consecutive runs.
5. Who is trading buy/sell across rising consecutive runs?
BAH64626586 successfully traded over 200 trades against my account, where my bids/asks were only at market value, so only open very short amounts of time.
Another successful strategy played the market, by purchasing early and selling late, after the market had climbed.