added proper configuration using aero
This commit is contained in:
1 parent
c823775c0c
commit
d2c554dcc8
8 files changed
+43
-14
No files matched your search
@@ -6,6 +6,7 @@
|
||||
:dependencies [[org.clojure/clojure "1.9.0"]
|
||||
[org.clojure/core.async "0.4.474"]
|
||||
;; web
|
||||
[aero "1.1.3"]
|
||||
[http-kit "2.3.0"]
|
||||
[compojure "1.6.1"]
|
||||
[javax.servlet/javax.servlet-api "3.1.0"]
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
:webserver ;; possible config from http-kit's run-server
|
||||
{:port #long #or [#env PORT 8080]
|
||||
:ip "0.0.0.0"
|
||||
:max-body 524288 ;; 512kb, small but enough
|
||||
:max-ws 524288}
|
||||
|
||||
:securities ;; list of tradable securities
|
||||
[{:sec-id :foo}
|
||||
{:sec-id :bar}
|
||||
{:sec-id :toto}
|
||||
{:sec-id :tata}]}
|
||||
@@ -0,0 +1 @@
|
||||
(ns book.cli.core)
|
||||
@@ -1,4 +1,4 @@
|
||||
(ns book.cli
|
||||
(ns book.cli.exchange
|
||||
(:require [book.match :refer [sell?]]
|
||||
[book.util :refer :all]
|
||||
[book.exchange :refer [empty-book create-exchange-for-security]]
|
||||
+11
-6
@@ -1,10 +1,15 @@
|
||||
(ns book.core
|
||||
(:require [book.cli]
|
||||
[book.web])
|
||||
(:require [book.cli.core]
|
||||
[book.rest.core]
|
||||
[aero.core :refer (read-config)])
|
||||
(:gen-class))
|
||||
|
||||
(def apps {:webserver book.rest.core/-main})
|
||||
|
||||
(defn -main [& argv]
|
||||
(case (first argv)
|
||||
"web" (apply book.web/-main (rest argv))
|
||||
"cli" (apply book.cli/-main (rest argv))
|
||||
(println "First argument must be web or cli")))
|
||||
(let [config (-> "config.edn" clojure.java.io/resource read-config)
|
||||
target (-> argv first keyword)
|
||||
target-fn (get apps target)]
|
||||
(if target-fn
|
||||
(apply target-fn [config])
|
||||
(println "target" target "not found"))))
|
||||
@@ -0,0 +1,11 @@
|
||||
(ns book.rest.core
|
||||
(:require [org.httpkit.server :refer [run-server]]
|
||||
[compojure.handler :refer [api]]
|
||||
[book.rest.exchange :refer [create-exchanges-api-for
|
||||
create-routes]]))
|
||||
|
||||
(defn -main [config]
|
||||
(let [webserver-config (:webserver config)
|
||||
exchange-apis (create-exchanges-api-for (:securities config))
|
||||
api-routes (create-routes exchange-apis)]
|
||||
(run-server (api api-routes) webserver-config)))
|
||||
@@ -1,4 +1,4 @@
|
||||
(ns book.web
|
||||
(ns book.rest.exchange
|
||||
(:require [book.exchange :refer [empty-book]]
|
||||
[org.httpkit.server :refer [run-server with-channel send! close on-close]]
|
||||
[compojure.route :refer [not-found]]
|
||||
@@ -39,6 +39,10 @@
|
||||
:trades-publisher trades-publisher
|
||||
:new-book-order-publisher new-book-order-publisher}))
|
||||
|
||||
(defn create-exchanges-api-for [security-definitions]
|
||||
(let [f (fn [sec] [(:sec-id sec) (create-exchange-api-for (:sec-id sec))])]
|
||||
(into {} (map f security-definitions))))
|
||||
|
||||
|
||||
(defn get-new-order-channel [exchange-apis sec-id]
|
||||
(let [exchange (get exchange-apis sec-id)
|
||||
@@ -135,9 +139,3 @@
|
||||
(GET "/securities/:sec-id/trades" [] (listen-to-trades exchange-apis))
|
||||
(GET "/securities/:sec-id/orders" [] (listen-to-orders exchange-apis)))
|
||||
(not-found "not found")))
|
||||
|
||||
|
||||
(defn -main [& args]
|
||||
(let [exchange-apis {:foo (create-exchange-api-for :foo) :bar (create-exchange-api-for :bar)}
|
||||
api-routes (create-routes exchange-apis)]
|
||||
(run-server (api api-routes) {:port 8080})))
|
||||
@@ -0,0 +1 @@
|
||||
(ns book.rest.marketdata)
|
||||
Reference in new issue
Block a user