From 1dbae11b21750dc72cf5575aae6021bd6661383c Mon Sep 17 00:00:00 2001 From: didier amyot Date: Sun, 8 Jul 2018 14:12:00 -0400 Subject: [PATCH] woohoo --- README.md | 17 +++++- resources/config.edn | 3 +- src/skirmish/cli/benchmark.clj | 16 +---- src/skirmish/exchange.clj | 108 ++++++++++++++++++--------------- src/skirmish/rest/exchange.clj | 11 ++-- 5 files changed, 83 insertions(+), 72 deletions(-) diff --git a/README.md b/README.md index 7cbefc1..c01b890 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Skrimish -![logo](//gitlab.com/didiercrunch/skirmish/raw/master/doc/logo.svg "Skrimish") +![logo](doc/logo.svg "Skrimish") A stock exchange simulator. The scope of this project is not yet defined but it should allow end user(s?) to exchange securities via the common exchange rules. @@ -9,6 +9,21 @@ allow end user(s?) to exchange securities via the common exchange rules. ## Installation Okay, this should be easy but it is hard... +## Hack me + +### Configuration +All configuration are set in the `resources/config.edn` file. +Configuration uses [aero](https://github.com/juxt/aero). + +### Technologies + +#### Server +* clojure +* kafka + +#### In the browser +* https://aftertheflood.com/projects/sparks/ +* http://metricsgraphicsjs.org/ ## Usage diff --git a/resources/config.edn b/resources/config.edn index e465f16..c2c578c 100644 --- a/resources/config.edn +++ b/resources/config.edn @@ -3,8 +3,6 @@ {:bootstrap.servers "localhost:9092" :topics-prefix "skirmish-01-"} - - :webserver ;; possible config from http-kit's run-server {:port #long #or [#env PORT 8080] :ip "0.0.0.0" @@ -16,6 +14,7 @@ {:sec-id :bar} {:sec-id :toto} {:sec-id :tata}] + :benchmark { :number-of-requests-per-securities 30}} diff --git a/src/skirmish/cli/benchmark.clj b/src/skirmish/cli/benchmark.clj index 5e52996..a948b90 100644 --- a/src/skirmish/cli/benchmark.clj +++ b/src/skirmish/cli/benchmark.clj @@ -16,17 +16,6 @@ (ws/connect url :headers headers :on-receive on-receive))) -(defn create-trades-channel [securities] - (let [output (chan 1 (map edn/read-string)) - url #(format "ws://localhost:%s/api/1/securities/%s/trades" 8080 %) - xf (comp (map :sec-id) - (map name) - (map url) - (map #(web-socket-to-channel % output)))] - (doall (sequence xf securities)) - (async/pub output :book.order/order-id))) - - (defn create-orders-channel [securities] (let [output (chan 1 (map edn/read-string)) url #(format "ws://localhost:%s/api/1/securities/%s/orders" 8080 %) @@ -79,7 +68,7 @@ ret)) -(defn benchmark [requests order trades] +(defn benchmark [requests orders] (let [decoded-responses (chan 1 (map decode-response)) responses (no-more-then-n-simultaneously #(%) (to-chan requests) 10)] (go (async/pipe responses decoded-responses)) @@ -108,9 +97,8 @@ (defn -main [config] (let [benchmark-config (:benchmark config) requests (-> benchmark-config :number-of-requests-per-securities (make-requests (:securities config))) - trades (create-trades-channel (:securities config)) orders (create-orders-channel (:securities config)) - results (benchmark requests orders trades)] + results (benchmark requests orders)] (display-results (async/! ! ! new-book-order-channel new-order)) - (doseq [trade new-trades] (>! trades-channel trade)) ;; TODO: user clojure.core.async/onto-chan - (recur (!! incoming-order-channel order) (build-response request order)) (catch [:error-type :4XX] e (build-response request e)) (catch [:error-type :5XX] e (build-response request e))))) -(defn chan-to-websocket [request chan ws-chan] - (on-close ws-chan (fn [status] (close! chan))) +(defn chan-to-websocket [request input-chan ws-chan] + (on-close ws-chan (fn [status] (close! input-chan))) (go-loop [] - (when-let [e (