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

78 lines
3.9 KiB
Clojure
Raw Permalink Normal View History

2022-06-07 09:44:49 -07:00
(ns coinbase-pro.order-test
(:require [coinbase-pro.order :as cb-order]
[coinbase-pro.test-helpers :refer [gen-order
gen-limit-order
gen-limit-buy
gen-limit-sell
gen-stop-gain
gen-stop-loss]]
[fudo-clojure.common :refer [is-valid? is-invalid? sample]]
[clojure.test :as t :refer [deftest testing is]]))
(defn gen-amount [& {:keys [min max]
:or {min 0 max (+ min 10000000)}}]
(bigdec (+ (rand (- max min)) min)))
(deftest test-order
(testing "order"
(is-valid? ::cb-order/base-order (gen-order))
(is-invalid? ::cb-order/base-order (gen-order { ::cb-order/product-id :btc-usd }))
(is-invalid? ::cb-order/base-order (gen-order { ::cb-order/product-id "USD-BTC" }))
(is-invalid? ::cb-order/base-order (gen-order { ::cb-order/product-id "BTCBTCBTC-USD" }))
(is-invalid? ::cb-order/base-order (gen-order { ::cb-order/product-id "BTC-USDC" }))
(is-invalid? ::cb-order/base-order (gen-order { ::cb-order/product-id nil }))
(is-invalid? ::cb-order/base-order (gen-order { ::cb-order/side :oops }))
(is-invalid? ::cb-order/base-order (gen-order { ::cb-order/side nil }))
(is-invalid? ::cb-order/base-order (gen-order { ::cb-order/price "12345" }))
(is-invalid? ::cb-order/base-order (gen-order { ::cb-order/price 5 }))
(is-invalid? ::cb-order/base-order (gen-order { ::cb-order/price nil }))
(is-invalid? ::cb-order/base-order (gen-order { ::cb-order/size "12345" }))
(is-invalid? ::cb-order/base-order (gen-order { ::cb-order/size 5 }))
(is-invalid? ::cb-order/base-order (gen-order { ::cb-order/size nil }))))
(testing "buy-order"
(is-valid? ::cb-order/buy-order (gen-order { ::cb-order/side :buy }))
(is-invalid? ::cb-order/buy-order (gen-order { ::cb-order/side :sell })))
(testing "sell-order"
(is-valid? ::cb-order/sell-order (gen-order { ::cb-order/side :sell }))
(is-invalid? ::cb-order/sell-order (gen-order { ::cb-order/side :buy })))
(testing "limit-buy-order"
(is-valid? ::cb-order/limit-buy-order (gen-limit-buy))
(is-invalid? ::cb-order/limit-buy-order (gen-limit-buy { ::cb-order/side :sell }))
(is-invalid? ::cb-order/limit-buy-order (gen-limit-buy { ::cb-order/type :market })))
(testing "limit-sell-order"
(is-valid? ::cb-order/limit-sell-order (gen-limit-sell))
(is-invalid? ::cb-order/limit-sell-order (gen-limit-sell { ::cb-order/side :buy }))
(is-invalid? ::cb-order/limit-sell-order (gen-limit-sell { ::cb-order/type :market })))
(testing "stop-gain-order"
(is-valid? ::cb-order/stop-gain-order (gen-stop-gain))
(is-invalid? ::cb-order/stop-gain-order (gen-stop-gain {::cb-order/stop :loss}))
(is-invalid? ::cb-order/stop-gain-order (gen-stop-gain {::cb-order/stop-price nil}))
(is-invalid? ::cb-order/stop-gain-order (gen-stop-gain {::cb-order/stop-price "12345"}))
(is-invalid? ::cb-order/stop-gain-order (gen-stop-gain {::cb-order/stop-price 5}))
(is-invalid? ::cb-order/stop-gain-order (gen-stop-gain {::cb-order/stop-price (bigdec 8)
::cb-order/price (bigdec 7)})))
(testing "stop-loss-order"
(is-valid? ::cb-order/stop-loss-order (gen-stop-loss))
(is-invalid? ::cb-order/stop-loss-order (gen-stop-loss {::cb-order/stop :entry}))
(is-invalid? ::cb-order/stop-loss-order (gen-stop-loss {::cb-order/stop-price nil}))
(is-invalid? ::cb-order/stop-loss-order (gen-stop-loss {::cb-order/stop-price "12345"}))
(is-invalid? ::cb-order/stop-loss-order (gen-stop-loss {::cb-order/stop-price 5}))
(is-invalid? ::cb-order/stop-loss-order (gen-stop-loss {::cb-order/stop-price (bigdec 7)
::cb-order/price (bigdec 8)})))