This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; This turns out to be very, very useful when working with floating point numbers in some cases. | |
;; E.g. if you switch some of your input from ^long to ^double your calculations might actually shift ever so slightly | |
;; which will make comparing old vs. new results tricky. | |
;; You'll need this in your project.clj file: | |
[com.google.guava/guava "LATEST"] | |
;; ..and this somewhere useful: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Based on this talk https://www.youtube.com/watch?v=BR5pDiPYsnw | |
;; | |
;; NOTE: I've not yet tested these for correctness(!) | |
(defn double-finite-or-zero ^double [^double n] | |
(if (Double/isFinite n) | |
n | |
0.0)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; https://www.Quanto.ga/ | |
;; NOTE: The normal and sane(!) way to do this would be to use an outer WITH-OPEN | |
;; – or even better put your stuff in a database! | |
(deftype GCedResource ;; Clojure WITH-OPEN macro (sort of?) on drugs. Bonus: It will work in context of laziness. | |
[resource] | |
Object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; https://www.Quanto.ga/ | |
(def ^:const exchange-use-dedicated-sl-and-tp-orders? | |
{:backtest false | |
:bitmex true | |
:oneb false}) | |
quantataraxia.core> (do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; https://www.Quanto.ga | |
;; clojure.core.async: how to deal with deadlocks | |
;; | |
;; If you have a channel that in the "reader" or consumer also sends | |
;; to itself you might end up with a deadlock in certain cases. Especially | |
;; if you don't want to use buffered channels -- perhaps because it is | |
;; impossible to predict how much of a buffer you will need: | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; www.Quanto.ga | |
;; | |
;; cp/upmap is from https://github.com/TheClimateCorporation/claypoole | |
quantataraxia.core> (do | |
(println "MAP:") | |
(println (time (doall (map (fn [x] (Thread/sleep x) x) | |
(range 500 50 -9))))) | |
(println "PMAP:") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Performance of with-local-vars vs. atom vs. volatile vs. unsynchronized-mutable field. | |
(definterface IOObject | |
(setVal [new-val]) | |
(getVal []) | |
(oswap [f]) | |
(oswap [f x]) | |
(oswap [f x y]) | |
(oswap [f x y z])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; I keep forgetting how to do this stuff for some reason, so here goes: | |
(let [c (async/chan 1 (map #(* % 2)))] | |
(async/go | |
(loop [] | |
(when-let [e (async/<! c)] | |
(println "async/go, e:" e) | |
(recur)))) | |
(async/>!! c 1) | |
(async/>!! c 2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(let [f (future | |
(try | |
(Thread/sleep 10000) | |
(catch Throwable e | |
(println e) | |
(println "isInterrupted:" (.isInterrupted (Thread/currentThread))) | |
(println "isAlive:" (.isAlive (Thread/currentThread))) | |
(println "interrupted:" (Thread/interrupted)))))] | |
(Thread/sleep 500) | |
(future-cancel f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; www.Quanto.ga | |
;;;;;;;;;;;;;;;;; | |
;; Test from https://www.bitmex.com/app/apiKeysUsage#Full-sample-calculation | |
(letfn [(sign [^String api-secret ^String s] | |
(let [h (com.google.common.hash.Hashing/hmacSha256 (.getBytes api-secret))] | |
(.toString (.hashString h s com.google.common.base.Charsets/UTF_8))))] | |
(let [apiKey "LAqUlngMIQkIUjXMUreyu3qn" | |
apiSecret "chNOOS4KvNXR_Xq4k4c9qsfoKWvnDecLATCRlcBwyKDYnWgO"] | |
;; Simple GET |