going somewhere
This commit is contained in:
1 parent
9f36d28ce2
commit
519ac9ce07
7 files changed
+114
-46
No files matched your search
@@ -3,7 +3,8 @@
|
||||
(:require [midje.sweet :refer :all]
|
||||
[skirmish.exchange :refer :all]
|
||||
[skirmish.match :refer [create-buy-book
|
||||
create-sell-book]]))
|
||||
create-sell-book
|
||||
match-order-in-book]]))
|
||||
|
||||
(def PersistentSortedList? (comp #(= % skirmish.PersistentSortedList) type))
|
||||
|
||||
@@ -21,7 +22,7 @@
|
||||
(fact "process-sell-order should work when there is a buy order that matches"
|
||||
(let [sell-book (create-sell-book)
|
||||
buy-book (create-buy-book {:type :buy :quantity 10 :price 3 :book.order/id 2})
|
||||
book {:sell sell-book :buy buy-book}
|
||||
book {:sell sell-book :buy buy-book :id 0}
|
||||
order {:type :sell :quantity 4 :price 2 :book.order/id 3}
|
||||
expt-new-buy-book [{:price 3 :quantity 6 :type :buy :book.order/id 2}]
|
||||
expt-new-trades [#:book.order{:book-id 2 :order-id 3 :price 3 :quantity 4 :type :buy}]
|
||||
@@ -44,7 +45,7 @@
|
||||
(fact "process-buy-order should work when there is a buy order that matches"
|
||||
(let [sell-book (create-sell-book {:type :sell :quantity 10 :price 3 :book.order/id 2})
|
||||
buy-book (create-buy-book)
|
||||
book {:sell sell-book :buy buy-book}
|
||||
book {:sell sell-book :buy buy-book :id 0}
|
||||
order {:type :buy :quantity 4 :price 4 :book.order/id 3}
|
||||
expt-new-sell-book [{:price 3 :quantity 6 :type :sell :book.order/id 2}]
|
||||
expt-new-trades [#:book.order{:book-id 2 :order-id 3 :price 3 :quantity 4 :type :sell}]
|
||||
@@ -60,11 +61,22 @@
|
||||
order-3 {:type :sell :quantity 17 :price 99 :book.order/id 9}
|
||||
order-4 {:type :sell :quantity 1 :price 102 :book.order/id 10}
|
||||
expt-book-4 {:buy [{:price 99 :quantity 8 :type :buy :book.order/id 8}]
|
||||
:sell [{:price 102 :quantity 1 :type :sell :book.order/id 10}]}
|
||||
:sell [{:price 102 :quantity 1 :type :sell :book.order/id 10}]
|
||||
:id 4}
|
||||
[book-1 _ _] (process-order book order-1)
|
||||
[book-2 _ _] (process-order book-1 order-2)
|
||||
[book-3 _ _] (process-order book-2 order-3)
|
||||
[book-4 _ _] (process-order book-3 order-4)]
|
||||
book-4 => expt-book-4)))
|
||||
|
||||
(facts "get-processed-orders"
|
||||
(fact "ss"
|
||||
(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)));;;
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user