denarius-exchange / denarius

An open-source financial exchange
Other
35 stars 5 forks source link

Add persistence storage (confirmed trades) #18

Closed analyticbastard closed 10 years ago

analyticbastard commented 10 years ago

Add the modules for database connectivity, regarding trades.

Available modules nildb : This database does not do anything mockdb: This database stores trades in memory

Interface Database modules must support the following interface init [opt] Database initialization with options passed from configuration insert [this broker-id-1 order-id-1 broker-id-2 order-id-2 size price] Element insertion list [this broker-id] Trade list for a given broker stop [opt] Database stop with options passed from configuration

Additional considerations At this time, no deletion is considered. All trades made in the engine must remain intact.

analyticbastard commented 10 years ago

H2 is a good candidate for a mocking database which can persist test data since it is embedded. This could also persist data in a production system if there is only one connector (in charge of everything, since it hosts the embedded database).

An embedded database is useful for testing since the deployment environment is minimum.

This code can help develop a database bridge for both customer funds data and customer trades:

(let [db-protocol "tcp"            ; "file|mem|tcp"
      db-host     "localhost:9092" ; "path|host:port"
      db-name     "Sample"]

  (def db {:classname   "org.h2.Driver" ; must be in classpath
           :subprotocol "h2"
           :subname (str db-protocol "://" db-host "/" db-name)
           ; Any additional keys are passed to the driver
           ; as driver-specific properties.
           :user     "sa"
           :password ""}))

;
; specify the path to your database driver
; 
(add-classpath "file:///c:/Installation/h2/bin/h2.jar")

;;
;; Here is an example of creating a symbol in the 
;; existing namespace as an alias to a namespace
;;
;(require '[clojure.java.jdbc :as sql]) 
;(sql/with-connection db
;  (sql/with-query-results rs ["select * from customer"]
;    (dorun (map #(println (:lastname %)) rs))))

Other non-embedded databases should be used for a real environment with several connectors in charge of different incoming trades.

analyticbastard commented 10 years ago

Commit 4cee0eb5fdfb8eebec98a770347a30461290ee8e is also related to this issue.

multimethods depending on a reference variable indicating the database to be used. The multimethod dispatch then selects which method to use to connect the database.

analyticbastard commented 10 years ago

Regarding this issue, a reflection mechanism must be used in order to free connector_node.clj from its reference to all possible database access implementors so that each is loaded dynamically depending on the configuration option.

analyticbastard commented 10 years ago

Changed title to reflect that this issue refers to the trades database

analyticbastard commented 10 years ago

This is affected by the changes in #29

analyticbastard commented 10 years ago

I consider the issue closed. The persistence storage is mature enough for the puposes of this issue. If it needs to be updated, a new issue must be opened.