diff --git a/project.clj b/project.clj index 7a6090a..23fbd81 100644 --- a/project.clj +++ b/project.clj @@ -19,6 +19,7 @@ [slingshot "0.12.2"] [spootnik/kinsky "0.1.22"] [org.clojars.fossi/kafka-streams-clojure "0.1.0-SNAPSHOT"] ;; JEAH! + [orchestra "2017.11.12-1"] [cheshire "5.8.0"]] :java-source-paths ["src/java"] :main ^:skip-aot skirmish.core diff --git a/resources/config.edn b/resources/config.edn index bf3716d..7ba8069 100644 --- a/resources/config.edn +++ b/resources/config.edn @@ -1,28 +1,37 @@ { - ;; + ;; Specify which middleware to use, it will default to :chan. :middleware :kafka - :kafka ;; all the kafka configuration + + ;; If set to true, orchestra will instrument all the spec'ed functions + :instrument-spec true + + ;; all the kafka configuration goes bellow. + :kafka {:bootstrap.servers #or [#env KAFKA_BOOTSTRAP_SERVERS "localhost:9092"] :topics-prefix "skirmish-01-"} - :api-server ;; possible config from http-kit's run-server that will affect the api-server + ;; possible config from http-kit's run-server that will affect the api-server + :api-server {:port #long #or [#env API_SERVER_PORT 1602] :ip "0.0.0.0" :max-body 524288 ;; 512kb, small but enough :max-ws 524288} - :api-bookkeeper ;; possible config from http-kit's run-server that will affect the api-bookkeeper + ;; possible config from http-kit's run-server that will affect the api-bookkeeper + :api-bookkeeper {:port #long #or [#env API_SERVER_PORT 1603] :ip "0.0.0.0" :max-body 524288 ;; 512kb, small but enough :max-ws 524288} - :securities ;; list of tradable securities + ;; list of tradable securities + :securities [{:sec-id :foo} {:sec-id :bar} {:sec-id :toto} {:sec-id :tata}] + ;; stupid parameters about benchmarking tools :benchmark { :number-of-requests-per-securities 30}} diff --git a/src/skirmish/core.clj b/src/skirmish/core.clj index ef0d680..d9f0889 100644 --- a/src/skirmish/core.clj +++ b/src/skirmish/core.clj @@ -5,6 +5,7 @@ [skirmish.exchange.core] [skirmish.middleware.core :refer [create-exchange-apis-for]] [aero.core :refer (read-config)] + [orchestra.spec.test :as st] [clojure.core.async :as async]) (:gen-class)) @@ -12,17 +13,16 @@ ;; arguments: the config map and the "exchange-api" {:api-server skirmish.rest.core/api-main :exchange-core skirmish.exchange.core/-main ;; should be skirmish.exchange.core/api-main - :api-bookkeeper skirmish.rest.core/bookeeper-main}) + :api-bookkeeper skirmish.rest.core/bookkeeper-main}) ;:benchmark skirmish.cli.benchmark/-main}) (defn run-all-targets-in-separate-threads [target-fns config exchange-apis] (println "running multiple targets. This is okay in dev but horrible in production") (println target-fns) (let [threads (map #(async/thread (% config exchange-apis)) target-fns) - finished-threads (async/merge threads)];; need to lock here + finished-threads (async/merge threads)] (loop [finished-thread (async/ "config.edn" clojure.java.io/resource read-config) xf (comp (map keyword) (map targets) (filter some?)) target-fns (sequence xf argv)] + (if (true? (:instrument-spec config)) + (st/instrument)) (if (seq target-fns) (run-all-targets target-fns config) (do diff --git a/src/skirmish/exchange/exchange.clj b/src/skirmish/exchange/exchange.clj index 464fe01..5b692bc 100644 --- a/src/skirmish/exchange/exchange.clj +++ b/src/skirmish/exchange/exchange.clj @@ -4,6 +4,7 @@ create-sell-book match-order-in-book]] [skirmish.util :refer :all] + [clojure.spec.alpha :as s] [clojure.core.async :refer [chan go >! expt-book-4))) (facts "get-processed-orders" - (fact "ss" + (fact "bug numero uno" (let [sell-book (create-buy-book {:type :buy :quantity 2 :price 14 :book.order/id 116} {:type :buy :quantity 8 :price 13 :book.order/id 117}) order {:type :sell :quantity 21 :price 13 :book.order/id 118} [trades new-book leftover-order] (match-order-in-book sell-book order) processed-order (get-processed-orders order leftover-order trades sell-book)] - processed-order => seq)));;; + processed-order => seq));;; + (fact "bug numero dos" + (let [order {:type :sell, :quantity 10, :price 2, :book.order/id 1} + leftover-order nil + trades [#:book.order{:type :buy, :quantity 10, :price 3, :order-id 1, :book-id 0}] + book {:sell (create-sell-book) + :buy (create-buy-book {:type :buy, :quantity 15, :price 3, :book.order/id 0})} + ret (get-processed-orders order leftover-order trades (:buy book))] + (count ret) => 3)))