refactoring...
This commit is contained in:
1 parent
f5e8ffd82d
commit
33c1d42e63
20 files changed
+5325
-101
No files matched your search
@@ -1,4 +1,4 @@
|
||||
(ns skirmish.rest.bookkeeper
|
||||
(ns skirmish.bookkeeper.bookkeeper
|
||||
(:require [skirmish.exchange.exchange :refer [empty-book create-exchange-for-security]]
|
||||
[org.httpkit.server :refer [run-server with-channel send! close on-close]]
|
||||
[compojure.route :refer [not-found]]
|
||||
@@ -14,10 +14,14 @@
|
||||
|
||||
(def order-id (atom -1))
|
||||
|
||||
(defn endpoint [name description path]
|
||||
{:name name :description description :url path})
|
||||
|
||||
(def endpoints [(endpoint "securities" "list all securities." "/api/1/securities")])
|
||||
|
||||
|
||||
(defn api-description [req]
|
||||
(let [body {"/api/1/securities" "list all securities."
|
||||
"/api/1/book" "For all information about the book."}]
|
||||
(let [body endpoints]
|
||||
(build-response req body)))
|
||||
|
||||
(defn subscribe-to-orders-publisher [exchange-api status-to-listen-on]
|
||||
@@ -42,9 +46,9 @@
|
||||
ret))
|
||||
|
||||
|
||||
(defn securities [exchange-apis]
|
||||
(defn securities [exchange-apis config]
|
||||
(fn [request]
|
||||
(build-response request {:securities (keys exchange-apis)})))
|
||||
(build-response request {:securities (:securities config)})))
|
||||
|
||||
|
||||
(defn get-security [exchange-apis]
|
||||
@@ -98,21 +102,20 @@
|
||||
(defn map-values [f m]
|
||||
(into {} (for [[k v] m] [k (f v)])))
|
||||
|
||||
(defn get-books [exchange-apis]
|
||||
(defn get-books [exchange-apis books]
|
||||
(fn [{{sec-id-str :sec-id} :route-params body :body :as request}]
|
||||
(let [sec-id (keyword sec-id-str)]
|
||||
(build-response request @(get books sec-id)))))
|
||||
|
||||
|
||||
(defn create-routes-for-bookkeeper [exchange-apis config]
|
||||
(let [books (map-values #(create-book %) exchange-apis)]
|
||||
(fn [{{sec-id-str :sec-id} :route-params body :body :as request}]
|
||||
(let [sec-id (keyword sec-id-str)]
|
||||
(build-response request @(get books sec-id))))))
|
||||
|
||||
|
||||
(defn create-routes-for-bookkeeper [exchange-apis]
|
||||
(let [get-book (get-books exchange-apis)]
|
||||
(routes
|
||||
(context "/api/1" []
|
||||
(GET "/" [] api-description)
|
||||
(GET "/securities" [] (securities exchange-apis))
|
||||
(GET "/securities" [] (securities exchange-apis config))
|
||||
(GET "/securities/:sec-id" [] (get-security exchange-apis))
|
||||
(GET "/securities/:sec-id/trades" [] (listen-to-trades exchange-apis))
|
||||
(GET "/securities/:sec-id/orders" [] (listen-to-orders exchange-apis))
|
||||
(GET "/securities/:sec-id/book" [] get-book))
|
||||
(GET "/securities/:sec-id/book" [] (get-books exchange-apis books)))
|
||||
(not-found "not found"))))
|
||||
@@ -0,0 +1,17 @@
|
||||
(ns skirmish.bookkeeper.core
|
||||
(:require [org.httpkit.server :refer [run-server]]
|
||||
[compojure.handler :refer [api]]
|
||||
[skirmish.util :refer [block-thread]]
|
||||
[skirmish.middleware.core :refer [create-exchange-apis-for]]
|
||||
[skirmish.bookkeeper.bookkeeper :refer [create-routes-for-bookkeeper]]
|
||||
[ring.middleware.cors :refer [wrap-cors]]))
|
||||
|
||||
(defn -main [config exchange-apis]
|
||||
(let [bookkeeper-config (:api-bookkeeper config)
|
||||
api-routes (create-routes-for-bookkeeper exchange-apis config)]
|
||||
(println "Running server with bellow config")
|
||||
(println bookkeeper-config)
|
||||
(run-server
|
||||
(-> api-routes api (wrap-cors :access-control-allow-origin #"http://localhost:3449"
|
||||
:access-control-allow-methods [:get :put :post :delete]))
|
||||
bookkeeper-config)))
|
||||
@@ -0,0 +1,4 @@
|
||||
(ns skirmish.broker.core)
|
||||
|
||||
|
||||
(defn -main [config exchange-apis])
|
||||
@@ -1,9 +1,10 @@
|
||||
(ns skirmish.core
|
||||
(:require [skirmish.cli.core]
|
||||
[skirmish.rest.core]
|
||||
[skirmish.cli.benchmark]
|
||||
[skirmish.exchange.core]
|
||||
[skirmish.wui.server]
|
||||
[skirmish.bookkeeper.core]
|
||||
[skirmish.exchange-gateway.core]
|
||||
[skirmish.middleware.core :refer [create-exchange-apis-for]]
|
||||
[aero.core :refer (read-config)]
|
||||
[orchestra.spec.test :as st]
|
||||
@@ -12,9 +13,9 @@
|
||||
|
||||
(def targets ;; a target is a function that blocks the thread and takes two
|
||||
;; arguments: the config map and the "exchange-api"
|
||||
{:api-server skirmish.rest.core/api-main
|
||||
{:api-server skirmish.exchange-gateway.core/-main
|
||||
:exchange-core skirmish.exchange.core/-main ;; should be skirmish.exchange.core/api-main
|
||||
:api-bookkeeper skirmish.rest.core/bookkeeper-main
|
||||
:api-bookkeeper skirmish.bookkeeper.core/-main
|
||||
:wui skirmish.wui.server/-main})
|
||||
|
||||
(defn run-all-targets-in-separate-threads [target-fns config exchange-apis]
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
(ns skirmish.exchange-gateway.core
|
||||
(:require [org.httpkit.server :refer [run-server]]
|
||||
[compojure.handler :refer [api]]
|
||||
[skirmish.util :refer [block-thread]]
|
||||
[skirmish.middleware.core :refer [create-exchange-apis-for]]
|
||||
[skirmish.exchange-gateway.exchange-gateway :refer [create-routes-for-exchange]]
|
||||
[ring.middleware.cors :refer [wrap-cors]]))
|
||||
|
||||
|
||||
(defn -main [config exchange-apis]
|
||||
(let [webserver-config (:api-server config)
|
||||
api-routes (create-routes-for-exchange exchange-apis)]
|
||||
(println "Running server with bellow config")
|
||||
(println webserver-config)
|
||||
(run-server (api api-routes) webserver-config)))
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
(ns skirmish.rest.exchange
|
||||
(ns skirmish.exchange-gateway.exchange-gateway
|
||||
(:require [skirmish.exchange.exchange :refer [empty-book create-exchange-for-security]]
|
||||
[org.httpkit.server :refer [run-server with-channel send! close on-close]]
|
||||
[compojure.route :refer [not-found]]
|
||||
@@ -1,23 +0,0 @@
|
||||
(ns skirmish.rest.core
|
||||
(:require [org.httpkit.server :refer [run-server]]
|
||||
[compojure.handler :refer [api]]
|
||||
[skirmish.util :refer [block-thread]]
|
||||
[skirmish.middleware.core :refer [create-exchange-apis-for]]
|
||||
[skirmish.rest.bookkeeper :refer [create-routes-for-bookkeeper]]
|
||||
[skirmish.rest.exchange :refer [create-routes-for-exchange]]))
|
||||
|
||||
|
||||
(defn api-main [config exchange-apis]
|
||||
(let [webserver-config (:api-server config)
|
||||
api-routes (create-routes-for-exchange exchange-apis)]
|
||||
(println "Running server with bellow config")
|
||||
(println webserver-config)
|
||||
(run-server (api api-routes) webserver-config)))
|
||||
|
||||
|
||||
(defn bookkeeper-main [config exchange-apis]
|
||||
(let [webserver-config (:api-bookkeeper config)
|
||||
api-routes (create-routes-for-bookkeeper exchange-apis)]
|
||||
(println "Running server with bellow config")
|
||||
(println webserver-config)
|
||||
(run-server (api api-routes) webserver-config)))
|
||||
@@ -2,7 +2,7 @@
|
||||
(:require [cheshire.core :refer [generate-string]]
|
||||
[clojure.string :refer [split starts-with? ends-with?]]))
|
||||
|
||||
|
||||
;; Access-Control-Allow-Origin
|
||||
|
||||
(def mime-types
|
||||
[["application/json" generate-string]
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
(ns skirmish.strategies.core
|
||||
(:require [clojure.core.async :as async :refer [>! <!]]))
|
||||
|
||||
|
||||
(defn strategy-one [])
|
||||
|
||||
(defprotocol SimpleStrategy
|
||||
"Implement this protocol if you wish to make a strategy"
|
||||
(get-urls-to-fetch [strategy msecs]
|
||||
"returns a list of all the url to fetch.")
|
||||
(get-wished-trades [strategy msec data]
|
||||
""))
|
||||
|
||||
(defrecord TheBananaStrategy [sec-id look-back-in-days period])
|
||||
|
||||
(extend-type TheBananaStrategy
|
||||
SimpleStrategy
|
||||
(get-urls-to-fetch [strat msecs]
|
||||
(let [sec-id (-> strat :sec-id name)
|
||||
one-day (* 24 3600 1000)
|
||||
from (- msecs (-> strat :look-back-in-days (* one-day)))
|
||||
period (:period strat)
|
||||
to msecs]
|
||||
(format "/api/v1/securities/%s/l1?from=%s&to=%s&period=period" sec-id from to period))))
|
||||
|
||||
|
||||
(defn get-data-for-strategy [strategy])
|
||||
|
||||
|
||||
(defn make-trades [wanted-trades])
|
||||
|
||||
|
||||
(defn framework [strategy msecs]
|
||||
(async/go-loop [_ (<! (async/timeout msecs))]
|
||||
(let [data-for-strategy (<! (get-data-for-strategy strategy))
|
||||
wanted-trades (strategy data-for-strategy)
|
||||
results (<! (make-trades wanted-trades))])
|
||||
(recur (<! (async/timeout msecs)))))
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
(ns skirmish.wui.components.create-order-page)
|
||||
|
||||
(defn page []
|
||||
[:h1 "create order page"])
|
||||
@@ -0,0 +1,4 @@
|
||||
(ns skirmish.wui.components.portfolio-page)
|
||||
|
||||
(defn page []
|
||||
[:h1 "portfolio page"])
|
||||
@@ -1,4 +1,8 @@
|
||||
(ns skirmish.wui.components.securities-page)
|
||||
(ns skirmish.wui.components.securities-page
|
||||
(:require [cljs-http.client :as http]
|
||||
[cljs.core.async :refer [<!]]
|
||||
[reagent.core :refer [atom]])
|
||||
(:require-macros [cljs.core.async.macros :refer [go]]))
|
||||
|
||||
(def table-head
|
||||
[:thead.has-background-grey-dark
|
||||
@@ -14,9 +18,21 @@
|
||||
[:td (:name sec)]
|
||||
[:td (:description sec)]]))
|
||||
|
||||
(defn get-securities [securities]
|
||||
(go (let [url "http://localhost:1603/api/1/securities"
|
||||
response (<! (http/get url {:with-credentials? false}))]
|
||||
(reset! securities (get-in response [:body :securities])))))
|
||||
|
||||
(defn create-security-table [securities]
|
||||
[:table.table.is-hoverable.is-fullwidth
|
||||
table-head
|
||||
[:tbody
|
||||
(for [sec securities] (create-row sec))]])
|
||||
|
||||
(defn security-table []
|
||||
(let [securities (atom [])]
|
||||
(get-securities securities)
|
||||
#(create-security-table @securities)))
|
||||
|
||||
(defn page [state]
|
||||
(let [securities [{:sec-id :foo} {:sec-id :bar} {:sec-id :toto}]]
|
||||
[:table.table.is-hoverable.is-fullwidth
|
||||
table-head
|
||||
[:tbody
|
||||
(for [sec securities] (create-row sec))]]))
|
||||
(security-table))
|
||||
@@ -9,24 +9,25 @@
|
||||
(defn page []
|
||||
[:div.content
|
||||
[:ul
|
||||
[:li "shits"
|
||||
[:li "General"
|
||||
[:ul
|
||||
[:li "add a list of bogus securities"]]]
|
||||
[:li "kafka"
|
||||
[:li "write trivial mock strategy framework."]
|
||||
[:li "write mock strategies."]
|
||||
[:li "think of a solution where to store data."]]]
|
||||
[:li "Web user interface"
|
||||
[:ul
|
||||
[:li done "setup kafka"]
|
||||
[:li "try kafka streams"]
|
||||
[:li done "pass every order in kafka"]]]
|
||||
[:li "Logic"
|
||||
[:li done "Add simple pages for every section"]
|
||||
[:li "Securities"
|
||||
[:ul
|
||||
[:li "display all the available securities"]
|
||||
[:li "display the book for selected securities"]]]]]
|
||||
[:li "Exchange"
|
||||
[:ul
|
||||
[:li done "les orders doivent inclurent les bornes"]
|
||||
[:li done "simplifier le spec des ordres en enlevant " [:code ":order/"]]
|
||||
[:li "finish insertion logic and test with spec"]
|
||||
[:li "link insertion logic to application"]]]
|
||||
[:li "User interface"
|
||||
[:li done "make an exchange that kind of work"]
|
||||
[:li "spec the exchange"]]]
|
||||
[:li "Book keeper"
|
||||
[:ul
|
||||
[:li "Add logo"]
|
||||
[:li "Faire un ui pour sell limit order"]
|
||||
[:li "Faire un ui pour buy limit order"]
|
||||
[:li "Faire un ui pour sell market order"]
|
||||
[:li "Faire un ui pour buy market order"]]]]])
|
||||
[:li "Find a place to store information about securities"]]]
|
||||
[:li "Brooker"
|
||||
[:ul
|
||||
[:li "Write a small broker"]]]]])
|
||||
@@ -30,6 +30,16 @@
|
||||
(session/put! :current-page #'pages/securities-page)
|
||||
(swap! state #(into % {:page :securities})))
|
||||
|
||||
(secretary/defroute "/portfolio" []
|
||||
(session/put! :current-page #'pages/portfolio-page)
|
||||
(swap! state #(into % {:page :portfolio})))
|
||||
|
||||
(secretary/defroute "/create-order" []
|
||||
(session/put! :current-page #'pages/create-order-page)
|
||||
(swap! state #(into % {:page :create-order})))
|
||||
|
||||
|
||||
|
||||
(secretary/defroute "/securities/:sec-id" [sec-id]
|
||||
(session/put! :current-page #'pages/security-page)
|
||||
(swap! state #(into % {:page :securities :sec-id (keyword sec-id)})))
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
(ns skirmish.wui.pages
|
||||
(:require [skirmish.wui.components.todo-page]
|
||||
[skirmish.wui.components.home-page]
|
||||
[skirmish.wui.components.portfolio-page]
|
||||
[skirmish.wui.components.create-order-page]
|
||||
[skirmish.wui.components.securities-page]
|
||||
[skirmish.wui.components.security-page]))
|
||||
|
||||
@@ -10,4 +12,8 @@
|
||||
|
||||
(def securities-page skirmish.wui.components.securities-page/page)
|
||||
|
||||
(def create-order-page skirmish.wui.components.create-order-page/page)
|
||||
|
||||
(def portfolio-page skirmish.wui.components.portfolio-page/page)
|
||||
|
||||
(def security-page skirmish.wui.components.security-page/page)
|
||||
+1
-1
@@ -15,7 +15,7 @@ $link: $turquoise;
|
||||
|
||||
$table-background-color: $grey-dark;
|
||||
$table-cell-heading-color: $grey-darker;
|
||||
$border: $yellow;
|
||||
$table-row-hover-background-color: $black-ter;
|
||||
|
||||
|
||||
@import "../../node_modules/bulma/sass/base/_all";
|
||||
|
||||
Reference in new issue
Block a user