refactoring...

This commit is contained in:
didier amyot committed 2018-07-24 18:46:36 -04:00
1 parent f5e8ffd82d
commit 33c1d42e63
20 files changed
+5320 -96

No files matched your search

+5123
View File
File diff suppressed because it is too large. Load diff
+3 -1
View File
@@ -13,6 +13,7 @@
[http-kit "2.3.0"]
[compojure "1.6.1"]
[com.taoensso/nippy "2.14.0"]
[ring-cors "0.1.12"]
[javax.servlet/javax.servlet-api "3.1.0"]
[org.apache.kafka/kafka-streams "1.1.0"]
[org.apache.kafka/kafka-clients "1.1.0"]
@@ -35,6 +36,7 @@
;; cljs
[org.clojure/clojurescript "1.10.339" :scope "provided"]
[cljs-http "0.1.45"]
[secretary "1.2.3"]
[venantius/accountant "0.2.4" :exclusions [org.clojure/tools.reader]]]
@@ -54,7 +56,7 @@
:min-lein-version "2.5.0"
:uberjar-name "skirmish.jar"
:main skirmish.wui.core
:main skirmish.core
:jvm-opts ["--add-modules" "java.xml.bind"]
:clean-targets ^{:protect false}
[:target-path
+4 -4
View File
@@ -29,10 +29,10 @@
;; list of tradable securities
:securities
[{:sec-id :foo}
{:sec-id :bar}
{:sec-id :toto}
{:sec-id :tata}]
[{:sec-id :foo :name "the foo company" :description "Sell names to developer."}
{:sec-id :bar :name "bar international" :description "Steal company."}
{:sec-id :toto :name "La compagnie des toto" :description "Serait trop long pour ecrire ici."}
{:sec-id :tata :name "Unicorn startup" :description "ambition: conquerir le monde!"}]
;; stupid parameters about benchmarking tools
:benchmark {
+29 -29
View File
@@ -1899,7 +1899,7 @@ a.box:active {
.content blockquote {
background-color: #0a0a0a;
border-left: 5px solid #ffdd57;
border-left: 5px solid #dbdbdb;
padding: 1.25em 1.5em; }
.content ol {
@@ -1948,7 +1948,7 @@ a.box:active {
width: 100%; }
.content table td,
.content table th {
border: 1px solid #ffdd57;
border: 1px solid #dbdbdb;
border-width: 0 0 1px;
padding: 0.5em 0.75em;
vertical-align: top; }
@@ -2587,12 +2587,12 @@ a.box:active {
background-color: #eeeeee;
color: #363636; }
.file-label:hover .file-name {
border-color: #ffdb4a; }
border-color: #d5d5d5; }
.file-label:active .file-cta {
background-color: #e8e8e8;
color: #363636; }
.file-label:active .file-name {
border-color: #ffd83d; }
border-color: #cfcfcf; }
.file-input {
height: 0.01em;
@@ -2604,7 +2604,7 @@ a.box:active {
.file-cta,
.file-name {
border-color: #ffdd57;
border-color: #dbdbdb;
border-radius: 4px;
font-size: 1em;
padding-left: 1em;
@@ -2616,7 +2616,7 @@ a.box:active {
color: #4a4a4a; }
.file-name {
border-color: #ffdd57;
border-color: #dbdbdb;
border-style: solid;
border-width: 1px 1px 1px 0;
display: block;
@@ -3023,7 +3023,7 @@ a.box:active {
padding: 0;
width: 100%; }
.progress::-webkit-progress-bar {
background-color: #ffdd57; }
background-color: #dbdbdb; }
.progress::-webkit-progress-value {
background-color: whitesmoke; }
.progress::-moz-progress-bar {
@@ -3203,7 +3203,7 @@ a.box:active {
.table.is-fullwidth {
width: 100%; }
.table.is-hoverable tbody tr:not(.is-selected):hover {
background-color: #fafafa; }
background-color: #242424; }
.table.is-hoverable.is-striped tbody tr:not(.is-selected):hover {
background-color: whitesmoke; }
.table.is-narrow td,
@@ -3534,7 +3534,7 @@ a.tag:hover {
.card-footer {
background-color: none;
border-top: 1px solid #ffdd57;
border-top: 1px solid #dbdbdb;
align-items: stretch;
display: flex; }
@@ -3547,7 +3547,7 @@ a.tag:hover {
justify-content: center;
padding: 0.75rem; }
.card-footer-item:not(:last-child) {
border-right: 1px solid #ffdd57; }
border-right: 1px solid #dbdbdb; }
.card .media:not(:last-child) {
margin-bottom: 0.75rem; }
@@ -3602,7 +3602,7 @@ a.dropdown-item {
color: #fff; }
.dropdown-divider {
background-color: #ffdd57;
background-color: #dbdbdb;
border: none;
display: block;
height: 1px;
@@ -3686,7 +3686,7 @@ a.dropdown-item {
.media .content:not(:last-child) {
margin-bottom: 0.75rem; }
.media .media {
border-top: 1px solid rgba(255, 221, 87, 0.5);
border-top: 1px solid rgba(219, 219, 219, 0.5);
display: flex;
padding-top: 0.75rem; }
.media .media .content:not(:last-child),
@@ -3697,7 +3697,7 @@ a.dropdown-item {
.media .media .media + .media {
margin-top: 0.5rem; }
.media + .media {
border-top: 1px solid rgba(255, 221, 87, 0.5);
border-top: 1px solid rgba(219, 219, 219, 0.5);
margin-top: 1rem;
padding-top: 1rem; }
.media.is-large + .media {
@@ -3745,7 +3745,7 @@ a.dropdown-item {
background-color: #00d1b2;
color: #fff; }
.menu-list li ul {
border-left: 1px solid #ffdd57;
border-left: 1px solid #dbdbdb;
margin: 0.75em;
padding-left: 0.75em; }
@@ -3876,7 +3876,7 @@ a.dropdown-item {
border-top-right-radius: 0; }
.message-body {
border-color: #ffdd57;
border-color: #dbdbdb;
border-radius: 4px;
border-style: solid;
border-width: 0 0 0 4px;
@@ -3940,7 +3940,7 @@ a.dropdown-item {
position: relative; }
.modal-card-head {
border-bottom: 1px solid #ffdd57;
border-bottom: 1px solid #dbdbdb;
border-top-left-radius: 6px;
border-top-right-radius: 6px; }
@@ -3954,7 +3954,7 @@ a.dropdown-item {
.modal-card-foot {
border-bottom-left-radius: 6px;
border-bottom-right-radius: 6px;
border-top: 1px solid #ffdd57; }
border-top: 1px solid #dbdbdb; }
.modal-card-foot .button:not(:last-child) {
margin-right: 10px; }
@@ -4582,7 +4582,7 @@ a.navbar-item,
.navbar-item.has-dropdown-up .navbar-link::after {
transform: rotate(135deg) translate(0.25em, -0.25em); }
.navbar-item.has-dropdown-up .navbar-dropdown {
border-bottom: 2px solid #ffdd57;
border-bottom: 2px solid #dbdbdb;
border-radius: 6px 6px 0 0;
border-top: none;
bottom: 100%;
@@ -4607,7 +4607,7 @@ a.navbar-item,
background-color: white;
border-bottom-left-radius: 6px;
border-bottom-right-radius: 6px;
border-top: 2px solid #ffdd57;
border-top: 2px solid #dbdbdb;
box-shadow: 0 8px 8px rgba(10, 10, 10, 0.1);
display: none;
font-size: 0.875rem;
@@ -4808,13 +4808,13 @@ a.navbar-item,
.panel-heading,
.panel-tabs,
.panel-block {
border-bottom: 1px solid #ffdd57;
border-left: 1px solid #ffdd57;
border-right: 1px solid #ffdd57; }
border-bottom: 1px solid #dbdbdb;
border-left: 1px solid #dbdbdb;
border-right: 1px solid #dbdbdb; }
.panel-heading:first-child,
.panel-tabs:first-child,
.panel-block:first-child {
border-top: 1px solid #ffdd57; }
border-top: 1px solid #dbdbdb; }
.panel-heading {
background-color: #0a0a0a;
@@ -4831,7 +4831,7 @@ a.navbar-item,
font-size: 0.875em;
justify-content: center; }
.panel-tabs a {
border-bottom: 1px solid #ffdd57;
border-bottom: 1px solid #dbdbdb;
margin-bottom: -1px;
padding: 0.5em; }
.panel-tabs a.is-active {
@@ -4895,7 +4895,7 @@ label.panel-block {
white-space: nowrap; }
.tabs a {
align-items: center;
border-bottom-color: #ffdd57;
border-bottom-color: #dbdbdb;
border-bottom-style: solid;
border-bottom-width: 1px;
color: whitesmoke;
@@ -4914,7 +4914,7 @@ label.panel-block {
color: #00d1b2; }
.tabs ul {
align-items: center;
border-bottom-color: #ffdd57;
border-bottom-color: #dbdbdb;
border-bottom-style: solid;
border-bottom-width: 1px;
display: flex;
@@ -4944,16 +4944,16 @@ label.panel-block {
border-radius: 4px 4px 0 0; }
.tabs.is-boxed a:hover {
background-color: #0a0a0a;
border-bottom-color: #ffdd57; }
border-bottom-color: #dbdbdb; }
.tabs.is-boxed li.is-active a {
background-color: white;
border-color: #ffdd57;
border-color: #dbdbdb;
border-bottom-color: transparent !important; }
.tabs.is-fullwidth li {
flex-grow: 1;
flex-shrink: 0; }
.tabs.is-toggle a {
border-color: #ffdd57;
border-color: #dbdbdb;
border-style: solid;
border-width: 1px;
margin-bottom: 0;
@@ -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]
(let [books (map-values #(create-book %) 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))))))
(build-response request @(get books sec-id)))))
(defn create-routes-for-bookkeeper [exchange-apis]
(let [get-book (get-books exchange-apis)]
(defn create-routes-for-bookkeeper [exchange-apis config]
(let [books (map-values #(create-book %) 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"))))
+17
View File
@@ -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)))
+4
View File
@@ -0,0 +1,4 @@
(ns skirmish.broker.core)
(defn -main [config exchange-apis])
+4 -3
View File
@@ -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,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]]
-23
View File
@@ -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)))
+1 -1
View File
@@ -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]
+39
View File
@@ -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 page [state]
(let [securities [{:sec-id :foo} {:sec-id :bar} {:sec-id :toto}]]
(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))]]))
(for [sec securities] (create-row sec))]])
(defn security-table []
(let [securities (atom [])]
(get-securities securities)
#(create-security-table @securities)))
(defn page [state]
(security-table))
+18 -17
View File
@@ -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 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 "display all the available securities"]
[:li "display the book for selected securities"]]]]]
[:li "Exchange"
[: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 done "make an exchange that kind of work"]
[:li "spec the exchange"]]]
[:li "Book keeper"
[:ul
[:li "Find a place to store information about securities"]]]
[:li "Brooker"
[:ul
[:li "Write a small broker"]]]]])
+10
View File
@@ -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)})))
+6
View File
@@ -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
View File
@@ -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";