Skip to content

Instantly share code, notes, and snippets.

@jjttjj
jjttjj / mult.cljc
Last active December 2, 2019 19:24
(ns mult
(:require [clojure.core.async :as a]))
(defprotocol MultFn
:extend-via-metadata true
(add-tap [this-fn f] [this-fn xf f]
"Adds a function `f` to 'tapset', a set of functions which are
each called on every value passed to `this-fn`. If a transducer `xf`
is supplied, subjects all values to `xf` before calling `f` on the
result. When a value is reduced, the function is removed from the
(ns mult
(:require[clojure.core.async :as a]))
(defprotocol MultFn
:extend-via-metadata true
(add-tap [this-fn f] [this-fn xf f]
"Adds a function `f` to 'tapset', a set of functions which are
each called on every value passed to `this-fn`. If a transducer `xf`
is supplied, subjects all values to `xf` before calling `f` on the
result. When a value is reduced, the function is removed from the
@jjttjj
jjttjj / app.cljs
Last active November 13, 2019 22:41
(ns app.index
(:require [cljs.core.async :as a]
[lib.dom :as d :refer-macros [tpl-let tpl-with tpl=]]))
;;EXAMPLE USAGE
(enable-console-print!)
(def todos-db (atom {}))
(ns iboga.impl.convert-old
(:require [clojure.spec.alpha :as s]
[clojure.string :as str]
[iboga.meta :as meta]
[iboga.util :as u]
[iboga.specs]
[medley.core :as m])
(:import [java.time LocalDate LocalDateTime]
java.time.format.DateTimeFormatter))
@jjttjj
jjttjj / convert1.clj
Last active October 20, 2019 14:58
Convert 1
(ns iboga.impl.convert
(:require [clojure.string :as str]
[iboga.meta :as meta]
[iboga.util :as u]
[medley.core :as m])
(:import [java.time LocalDate LocalDateTime]
java.time.format.DateTimeFormatter))
(defmulti to-ib* (fn [k v] k))
(defmulti from-ib* (fn [k v] k))
(require '[clojure.core.async :as a])
(do
(def conn1 {:handlers (atom #{})})
(def on? (atom true))
;;;keep passing random ints to every handler
(def process
(future (while @on?
(defn mkput [a p rf cbs]
(fn [x]
(if (realized? p)
false
(let [result (rf a x)]
(if (reduced? result)
(let [x @@result]
;;run callbacks then deliver
(doseq [cb @cbs] (cb x))
(defn client
"Takes one or more message handler functions and returns a map which
represents an IB api client."
[& handlers]
(let [handlers (atom (set handlers))
handle-message (fn [msg]
(doseq [f @handlers]
(try (f (unqualify-msg msg))
(catch Throwable t
(log/error t "Error handling message")))))
(defn wrapper
[cb]
(reify
com.ib.client.EWrapper
(^void tickOptionComputation [this ^int tickerId ^int field ^double
impliedVol ^double delta ^double optPrice
^double pvDividend ^double gamma ^double
vega ^double theta ^double undPrice]
(cb {:field field,
:type :tickOptionComputation,
@jjttjj
jjttjj / core.clj
Last active December 14, 2018 19:35
A minimum viable Interactive Brokers client from clojure with no dependencies!
(ns iboga.core
(:require [clojure.string :as str])
(:import [java.io BufferedReader DataInputStream DataOutputStream IOException]
[java.net InetSocketAddress Socket SocketException]
java.nio.ByteBuffer
java.nio.charset.StandardCharsets))
(defn socket-open? [socket]
(not (or (.isClosed socket) (.isInputShutdown socket) (.isOutputShutdown socket))))