coinbase-pro-client/test/coinbase_pro/test_helpers.clj

50 lines
1.7 KiB
Clojure

(ns coinbase-pro.test-helpers
(:require [clojure.test :as t]
[clojure.spec.alpha :as s]
[fudo-clojure.common :refer [sample]]
[coinbase-pro.order :as cb-order]))
(defn gen-amount [& {:keys [min max]
:or {min 0 max (+ min 10000000)}}]
(bigdec (+ (rand (- max min)) min)))
(defn gen-order
([] (gen-order {}))
([ks] (merge {::cb-order/product-id (sample ["BTC-USD" "ETH-USD" "ADA-USD"])
::cb-order/type (sample [:limit :market])
::cb-order/side (sample [:buy :sell])
::cb-order/price (gen-amount)
::cb-order/size (gen-amount)}
ks)))
(defn gen-limit-order
([ks] (gen-order (merge { ::cb-order/type :limit } ks)))
([] (gen-limit-order {})))
(defn gen-limit-buy
([ks] (gen-limit-order (merge { ::cb-order/side :buy } ks)))
([] (gen-limit-buy {})))
(defn gen-limit-sell
([ks] (gen-limit-order (merge { ::cb-order/side :sell } ks)))
([] (gen-limit-sell {})))
(defn gen-stop-gain
([] (gen-stop-gain {}))
([ks]
(let [stop-price (gen-amount)
price (gen-amount :min stop-price)]
(gen-limit-buy (merge {::cb-order/stop :entry
::cb-order/stop-price stop-price
::cb-order/price price}
ks)))))
(defn gen-stop-loss
([] (gen-stop-loss {}))
([ks]
(let [stop-price (gen-amount)
price (gen-amount :max stop-price)]
(gen-limit-sell (merge {::cb-order/stop :loss
::cb-order/stop-price stop-price
::cb-order/price price}
ks)))))