Skip to content

apanevin/simple-exchange-matcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Simple Exchange Matcher

Simple Scala application for processing securities exchanges between clients.

Overview

This application works with two text files: clients and orders. After finishing it creates a result file with all processed clients. You can read about matching strategies in the following section.

Clients file

Clients file has the following fields:

  • Client name
  • Client balance in dollars
  • Security 'A' amount
  • Security 'B' amount
  • Security 'C' amount
  • Security 'D' amount

You can find the example file here.

Orders file

Orders file has the following fields:

  • Client name, who placed this order
  • Operation symbol: 's' for sel, 'b' for buy
  • Security name
  • Order price (for one security)
  • Amount of buying or selling securities

You can find the example file here.

Exchange matchers

There are two possible matcher strategies: simple and partial.

Simple matcher creates an exchange by joining on security amount and price. Partial matcher creates an exchange by joining only on security price and it may take needed amount from different orders.

Necessary strategy can be chosen by overriding exchange.matcher.class property.

Configuring

You can specify list of parameters:

  • file.input.clients.path path to clients file
  • file.input.orders.path path to orders file
  • file.output.clients.name output file name
  • file.delimiter input and output files delimiter
  • exchange.matcher.class full class name, which extends ExchangeMatcher trait and matches clients offers

Default application parameters can be changed by editing properties file or by passing them to JVM while running (e.g. java -Dname=value -jar).

Building

Application uses Maven for compiling, building and testing. You can build it using:

mvn clean package

This command will create jar with all compiled code and jar with code and all necessary dependencies. You can find jars at target/ folder.

Running

Running without overriding parameters:

java -jar ${simple-exchange-matcher-directory}/target/simple-exchange-matcher-<version>-jar-with-dependencies.jar

Running with parameters specified:

java \
-Dfile.output.clients.name=processed_clients_with_simple_strategy.txt \
-Dexchange.matcher.class=com.github.apanevin.matcher.service.SimpleExchangeMatcher \
-jar ${simple-exchange-matcher-directory}/target/simple-exchange-matcher-<version>-jar-with-dependencies.jar

Testing

Scalatest is used for unit testing. You can run test with Maven command:

mvn test

Note, that mvn package also runs all unit tests.